Warning: Creating default object from empty value in capabilities.php on line 655

This is really two questions very related.
I am trying to over-ride the display of buddy press nickname because I think it's confusing for @messages, and the buddy press profile URL also contains the @username so I just want to stop displaying the nickname everywhere. I found a good plugin, but when I activate it, I get the warning error "Warning: Creating default object from empty value in capabilities.php on line 655" on my site. I can turn off warnings but it seems like this indicates a potential issue that is common to many plugins it seems on search.
My question is please, do you know what it is in the Buddypress Usernames Only plugin at http://wordpress.org/plugins/buddypress-usernames-only/ which causes this error for non-logged in users? It goes away when they log in but this is the first thing a potential user sees before logging in.
If it is not easy to remove this bug in the mentioned pug in, does WPMUDev offer any alternative plugin, free or premium, that will give the same function of over-riding the nickname with the username for member lists, menu and buddy press member references?
I will also post on the plugin support, but the problem seemed to affect so many trying to search for it, with few real solutions except suppressing warnings, it would be good to know what's causing it, and if a WPMUDev plugin already provides this I wonder if it's even better.
Thank you for any help or direction!

  • Jack Kitterhing

    Hi there @Aurelio,

    Hope you're well today and thanks for your question.

    We don't currently offer a suitable alternative plugin, I've taken a look at the plugin in question and unfortunately it would take a considerable amount of time to go through the code and it hasn't been updated in a while and isn't technically compatible with the latest version of WordPress or BuddyPress.

    I'll include one of our developers @Hoang Ngo to see if he has any ideas.


    Kind Regards

  • Hoang Ngo

    Hi @Aurelio,

    I hope you are well today.

    Firstly, i think your site a left the WP_DEBUG is true, this is unsafe for live site, so please go to your wp-config.php, find the code look like this
    And change to
    define('WP_DEBUG', false);
    Secondly, the issue is fine, it's because this code in file /plugins/buddypress-usernames-only/bp-usernames-only.php

    function ray_wp_toolbar_title( $wp_admin_bar ) {
    	global $current_user, $bp;
    	$current_user->display_name = ray_bp_username_compatibility( $bp->loggedin_user->userdata );
    add_action( 'admin_bar_menu', 'ray_wp_toolbar_title', 6 );

    From here you can see, the function trying to get the $current_user, but if you not login, so the $current_user is null and when you try to use {null object}->property, php will warning "Creating default object from empty value"

    To fix, please update the code like this

    function ray_wp_toolbar_title( $wp_admin_bar ) {
    	global $current_user, $bp;
    	$current_user->display_name = ray_bp_username_compatibility( $bp->loggedin_user->userdata );
    if ( is_user_logged_in() ) {
    	add_action( 'admin_bar_menu', 'ray_wp_toolbar_title', 6 );

    If you have any issues please don't hesitate to let us know so we can assist

    Best Regards

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.