What’s the variable $user_info
in you code? Probably you mean $commentator_info
? If yes, this is certainly the error. You are trying to extract wp_capabilities
(?) from a non-initialized variable ($user_info
).
Try this:
<?php
$comment_id = get_comment_ID();
$comment_data = get_comment($comment_id);
$commentator_id = $comment_data->user_id;
$commentator_info = get_userdata($commentator_id); // get_userdata, with the user ID specified, returns a WP_User object.
if ( user_can($commentator_info, 'editor') ) { // user_can accept the user ID or the whole user object ($commentator_info).
// echo markup here
}
Changes: added $comment_id
and $comment_data
variables (now it’s more readable), deleted $capabilities
(you don’t need to store the capabilities in a variable, you can check them directly passing the whole user object (or the user ID) and the capability you want to verify to user_can()
. Added user_can()
and removed the array-key check.