wp cron – Delete all users when they don’t update profile_fields

Question

  1. I create a profile_fields named name, when users sign up for an account they will receive an email containing the nickname.
  2. When the user logs in, there will be a page to enter profile_fields (name), if profile_fields = nickname (from email), they will be redirected to the main edit page.

(1,2 I did it).

I want users who can’t update profile_fields (name) for a day, to be permanently deleted.
Is there any way to make this work? please, i have searched many places but to no avail
I found a code and corrected it but I don’t know if it’s wrong???

function my_clearOldUsers() {
    global $wpdb;
    $query = $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE datediff(now(), user_registered) > 1");
    if ($oldUsers = $wpdb->get_results($query, ARRAY_N)) {
        foreach ($oldUsers as $user_id) {
            $nickname = $user->user_login
            $xacminh = get_user_meta( $user_id[0], 'name', true );
            if($xacminh != $nickname) {
            wp_delete_user($user_id[0]); 
            } 
        }
    }
}
add_action('my_dailyClearOut', 'my_clearOldUsers');  ```

0
minhte 5 months 2022-03-07T11:37:22-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse