Skip to:
Content
Pages
Categories
Search
Top
Bottom

Problems with "loggedin_user_id()" in code

  • @vectoholic

    Participant

    Hey Folks,

    i’am writing a little tool to create custom friendlists of the users friends.
    And therefor I need to get the UserID from the user who is creating the list, to create an directory on the server, where the userID´s of the friends in the list are stored! But I can´t get the userId in my code.

    here is my code:

    http://codepad.org/yczLwS4o

    Pls check lines 7 to 11 for the function that gets the UserID and then check line 14 where i call the function!

    Thx for your help

    P.S. I’am working with Buddypress-Version 1.9.2!

Viewing 11 replies - 1 through 11 (of 11 total)
  • @shanebp

    Moderator

    Use WP to get the id: get_current_user_id();

    Or avoid calling the bp global and use bp_loggedin_user_id()

    @vectoholic

    Participant

    First of all..- thx for the fast reply!

    But in both cases…

    bp_loggedin_user_id(); –> CODE

    get_current_user_id(); –> CODE

    I pasted in the code in line 8!

    …I get an “500 Internal Server Error” and don´t know why!!!

    I would really appreciate some help on this one!

    thx

    @henrywright

    Moderator

    I’m not sure what exactly is on line 8 but make sure you use opening and closing PHP tags like this:

    <?php bp_loggedin_user_id(); ?>
    
    <?php get_current_user_id(); ?>

    @vectoholic

    Participant

    Thx for the advice…I already checked it!

    @henrywright

    Moderator

    Sorry, I didn’t see you’d posted the link to your code. I don’t think the 500 Internal Server Error is being caused by your use of those functions. Perhaps the error you’re getting is a result of code elsewhere?

    @vectoholic

    Participant

    but when I put in a string, instead of the bp_loggedin_user_id(); everything works just fine! So I don´t think it’s somewhere else!

    Like here http://codepad.org/1KjIwqLB

    @henrywright

    Moderator

    get_current_user_id() returns an int. Not sure if the type in this case will make much difference but perhaps your function is expecting a string?

    Try doing this:

    $user_id = get_current_user_id();
    $user_id = (string)$user_id;

    Ref: https://codex.wordpress.org/Function_Reference/get_current_user_id

    @vectoholic

    Participant

    I have The Problem that my php-file doesn’t accept any
    WP ore bp functions! Do I have to kind of INIT a php-file before
    I can get access to the WP or BP Core…?

    @henrywright

    Moderator

    To explain what I mean’t, see this example:

    http://codepad.org/kY1hW06z

    @shanebp

    Moderator

    >my php-file doesn’t accept any WP ore bp functions

    Why are you trying to load it outside WP?

    Write your code as a BP plugin.

    Creating a Plugin

    Checking For BuddyPress

    @vectoholic

    Participant

    thx Folks…that was the hint I needed…everythings working fine now…after I changed everything into a plugin!

    Didin´t know about the PLUGIN STUFF, as I’am kind a WP-Neewbe (when it comes to programming)!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Problems with "loggedin_user_id()" in code’ is closed to new replies.
Skip to toolbar