Skip to:

Error using bp_displayed_user_id()

  • had_hc


    Hi, I’m sorry if the question is quite noobish; its because I am. I’m trying to use bp_displayed_user_id() for a code I’m writing. It’s fine when use inside a function, but when using outside of function, i got error “Fatal error: Call to undefined function bp_displayed_user_id()…”. Can anybody explain to me why so?

    to paint a better picture, i’m trying to set different BP profile landing page for different user roles. Here’s the code that i put in bp-custom.php

    global $bp;
    $displayed_user = bp_displayed_user_id();
    $member_id = get_userdata( $displayed_user );
    if ( $member_id->roles[0] == $role ){
    	$default_landing = define('BP_DEFAULT_COMPONENT', 'my-store' );
    } else {
    	$default_landing = define('BP_DEFAULT_COMPONENT', 'following' );

    It’s a bit out of topic, but if I use the above code in a function, can anybody point me to what hook/action to use along the function to be able to fire up the above code?

    Hope I’m making some sort of sense here.

Viewing 1 replies (of 1 total)

  • shanebp


    You are calling bp_displayed_user_id() before it is available.


    function hadhc_loaded() {
       if ( bp_is_user() ) {
        // add your code here and it will only run if on a profile page
    add_action( 'bp_loaded', 'hadhc_landing' );
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar