Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Add a badge for admins and customer service reps 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_eer_review_admin_badges( $author_html, $author, $comment_id ) {
- $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( 'shopp-csr', $roles ) ) {
- // Set the badge text for customer service reps.
- $badge_text = 'mod';
- } 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_eer_review_admin_badges', 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement