Hot answers tagged

14

WordPress distinguishes usermeta keys between sites by using the database prefix for each site. For example, instead of using the favorite_posts key, you'd use the meta key wp_23_favorite_posts. To get the prefix, you can use $wpdb->get_blog_prefix(). But wait, there's actually a whole API dedicated to this. Rather than using *_user_meta(), use *...


11

For an author's profile link, use bp_core_get_user_domain( $user_id ) to get the URL, and bp_core_get_userlink( $user_id ) to get an HTML link element, including display name. For the xprofile data, use xprofile_get_field_data( $field, $user_id ) $field can be either the name of the field (like 'Biography') or the numerical field id.


10

I had the same need and created the following hack: <?php function hack_add_custom_user_profile_fields(){ global $pagenow; # do this only in page user-new.php if($pagenow !== 'user-new.php') return; # do this only if you can if(!current_user_can('manage_options')) return false; ?> <table id="...


9

If you plan to use this code on frontend, I would check if email is free to use. Otherwise, you are creating a security hole. if (isset( $_POST['email'])) { // check if user is really updating the value if ($user_email != $_POST['email']) { // check if email is free to use if (email_exists( $_POST['email'] )){ // ...


9

There are two ways I've discovered doing this: Author Page with a custom rewrite rule A custom template files paired with a rewrite rule The first is more simple to implement, but may not work in all circumstances (one of which I'll describe soon). Custom Rewrite Rule I found this solution a few days ago here: URL Rewriting And here's the code, with ...


9

You technically don't have to set a nickname, it will be filled with your username if you clear the field out. Display name is selectable between the user's username, first name, last name, first/last, or last/first, or nickname. The nickname exists to give you an option to set display name to something other than your username or real name.


9

user_nicename is url sanitized version of user_login. In general, if you don't use any special characters in your login, then your nicename will always be the same as login. But if you enter email address in the login field during registration, then you will see the difference. For instance, if your login is user@example.com then you will have userexample-...


8

You need to use wp_update_user() for the email, as it is not user-meta but core user data. The code should look something like this: $args = array( 'ID' => $current_user->id, 'user_email' => esc_attr( $_POST['user_email'] ) ); wp_update_user( $args ); Note: that's untested, but it should work out of the box.


8

You need to do this in steps: Decide when you are going to parse the user's meta to change the value. Define a function to do that. Hook that function to the appropriate action. The original answer defined what you need to do for step #2, using preg_match() to parse the Twitter URL and extract the username. function update_the_user( $user ) { // ...


6

Not sure how this would differ with multi-site, but this is how you'd do this outside the loop normally: <?php # get post data $temp_post = get_post($post_id); # grab the author meta $user_id = $temp_post->post_author; # grab the field you're looking for $first_name = get_the_author_meta('first_name',$user_id); # display field echo $first_name; ?&...


6

wp_update_user & metadata wp_update_user updates records in the *_users table. It isn't meant to update custom metadata in the *_usermeta table. Hence your "problem" is actually expected behavior. The $userdata argument passed to wp_update_user can contain the following fields: ID, user_pass, user_login, user_nicename, user_url, user_email, ...


6

Why don't use built-in functionality of PHP? Put the following line right before the foreach: usort($members, create_function('$a, $b', 'return strnatcasecmp($a->last_name, $b->last_name);')); References: usort create_function strnatcasecmp


6

Clients get added by admins, clients have a parent child relationship with employees which makes filtering easy. So all we need to do is remove anything that doesn't have to do with employees and filter for employees with a certain meta value. First thing's first, whenever a new user is registered on the admin side of our CMS we will assign it a parent of ...


5

I had the same problem. Adding "true" to "get_user_meta" worked for me. For example: FROM: $reminders = get_user_meta($current_user->ID,"reminders"); TO: $reminders = get_user_meta($current_user->ID,"reminders",true);


5

why not store the blog id together with the array of postIds, so you will have something like this stored in the user meta data: Array ( [blogid1] => Array(1,2,4,7), [blogid2] => Array(3,6,8,10) ) you can use the global $blog_id to get the current blogid. On a non multisite setup, the blogid will be 0 and should still work when you try to get ...


5

Have you tried to go with the "Safe usage" alternative given in the commented section? I honestly don't have any experience with wp_get_current_user(), since I never use it, but anyhow, this ought to work: global $current_user; echo 'Username: ' . $current_user->user_login . '<br />'; echo 'User email: ' . $current_user->user_email . '<br /&...


5

The Native get_users() function returns an array of user objects and each on holds [ID] => 1 [user_login] => admin [user_pass] => $P$Bxudi6gJMk2GRt2ed3xvZ06c1BPZXi/ [user_nicename] => admin [user_email] => admin@host.com [user_url] => http://localhost/ [user_registered] => 2010-06-29 07:08:55 [user_activation_key]...


5

A simple example would be to get all users for a specific role, iterate over the returned results and apply the delete_user_meta function for the given meta_key. Stir and let simmer for a fraction of a second and all user meta for that key shall be gone. function say_goodby_to_the_meta(){ $role = 'subscriber'; $users = get_users('role='.$role); ...


5

There are far better ways of doing this. Instead of modifying the user table, make use of User Meta. It has a dedicated table, and works the same way as post meta, but for users. add_user_meta get_user_meta update_user_meta There are many tutorials explaining how to add additional fields to the user profile using User meta to store them, and it's how a ...


5

You have already found out that using update_user_meta() if the meta field for the user does not exist, it will be added. ie update_user_meta() can do the task of add_user_meta() However, the difference between them is the return values update_user_meta() returns False if no change was made (if the new value was the same as previous value) or if the ...


5

There is no one answer, because both have pros and cons depending on what you want to store and why. A (probably non-exhaustive) list of differences to consider for a choice: Capabilities are designed to check if a user can do something or not. user_can and current_user_can are there to help you to check user permissions. You can implement that with user ...


5

Both write their data in the “usermeta” table. User options stored in the usermeta table retain the wordpress table prefix e.g. wp_ whereas the user meta also stored in the usermeta table doesn't. User options support blog-specific options, useful in multisite. The user meta is based on the user id specific meta data like profile information. The ...


5

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 ...


4

As far as i know it should be possible to login with your email with wp 3.1, which will come soon. Using an email as username is already possible. "@" and "." are allowed characters for usernames. Hope that helps.


4

Thats just PHP serialized array notation. You would get that same result by this code: $meta_value = array( 'alumni' => 'Yes', 'donations_collected' => '10' ); update_user_meta( $team_member_id, 'wp_s2member_custom_fields', $meta_value); So if you want to then change the donations_collected value to 11: $meta_value = get_user_meta( $...


4

Just use $current_user global, your function will be something like this: function mamaduka_get_user_id() { global $current_user; echo 'Before wp_get_current_user <br />'; echo 'After wp_get_current_user <br />'; echo 'ID= ' . $current_user->ID . '<br />'; }


4

you can save the 1000 conditional checks by using str_replace and your code would be much more efficient, something like this: //create the select options $options =''; for($i=1;$i<=1000;$i++) { $options.= '<option value="'.$i.'">'.$i.'</option>'; } //get the saved data $saved = get_the_author_meta( 'number_pick', $user->ID ); $saved ...


4

Just a plugin concept … Add a form with a button to each user profile, post or wherever you want it named Follow or Unfollow. Show the button only if is_user_logged_in(). You may use a widget for the form. On form submit update a user meta named follows for the user who clicked the button and another one named followers for … well … the user who just got a ...


4

How about using get_users()? You probably don't even need parameters for it, default behavior should be just what you're looking for.


4

You can just assign a new value to the 1h_userbadge_comments25 key. Like so... <?php $meta_value = get_user_meta($user_id, 'lh_userbadges', false); // just assign this key a new value $meta_value['lh_userbadge_comments25'] = 25; Then just save it again. <?php update_user_meta( $user_id, 'lh_userbadges', $meta_value ); Whether or not storing all ...



Only top voted, non community-wiki answers of a minimum length are eligible