Skip to:
Content
Pages
Categories
Search
Top
Bottom

bp_init | get displayed user


  • Wojciech
    Participant

    @wojciechr

    Hi,

    befor I updated to V12 I used bp_init hook to set the default profile tab by using BP_DEFAULT_COMPONENT. In my case I set a new default tab only on the users own pages like this:

    function set_profile_default_tab() {
    global $bp;
    
        if ( bp_is_user() ) {
    		
    		$current_user = get_current_user_id();
    		$displayed_user = $bp->displayed_user;
    		$displayed_user_id = $displayed_user->id;
     
    		if ($current_user == $displayed_user_id) {
    		
    			$default_tab = 'dashboard';
     
    			if ( ! empty( $default_tab ) )  {
    				
    				buddypress()->active_components[ $default_tab ] = 1;
    
    				// Set Default Tab
    				
    				define( 'BP_DEFAULT_COMPONENT', $default_tab );
    				
    
    			}
    
    		}
        }
    }
    
    add_action( 'bp_init', 'set_profile_default_tab', 99 );

    But after update this isn’t working. I’m not able to get the user id of the displayed user.
    Has anyone an idea how to get the user id of the displayed user while using the bp_init hook?

Viewing 1 replies (of 1 total)
  • Hi @wojciechr

    Since BuddyPress 12.0.0, we’ve delayed the moment when the displayed user is set to comply with the WP Rewrite API. You now need to wait for bp_parse_query to get it. I advise you to use a later priority than default one (eg: 20).

    The other option is to download and activate the BP Classic plugin. It will bring backward compatibility with your code.

    My advice is to prefer 1st option 😅

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar