/** * Save core fields of the user (i.e. the wp_users data) * * @uses wp_insert_user * @param array $submitted * @return int User ID * @access public * @since 1.0.0 */ public function update_core_user($submitted) { $core_fields = array_intersect(array_keys($submitted), $this->get_core_keys()); if (empty($core_fields)) { return 0; } $values = array(); /* If we're updating an active user, set the ID */ if (0 !== $this->ID) { $values['ID'] = $this->ID; } foreach ($core_fields as $field) { $values[$field] = $submitted[$field]; } /* Insert the user */ if (0 == $this->ID) { if (!isset($values['user_pass']) || strlen($values['user_pass']) == 0) { charitable_get_notices()->add_error('<strong>ERROR:</strong> Password field is required.'); return false; } if (!isset($values['user_login'])) { $values['user_login'] = $values['user_email']; } /** * `wp_insert_user` calls `sanitize_user` internally - make the * same call here so `$values[ 'user_login' ]` matches what is * eventually saved to the database */ $values['user_login'] = sanitize_user($values['user_login'], true); $user_id = wp_insert_user($values); if (is_wp_error($user_id)) { charitable_get_notices()->add_errors_from_wp_error($user_id); return false; } $this->init(self::get_data_by('id', $user_id)); $signon = Charitable_User::signon($values['user_login'], $values['user_pass']); if (is_wp_error($signon)) { charitable_get_notices()->add_errors_from_wp_error($signon); return false; } do_action('charitable_after_insert_user', $user_id, $values); } else { $values['ID'] = $this->ID; $user_id = wp_update_user($values); } /* If there was an error when inserting or updating the user, lodge the error. */ if (is_wp_error($user_id)) { charitable_get_notices()->add_errors_from_wp_error($user_id); return false; } do_action('charitable_after_save_user', $user_id, $values); return $user_id; }