Skip to content

Instantly share code, notes, and snippets.

@fillipetech
Forked from bekarice/edd-review-admin-badge.php
Created February 28, 2019 06:33
Show Gist options
  • Save fillipetech/ca4bc47b6f1ee06cb63560f0ca31dac7 to your computer and use it in GitHub Desktop.
Save fillipetech/ca4bc47b6f1ee06cb63560f0ca31dac7 to your computer and use it in GitHub Desktop.
Adds badges to EDD reviews / review comments for admins & vendors
/**
* Add a badge for admins and vendors to product reviews / review comments.
*
* @param string $author_html displays comment author's name linked to comment author's site
* @param string $author comment author's display name
* @param int $comment_id comment ID
* @return string $author_html updated author html preceded by badge.
*/
function sww_edd_review_admin_badges( $author_html, $author, $comment_id ) {
if ( is_admin() || ! is_singular( 'download' ) ) {
return $author_html;
}
$user_id = get_comment( $comment_id )->user_id;
if ( $user_id ) {
$roles = get_userdata( $user_id )->roles;
if ( in_array( 'administrator', $roles ) ) {
// Set the badge text to display for administrators.
$badge_text = 'admin';
} elseif( in_array( 'frontend_vendor', $roles ) ) {
// Set the badge text for shop vendors
$badge_text = 'vendor';
} else {
return $author_html;
}
// Adjust the badge CSS as desired here
$style = 'display: inline-block; background: #666; color: #fff; padding: 3px 5px; border-radius: 3px; margin-right: 5px;';
$author_html = '<div class="review-badge" style="' . $style . '">' . $badge_text . '</div>' . $author_html;
}
return $author_html;
}
add_filter( 'get_comment_author_link', 'sww_edd_review_admin_badges', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment