Notifications
Clear all

[Solved] Notice: Trying to get property 'roles' of non-object ERROR

4 Posts
3 Users
1 Reactions
900 Views
Posts: 5
Topic starter
(@bottas)
Active Member
Joined: 5 years ago

Since the new update came out (WpForo 2), logged in users, except the admin, are presented with a really annoying banner on top of my website showing this error message: "Notice: Trying to get property 'roles' of non-object in /var/www/vhosts/mydomain.com/httpdocs/wp-content/plugins/wpforo/includes/hooks.php on line 22"

I already tried many things, I was able to temporarily fix it by changing this lines of code (22-27) in the hooks.php file. I copied this code from a really old post that I found in your support forum. But as I said this just temporary, every new update I need to manually change the code. Is there a way you can help me?

ORIGINAL PIECE OF CODE:

add_action( 'show_admin_bar', function( $show_admin_bar ) {
	if( ! is_super_admin() && is_user_logged_in() && ! array_intersect( [ 'editor', 'administrator', 'author', ], (array) WPF()->wp_current_user->roles ) ) {
		$show_admin_bar = (bool) array_intersect( WPF()->current_user_groupids, wpforo_setting( 'general', 'admin_bar' ) );
	}
	return $show_admin_bar;
});



HOW I CHANGED IT: 

function my_admin_bar_control_function() {
    if (current_user_can('administrator') || current_user_can('editor') || current_user_can('author') ) {
        show_admin_bar(true);
    } else {
        show_admin_bar(false);
    }
}
add_action('init', 'my_admin_bar_control_function', 20);
3 Replies
dimalifragis
Posts: 2611
(@dimalifragis)
Famed Member
Joined: 5 years ago

You should DISABLE debug issues to be displayed in the website. Enable them to debug.log.

About your issue, could be some conflict with an other plugin (a plugin that has to do with users).

Chris
Posts: 3627
(@chris)
Famed Member
Joined: 3 years ago

Hi @bottas,

Please update to 2.0.4 and delete all caches. This issue should already be fixed.

1 Reply
(@bottas)
Joined: 5 years ago

Active Member
Posts: 5

@chris Yes after the update everything works amazingly. Thank you very much.