Current user in plugin returns NULL

I am currently developing a plugin and I am trying to make use of the $current_user global. class Something { public function __construct() { $this->get_user(); var_dump( $this->user ); } private function get_user() { require_once( ABSPATH . ‘/wp-includes/pluggable.php’ ); $this->user = wp_get_current_user(); } } This actually works. However, I need to call pluggable.php file which shouldn’t … Read more

How to query users who have empty first_name?

So far I have tried these three options and all 3 of them are not working. Option 1 $options = array( ‘meta_key’ => ‘first_name’, ‘meta_value’ => ”, ‘meta_compare’ => ‘=’, ); $users = get_users( $options ); Option 2 $options = array( ‘meta_key’ => ‘first_name’, ‘meta_value’ => null, ‘meta_compare’ => ‘=’, ); $users = get_users( $options … Read more

trying to list users & display first – last name

For some reason this is not working for me 🙁 $get_members = array( ‘blog_id’ => $GLOBALS[‘blog_id’], ‘role’ => ‘sm_flagar’, ); $blogusers = get_users($get_members); foreach ($blogusers as $user) { echo “<li><a href=\””.$user->user_url.”\”>”. $user->first_name .” “. $user->last_name .”</a></li>”; } 1 Answer 1 first_name and last_name are stored in the usermeta table. Therefore you have to use get_user_meta() … Read more

How to get current user’s phone number

I’m trying that : <?php $phone = get_user_meta($current_user->ID,’phone_number’,true); echo $phone; ?> But it’s not working 5 Answers 5 <?php // number 9 will be user ID $all_meta_for_user = get_user_meta( 9 ); print_r( $all_meta_for_user ); // find the key that you want Array ( [first_name] => Array ( [0] => Tom ) [last_name] => Array ( … Read more

get current user not working

I was trying this code to get current user info, but showing nothing. My WordPress version is 3.3.1 <?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 />’; … Read more