Preventing user enumeration: which logic is better?

Logic #1 is checking the returned value of the preg_match function with respect to 0 and with operator ===. That means the returned value of the preg_match function has to be (int) 0 or (string) 0. And after that it is checking if $_REQUEST[‘author’] is empty or not. And in Logic #2 is checking the … Read more

Copy user role on multisite so the user can access subsites with same role

You can use the below function to copy all the users to all the subsite. It’s actually getting all the user IDs and subsites IDs first, then it’s looping over every sites and users to assign all the users to every subsite. Here is the updated code- add_action(‘wp’,’the_dramatist_add_current_user_to_site’); function the_dramatist_add_current_user_to_site() { global $wpdb; $all_users = … Read more

Get multiple users with meta value in one query and populate WP_User class

For anyone interested. Got it solved using the get_user_metadata filter to short circuit the metaquery and cache loading. Steps: Run query Store result data in the class property Add get_user_metadata filter Start foreach loop on results Trigger new WP_User( $result_value ) for each result Within the filter function, validate meta key on $wpdb->get_blog_prefix() . ‘capabilities’. … Read more

How to set custom avatar for users?

We can use the get_avatar_url filter to modify the avatar’s url. If all the relevant get_avatar() calls, have user id as an input argument, then it’s easy to get the corresponding user’s meta value, with get_user_meta(), within the filter’s callback. Otherwise we need to handle all possible input cases, for get_avatar( $some_input ), as it … Read more