PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

Can't Use Wordpress Function

s2Member Plugin. A Membership plugin for WordPress®.

Can't Use Wordpress Function

Postby KirkWard » October 26th, 2010, 1:44 pm

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.
User avatar
KirkWard
Experienced User
Experienced User
 
Posts: 61
Joined: October 22, 2010

Re: Can't Use Wordpress Function

Postby arwyl » October 26th, 2010, 6:33 pm

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.)
In theory, theory and practice are the same; in practice they aren't.
User avatar
arwyl
Experienced User
Experienced User
 
Posts: 6
Joined: October 26, 2010

Re: Can't Use Wordpress Function

Postby KirkWard » October 26th, 2010, 7:05 pm

I don't quite understand what is happening or how to use it. Can you explain further?
User avatar
KirkWard
Experienced User
Experienced User
 
Posts: 61
Joined: October 22, 2010

Re: Can't Use Wordpress Function

Postby Dr Dave » October 26th, 2010, 8:24 pm

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
User avatar
Dr Dave
Experienced User
Experienced User
 
Posts: 16
Joined: July 8, 2010

Re: Can't Use Wordpress Function

Postby KirkWard » October 26th, 2010, 8:50 pm

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.
User avatar
KirkWard
Experienced User
Experienced User
 
Posts: 61
Joined: October 22, 2010

Re: Can't Use Wordpress Function

Postby Dr Dave » October 26th, 2010, 11:49 pm

Very good! Glad you got it working.
User avatar
Dr Dave
Experienced User
Experienced User
 
Posts: 16
Joined: July 8, 2010

Re: Can't Use Wordpress Function

Postby Jason Caldwell » October 27th, 2010, 2:22 am

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
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA


Return to s2Member Plugin

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron