Add a member number to new user

To get the ID of the user that was created last, you could run the following query: SELECT id FROM wp_users ORDER BY user_registered DESC LIMIT 1 To do this within the context of your code, do this: global $wpdb; $last_user_id = $wpdb->get_results(“SELECT id FROM $wpdb->users ORDER BY user_registered DESC LIMIT 1”); That will give … Read more

update_user_meta doesn’t work with AJAX

First You can get rid of nasty globals in your AJAX call. I’m not sure what the $st variable that you were output is all about so I’ve excluded, but you can include as you wish – add_action(‘wp_ajax_change_subscription’, ‘change_subscription’); function change_subscription(){ if(!empty($_POST[‘term_id’]) && !empty($_POST[‘type’])) : $user_id = get_current_user_id(); update_user_meta( $user_id, ‘hannit_meta’, ‘My Value’ ); endif; … Read more

Delete user from frontend

Taken directly form the wp_delete_user documentation: if(is_user_logged_in() && !empty($_GET[‘DeleteMyAccount’])) { add_action(‘init’, ‘remove_logged_in_user’); } function remove_logged_in_user() { require_once(ABSPATH.’wp-admin/includes/user.php’ ); $current_user = wp_get_current_user(); wp_delete_user( $current_user->ID ); } Things to note: Your code didn’t check if the user was logged in or not by the time you’re printing the remove user link, the init action has already happened … Read more

How To Get User Data in Callback Function for pre_user_nicename?

If anyone should be faced with this problem, check if you have defined a callback function to set the user_login on pre_user_login. This filter is applied inside the wp_insert_user()-function and produced a same username again. Therefore the nicename was changed by adding a “-2”. So, my problem was that I reset the user_logins again and … Read more

What is the meta-box-order_post_hash used for?

I could only find the following core code references for the meta-box-order_ string: /wp-admin/includes/ajax-actions.php: update_user_option($user->ID, “meta-box-order_$page”, $order, true); and /wp-admin/includes/template.php: … get_user_option( “meta-box-order_$page” ) … that’s related to the ordering of meta-boxes. I doubt your $page value is post_hash, so my first guess is that this comes from a plugin/theme? If not then the user … Read more

Issue with foreach on duplicate meta_key’s

Here is an example of getting the user IDs, looping through each, grabbing a meta_key as an array, adding new values to it and remove old values, saving the meta back, then grabbing it again to loop through each item in the array for output. Array is just an example of duplicate keys. $user_query = … Read more

User Relationship

if I were you, I would use the wp_usermeta table. it is possible to add information to this table easily: add_user_meta(NEW_USER_ID, “PARENT_USER_ID”,USER_ID,true); USER_ID: the Id of top level user, (In your case id of user A) “PARENT_USER_ID”: some key that you could search and find result based on NEW_USER_ID: The Id of sub_user true: To … Read more

Get users primary blog URL in MultiSite

There’s actually a function for that: get_active_blog_for_user() https://developer.wordpress.org/reference/functions/get_active_blog_for_user/ $user_id = get_current_user_id(); $user_blog = get_active_blog_for_user( $user_id ); echo $user_blog->siteurl;

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)