Assign random (and unique) user meta upon registration

You can use the hook user_register to modify user data upon registration. You can use the function add_user_meta to add custom data to a user. Example: add_action(‘user_register’, ‘add_pin_number’, 10, 1); function add_pin_number($user_id) { add_user_meta( $user_id, ‘pin_number’, $random_number , true ); } You can look for php function out there to help you creating the random … Read more

Filter for users on custom post type

Check this code do_action(‘user_register’, $user_id); add_action (‘user_register’, “test”); function test($user_id) { $user = new WP_User($user_id); $role_of_user = $user->roles[0]; if($role_of_user == ‘your role’){ $my_post = array( ‘post_title’ => ‘My post’, ‘post_content’ => ‘This is my post.’, ‘post_status’ => ‘publish’, ‘post_author’ => $user_id ); wp_insert_post( $my_post ); } } It will create a post when a user … Read more

Avoid user registrations with specific email provider

See this hook: register_post add_action(‘register_post’, ‘ban_email_2334’, 10, 3); function ban_email_2334( $username, $email, $errors ){ $result = array(); // check if email is from the provider you wish to ban preg_match(‘/bannedprovider.com/i’, $email, $result); if( !empty( $result )){ $errors->add(‘spam_email’, __( ‘Some choicest abuses you might want to pass on’ )); } return; } This will throw an … Read more

Woocomemrce order and registration fileds to UPPERCASE

First add the following code (and probably the WC Test Payment Gateway) and do a test order to get a list of all the data keys that are set in the order process via the woocommerce_after_checkout_validation filter: add_action(‘woocommerce_after_checkout_validation’,’custom_modify_order’,10,1); function custom_modify_order($posted) { foreach ($posted as $key => $value) {$data .= $key.”:”.$value.PHP_EOL;} $fh = fopen(get_stylesheet_directory().’/orderdebug.txt’,’w’); fwrite($fh,$data); fclose($fh); … Read more

Restrict partially matching usernames

There’s a validate_username filter hook that is used by validate_user() which is in turn used by register_new_user(). So you can disallow usernames containing admin or other prohibited terms: add_filter( ‘validate_username’, ‘wpse257667_check_username’, 10, 2 ); function wpse257667_check_username( $valid, $username ) { // This array can grow as large as needed. $disallowed = array( ‘admin’, ‘other_disallowed_string’ ); … 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