Ejemplo n.º 1
0
 /**
  * create the new temporary user
  *
  * @param  string  $email     the user-submitted email
  * @param  string  $time      the user-submitted expiration
  *
  * @return integer $user      the newly created user ID
  */
 protected static function create_new_user($email = '', $time = '')
 {
     // make sure the user calling the action has permission to do so
     if (false === TempAdminUser_Utilities::check_user_perm()) {
         return;
     }
     // first get our password, since we use it in multiple places
     $password = TempAdminUser_Utilities::generate_password();
     // set my user args
     $user_args = array('user_login' => TempAdminUser_Utilities::create_username($email), 'user_pass' => $password, 'user_email' => sanitize_email($email, true), 'role' => 'administrator');
     // filter the args
     $user_args = apply_filters('tempadmin_new_user_args', $user_args);
     // create the user
     $user_id = wp_insert_user($user_args);
     // return an error message if the user was not created
     if (is_wp_error($user_id)) {
         // get my first error code
         $code = $user_id->get_error_code();
         // return the array
         return array('error' => true, 'errcode' => $code, 'message' => $user_id->get_error_message($code));
     }
     // now add our custom meta keys
     update_user_meta($user_id, '_tempadmin_user', true);
     update_user_meta($user_id, '_tempadmin_created', time());
     update_user_meta($user_id, '_tempadmin_expire', TempAdminUser_Utilities::get_user_expire_time($time));
     // and update some basic WP related user meta
     update_user_meta($user_id, 'show_welcome_panel', 0);
     update_user_meta($user_id, 'dismissed_wp_pointers', 'wp330_toolbar,wp330_saving_widgets,wp340_choose_image_from_library,wp340_customize_current_theme_link,wp350_media,wp360_revisions,wp360_locks');
     // first check for the bypass
     if (true === apply_filters('tempadmin_send_email_notification', true)) {
         self::new_user_notification($user_id, $password);
     }
     // return the user ID
     return $user_id;
 }