get_user_meta() doesn’t include user email?

get_user_meta retrieves a single meta field or all fields of the user_meta data for the given user. This means that all the values that are stored in user_meta table can be got using get_user_meta. Email is not stored as meta data so you cant get email using get_user_meta. Email is stored with username and password … Read more

Get multiple roles with get_users

Fastforward to WordPress 4.4 – it will support the role__in attribute! It looks like WordPress 4.4 is our lucky version number, because it will support both the role__in and role__not_in attributes of the WP_User_Query class. So to include the subscriber, contributor and author roles, we can simply use: $users = get_users( [ ‘role__in’ => [ … Read more

Display user registration date

get_current_user_id() give you the user id of the logged in user. And that is: you. You have to get all users: <?php $users = get_users(); foreach( $users as $user ) { $udata = get_userdata( $user->ID ); $registered = $udata->user_registered; printf( ‘%s member since %s<br>’, $udata->data->display_name, date( “M Y”, strtotime( $registered ) ) ); }

How to get WordPress Username in Array format

The other answers are correct, but it’s possible to achive the same thing with less code using wp_list_pluck(): $users = get_users(); $user_names = wp_list_pluck( $users, ‘display_name’ ); wp_list_pluck() used that way will get the display_name field of all the users in an array without needing to do a loop.

Make WooCommerce pages accessible for logged in users only

Put this in your functions.php file: function wpse_131562_redirect() { if ( ! is_user_logged_in() && (is_woocommerce() || is_cart() || is_checkout()) ) { // feel free to customize the following line to suit your needs wp_redirect(home_url()); exit; } } add_action(‘template_redirect’, ‘wpse_131562_redirect’); What does it do? We check if a not-logged-in user wants to see a WooCommerce page, … Read more

Make display name unique

As far as I’m aware, all you can do is filter the display name via pre_user_display_name and check if it already exists. Unfortunately WP_User_Query doesn’t support querying by display_name, so we also have to add to the WHERE clause via pre_user_query. Additionally, there is no elegant way I can think of to handle the case … Read more

Difference between update_user_meta and update_user_option

In layman terms there is no major difference! update_user_option() uses update_user_meta() internally. The only difference is update_user_option() prefix the option name with database table prefix + blog ID if you are in multisite and just table prefix if you are in single site installation. Take a look at the code of update_user_option() /** * Update … Read more

Remove Ability for Other Users to View Administrator in User List?

Hi @Carlos: Try adding the following to your theme’s functions.php file, or in a .php file within a plugin that you might be writing (which works for WordPress 3.1.x): add_action(‘pre_user_query’,’yoursite_pre_user_query’); function yoursite_pre_user_query($user_search) { $user = wp_get_current_user(); if ($user->ID!=1) { // Is not administrator, remove administrator global $wpdb; $user_search->query_where = str_replace(‘WHERE 1=1’, “WHERE 1=1 AND {$wpdb->users}.ID<>1”,$user_search->query_where); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)