Page 1 of 1

Can't Use Wordpress Function

PostPosted: October 26th, 2010, 1:44 pm
by KirkWard
I was testing the Wordpress function ...
Code: Select all
wp_get_current_user()

and it did not return data from the Wordpress database for the current logged in member.

Why come?

Does s2 block the function?

I used as follows, cut and pasted from the WP function reference ...
Code: Select all
<?php
    wp_get_current_user();
    /**
     * @example Safe usage: $current_user = wp_get_current_user();
     * if ( !($current_user instanceof WP_User) )
     *     return;
     */
    echo 'Username: ' . $current_user->user_login . '<br />';
    echo 'User email: ' . $current_user->user_email . '<br />';
    echo 'User level: ' . $current_user->user_level . '<br />';
    echo 'User first name: ' . $current_user->user_firstname . '<br />';
    echo 'User last name: ' . $current_user->user_lastname . '<br />';
    echo 'User display name: ' . $current_user->display_name . '<br />';
    echo 'User ID: ' . $current_user->ID . '<br />';
?>

I got the text echo, but not the array data.

Re: Can't Use Wordpress Function

PostPosted: October 26th, 2010, 6:33 pm
by arwyl
Well, you haven't really assigned a value to the $current_user variable, so the array is empty.

The second line of your code, right after the php tag, should read:

Code: Select all
$current_user=wp_get_current_user();


(This is exemplified in the commented bit of your code snippet, btw.)

Re: Can't Use Wordpress Function

PostPosted: October 26th, 2010, 7:05 pm
by KirkWard
I don't quite understand what is happening or how to use it. Can you explain further?

Re: Can't Use Wordpress Function

PostPosted: October 26th, 2010, 8:24 pm
by Dr Dave
Kirk,

s2member doesn't block the function, it transforms it. Once set in motion, s2m creates its own set of API Constants you can use to do virtually anything.

Have you looked at the plugin backend? Just go to s2member --> API / Scripting and you'll find all sorts of goodies.

Jason's put a ton of cheats in there.

I'd offer you more, but I'm the type who has to read --> click a mouse --> read more --> type some, and then cross my fingers;-)

Dave

Re: Can't Use Wordpress Function

PostPosted: October 26th, 2010, 8:50 pm
by KirkWard
Got it working ....

Finally dawned on me what arwyl was telling me. This works ...

Code: Select all
  <?php
       $current_user = wp_get_current_user();
        echo 'Username: ' . $current_user->user_login . '<br />';
        echo 'User email: ' . $current_user->user_email . '<br />';
        echo 'User level: ' . $current_user->user_level . '<br />';
        echo 'User first name: ' . $current_user->user_firstname . '<br />';
        echo 'User last name: ' . $current_user->user_lastname . '<br />';
        echo 'User display name: ' . $current_user->display_name . '<br />';
        echo 'User ID: ' . $current_user->ID . '<br />';
    ?>


I am sort of familiar with this function, having experimented with it (but not really used it) before. Was wondering if it worked in the protected area, so I started there.

Re: Can't Use Wordpress Function

PostPosted: October 26th, 2010, 11:49 pm
by Dr Dave
Very good! Glad you got it working.

Re: Can't Use Wordpress Function

PostPosted: October 27th, 2010, 2:22 am
by Jason Caldwell
arwyl wrote:Well, you haven't really assigned a value to the $current_user variable, so the array is empty.
The second line of your code, right after the php tag, should read:
Code: Select all
$current_user=wp_get_current_user();

(This is exemplified in the commented bit of your code snippet, btw.)

User "arwyl", forum rank updated to:
Experienced User