An object in PHP is a data type that you can read more data types here
It’s good practice to check variable types before using them. In your case, you are assuming $user_meta
is an object. Since you are filtering the_content()
, it might be called some place else and returning that error.
Here is your code updated with is_object()
to check on that variable before you use it:
function Milyin_After_Content($content) {
if( is_single() ):
ob_start();
$user_meta=get_userdata(get_the_author_meta('ID'));
// NOTE:
// First check
if(is_object($user_meta)){
// Then set your variable here
$user_role=$user_meta->roles;
if (in_array("administrator", $user_role) || in_array("um_verified", $user_role)){
echo '<svg height="12pt" viewBox="0 0 512 512" width="12pt" xmlns="http://www.w3.org/2000/svg"><path d="m256 0c-141.164062 0-256 114.835938-256 256s114.835938 256 256 256 256-114.835938 256-256-114.835938-256-256-256zm0 0" fill="#1f1fff"/><path d="m385.75 201.75-138.667969 138.664062c-4.160156 4.160157-9.621093 6.253907-15.082031 6.253907s-10.921875-2.09375-15.082031-6.253907l-69.332031-69.332031c-8.34375-8.339843-8.34375-21.824219 0-30.164062 8.339843-8.34375 21.820312-8.34375 30.164062 0l54.25 54.25 123.585938-123.582031c8.339843-8.34375 21.820312-8.34375 30.164062 0 8.339844 8.339843 8.339844 21.820312 0 30.164062zm0 0" fill="#fff"/></svg>';
}
$code_content_2 = ob_get_clean();
$content .= $code_content_2;
}
endif;
return $content;
}
add_filter('the_content', 'Milyin_After_Content_2', 10);
(Also note @WebElaine’s comment above, you should be using two pipes in that if() statement.)
Hope that helps!