Can I set user meta for theoretical user 0?

It turns out (via comments) that (ab)using user 0 is a really bad idea. However, WordPress is built to allow new things to get meta-tables. Which led me to make Guest Meta as a plugin. It’s available on GitHub as a gist and below in its current form. I have to point out that this … Read more

Assign a role to the user who registers on a form

$POST = filter_var_array($_POST, FILTER_SANITIZE_STRING); $nome = $POST[‘nome’]; $cognome = $POST[‘cognome’]; $email = $POST[’email’]; $token = $POST[‘stripeToken’]; $nickname = $nome . ‘ ‘ . $cognome; // Inserisce utente nel DB $user_data = [ ‘user_login’ => $nickname, ‘user_pass’ => wp_generate_password (), ‘user_email’ => $email, ]; $user_id = wp_insert_user($user_data); update_user_meta( $user_id, ‘first_name’, $nome); update_user_meta( $user_id, ‘last_name’, $cognome); update_user_meta( … Read more

Why get_users() not working on the admin backend?

Perhaps user.php has not yet been loaded. get_users() is a wrapper for WP_User_Query, which is defined in wp-includes/user.php. Hooks indicate template_redirect is after wp, after users are registered. Perhaps you could try conditionally hooking ‘template_redirect’ on the front-end and ‘user_admin_menu’ on the back-end. if (is_admin()){ add_action(‘user_admin_menu’,’manage_new_user_submit’); } else { add_action(‘template_redirect’,’manage_new_user_submit’); } Also, you might remove … Read more

User last login and user last visit problem

When you are using human_time_diff for convert time to human readable format. your last_visit meta empty that is why it is return 50 years. so before convert human_time_diff you have to check value is not empty. use below code to display last_login, last_visit. $users = get_users(); foreach( $users as $user ) { $udata = get_userdata( … Read more