AI Search
Classic Search
 Search Phrase:
 Search Type:
Advanced search options
 Search in Forums:
 Search in date period:

 Sort Search Results by:

AI Assistant
Notifications
Clear all

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

4 Posts
3 Users
1 Reactions
1,712 Views
Posts: 5
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@bottas)
Active Member
Joined: 6 years ago
[#22875]

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);
 Capture

3 Replies
dimalifragis
Posts: 2600
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@dimalifragis)
Famed Member
Joined: 6 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: 3609
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@chris)
Famed Member
Joined: 5 years ago

Hi @bottas,

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


1 Reply
(@bottas)
Joined: 6 years ago

Active Member
Posts: 5
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian

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


Share: