Skip to:
Content
Pages
Categories
Search
Top
Bottom

Help using $bp->displayed_user->id

  • Avatar of wpmubp.org
    wpmubp
    Participant

    @takuya

    Is there any way that I can use $bp->displayed_user->id within a php code?

    I’m using an external plugin, which needs to retrieve user id like this:

    <?php functionname (userid, 'definition') ?>

    and I was trying to use $bp->displayed_user->id to get user id, but I couldn’t. I also tried wp’s the_author_ID but it failed as I can’t use it within the loop.

    <?php echo $bp->displayed_user->id ?>

    This above returns the user ID properly… but it can’t be used within another php code as far as I’ve tried…

    Do you know any other ways to get user ID?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Avatar of Jan M.
    Jan M.
    Participant

    @jotem

    You’ll have to declare $bp as a global variable in your function, so you can access it in your function.

    global $bp;

    echo $bp->displayed_user->id; //Should work fine

    Avatar of wpmubp.org
    wpmubp
    Participant

    @takuya

    thanks, but not sure how to write it properly… Should it be like this?

    <?php<br />
    global $bp;<br />
    echo $bp->displayed_user->id;<br />
    functionname ($bp->displayed_user->id, 'definition')<br />
    ?>

    Avatar of wpmubp.org
    wpmubp
    Participant

    @takuya

    This is the code I’m trying to make it work…

    <?php global $bp;

    echo $bp->displayed_user->id;

    get_cimyFieldValue ($bp->displayed_user->id, 'CURRENT')

    ?>

    It now returns the user ID properly, but it just shows the user ID and not returning the plugin function at all. wondering why the plugin code doesn’t show specific filed data based on the user id given…

    Avatar of Burt Adsit
    Burt Adsit
    Participant

    @burtadsit

    I’m not sure what that function does but perhaps echo get_cimyFieldValue(..) would work? Does it echo the results of what it does?

    Avatar of wpmubp.org
    wpmubp
    Participant

    @takuya

    It’s supposed to return text field data from wp’s profile, but so far it only returns the user id. (even if I add echo before the function)

    Avatar of Vernon Fowler
    Vernon Fowler
    Participant

    @vernonfowler

    Adding `global $bp;` helped me in a basic conditional test. Thanks and I hope this old issue has been resolved.

    Avatar of workinclasshero
    workinclasshero
    Participant

    @workinclasshero

    The problem is you need to store the result in a variable like this:

    $userID = $bp->displayed_user->id;

    I know this is an old thread but it might help someone down the road.

Viewing 7 replies - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.