How to make WordPress ‘editor’ role to list/view/add/edit users only with the role ‘author’?

In addition to the code piece in the question, 1. To display only the author roles in the user list page of editor: add_action(‘pre_user_query’,’editors_edit_author_list’); function editors_edit_author_list($user_search) { $user = wp_get_current_user(); if($user->ID != 1) { $user_meta=get_userdata($user->ID); //$user_roles= $user_meta->roles; global $wpdb; if(in_array(‘editor’, $user_meta->roles)) { $user_search->query_where = str_replace( ‘WHERE 1=1’, “WHERE 1=1 AND {$wpdb->users}.ID IN ( SELECT {$wpdb->usermeta}.user_id … Read more

SQL to set Display Name to First Name + Last Name

Figured out the SQL query that can be used to reset the display_name to first_name + last_name. And it’s simpler than the JOINs that I was trying when I posted the question. UPDATE wp_users SET display_name = Concat( (SELECT meta_value FROM wp_usermeta WHERE meta_key = ‘first_name’ AND user_id = id ), ‘ ‘, (SELECT meta_value … Read more

How can I show a button in WordPress but make it unclickable unless logged in?

You didn’t provide any code so I’ll give you some pseudo code and you make of it what you will: Your HTML button: <a href=”<?php echo $download_url; ?>” class=”download-button<?php echo $is_disabled; ?>”>Download</a> Now, you’re going to want to write some CSS style rules for the following: .download-button{} .download-button.disabled{} Make one look like a bright, vibrant, … Read more

Update user role for expired membership

If you need to get the value of a field in a custom database table you can try using an SQL query. You’ll have to check the column or table name to construct final version of the query. add_action( ‘profile_update’, ‘my_profile_update’, 10, 2 ); function my_profile_update( $user_id, $old_user_data ) { global $wpdb; $status = $wpdb->get_var( … Read more