Archived topic
Help with functions code not working in GP
3 replies · Started by Ian on June 13, 2020
This may or may not be related to GP but I used to run this code in the previous theme and it worked. It's a script inside fucntions.php to show ad "Admin" label for authors of the blog post within Wordpress comments. Since launching 2 sites in GP, I cannot even get Wordpress to accept this inside functions.php. Check another old site not using GP and it still works. Maybe someone who has more expertise in this area can guide me through this? When I try to add this inside WP Editor for functions.php, I get this error: "syntax error, unexpected '}', expecting end of file"
// Get comment author role
function wpb_get_comment_author_role($author, $comment_id, $comment) {
$authoremail = get_comment_author_email( $comment);
// Check if user is registered
if (email_exists($authoremail)) {
$commet_user_role = get_user_by( 'email', $authoremail );
$comment_user_role = $commet_user_role->roles[0];
// HTML output to add next to comment author name
// $this->comment_user_role = ' <span class="comment-author-label comment-author-label-'.$comment_user_role.'">' . ucfirst($comment_user_role) . '</span>';
$this->comment_user_role = ' <span class="comment-author-label comment-author-label-'.$comment_user_role.'">admin</span>';
} else {
$this->comment_user_role = '';
}
return $author;
}
// Display comment author
function wpb_comment_author_role($author) {
return $author .= $this->comment_user_role;
}
}
new WPB_Comment_Author_Role_Label;
endif;
Hi there,
I'm not sure what this code does unfortunately.
Does it work in a twenty series default WP theme?
Let me know :)
Hey Leo,
I see where you are heading with this. Your comment pointed me to spin up a staging site and swapping the theme. Turns out, Wordpress Editor does not allow this php function to be inserted. I SFTP'ed in and made adjustments there and the code stuck.
For the record, this bit of code adds a label (ie. administrator, author, subscriber etc..) beside the commenter's name.
Thank you!
No problem :)