Beispiel #1
0
 /**
  * Save section data
  *
  * @since 1.0.0
  *
  * @param WP_User $user
  */
 public function save($user = null)
 {
     // Primary Site
     $user->primary_blog = isset($_POST['primary_blog']) ? (int) $_POST['primary_blog'] : null;
     // Temporarily save this here, because it's not handled by WordPress
     if (!empty($user->primary_blog)) {
         update_user_meta($user->ID, 'primary_blog', $user->primary_blog);
     }
     parent::save($user);
 }
Beispiel #2
0
 /**
  * Save section data
  *
  * @since 0.2.0
  *
  * @param WP_User $user
  */
 public function save($user = null)
 {
     // Color Scheme
     $user->admin_color = isset($_POST['admin_color']) ? sanitize_text_field($_POST['admin_color']) : 'fresh';
     // Double negative visual editor
     $user->rich_editing = isset($_POST['rich_editing']) ? 'false' : 'true';
     // Admin bar front
     $user->show_admin_bar_front = isset($_POST['admin_bar_front']) ? 'true' : 'false';
     // Enable comments shortcuts
     $user->comment_shortcuts = isset($_POST['comment_shortcuts']) ? 'true' : 'false';
     // Force SSL
     $user->use_ssl = isset($_POST['use_ssl']) ? 1 : 0;
     // Allow third party plugins to save data in this section
     parent::save($user);
 }
Beispiel #3
0
 /**
  * Save section data
  *
  * @since 0.2.0
  *
  * @param  WP_User  $user
  */
 public function save($user = null)
 {
     // Password (1)
     $pass1 = isset($_POST['pass1']) ? $_POST['pass1'] : '';
     // Password (2)
     $pass2 = isset($_POST['pass2']) ? $_POST['pass2'] : '';
     /** This filter is documented in wp-admin/includes/user.php */
     do_action_ref_array('check_passwords', array($user->user_login, &$pass1, &$pass2));
     // Check for "\" in password
     if (false !== strpos(wp_unslash($pass1), "\\")) {
         $this->errors->add('pass', __('<strong>ERROR</strong>: Passwords may not contain the character "\\".'), array('form-field' => 'pass1'));
     }
     // Checking the password has been typed twice the same
     if ($pass1 !== $pass2) {
         $this->errors->add('pass', __('<strong>ERROR</strong>: Please enter the same password in both password fields.'), array('form-field' => 'pass1'));
     }
     // Set the password
     if (!empty($pass1)) {
         $user->user_pass = $pass1;
     }
     // Checking email address
     if (isset($_POST['email'])) {
         // Sanitize the email
         $user->user_email = sanitize_text_field(wp_unslash($_POST['email']));
         // Email empty
         if (empty($user->user_email)) {
             $this->errors->add('empty_email', __('<strong>ERROR</strong>: Please enter an email address.'), array('form-field' => 'email'));
             // Email invalid
         } elseif (!is_email($user->user_email)) {
             $this->errors->add('invalid_email', __('<strong>ERROR</strong>: The email address is not correct.'), array('form-field' => 'email'));
             // Email in use
         } elseif (($owner_id = email_exists($user->user_email)) && $owner_id !== $user->ID) {
             $this->errors->add('email_exists', __('<strong>ERROR</strong>: This email is already in use.'), array('form-field' => 'email'));
         }
     }
     // Bail if password change errors occurred
     if ($this->errors->get_error_code()) {
         return $this->errors;
     }
     // Allow third party plugins to save data in this section
     parent::save($user);
 }
 /**
  * Save section data
  *
  * @since 0.2.0
  *
  * @param WP_User $user
  */
 public function save($user = null)
 {
     // Color Scheme
     $user->admin_color = isset($_POST['admin_color']) ? sanitize_text_field($_POST['admin_color']) : 'fresh';
     // Double negative visual editor
     $user->rich_editing = isset($_POST['rich_editing']) ? 'false' : 'true';
     // Admin bar front
     $user->show_admin_bar_front = isset($_POST['admin_bar_front']) ? 'true' : 'false';
     // Enable comments shortcuts
     $user->comment_shortcuts = isset($_POST['comment_shortcuts']) ? 'true' : 'false';
     // Force SSL
     $user->use_ssl = isset($_POST['use_ssl']) ? 1 : 0;
     // Primary Site
     $user->primary_blog = isset($_POST['primary_blog']) ? (int) $_POST['primary_blog'] : null;
     // Temporarily save this here, because it's not handled by WordPress
     if (!empty($user->primary_blog)) {
         update_user_meta($user->ID, 'primary_blog', $user->primary_blog);
     }
     // Allow third party plugins to save data in this section
     parent::save($user);
 }
 /**
  * Save section data
  *
  * @since 0.2.0
  *
  * @param WP_User $user
  */
 public function save($user = null)
 {
     // Role changes
     if (isset($_POST['role']) && is_array($_POST['role']) && current_user_can($this->cap, $user->ID)) {
         // Loop through new roles
         foreach ($_POST['role'] as $blog_id => $new_role) {
             // Switch to the blog
             if (is_multisite()) {
                 switch_to_blog($blog_id);
             }
             // Only allow switching to to editable role for site
             $editable_roles = get_editable_roles();
             if (!empty($new_role) && !empty($editable_roles[$new_role])) {
                 $user->set_role($new_role);
             }
             // Switch back
             if (is_multisite()) {
                 restore_current_blog();
             }
         }
     }
     // Allow third party plugins to save data in this section
     parent::save($user);
 }
 /**
  * Save section data
  *
  * @since 0.2.0
  *
  * @param WP_User $user
  */
 public function save($user = null)
 {
     // User Login
     if (isset($_POST['user_login'])) {
         // Set the login
         $user->user_login = sanitize_user($_POST['user_login'], true);
         // Invalid login
         if (!validate_username($user->user_login)) {
             $this->errors->add('user_login', __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.'));
         }
         // Login already exists
         if (username_exists($user->user_login)) {
             $this->errors->add('user_login', __('<strong>ERROR</strong>: This username is already registered. Please choose another one.'));
         }
         // Checking that username has been typed
         if (empty($user->user_login)) {
             $this->errors->add('user_login', __('<strong>ERROR</strong>: Please enter a username.'));
         }
         // Return if errored
         if ($this->errors->get_error_code()) {
             return $this->errors;
         }
     }
     // First
     $user->first_name = isset($_POST['first_name']) ? sanitize_text_field($_POST['first_name']) : '';
     // Last
     $user->last_name = isset($_POST['last_name']) ? sanitize_text_field($_POST['last_name']) : '';
     // Nickname
     if (isset($_POST['nickname'])) {
         // Set the nick
         $user->nickname = sanitize_text_field($_POST['nickname']);
         // Nickname was empty
         if (empty($user->nickname)) {
             $this->errors->add('nickname', __('<strong>ERROR</strong>: Please enter a nickname.'));
             return $this->errors;
         }
     }
     // Display
     $user->display_name = isset($_POST['display_name']) ? sanitize_text_field($_POST['display_name']) : '';
     // Description
     $user->description = isset($_POST['description']) ? trim($_POST['description']) : '';
     // Website
     if (isset($_POST['url'])) {
         // Emptying URL
         if (empty($_POST['url']) || in_array($_POST['url'], wp_allowed_protocols(), true)) {
             $user->user_url = '';
             // Validate
         } else {
             $user->user_url = esc_url_raw($_POST['url']);
             $protocols = implode('|', array_map('preg_quote', wp_allowed_protocols()));
             $user->user_url = preg_match('/^(' . $protocols . '):/is', $user->user_url) ? $user->user_url : 'http://' . $user->user_url;
         }
     }
     // Look for contact methods
     $methods = wp_get_user_contact_methods($user);
     // Contact methods
     foreach (array_keys($methods) as $method) {
         if (isset($_POST[$method])) {
             $user->{$method} = sanitize_text_field($_POST[$method]);
         }
     }
     // Allow third party plugins to save data in this section
     parent::save($user);
 }