function doUpdateRecord($data) { $email = $_POST['crg_login_email']; $user = get_user_by('email', $email); $content = $_POST['notes']; $title = $_POST['Last_Name'] . ", " . $_POST['First_Name']; $userdata = array('ID' => $user->ID, 'first_name' => $_POST['First_Name'], 'last_name' => $_POST['Last_Name']); $returnValue = wp_update_user($userdata); $form = get_page_by_title($title, 'OBJECT', 'InfoForm'); if ($form) { $my_post = array('ID' => $form->ID, 'post_title' => $title, 'post_author' => $user->ID, 'post_content' => $content, 'post_type' => 'InfoForm'); wp_update_post($my_post); foreach ($data as $k => $v) { update_post_meta($form->ID, $k, $v); } } else { $my_post = array('post_title' => $title, 'post_content' => $content, 'post_author' => $user->ID, 'post_type' => 'InfoForm'); // Insert the post into the database $form_id = wp_insert_post($my_post); foreach ($data as $k => $v) { add_post_meta($form_id, $k, $v); } $link = "/info-sheet/?user="******"\r\n"; wp_mail($admin_email, $subject, $body, $headers); } }
function openfire_authenticate($user, $username, $password) { global $openfire; $openfire->of_logInfo("openfire_authenticate 1 " . $username . " " . $password); if (!openfire_wants_to_login()) { return new WP_Error('user_logged_out', sprintf(__('You are now logged out of Azure AD.', AADSSO), $username)); } // Don't re-authenticate if already authenticated if (strrpos($username, "@") == false || is_a($user, 'WP_User')) { return $user; } $openfire->of_logInfo("openfire_authenticate 2 "); // Try to find an existing user in WP where the UPN of the current AAD user is // (depending on config) the 'login' or 'email' field if ($username && $password && $openfire->of_authenticate_365($username, $password)) { $user = get_user_by("email", $username); if (!is_a($user, 'WP_User')) { $openfire->of_logInfo("openfire_authenticate 3"); // Since the user was authenticated with AAD, but not found in WordPress, // need to decide whether to create a new user in WP on-the-fly, or to stop here. $openfire->of_logInfo("openfire_authenticate 4"); $paras = explode("@", $username); $userid = $paras[0] . "." . $paras[1]; $new_user_id = wp_create_user($userid, $password, $username); $user = new WP_User($new_user_id); $user->set_role('subscriber'); $first_name = $openfire->of_get_given_name(); $last_name = $openfire->get_family_name(); $display_name = $first_name . " " . $last_name; wp_update_user(array('ID' => $new_user_id, 'display_name' => $display_name, 'first_name' => $first_name, 'last_name' => $last_name)); } } return $user; }
/** * Updates user data * * @return (array) */ public function update_user($user_id) { $input = $this->input(); $user['ID'] = $user_id; if (!(defined('IS_WPCOM') && IS_WPCOM)) { foreach ($input as $key => $value) { if (!is_array($value)) { $value = trim($value); } $value = wp_unslash($value); switch ($key) { case 'first_name': case 'last_name': $user[$key] = $value; break; case 'display_name': case 'name': $user['display_name'] = $value; break; } } } if (isset($input['roles'])) { if (is_array($input['roles'])) { $user['role'] = $input['roles'][0]; } else { $user['role'] = $input['roles']; } } $result = wp_update_user($user); if (is_wp_error($result)) { return $result; } return $this->get_user($user_id); }
/** * Process change profile form * * @access public * @return void */ public static function process_change_profile_form() { if (!isset($_POST['change_profile_form'])) { return; } $user = wp_get_current_user(); $nickname = $_POST['nickname']; $email = $_POST['email']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; if (empty($nickname)) { $_SESSION['messages'][] = array('warning', __('Nickname is required.', 'realia')); return; } if (empty($email)) { $_SESSION['messages'][] = array('warning', __('E-mail is required.', 'realia')); return; } update_user_meta($user->ID, 'nickname', $nickname); update_user_meta($user->ID, 'user_email', $email); wp_update_user(array('ID' => $user->ID, 'user_email' => $email)); update_user_meta($user->ID, 'last_name', $last_name); update_user_meta($user->ID, 'first_name', $first_name); $_SESSION['messages'][] = array('success', __('Profile has been successfully updated.', 'realia')); }
private function scramble_password() { if ($this->options['scramble_passwords'] && $this->new_user == false) { $this->user->user_pass = wp_hash_password(wp_generate_password(12, true, true)); wp_update_user($user); } }
/** * Authenticates the user using SAML * * @return void */ public function authenticate() { if (isset($_GET['loggedout']) && $_GET['loggedout'] == 'true') { header('Location: ' . get_option('siteurl')); exit; } elseif ($this->settings->get_allow_sso_bypass() == true && (isset($_GET['use_sso']) && $_GET['use_sso'] == 'false' || isset($_POST['use_sso']) && $_POST['use_sso'] == 'false')) { // User wants native WP login, do nothing } else { $redirect_url = array_key_exists('redirect_to', $_GET) ? wp_login_url($_GET['redirect_to']) : get_admin_url(); $this->saml->requireAuth(array('ReturnTo' => $redirect_url)); $attrs = $this->saml->getAttributes(); if (array_key_exists($this->settings->get_attribute('username'), $attrs) && array_key_exists($this->settings->get_attribute('email'), $attrs)) { $username = $attrs[$this->settings->get_attribute('username')][0]; $email = $attrs[$this->settings->get_attribute('email')][0]; if (get_user_by('login', $username)) { //$this->simulate_signon($username); // FIX https://wordpress.org/support/topic/passwords-of-existing-users-not-working-how-to-update#post-6835783 require_once ABSPATH . WPINC . '/ms-functions.php'; $user = get_user_by('login', $username); if ($user) { $newpass = $this->user_password($username, $this->secretsauce); wp_set_password($newpass, $user->ID); wp_update_user(array('ID' => $user->ID, 'user_email' => $email)); } $this->simulate_signon($username); } else { $this->new_user($attrs); } } else { die('A username and email was not provided. ' . $this->support_message); } } }
/** * @Given /^Users exist:$/ */ public function usersExist(TableNode $table) { $usersData = $table->getHash(); add_filter('send_password_change_email', '__return_false'); add_filter('send_email_change_email', '__return_false'); foreach ($usersData as $userData) { if (empty($userData['login'])) { throw new \InvalidArgumentException('You must provide a user login!'); } $user = get_user_by('login', $userData['login']); $data = $this->getUserDataFromTable($userData); if ($user) { $data['ID'] = $user->ID; } $result = $user ? wp_update_user($data) : wp_insert_user($data); if (is_wp_error($result)) { throw new \UnexpectedValueException('User could not be created: ' . $result->get_error_message()); } foreach ($this->getUserMetaDataFromTable($userData) as $key => $value) { update_user_meta($user->ID, $key, $value); } } remove_filter('send_password_change_email', '__return_false'); remove_filter('send_email_change_email', '__return_false'); }
/** * Register the default color schmea for every new registered user * * @param int $userId the user id */ public function registerDefaultColorSchema($userId) { $setting = $this->getOptions(); if ($setting['default']) { wp_update_user(array('ID' => $userId, 'admin_color' => $setting['default'])); } }
static function updateProfileInformation($data) { global $_js_helper; $success = 0; if (!$_js_helper->is_logged()) { return false; } $args = wp_parse_args($data, array()); if ($args['edit_task'] && $args['edit_task'] == 'change_password') { $current_user = JS_Helper::get_current_js_user(); if (!wp_check_password($args['old_pass'], $current_user->user_pass, $current_user->ID)) { return -2; } } $meta_data = $args['meta']; unset($args['meta']); if (!is_wp_error(wp_update_user($args))) { $success++; } if ($meta_data) { foreach ($meta_data as $meta_key => $meta_value) { $success += update_user_meta($args['ID'], $meta_key, $meta_value) ? 1 : 0; } } return strval($success); }
public function run_update_method($token = null) { $response = new OAuth2\Response(); if (!isset($token['user_id']) || $token['user_id'] == 0) { $response->setError(400, 'invalid_request', 'Missing or invalid access token'); $response->send(); exit; } $user_id =& $token['user_id']; if (!current_user_can('edit_user', $user_id)) { $response->setError(400, 'invalid_request', 'You are not allowed to edit this user'); $response->send(); exit; } $user_id = wp_update_user(array('ID' => $user_id, 'display_name' => sanitize_text_field($_POST['name']))); if (is_wp_error($user_id)) { // There was an error, probably that user doesn't exist. $response->setError(400, 'invalid_request', 'There was an error updating me'); $response->send(); exit; } else { $return = array('success' => 'updated-me'); $response = new OAuth2\Response($return); $response->send(); exit; } }
public function update_field_value($object_id, $field_id, $value) { if (!in_array($field_id, self::$VALID_FIELDS)) { return; } wp_update_user(array('ID' => $object_id, $field_id => $value)); }
function rcl_confirm_user_registration() { global $wpdb, $rcl_options; $reglogin = $_GET['rglogin']; $regpass = $_GET['rgpass']; $regcode = md5($reglogin); if ($regcode == $_GET['rgcode']) { if ($user = get_user_by('login', $reglogin)) { wp_update_user(array('ID' => $user->ID, 'role' => get_option('default_role'))); $time_action = current_time('mysql'); $action = $wpdb->get_var($wpdb->prepare("SELECT time_action FROM " . RCL_PREF . "user_action WHERE user = '******'", $user->ID)); if (!$action) { $wpdb->insert(RCL_PREF . 'user_action', array('user' => $user->ID, 'time_action' => $time_action)); } $creds = array(); $creds['user_login'] = $reglogin; $creds['user_password'] = $regpass; $creds['remember'] = true; $sign = wp_signon($creds, false); if (!is_wp_error($sign)) { rcl_update_timeaction_user(); do_action('rcl_confirm_registration', $user->ID); wp_redirect(rcl_get_authorize_url($user->ID)); exit; } } } if ($rcl_options['login_form_recall'] == 2) { wp_safe_redirect('wp-login.php?checkemail=confirm'); } else { wp_redirect(get_bloginfo('wpurl') . '?action-rcl=login&error=confirm'); } exit; }
/** * Sets the user password */ function palo_action_register($user_id) { $userdata = array(); $userdata['ID'] = $user_id; $userdata['user_pass'] = $_POST['palo_password']; wp_update_user($userdata); }
function validate_form_saved($fields) { if (isset($_POST['submit'])) { $current_user = wp_get_current_user(); $user_email = $_POST['user_email']; // receiving email address //Si cambio de usuario y existe es error y no continua if ($current_user->user_email != $_POST['user_email'] && username_exists($user_email) != false) { ?> <script> jQuery(document).on('ready', function(){ jQuery("#emailErr").html("Intenta con otro email, este ya está registrado"); jQuery("#emailErr").show(); }); </script> <?php return; } //Actualiza los daos basicos $current_user->user_email = $user_email; $current_user->user_login = $user_email; $current_user->first_name = $_POST['user_first_name']; wp_update_user($current_user); //Recorre todos los campos del formulario y valida foreach ($fields as $field) { $keyfield = sanitize_key($field->Name) . "_" . $field->Id; update_user_meta($current_user->ID, sanitize_key($field->Name), $_POST[$keyfield], $current_user->get(sanitize_key($field->Name))); } } }
function acxu_createUser($args) { global $wp_xmlrpc_server; $wp_xmlrpc_server->escape($args); $nickname = $args[0]; //$password = $args[1]; //if ( ! $user = $wp_xmlrpc_server->login( $username, $password ) ) // return $wp_xmlrpc_server->error; $user_name = time() . "_" . rand(1000, 9999); $user_email = $user_name . "@bbuser.org"; if (!username_exists($user_name) && !email_exists($user_email)) { $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false); $user_id = wp_create_user($user_name, $random_password, $user_email); if ($nickname == "") { $nickname = $user_email; } // Update the user to set the nickname wp_update_user(array('ID' => $user_id, 'nickname' => $nickname)); // Get the user object to set the user's role $wp_user_object = new WP_User($user_id); //http://en.support.wordpress.com/user-roles/ $wp_user_object->set_role('author'); return $user_name . " " . $random_password; } else { return "ERROR: User Name or Email Already Exists"; } }
function set_default_admin_color($user_id) { $default_color = ub_get_option('ucs_default_color_scheme', false); if ($default_color && $default_color !== 'false') { $args = array('ID' => $user_id, 'admin_color' => $default_color); wp_update_user($args); } }
function testUserWithoutFirstAndLastName() { $user_id = wp_insert_user(array('user_login' => 'lorem_ipsum', 'user_pass' => 'tmppass')); $this->assertEquals($this->getURI('lorem_ipsum'), Wordlift_User_Service::get_instance()->get_uri($user_id)); $update_user_id = wp_update_user(array('ID' => $user_id, 'user_login' => 'lorem_ipsum', 'user_pass' => 'tmppass', 'first_name' => 'Lorem', 'last_name' => 'Ipsum')); $this->assertEquals($update_user_id, $user_id); $this->assertEquals($this->getURI('lorem_ipsum'), Wordlift_User_Service::get_instance()->get_uri($user_id)); }
/** * Test the "get_student_name" method. */ public function testGetStudentName() { $edr_crt = Edr_Manager::get('edr_crt'); $student = get_user_by('id', 1); $this->assertEquals($student->display_name, $edr_crt->get_student_name($student)); wp_update_user(array('ID' => $student->ID, 'first_name' => 'FirstName', 'last_name' => 'LastName')); $this->assertEquals('FirstName LastName', $edr_crt->get_student_name($student)); }
/** * Update the user properties. * * @param array $userdata * @return \Themosis\User\User|\WP_Error */ public function update(array $userdata) { $userdata = array_merge($userdata, ['ID' => $this->ID]); $user = wp_update_user($userdata); if (is_wp_error($user)) { return $user; } return $this; }
function px_verify_view_registration_page() { global $errors; $http_post = 'POST' == $_SERVER['REQUEST_METHOD']; if ($http_post) { $action = $_POST['wp-submit']; $code = esc_attr($_POST['purchase_code']); $verify = px_verify_purchase($code); if ($action == 'Register') { if (!is_wp_error($verify)) { $user_login = $_POST['user_login']; $user_email = $_POST['user_email']; $errors = register_new_user($user_login, $user_email); if (!is_wp_error($errors)) { $user_id = $errors; $pxarr1 = px_verify_globals(1); $pxarr2 = px_verify_globals(2); $pxarr2 = array_keys($pxarr2); if ($verify['px_envato_item'] == $pxarr1['item1']) { wp_update_user(array('ID' => $user_id, 'role' => $pxarr2[0])); } else { if ($verify['px_envato_item'] == $pxarr1['item2']) { wp_update_user(array('ID' => $user_id, 'role' => $pxarr2[1])); } else { wp_update_user(array('ID' => $user_id, 'role' => 'bbp_blocked')); } } do_action('px_verifier_user_registration', $user_id, $verify); update_user_meta($user_id, 'px_envato_username', $verify['px_envato_username']); update_user_meta($user_id, 'px_envato_purchase_date', $verify['px_envato_purchase_date']); update_user_meta($user_id, 'px_envato_purchase_code', $verify['px_envato_purchase_code']); update_user_meta($user_id, 'px_envato_license', $verify['px_envato_license']); update_user_meta($user_id, 'px_envato_item', $verify['px_envato_item']); update_user_meta($user_id, 'px_envato_support_amount', $verify['px_envato_support_amount']); update_user_meta($user_id, 'px_envato_support_until', $verify['px_envato_support_until']); $redirect_to = 'wp-login.php?checkemail=registered'; wp_safe_redirect($redirect_to); exit; } else { px_verify_view_registration_form($errors, $verify); } } else { px_verify_view_verification_form($verify); } } elseif ($action == 'Verify') { if (!is_wp_error($verify)) { px_verify_view_registration_form($errors, $verify); } else { px_verify_view_verification_form($verify); } } } else { px_verify_view_verification_form(); } px_verify_custom_style(); exit; }
public static function user_register($user_id) { $std_nicename = $user_id + self::$prefix_number; $user = get_user_by('id', $user_id); if (isset($user->user_nicename) && $user->user_nicename == $std_nicename) { return; } wp_update_user(['ID' => $user_id, 'user_nicename' => $std_nicename]); }
public function drmc_register_extra_fields($user_id) { $fname = $this->ucname($_POST['first_name']); $lname = $this->ucname($_POST['last_name']); update_user_meta($user_id, 'drmc_department', $_POST['drmc_department']); update_user_meta($user_id, 'first_name', $fname); update_user_meta($user_id, 'last_name', $lname); wp_update_user(array(ID => $user_id, 'display_name' => $fname . ' ' . $lname)); }
public static function addUserToGroup($userId, $groupId) { // Get the user object. // todo: groupId should be rone name like 'administrator', 'editor' $new_role = $groupId; // update user role using wordpress function wp_update_user(array('ID' => $userId, 'role' => $new_role)); return true; }
public function test_programmatic_save_user() { $base = $this->_get_elements(); $base->add_user_form('test meta box'); $user_id = wp_create_user(rand_str(), rand_str(), '*****@*****.**'); wp_update_user(array('ID' => $user_id, 'role' => 'editor')); $user = new WP_User($user_id); $this->assertEquals(array('editor'), $user->roles); }
/** * Update the user properties. * * @param array $attributes * * @return bool|int */ public function update(array $attributes = []) { $attributes = array_merge($attributes, ['ID' => $this->ID]); if (is_wp_error(wp_update_user($attributes))) { return false; } $this->setRawAttributes($attributes, true); return true; }
/** * Simple update. */ public function update(&$object) { global $wpdb; $content_id = $object->get_id(); if ('user' === $this->meta_type) { wp_update_user(array('ID' => $customer_id, 'user_email' => $object->get_content())); } else { wp_update_post(array('ID' => $content_id, 'post_title' => $object->get_content())); } }
function myplugin_user_register($user_id) { $role = $_POST['role']; $user_id = wp_update_user(array('ID' => $user_id, 'role' => $role)); $customer = "customer"; if ($role == $customer) { // automatic approval for customer update_user_meta($user_id, 'wp-approve-user', true); } }
public function test_update_user_password_is_not_synced() { $this->server_event_storage->reset(); $new_password = '******'; wp_update_user(array('ID' => $this->user_id, 'user_pass' => $new_password)); $this->sender->do_sync(); // Don't sync the password changes since we don't track passwords $events = $this->server_event_storage->get_all_events(); $this->assertEmpty($events); }
/** * Save the author when the post is saved. * * @param int $post_id The ID of the post being saved. */ public function save($post_id) { if (!isset($_POST['myplugin_inner_custom_box_nonce'])) { return $post_id; } $nonce = $_POST['myplugin_inner_custom_box_nonce']; if (!wp_verify_nonce($nonce, 'myplugin_inner_custom_box')) { return $post_id; } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } else { if (!current_user_can('edit_post', $post_id)) { return $post_id; } } remove_action('save_post', array($this, 'save')); $firstName = sanitize_text_field($_POST['first_name']); $lastName = sanitize_text_field($_POST['last_name']); $classLevel = sanitize_text_field($_POST['class_level']); $email_address = sanitize_text_field($_POST['email_address']); $username = $firstName . "_" . $lastName; if (username_exists($username)) { $user_query = new WP_User_Query($username); if (!empty($user_query->results)) { foreach ($user_query->results as $user) { $userID = $user->ID; $user_check = get_userdata($userID); if ($username == $user_check->user_login && $email_address == $user_check->user_email) { $userdata = array('ID' => $userID, 'nickname' => $classLevel); $user_id = wp_update_user($userdata); if (!is_wp_error($user_id)) { $my_post = array('ID' => $post_id, 'post_author' => $userID); wp_update_post($my_post); } } } } } else { $userID = wp_create_user($username, "", $email_address); $userdata = array('ID' => $userID, 'first_name' => $firstName, 'last_name' => $lastName, 'nickname' => $classLevel, 'display_name' => $firstName . " " . $lastName); $user_id = wp_update_user($userdata); if (!is_wp_error($user_id)) { $my_post = array('ID' => $post_id, 'post_author' => $userID); wp_update_post($my_post); } } add_action('save_post', array($this, 'save')); }
function create_microweb() { global $_POST, $current_site, $current_user; if (!is_array($_POST['blog'])) { wp_die(__('Can’t create an empty site.')); } $blog = $_POST['blog']; $email = sanitize_email($blog['email']); $title = $blog['title']; $domain = $blog['domain']; if (empty($domain)) { print_r(__('Missing or invalid site address.')); } if (empty($email)) { print_r(__('Missing email address.')); } if (!is_email($email)) { print_r(__('Invalid email address.')); } if (is_subdomain_install()) { $newdomain = $domain . '.' . preg_replace('|^www\\.|', '', $current_site->domain); $path = $current_site->path; } else { $newdomain = $current_site->domain; $path = $current_site->path . $domain . '/'; } $password = '******'; $user_id = email_exists($email); if ($user_id) { $password = wp_generate_password(12, false); $user_id = wp_update_user(array("ID" => $user_id, "user_pass" => $password)); if (false == $user_id) { print_r(__('There was an error updating the user.')); } else { wp_new_user_notification($user_id, $password); } } $id = wpmu_create_blog($newdomain, $path, $title, $user_id, array('public' => 1), $current_site->id); if (!is_wp_error($id)) { update_user_meta($user_id, "agent-web", $path); if (!is_super_admin($user_id) && !get_user_option('primary_blog', $user_id)) { update_user_option($user_id, 'primary_blog', $id, true); } $content_mail = sprintf(__('New site created by %1$s Address: %2$s Name: %3$s'), $current_user->user_login, get_site_url($id), stripslashes($title)); wp_mail(get_site_option('admin_email'), sprintf(__('[%s] New Site Created'), $current_site->site_name), $content_mail, 'From: "Site Admin" <' . get_site_option('admin_email') . '>'); wpmu_welcome_notification($id, $user_id, $password, $title, array('public' => 1)); // wp_redirect( add_query_arg( array( 'update' => 'added', 'id' => $id ), 'site-new.php' ) ); // exit; } else { wp_die($id->get_error_message()); } }