Tag Info

Hot answers tagged

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

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

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

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

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

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

I came across a tutorial about 'Custom User Taxonomies in WordPress' and there is a plugin based on that 'User Taxonomies' but these are for creating taxonomies for Users. Have a read thought the tutorial it might help. I think what you're talking about is to associating posts' taxonomies with users. I think you need to use something like ...


3

wp_insert_user returns your new user's ID, if created successful. You can add the user_meta to this ID: $userid = wp_insert_user( $userdata ); if ( !is_wp_error( $userid ) ) { // check if insert was successful add_user_meta( $userid, 'verification_ref', $ref ); // add the meta } else { /* Error Handling */ }


2

How can I write a bulk MySQL command to add in the value wp_capabilites='a:1:{s:10:"subscriber";b:1;}' into each user_id except 1, 2 and 3 ie. the newly imported users? You don't. That is a serialized array which is a PHP construct. MySQL has no idea what to do with it. To the database, it is just an string. To PHP it is a representation-- a ...


2

WordPress records when a user was registered in the $wpdb->users (usually wp_users) table in the column user_registered. So you can use that to calculate the average account age. There's no internal function for this, so you'll have to use $wpdb directly. This stackoverflow answer has some good info about calculating the average of a series of dates. ...


2

You'll want to use the 'meta_query' argument of WP_Query ( http://codex.wordpress.org/Class_Reference/WP_Query ) Here's a snippet that uses two separate meta key comparisons: $query_args = array( 'post_type' => 'event', 'order' => 'ASC', 'orderby' => 'meta_value_num', 'meta_key' => '_start_date', 'meta_query' => array ( ...


2

I think I figured this one out. I had misread this answer and hooked the function I wrote to wp_clear_auth_cookie (actually a function itself!) instead of clear_auth_cookie (the real hook), so that wasn't working. But now using the real hook, I think it might be. Correct me if I'm wrong. Below is the function with the hook. function users_last_login() { ...


2

get_user_meta() with omitted key argument will return all data for the object. Trying to retrieve metadata selectively is usually pointless optimization from performance point of view, since everything built on Metadata API tends to just query all data anyway and cache it (which in turn object cache plugin makes persistent and snappy).


2

On the "profile page", i.e. user-edit.php in the admin back-end, the user ID of the profile currently being edited lives in the $user_id global. Hence: global $user_id; update_user_meta( $user_id, 'key', 'value' ); is the essence of what you are looking for. Whether the current user is an admin needs to be checked only if you have the edit_users ...


2

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


2

You need to create your own hook for registration_errors filter: add_filter( 'registration_errors', 'wpse8170_registration_errors', 10, 3 ); function wpse8170_registration_errors( $errors, $sanitized_user_login, $user_email ) { if ( /* something happens */ ) { $errors->add( 'myexception_code', 'This is my message' ); } return ...


2

Take a look at the WordPress Codex: Customizing The Registration Form Theme and plugin developers can customize WordPress's built-in user registration page through the use of hooks. Customizing the registration form involves utilizing the following three hooks: register_form Allows rendering of new HTML form elements. ...


1

You should take a look at the first example for the shortcode_atts() page in the Codex: function bartag_func( $atts ) { extract( shortcode_atts( array( 'foo' => 'no foo', 'bar' => 'default bar', ), $atts, 'bartag' ) ); // etc... That great little function parses and sets defaults for a shortcode with two potential ...


1

Regarding Edit #3 I would rewrite it like this: //* Shortcode for getting users function list_of_users( $atts ) { extract( shortcode_atts( array( 'display' => 'all', 'user' => '30' ), $atts )); $content = ''; switch ( $display ) { case 'all': $content = ...


1

To display the user meta data in the User's page, you need the filters manage_users_custom_column and manage_users_columns: Sortable Custom Columns in User Panel (users.php)? And to add the fields in the User/Profile pages, the following (from Checkboxes in registration form): // PROFILE add_action( 'show_user_profile', 'user_field_wpse_87261' ); ...


1

Actually I found this to be more strait forward and simpler: //add columns to User panel list page function add_user_columns($column) { $column['address'] = 'Street Address'; $column['zipcode'] = 'Zip Code'; return $column; } add_filter( 'manage_users_columns', 'add_user_columns' ); //add the data function add_user_column_data( $val, ...


1

You need to add the new merge tags with the gform_custom_merge_tags filter, and then replace them with the gform_replace_merge_tags filter, like this: Edit: you need to use the gform_field_content filter to replace the field's default value, see below. add_filter('gform_custom_merge_tags', 'wpse_121476_custom_merge_tags', 10, 4); ...


1

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 value into the bulk actions dropdown box: add_action('admin_footer', ...


1

First of all get_users_of_blog has been deprecated, so you should use get_users instead, or run a WP_User_Query. After that, the_author_meta echo the meta value, not return anything. To return the meta you should use get_the_author_meta() $blogusers = get_users( $args ); // for args see codex if ($blogusers) { foreach ( $blogusers as $bloguser ) { ...


1

In your case $registered is the user id not the user object so it does not work. Please use the code as given below. add_action( 'user_register', 'set_user_registration_date', 10, 1 ); function set_user_registration_date( $user_id ) { $user = get_userdata ( $user_id ); // Update the registration meta data update_user_meta ( $user_id, ...


1

Okay, there are a couple of things to do: Get last_active for the user Calculate the days since last_active Set last_active_days_ago for the user So you can go like this: function daysAgo( $time ) { $time = time() - $time; $daysAgo = $time / 86400; // calculate days return $daysAgo; } function set_user_last_active_days_ago( $user_id ) { // ...


1

Before answer, a side note: what you want can be done a in a lot simpler and more performant way just creating a real post type: register a cpt, maybe not public (so no ui is showed on dashboard), and on user profile saving/updating just create/update a cpt entry. Doing so you do not need any external class and you can just use the core wp functions, to ...


1

Please look at the last two lines of code. I am trying to print the id of the user. It works when used in the theme files but not inside the plugin. //Test Usermeta $user = get_userdatabylogin('vijay'); echo $user->ID; // prints the id of the user; In PHP, you cannot (normally) execute a user function before it has been defined. The plugin is ...



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