Make WooCommerce pages accessible for logged in users only

Put this in your functions.php file: function wpse_131562_redirect() { if ( ! is_user_logged_in() && (is_woocommerce() || is_cart() || is_checkout()) ) { // feel free to customize the following line to suit your needs wp_redirect(home_url()); exit; } } add_action(‘template_redirect’, ‘wpse_131562_redirect’); What does it do? We check if a not-logged-in user wants to see a WooCommerce page, … Read more

Make display name unique

As far as I’m aware, all you can do is filter the display name via pre_user_display_name and check if it already exists. Unfortunately WP_User_Query doesn’t support querying by display_name, so we also have to add to the WHERE clause via pre_user_query. Additionally, there is no elegant way I can think of to handle the case … Read more

Where can I find documentation on what characters are allowed in user names and why?

You can use spaces in usernames, no problem. Several users on wordpress.org have spaces in their usernames. Strict mode only allows these characters: a-z0-9<space>_.\-@ However WP doesn’t default to strict mode. Now, multisite has different restrictions, and it may strip spaces there. This is because usernames are used to create independent blogs and such on … Read more

Difference between update_user_meta and update_user_option

In layman terms there is no major difference! update_user_option() uses update_user_meta() internally. The only difference is update_user_option() prefix the option name with database table prefix + blog ID if you are in multisite and just table prefix if you are in single site installation. Take a look at the code of update_user_option() /** * Update … Read more

How to search all user meta from users.php in the admin

Hi @user2041: Clearly as you know you need to modify the search that’s performed which you can do by modifying the values in the instance of the WP_User_Search class used for the search (you can find the source code at /wp-admin/includes/user.php if you’d like to study it.) The WP_User_Search Object Here’s what a print_r() of … Read more

Adding fields to the “Add New User” screen in the dashboard

user_new_form is the hook that can do the magic here. function custom_user_profile_fields($user){ ?> <h3>Extra profile information</h3> <table class=”form-table”> <tr> <th><label for=”company”>Company Name</label></th> <td> <input type=”text” class=”regular-text” name=”company” value=”<?php echo esc_attr( get_the_author_meta( ‘company’, $user->ID ) ); ?>” id=”company” /><br /> <span class=”description”>Where are you?</span> </td> </tr> </table> <?php } add_action( ‘show_user_profile’, ‘custom_user_profile_fields’ ); add_action( ‘edit_user_profile’, ‘custom_user_profile_fields’ … Read more