how to get specific fields from get_user_meta()

The function’s arguments are as follows: user ID, custom field name (meta key), data return method (optional). So if you wanted to grab data in usermeta with the key of ‘member_zip_code’, you would run: get_user_meta( $user_id, ‘member_zip_code’, true ); Alternatively, in your prior method, you could grab the additional data like this: $data = get_user_meta … Read more

How we can get the user id by its display_name

You can use the following function: function get_user_id_by_display_name( $display_name ) { global $wpdb; if ( ! $user = $wpdb->get_row( $wpdb->prepare( “SELECT `ID` FROM $wpdb->users WHERE `display_name` = %s”, $display_name ) ) ) return false; return $user->ID; } This is the same code get_user_by() uses, but since that function only allows ID, slug, email or login … Read more

Add a button to users.php

Okay.. you COULD add a button like you mentioned; but I think this is going to require a lot more code. The users.php page is using the WP List Table class.. which means we can hook into the bulk actions and add our custom value there. So, let’s create a function to add a new … Read more

Wp_User_Query not sorting by meta key

you can try this code $args = array( ‘meta_query’ => array( array( ‘key’ => ‘score’, ‘value’ => 0, ‘compare’ => ‘>’, ‘type’ => ‘numeric’ ) ), ‘orderby’ => ‘meta_value_num’, ‘number’ => 20 ); $suggested_user_query = new WP_User_Query( $args ); $users = $suggested_user_query->get_results(); echo ‘<div id=”user_suggest”>’; echo ‘<ul>’; foreach ($users as $user) { // get all … Read more

Extending WP_User class and using this sub-class during the whole lifecycle

If I did understand well, we need to cache a value retrieved from another REST service, from the login to logout of the user on the wordpress installation, so we will hook into this wp_login to get the value and cache it using Transient API, Options API or a persistent caching plugin. add_action(‘wp_login’, ‘my_get_and_cache_rest_value’); function … Read more

How do you add a custom option to user data?

To add a field to the profile/user edit page you need to use the edit_user_profile hook and show_user_profile hook so: add_action( ‘show_user_profile’, ‘my_extra_user_fields’ ); add_action( ‘edit_user_profile’, ‘my_extra_user_fields’ ); function my_extra_user_fields( $user ) { ?> <h3>User avatar</h3> <table class=”form-table”> <tr> <th><label for=”user_avatar”>User avatar</label></th> <td> <input id=”user_avatar” name=”user_avatar” type=”text” value=” <?php $user_avatar = get_the_author_meta( ‘user_avatar’, $user->ID ); … Read more

How do you make the email field on the profile page read only for subscribers?

Although the readonly attribute can be removed using Chrome/Firebug inspector (making the field editable again), much probably the average user will not know this. <?php function wpse50730_script_enqueuer(){ if(current_user_can(‘subscriber’)) { echo ‘<script type=”text/javascript”> jQuery(document).ready( function($) { $(“.form-table #email”).attr(“readonly”, true); }); </script>’; } } add_action(‘admin_head-profile.php’, ‘wpse50730_script_enqueuer’);

Add mass action to wp-admin/users.php

Unfortunately this isn’t possible. Custom actions cannot be added to the bulk actions dropdown (see trac tickets: http://core.trac.wordpress.org/ticket/12732 and http://core.trac.wordpress.org/ticket/16031). For posts you can use the restrict_manage_posts hook to create another drop-down / add buttons to trigger your custom action. But there is no restrict_manage_* hook available for the user table. So the only (and … Read more

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