Latest Product Reviews Dashboard Widget
Shows the five newest product reviews with star rating, product and approval status on the dashboard, so you can answer or approve them quickly.
Opens WPIDE on
Code
add_action( 'wp_dashboard_setup', function () {
if ( ! current_user_can( 'moderate_comments' ) ) {
return;
}
wp_add_dashboard_widget( 'wpide_latest_reviews', 'Latest product reviews', function () {
$reviews = get_comments( array(
'post_type' => 'product',
'type' => 'review',
'status' => 'all',
'number' => 5,
) );
if ( ! $reviews ) {
echo '<p>' . esc_html( 'No reviews yet.' ) . '</p>';
return;
}
echo '<ul>';
foreach ( $reviews as $review ) {
$rating = (int) get_comment_meta( $review->comment_ID, 'rating', true );
printf(
'<li style="margin-bottom:10px"><span aria-label="%1$s" style="color:#dba617">%2$s</span> <a href="%3$s">%4$s</a>%5$s<br><em>%6$s</em> – %7$s</li>',
esc_attr( sprintf( 'Rated %d out of 5', $rating ) ),
esc_html( str_repeat( '★', $rating ) . str_repeat( '☆', 5 - $rating ) ),
esc_url( get_edit_post_link( $review->comment_post_ID ) ),
esc_html( get_the_title( $review->comment_post_ID ) ),
'0' === $review->comment_approved ? ' <strong style="color:#d63638">' . esc_html( '(pending)' ) . '</strong>' : '',
esc_html( wp_trim_words( $review->comment_content, 18 ) ),
esc_html( $review->comment_author )
);
}
echo '</ul>';
} );
} );
Notes
Pending reviews are marked so you can moderate them from Products > Reviews.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.