Tag Info

Hot answers tagged

11

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


7

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

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.


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; get_currentuserinfo(); echo 'Username: ' . $current_user->user_login . '<br />'; echo 'User email: ' . ...


5

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


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

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.


5

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


4

First of all, you ned a function (template tag) to display the url. You can write a custom function that output the url in the format you want, however, putting the username in a public url can be a security issue. The function can handle the link and accept an argument $user that can be a user id or a user object. If non is passed, the function will try to ...


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


4

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.


4

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


4

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);


4

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


4

Just in case anyone (just like me) comes across this thread, you can extend this to show custom fields. Add this to your theme's functions.php: // Extend user profile // CUSTOM USER PROFILE FIELDS function my_custom_userfields( $contactmethods ) { // ADD CONTACT CUSTOM FIELDS $contactmethods['contact_phone_office'] = 'Office Phone'; ...


4

No. There are no hooks or filters to add an input field to the create user form. Maybe it is possible to add an input field via jQuery. I have not tested it. If it is pssible to add an input field, than it should be possible to save this information because the process of creating an user is the same as updating an existing user. Update Yes, it is ...


4

If it's information that logically belongs to a post/page - you store it in postmeta (with update_post_meta function). If it's something that pertains to a user - usermeta table is for you. More still, there's Settings API in case you have a plugin that needs to persist any settings. From your question it is somewhat unclear which of these would be best for ...


4

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


3

Are you by chance using Firefox to test your page? If so its prefetching function combined with WordPress rel='next' could be the culprit. Check your page source for those rel tags, and see if Firebug registers an extra GET request to the page specified in the href attribute of the rel tag. There is a Firefox extension Fasterfox, and it will prefetch ...


3

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


3

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


3

I don't see an "orderby Rand()" parameter for either get_users or WP_User_Query. There is a filter called pre_user_query that could be used but I am not sure I see the benefit of that when shuffle will randomize the array you already have. $args = array( 'fields' => 'all_with_meta', 'exclude' => array(1), ); $users = get_users( $args ); ...


3

You need to use the filter 'manage_' . $screen->id . '_columns' to add a column and manage_users_custom_column to display its value. add_filter( 'manage_users_columns', 'column_register_wpse_101322' ); add_filter( 'manage_users_custom_column', 'column_display_wpse_101322', 10, 3 ); function column_register_wpse_101322( $columns ) { $columns['uid'] ...


3

User passwords are stored in the database as what is called a hash. hashes are not reversible even if you know the hash and the mechanism used to create it. The only way to "decrypt" a hash is to take a password, hash it, compare it against the target hash, and try again... over and over until you get a match. If you think about that, you aren't really ...


3

The obvious advantage of user meta is that you can use the WordPress API to record and retrieve these extra columns, without writing extra PHP classes or SQL queries. The wp_usermeta table is pretty well indexed, in fact, it uses one row per field (rather than one column if you use a custom table), and you don't have to worry about performance. Using the ...


3

Hi @Holidaymaine: Not sure where you are doing wrong, but try the following instead which is a self contained test.php file you can drop into the root of your website and load in your browser with http://yoursite.com/test.php (assuming you replace yoursite.com with your site's domain! Also, note how I adding in a WHERE {$wpdb->usermeta}.meta_key = ...


3

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 />'; }


3

wp_get_current_user() is actually just a wrapper for $current_user and get_currentuserinfo(), so you can use both. It's important, though, to only call it on or after the init hook. Calling it before will only return 0, as you've experienced.


3

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'] )){ // ...


3

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



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