Show extra user profile meta for current user

You should use get_user_meta instead of get_the_author_meta(). because get_the_author_meta() has Valid values for the $field parameter include: get_the_author_meta you can take reference from below code. $school_id = get_user_meta( $current_user->ID, ‘school-id’,true); if ( !empty($school_id) ) { ?> <p class=”school-id”> <p> <?php echo $school_id; # what you want to do with school id ?> </p> </p> <?php … Read more

how to set default update_user_meta values wordpress

You can use the user_register action to run your user meta update when a user registers. /** * Sets the user meta key ‘_sb_pkg_type’ to ‘free’ when a user registers. * * @param int $user_id ID for the user who has registered. */ function wpse_update_user_meta_pkg_type( $user_id ) { update_user_meta( $user_id, ‘_sb_pkg_type’, ‘free’ ); } // … Read more

check for duplicate user meta data before updating

You can check duplicate user meta using sql query.in below code if duplicate record found of other users then it will display error message and not update value. add below code in active theme’s functions.php file. function save_cust_user_profile_fields( $user_id ) { if ( isset($_POST[‘social_number’]) ) { global $wpdb; $social_number = $_POST[‘social_number’]; # query to check … Read more

Login redirect. Check user meta and redirect accordingly

woocommerce_login_redirect is similar to login_redirect and it has a users parameter. That means you don’t have to use get_current_user_id() (which was returning 0 when I tested it). Instead, replace get_current_user_id() with $user->ID;. For example: function redirect_login_to_tos($redirect, $user) { $user_id = $user->ID; $checkout_tos2 = get_user_meta($user_id, ‘checkout_tos2’, true); $checkout_tos3 = get_user_meta($user_id, ‘checkout_tos3’, true); if($checkout_tos2 != ‘agreed’ || … Read more

Run Username SQL Query from WordPress Child Theme Functions File

There are many ways you can achieve this… In your instance, as you pointed out $wpdb, here is the possible ways you can achieve this: 1. Use $wpdb::query You can run this query directly using $wpdb’s query method as: add_action(“init”, “username_query”) function username_query(){ global $wpdb; $prefix = $wpdb->prefix; $query = “UPDATE `{$prefix}wp_users` SET `user_login`= ‘new-admin-name-here’ … Read more

Using WP for user management

You might want to take a look at the REST API that comes out of the box with WordPress. Here are the docs for Users, you can register users and list/retrieve/update them https://developer.wordpress.org/rest-api/reference/users/ Here’s the information about how to authenticate to use the API (so that you can Reigister Users for instance) https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/