Hot answers tagged

4

The rich_editing user option stores this check box value: wether or not do enable the visual editor for that particular user. If it's disabled then the content editor will look like this:


4

You forgot option 3 - Add a special table in which the pair (user,post id) will be the index. Ok I am not a MySQL person so maybe it is too extreme, but maybe having two tables one with users as index and one with posts will be even better. The thing about performance is that there are rarely absolute solutions for everybody at anytime, and the "best" ...


3

Trying to detect when a UI was triggered, is indeed the wrong general approach (unless you want to tie to the UI). A proper one will be to hook on the user_register action. add_action( 'user_register', 'wpse223196_registration_save', 10, 1 ); function wpse223196_registration_save( $user_id ) { add_user_meta($user_id, 'score', 5); }


3

Register a collection post type to represent a single collection. You'll get permalinks and rewrite rules to resolve the requests for free. Insert a new collection post for a user when they create a collection, and save the chosen post IDs as an array in post meta. You can pass that array directly as post__in argument in a WP_Query instance to load the ...


3

get_users() does not allow you to directly sort by whatever you like, but there are ways around it. The Codex for get_users() says: orderby - Sort by 'ID', 'login', 'nicename', 'email', 'url', 'registered', 'display_name', 'post_count', 'include', or 'meta_value' (query must also contain a 'meta_key' - see WP_User_Query). meta_value is a very powerful ...


3

I tested your code in both Wordpress 4.4 and in Wordpress 4.3.1. With version 4.4, I encounter exactly the same issue as you. However, your code works correctly in version 4.3.1! I think this is a Wordpress bug. I don't know if it's been reported yet. I think the reason behind the bug might be that the submit button is sending the query vars twice. If ...


3

What Caused the Problem The problem was that the restrict_manage_users action gets called twice: once ABOVE the Users table, and once BELOW it. This means that TWO select dropdowns get created with the same name. When the Filter button is clicked, whatever value is in the second select element (i.e. the one BELOW the table) overrides the value in the first ...


3

In the core, the bottom input names are marked with the instance number, e.g. new_role (top) and new_role2 (bottom). Here are two approaches for a similar naming convention, namely course_section1 (top) and course_section2 (bottom): Approach #1 Since the $which variable (top,bottom) doesn't get passed to the restrict_manage_users hook, we could get around ...


2

There is the action hook user_register that is called immediately after a user is added to the database. The user id is passed to the hook as an argument. You can use wp_insert_post to insert a new post in that action. You just need to get the relevant info from the user and add it to the post. You can add custom fields to the post you create by referencing ...


2

This is a different Javascript solution that may be helpful for some people. In my case I simply removed the 2nd (bottom) select list entirely. I find that I never use the bottom inputs anyway... add_action( 'in_admin_footer', function() { ?> <script type="text/javascript"> jQuery(".tablenav.bottom ...


2

Maybe this will answer your question: (Note: Due to bug #23268, value was required for NOT EXISTS comparisons to work correctly prior to 3.9. You had to supply some string for the value parameter. An empty string or NULL will NOT work. However, any other string will do the trick and will NOT show up in your SQL when using NOT EXISTS. Need inspiration? ...


2

If you are working with serialized data as your meta_value, that sucks, as Pieter suggested, it's best not to. However if there is no way around the serialization problem then I wonder if a meta_query using a compare value of LIKE might help... Example: //psuedo serialized data... (e.g. value of meta_key = fruits_user_like) ...


2

You're close - just need to tweak your arguments: <?php echo get_user_meta( $customer_id, 'billing_phone', true ) ?> Just make sure $customer_id is the ID of the user - you probably want get_current_user_id() instead.


2

There's no built-in functionality to append meta values you'll need to do it manually. If you plan on adding multiple values I would suggest saving it as an array but it will serialize it in the database which will make it harder to run WP_Meta_Query on. $user_id = fav_authors_get_user_id(); $fav_author_id = 2; $author_list = get_user_meta( ...


2

Finally I found answer by myself. Let's explore it with two user meta's current_login, last_login.Lets see the code. //function for setting the last login function set_last_login($login) { $user = get_userdatabylogin($login); $curent_login_time = get_user_meta( $user->ID , 'current_login', true); //add or update the last login value for ...


2

Roles First of all you need to register the 2 roles, look at add_role. When you register the role, you are free to assign any capability you want. Only be careful to add the roles when your theme / plugin is activated and possibly remove them (see remove_role) when it is disabled. Meta Data You can do the association using a meta entry like ...


2

There is no tax_query parameter for the WP_User_Query class. Since you've tagged the question with user-meta I can only assume you store the ID (or even the term name itself?) of a particular shop-category term as a user meta entry. In this case you would need something like this: // The 'WP_User_Query' arguments array $args = array( 'role' ...


2

You probably haven't changed the display name, which is probably what is being displayed. "nicename" is used for the author's posts page url and not for display. UPDATE wp_users SET display_name = replace(display_name, @old_user, @new_user);


2

Use this action hook found in buddypress/bp-xprofile/classes/class-bp-xprofile-profiledata.php do_action_ref_array( 'xprofile_data_after_save', array( $this ) ); You'll need to use the actual field_id for your xprofile description. This example assumes it is 25. You can get the field_idby going to wp-admin > Users > Profile Fields and clicking ...


1

The username is not a user meta entry, so you'll probably want to work with a WP_User object instead: $user = get_user_by( 'id', $_uid ); echo $user->user_login;


1

You have not provided the whole code so don't understand where you are wrong, this script is working fine for me. add_action( 'personal_options_update', 'save_extra_profile_fields' ); add_action( 'edit_user_profile_update', 'save_extra_profile_fields' ); function save_extra_profile_fields( $user_id ) { if ( current_user_can('edit_user',$user_id) ) ...


1

@Cristián Lávaque Thank you for the hints ;) Actually I managed to resolve the issue blocking this function (show the hidden comment above). In case this would help anyone here is the final working code: function check_post_limit() { if ( current_user_can( 'edit_posts' ) ) { global $userdata; global $wpdb; ...


1

User meta information, like that on the profile page, is stored in the usermeta table in the database. You can add extra fields by hooking into the show_user_profile and edit_user_profile action hooks. Then you can save the information by hooking into the personal_options_update and edit_user_profile_update action hooks with a function that updates the new ...


1

This is my working code based on @bybloggers answer (thanks by the way) I just learn that we shouldn't be using template_redirect hook and then exiting php, because some things may stop working because the abrupt interruption of php executing code. The explanation is here: ...


1

What is the exact meta_key and meta_value for the field I created using the function custom_user_profile_fields ? created_by and some user ID, for example: $args = array( 'meta_key' => 'created_by', 'meta_value' => 123, ) You could use a meta_query for more complex searches. $args = array( 'meta_query' => ...


1

Edit the user in phpmyadmin, enter the password as text in the user_pass field and there is a “Function” column with drop down boxes. On this field just select MD5 in the function column. When you save it phpMyAdmin will automatically md5 hash it for you.


1

I could only find the following core code references for the meta-box-order_ string: /wp-admin/includes/ajax-actions.php: update_user_option($user->ID, "meta-box-order_$page", $order, true); and /wp-admin/includes/template.php: ... get_user_option( "meta-box-order_$page" ) ... that's related to the ordering of meta-boxes. I doubt your ...


1

Please add following condition. $mailSent = get_user_meta($us_id, 'mail_sent', true); if($mailSent){ update_user_meta($us_id, 'mail_sent', 'mail sent'); }else{ $borrower_mail=wp_mail($to, $subject, $body); }


1

Try this: global $current_user; $user_id = $current_user->ID; // current user ID $meta = get_user_meta( $user_id, 'title', 'Manager' ); // subject meta if($meta != '') // updates meta if exists update_user_meta($user_id, 'title', 'Manager'); else // creates new meta if not exists add_user_meta($user_id, 'title', 'Manager');


1

wp_kses_post if you want to allow certain HTML in your textarea/wp editor (safest, as @Bordoni said). esc_textarea is what you might looking for.



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