/** * Installs the blog * * {@internal Missing Long Description}} * * @since 2.1.0 * * @param string $blog_title Blog title. * @param string $user_name User's username. * @param string $user_email User's email. * @param bool $public Whether blog is public. * @param string $deprecated Optional. Not used. * @param string $user_password Optional. User's chosen password. Will default to a random password. * @param string $language Optional. Language chosen. * @return array Array keys 'url', 'user_id', 'password', 'password_message'. */ function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '', $language = '') { if (!empty($deprecated)) { _deprecated_argument(__FUNCTION__, '2.6'); } wp_check_mysql_version(); wp_cache_flush(); make_db_current_silent(); populate_options(); populate_roles(); update_option('blogname', $blog_title); update_option('admin_email', $user_email); update_option('blog_public', $public); if ($language) { update_option('WPLANG', $language); } $guessurl = wp_guess_url(); update_option('siteurl', $guessurl); // If not a public blog, don't ping. if (!$public) { update_option('default_pingback_flag', 0); } /* * Create default user. If the user already exists, the user tables are * being shared among blogs. Just set the role in that case. */ $user_id = username_exists($user_name); $user_password = trim($user_password); $email_password = false; if (!$user_id && empty($user_password)) { $user_password = wp_generate_password(12, false); $message = __('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.'); $user_id = wp_create_user($user_name, $user_password, $user_email); update_user_option($user_id, 'default_password_nag', true, true); $email_password = true; } else { if (!$user_id) { // Password has been provided $message = '<em>' . __('Your chosen password.') . '</em>'; $user_id = wp_create_user($user_name, $user_password, $user_email); } else { $message = __('User already exists. Password inherited.'); } } $user = new WP_User($user_id); $user->set_role('administrator'); wp_install_defaults($user_id); flush_rewrite_rules(); wp_new_blog_notification($blog_title, $guessurl, $user_id, $email_password ? $user_password : __('The password you chose during the install.')); wp_cache_flush(); /** * Fires after a site is fully installed. * * @since 3.9.0 * * @param WP_User $user The site owner. */ do_action('wp_install', $user); return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message); }
function test_getMyGuardians() { // Survivor's guardian list should start empty. $this->assertEquals(array(), $this->plugin->getMyGuardians()); // After adding a guardian, which is a user that // must actually exist, then the current user's // guardian list should include that user. $this->plugin->addGuardian('sam'); $expected = array(get_userdata(username_exists('sam'))); $this->assertEquals($expected, $this->plugin->getMyGuardians()); // Adding the same guardian again should not result // in a duplicate guardian. $this->plugin->addGuardian('sam'); $this->assertEquals($expected, $this->plugin->getMyGuardians()); // Let's add another guardian for good measure. $this->plugin->addGuardian('john'); $expected = array_merge($expected, array(get_userdata(username_exists('john')))); $this->assertEquals($expected, $this->plugin->getMyGuardians()); // Removing a guardian should remove them from // the list of guardians retrieved. $this->plugin->removeGuardian('sam'); array_shift($expected); $this->assertEquals($expected, $this->plugin->getMyGuardians()); // 'john' should still be a guardian, as he was // added but not removed. $this->assertTrue($this->plugin->isMyGuardian('john')); // This means there should be 1 and only 1 guardian // in the list. $this->assertCount(1, $this->plugin->getMyGuardians()); }
function lls_authenticate($user, $username) { // 1. Get all active session for this user if (!username_exists($username) || !($user = get_user_by('login', $username))) { return null; } // will trigger WP default no username/password matched error // setup vars $max_sessions = 5; $max_oldest_allowed_session_hours = 4; $error_code = 'max_session_reached'; $error_message = "Maximum {$max_sessions} login sessions are allowed. Please contact site administrator."; $manager = WP_Session_Tokens::get_instance($user->ID); $sessions = $manager->get_all(); // 2. Count all active session $session_count = count($sessions); // 3. Return okay if active session less then $max_sessions if ($session_count < $max_sessions) { return $user; } $oldest_activity_session = lls_get_oldest_activity_session($sessions); // 4. If active sessions is equal to 5 then check if a session has no activity last 4 hours // 5. if oldest session have activity return error if ($session_count >= $max_sessions && !$oldest_activity_session || $session_count >= $max_sessions && $oldest_activity_session['last_activity'] + $max_oldest_allowed_session_hours * HOUR_IN_SECONDS > time()) { return new WP_Error($error_code, $error_message); } // 5. Oldest activity session doesn't have activity is given recent hours // destroy oldest active session and authenticate the user $verifier = lls_get_verifier_by_session($oldest_activity_session, $user->ID); lls_destroy_session($verifier, $user->ID); return $user; }
function wppb_check_username_value($message, $field, $request_data, $form_location) { global $wpdb; if ($field['required'] == 'Yes') { if (isset($request_data['username']) && trim($request_data['username']) == '' || $form_location == 'register' && !isset($request_data['username'])) { return wppb_required_field_error($field["field-title"]); } } if (!empty($request_data['username'])) { if ($form_location == 'register') { if (username_exists($request_data['username'])) { return __('This username already exists.', 'profile-builder') . '<br/>' . __('Please try a different one!', 'profile-builder'); } if (!validate_username($request_data['username'])) { return __('This username is invalid because it uses illegal characters.', 'profile-builder') . '<br/>' . __('Please enter a valid username.', 'profile-builder'); } } $wppb_generalSettings = get_option('wppb_general_settings'); if ($wppb_generalSettings['emailConfirmation'] == 'yes') { if (is_multisite() && $request_data['username'] != preg_replace('/\\s+/', '', $request_data['username'])) { return __('This username is invalid because it uses illegal characters.', 'profile-builder') . '<br/>' . __('Please enter a valid username.', 'profile-builder'); } $userSignup = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "signups WHERE user_login = %s", $request_data['username'])); if (!empty($userSignup)) { return __('This username is already reserved to be used soon.', 'profile-builder') . '<br/>' . __('Please try a different one!', 'profile-builder'); } } } return $message; }
function registration_validation($username, $password, $email) { global $reg_errors; $reg_errors = new WP_Error(); if (empty($username) || empty($password) || empty($email)) { $reg_errors->add('field', 'Required form field is missing'); } if (4 > strlen($username)) { $reg_errors->add('username_length', 'Username too short. At least 4 characters is required'); } if (username_exists($username)) { $reg_errors->add('user_name', 'Sorry, that username already exists!'); } if (!validate_username($username)) { $reg_errors->add('username_invalid', 'Sorry, the username you entered is not valid'); } if (5 > strlen($password)) { $reg_errors->add('password', 'Password length must be greater than 5'); } if (!is_email($email)) { $reg_errors->add('email_invalid', 'Email is not valid'); } if (email_exists($email)) { $reg_errors->add('email', 'Email Already in use'); } if (is_wp_error($reg_errors)) { foreach ($reg_errors->get_error_messages() as $error) { echo '<div>'; echo '<strong>ERROR</strong>:'; echo $error . '<br/>'; echo '</div>'; } } }
function checkauthor($author) { global $wpdb; //mtnames is an array with the names in the mt import file $pass = '******'; if (!in_array($author, $this->mtnames)) { //a new mt author name is found ++$this->j; $this->mtnames[$this->j] = $author; //add that new mt author name to an array $user_id = username_exists($this->newauthornames[$j]); //check if the new author name defined by the user is a pre-existing wp user if (!$user_id) { //banging my head against the desk now. if ($newauthornames[$this->j] == 'left_blank') { //check if the user does not want to change the authorname $user_id = wp_create_user($author, $pass); $this->newauthornames[$this->j] = $author; //now we have a name, in the place of left_blank. } else { $user_id = wp_create_user($this->newauthornames[$this->j], $pass); } } else { return $user_id; // return pre-existing wp username if it exists } } else { $key = array_search($author, $this->mtnames); //find the array key for $author in the $mtnames array $user_id = username_exists($this->newauthornames[$key]); //use that key to get the value of the author's name from $newauthornames } return $user_id; }
function confirm_email($user, $key) { require_once WPPR_PLUGIN_DIR . '/models/signup-model.php'; $model = new Signup_Model(); if (isset($_GET['key']) && !empty($_GET['key']) && isset($_GET['user']) && !empty($_GET['user'])) { //Sanitize keys $model->key = sanitize_key($_GET['key']); $model->user = sanitize_user($_GET['user']); $result = $model->validate_key(); if ($result !== false && !username_exists($model->user)) { $userdata = array($model->user, $model->user, $result['signup_password'], $result['signup_email'], $result['signup_date'], $model->user); //Transfer record from wp_signup table to wp_users $confirmed = $model->register_user($userdata); if ($confirmed) { // Notify admin of new registration //wp_new_user_notification( $result ); echo $this->redirect_on_success(); } else { echo $this->redirect_on_error(); } } else { echo $this->redirect_on_error(); } } }
function validate_signup() { require_once WPPR_PLUGIN_DIR . '/models/signup-model.php'; $model = new Signup_Model(); if (username_exists($this->username)) { return new WP_Error('username_unavailable', 'Username already taken'); } if (!validate_username($this->username)) { // invalid username return new WP_Error('username_invalid', 'Username is invalid'); } if (strlen($this->username) < 4) { return new WP_Error('username_length', 'Username too short. At least 4 characters is required'); } if (!is_email($this->email)) { return new WP_Error('email_invalid', 'Email is not valid'); } if (email_exists($this->email)) { return new WP_Error('email', 'Email is already in used.'); } if ($model->validate_email($this->email)) { return new WP_Error('email', 'You already used this email to signup. Please check your email for confirmation.'); } if (strlen($this->password) <= 5) { return new WP_Error('password_too_short', 'Password is too short.'); } }
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 wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '') { global $wp_rewrite; wp_check_mysql_version(); wp_cache_flush(); make_db_current_silent(); populate_options(); populate_roles(); update_option('blogname', $blog_title); update_option('admin_email', $user_email); update_option('blog_public', $public); $guessurl = wp_guess_url(); update_option('siteurl', $guessurl); // If not a public blog, don't ping. if (!$public) { update_option('default_pingback_flag', 0); } // Create default user. If the user already exists, the user tables are // being shared among blogs. Just set the role in that case. $user_id = username_exists($user_name); if (!$user_id) { $random_password = wp_generate_password(); $user_id = wp_create_user($user_name, $random_password, $user_email); } else { $random_password = __('User already exists. Password inherited.'); } $user = new WP_User($user_id); $user->set_role('administrator'); wp_install_defaults($user_id); $wp_rewrite->flush_rules(); wp_new_blog_notification($blog_title, $guessurl, $user_id, $random_password); wp_cache_flush(); return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $random_password); }
function um_submit_form_errors_hook_login($args) { global $ultimatemember; $is_email = false; $form_id = $args['form_id']; $mode = $args['mode']; if (isset($args['username']) && $args['username'] == '') { $ultimatemember->form->add_error('username', __('Please enter your username or email', 'ultimatemember')); } if (isset($args['user_login']) && $args['user_login'] == '') { $ultimatemember->form->add_error('user_login', __('Please enter your username', 'ultimatemember')); } if (isset($args['user_email']) && $args['user_email'] == '') { $ultimatemember->form->add_error('user_email', __('Please enter your email', 'ultimatemember')); } if (isset($args['username'])) { $field = 'username'; if (is_email($args['username'])) { $is_email = true; $data = get_user_by('email', $args['username']); $user_name = isset($data->user_login) ? $data->user_login : null; } else { $user_name = $args['username']; } } else { if (isset($args['user_email'])) { $field = 'user_email'; $is_email = true; $data = get_user_by('email', $args['user_email']); $user_name = isset($data->user_login) ? $data->user_login : null; } else { $field = 'user_login'; $user_name = $args['user_login']; } } if (!username_exists($user_name)) { if ($is_email) { $ultimatemember->form->add_error($field, __(' Sorry, we can\'t find an account with that email address', 'ultimatemember')); } else { $ultimatemember->form->add_error($field, __(' Sorry, we can\'t find an account with that username', 'ultimatemember')); } } else { if ($args['user_password'] == '') { $ultimatemember->form->add_error('user_password', __('Please enter your password', 'ultimatemember')); } } $user = get_user_by('login', $user_name); if ($user && wp_check_password($args['user_password'], $user->data->user_pass, $user->ID)) { $ultimatemember->login->auth_id = username_exists($user_name); } else { $ultimatemember->form->add_error('user_password', __('Password is incorrect. Please try again.', 'ultimatemember')); } // add a way for other plugins like wp limit login // to limit the login attempts $user = apply_filters('authenticate', null, $user_name, $args['user_password']); // if there is an error notify wp if ($ultimatemember->form->has_error($field) || $ultimatemember->form->has_error($user_password)) { do_action('wp_login_failed', $user_name); } }
/** * Processes credentials to pass into wp_signon to log a user into WordPress. * * @uses check_ajax_referer() * @uses wp_signon() * @uses is_wp_error() * * @param $user_login (string) Defaults to $_POST['user_login'] * @param $password (string) * @param $is_ajax (bool) Process as an AJAX request * @package AJAX * * @return userlogin on success; 0 on false; */ public function login_submit($user_login = null, $password = null, $is_ajax = true) { /** * Verify the AJAX request */ if ($is_ajax) { check_ajax_referer('login_submit', 'security'); } $username = empty($_POST['user_login']) ? $user_login : sanitize_text_field($_POST['user_login']); $password = empty($_POST['password']) ? $password : sanitize_text_field($_POST['password']); $remember = !empty($_POST['rememberme']) ? true : false; // Currently wp_signon returns the same error code 'invalid_username' if // a username does not exists or is invalid if (validate_username($username)) { if (username_exists($username)) { $creds = array('user_login' => $username, 'user_password' => $password, 'remember' => $remember); $user = wp_signon($creds, false); $status = is_wp_error($user) ? $this->status($user->get_error_code()) : $this->status('success_login'); } else { $status = $this->status('username_does_not_exists'); } } else { $status = $this->status('invalid_username'); } if ($is_ajax) { wp_send_json($status); } else { return $status; } }
/** * Searches through the content of an activity item to locate usernames, * designated by an @ sign. * * @since BuddyPress (1.5) * * @param string $content The content of the activity, usually found in $activity->content. * @return mixed Associative array with user ID as key and username as value. Boolean false if no mentions found. */ function bp_activity_find_mentions($content) { $pattern = '/[@]+([A-Za-z0-9-_\\.@]+)\\b/'; preg_match_all($pattern, $content, $usernames); // Make sure there's only one instance of each username if (!($usernames = array_unique($usernames[1]))) { return false; } $mentioned_users = array(); // We've found some mentions! Check to see if users exist foreach ((array) $usernames as $key => $username) { if (bp_is_username_compatibility_mode()) { $user_id = username_exists($username); } else { $user_id = bp_core_get_userid_from_nicename($username); } // user ID exists, so let's add it to our array if (!empty($user_id)) { $mentioned_users[$user_id] = $username; } } if (empty($mentioned_users)) { return false; } return $mentioned_users; }
public function test_add_a_guardian() { $guardian_id = username_exists('sam'); $this->plugin->addGuardian($guardian_id, get_current_user_id()); $this->assertTrue(in_array($guardian_id, get_user_meta(get_current_user_id(), 'better-angels_guardians'))); return $guardian_id; }
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"; } }
public function user_register() { global $wpdb; $data = $_POST; $login_data = array(); $resp = new ajax_response($data['action'], true); $code_data = $wpdb->get_results('SELECT * FROM ' . $wpdb->register_codes . ' WHERE 1=1 AND register_code == ' . $wpdb->escape($data['sec_code'])); if ($code_data->register_code_used == 0) { $username = $wpdb->escape($data['user_name']); $exists = username_exists($username); if (!$exists) { $user_id = wp_create_user($username, wp_generate_password($length = 12, $include_standard_special_chars = false), $username); wp_new_user_notification($user_id, null, true); if (!is_wp_error($user_id)) { $user = get_user_by('id', $user_id); $wpdb->update($wpdb->register_codes, array('register_code_used' => 1, 'register_code_used_by' => $user->data->user_login), array('register_code' => $wpdb->escape($data['sec_code']))); $resp->set_status(true); $resp->set_message($user->data->user_login . ' is successfully registered. Please switch to the login tab to login.'); } else { foreach ($user_id->errors as $k => $error) { $resp->set_message(array($error[0])); } } } else { $resp->set_message('User already exists. Please use a different email address.'); } } else { $resp->set_message('Security token not recognized. Could not register you without a valid security token.'); } echo $resp->encode_response(); die; }
function wp_install($blog_title, $user_name, $user_email, $public, $meta = '') { global $wp_rewrite; wp_check_mysql_version(); wp_cache_flush(); make_db_current_silent(); populate_options(); populate_roles(); update_option('blogname', $blog_title); update_option('admin_email', $user_email); update_option('blog_public', $public); $schema = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://'; $guessurl = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); update_option('siteurl', $guessurl); // If not a public blog, don't ping. if (!$public) { update_option('default_pingback_flag', 0); } // Create default user. If the user already exists, the user tables are // being shared among blogs. Just set the role in that case. $user_id = username_exists($user_name); if (!$user_id) { $random_password = substr(md5(uniqid(microtime())), 0, 6); $user_id = wp_create_user($user_name, $random_password, $user_email); } else { $random_password = __('User already exists. Password inherited.'); } $user = new WP_User($user_id); $user->set_role('administrator'); wp_install_defaults($user_id); $wp_rewrite->flush_rules(); wp_new_blog_notification($blog_title, $guessurl, $user_id, $random_password); wp_cache_flush(); return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $random_password); }
function user_login($username, $password) { $res_arr = array(); if (empty($username) || empty($password)) { $res_arr['errormsg'] = 'Required field is missing'; return $res_arr; //return $errors; } $user_id = username_exists($username); $user = user_pass_ok($username, $password); if (!empty($user_id)) { $user_data = get_userdata($user_id); if ($user == 1) { $res_arr['Id'] = $user_id; $res_arr['username'] = $username; return $res_arr; } else { $res_arr['errormsg'] = 'Invalid password'; return $res_arr; } } else { $res_arr['errormsg'] = 'Invalid username'; return $res_arr; } }
/** * Installs the blog * * {@internal Missing Long Description}} * * @since 2.1.0 * * @param string $blog_title Blog title. * @param string $user_name User's username. * @param string $user_email User's email. * @param bool $public Whether blog is public. * @param null $deprecated Optional. Not used. * @param string $user_password Optional. User's chosen password. Will default to a random password. * @return array Array keys 'url', 'user_id', 'password', 'password_message'. */ function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '') { if (!empty($deprecated)) { _deprecated_argument(__FUNCTION__, '2.6'); } wp_check_mysql_version(); wp_cache_flush(); make_db_current_silent(); if (!is_file(ABSPATH . 'wp-admin/install.sql')) { //[ysd]如果有install.sql不设置默认options数据 populate_options(); } else { validate_active_plugins(); //[ysd] 禁用 不可用的插件 } populate_roles(); update_option('blogname', $blog_title); update_option('admin_email', $user_email); update_option('blog_public', $public); $guessurl = isset($_SERVER['HTTP_APPNAME']) ? 'http://' . substr($_SERVER['HTTP_APPNAME'], 5) . '.1kapp.com' : wp_guess_url(); //[ysd] 固定了guessurl update_option('siteurl', $guessurl); update_option('home', $guessurl); get_option('siteurl'); // If not a public blog, don't ping. if (!$public) { update_option('default_pingback_flag', 0); } // Create default user. If the user already exists, the user tables are // being shared among blogs. Just set the role in that case. $user_id = username_exists($user_name); $user_password = trim($user_password); $email_password = false; if (!$user_id && empty($user_password)) { $user_password = wp_generate_password(12, false); $message = __('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.'); $user_id = wp_create_user($user_name, $user_password, $user_email); update_user_option($user_id, 'default_password_nag', true, true); $email_password = true; } else { if (!$user_id) { // Password has been provided $message = '<em>' . __('Your chosen password.') . '</em>'; $user_id = wp_create_user($user_name, $user_password, $user_email); } else { $message = __('User already exists. Password inherited.'); } } $user = new WP_User($user_id); $user->set_role('administrator'); if (!file_exists(ABSPATH . 'wp-admin/without_default')) { wp_install_defaults($user_id); } //[ysd],如果打包时设置了默认数据,才会设置默认数据 flush_rewrite_rules(); wp_new_blog_notification($blog_title, $guessurl, $user_id, $email_password ? $user_password : __('The password you chose during the install.')); wp_cache_flush(); return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message); }
public function adminLoggedIn($username) { if (!username_exists($username)) { return; } $userinfo = get_user_by('login', $username); $this->log->write('login', Metapod::getDateTime() . ' - ' . $userinfo->user_login); }
/** * Validate username field. * * @access public * @since 1.0.0 * @return void */ public static function validate_username($passed, $fields, $values) { $username = $values['user']['username_email']; if (is_email($username) && !email_exists($username) || !is_email($username) && !username_exists($username)) { return new WP_Error('username-validation-error', __('This user could not be found.', 'wpum')); } return $passed; }
/** * Function generate_unique_username */ function generate_unique_username($term_name, $count = '') { if (!username_exists($term_name . $count)) { return $term_name . $count; } $count = $count == '' ? 1 : absint($count) + 1; $this->generate_unique_username($term_name, $count); }
function aitAddNewClaim() { if (defined('AIT_SERVER')) { return 0; } if (!empty($_POST['itemId']) && !empty($_POST['username']) && !empty($_POST['name']) && !empty($_POST['email'])) { // check username and email if exist if (username_exists($_POST['username'])) { _e("This username is already registered. Please choose another one.", "ait"); exit; } if (email_exists($_POST['email'])) { _e("This email is already registered, please choose another one.", "ait"); exit; } global $aitThemeOptions; // Check for nonce security $nonce = $_POST['nonce']; if (!wp_verify_nonce($nonce, 'ajax-nonce')) { _e('Bad nonce', 'ait'); exit; } $claim = array('post_title' => $_POST['username'], 'post_content' => $_POST['message'], 'post_type' => 'ait-claim', 'post_status' => 'publish', 'comment_status' => 'closed', 'ping_status' => 'closed'); $claimId = wp_insert_post($claim); if ($claimId == 0) { return 0; } update_post_meta($claimId, 'item_id', $_POST['itemId']); update_post_meta($claimId, 'username', $_POST['username']); update_post_meta($claimId, 'name', $_POST['name']); update_post_meta($claimId, 'email', $_POST['email']); update_post_meta($claimId, 'number', $_POST['number']); update_post_meta($claimId, 'status', 'new'); // send email to admin if (isset($aitThemeOptions->directory->claimAdminEmail)) { $to = get_option('admin_email'); $subject = strip_tags($aitThemeOptions->directory->claimAdminEmailSubject); $postLink = get_permalink(intval($_POST['itemId'])); $post = get_post(intval($_POST['itemId'])); $bodyHtml = $aitThemeOptions->directory->claimAdminEmailBody; $bodyHtml = str_replace('[item]', '<a href="' . $postLink . '" target="_blank">' . $post->post_title . '</a>', $bodyHtml); $bodyHtml = str_replace('[name]', $_POST['name'], $bodyHtml); $bodyHtml = str_replace('[username]', $_POST['username'], $bodyHtml); $bodyHtml = str_replace('[email]', $_POST['email'], $bodyHtml); $bodyHtml = str_replace('[phone]', $_POST['number'], $bodyHtml); $bodyHtml = str_replace('[message]', $_POST['message'], $bodyHtml); $bodyHtml = str_replace('[link]', admin_url('/edit.php?post_type=ait-claim'), $bodyHtml); $headers = 'From: ' . $aitThemeOptions->directory->claimAdminEmailFrom . "\r\n"; add_filter('wp_mail_content_type', 'aitSetHtmlMail'); wp_mail($to, $subject, $bodyHtml, $headers); remove_filter('wp_mail_content_type', 'aitSetHtmlMail'); } echo "success"; } else { _e("Please fill out inputs", "ait"); } exit; }
/** * Changes Admin User * * Changes the username and id of the 1st user * * @param string $username the username to change if changing at the same time * @param bool $id whether to change the id as well * * @return bool success or failure * **/ private function change_admin_user($username = null, $id = false) { global $wpdb; $itsec_files = ITSEC_Core::get_itsec_files(); if ($itsec_files->get_file_lock('admin_user')) { //make sure it isn't already running //sanitize the username $new_user = sanitize_text_field($username); //Get the full user object $user_object = get_user_by('id', '1'); if (!is_null($username) && validate_username($new_user) && false === username_exists($new_user)) { //there is a valid username to change if ($id === true) { //we're changing the id too so we'll set the username $user_login = $new_user; } else { // we're only changing the username //query main user table $wpdb->query("UPDATE `" . $wpdb->users . "` SET user_login = '******' WHERE user_login='******';"); if (is_multisite()) { //process sitemeta if we're in a multi-site situation $oldAdmins = $wpdb->get_var("SELECT meta_value FROM `" . $wpdb->sitemeta . "` WHERE meta_key = 'site_admins'"); $newAdmins = str_replace('5:"admin"', strlen($new_user) . ':"' . esc_sql($new_user) . '"', $oldAdmins); $wpdb->query("UPDATE `" . $wpdb->sitemeta . "` SET meta_value = '" . esc_sql($newAdmins) . "' WHERE meta_key = 'site_admins'"); } $itsec_files->release_file_lock('admin_user'); return true; } } elseif ($username !== null) { //username didn't validate $itsec_files->release_file_lock('admin_user'); return false; } else { //only changing the id $user_login = $user_object->user_login; } if ($id === true) { //change the user id $wpdb->query("DELETE FROM `" . $wpdb->users . "` WHERE ID = 1;"); $wpdb->insert($wpdb->users, array('user_login' => $user_login, 'user_pass' => $user_object->user_pass, 'user_nicename' => $user_object->user_nicename, 'user_email' => $user_object->user_email, 'user_url' => $user_object->user_url, 'user_registered' => $user_object->user_registered, 'user_activation_key' => $user_object->user_activation_key, 'user_status' => $user_object->user_status, 'display_name' => $user_object->display_name)); if (is_multisite() && $username !== null && validate_username($new_user)) { //process sitemeta if we're in a multi-site situation $oldAdmins = $wpdb->get_var("SELECT meta_value FROM `" . $wpdb->sitemeta . "` WHERE meta_key = 'site_admins'"); $newAdmins = str_replace('5:"admin"', strlen($new_user) . ':"' . esc_sql($new_user) . '"', $oldAdmins); $wpdb->query("UPDATE `" . $wpdb->sitemeta . "` SET meta_value = '" . esc_sql($newAdmins) . "' WHERE meta_key = 'site_admins'"); } $new_user = $wpdb->insert_id; $wpdb->query("UPDATE `" . $wpdb->posts . "` SET post_author = '" . $new_user . "' WHERE post_author = 1;"); $wpdb->query("UPDATE `" . $wpdb->usermeta . "` SET user_id = '" . $new_user . "' WHERE user_id = 1;"); $wpdb->query("UPDATE `" . $wpdb->comments . "` SET user_id = '" . $new_user . "' WHERE user_id = 1;"); $wpdb->query("UPDATE `" . $wpdb->links . "` SET link_owner = '" . $new_user . "' WHERE link_owner = 1;"); $itsec_files->release_file_lock('admin_user'); return true; } } return false; }
public function registration($userdata) { $reg_errors = new WP_Error(); if (!isset($userdata) && empty($userdata) && !is_array($userdata)) { $reg_errors->add('data_invalid', 'Chybí vstupní data'); return $reg_errors; } $userLogin = array_key_exists('user_login', $userdata) ? sanitize_user($userdata['user_login']) : ''; $userPass = array_key_exists('user_pass', $userdata) ? esc_attr($userdata['user_pass']) : ''; $userEmail = array_key_exists('user_email', $userdata) ? sanitize_email($userdata['user_email']) : ''; $userUrl = array_key_exists('user_url', $userdata) ? esc_url($userdata['user_url']) : ''; $firstName = array_key_exists('first_name', $userdata) ? sanitize_text_field($userdata['first_name']) : ''; $lastName = array_key_exists('last_name', $userdata) ? sanitize_text_field($userdata['last_name']) : ''; $nickname = array_key_exists('nickname', $userdata) ? sanitize_text_field($userdata['nickname']) : ''; $description = array_key_exists('description', $userdata) ? sanitize_text_field($userdata['description']) : ''; if (empty($userLogin) || empty($userPass) || empty($userEmail)) { $reg_errors->add('field', 'Nejsou vyplnněny povinné pole formuláře.'); } if (4 > strlen($userLogin)) { $reg_errors->add('username_length', 'Příliš krátké uživatelské jméno. Zadejte minimálně 5 znaků.'); } if (username_exists($userLogin)) { $reg_errors->add('user_name', 'Je nám líto ale uživatelské jméno již existuje.'); } if (!validate_username($userLogin)) { $reg_errors->add('username_invalid', 'Neplatné uživatelské jméno.'); } if (5 > strlen($userPass)) { $reg_errors->add('password', 'Heslo musí obsahovat minimálně 6 znaků.'); } if (!is_email($userEmail)) { $reg_errors->add('email_invalid', 'Zadaný e-mail je ve špatném formátu.'); } if (email_exists($userEmail)) { $reg_errors->add('email', 'Zadaný e-mail již existuje.'); } if (!empty($userUrl)) { if (!filter_var($userUrl, FILTER_VALIDATE_URL)) { $reg_errors->add('website', 'Url adresa Vašich stránek není validní.'); } } if (is_wp_error($reg_errors) && count($reg_errors->errors) > 0) { return $reg_errors; } $_userdata = array('user_login' => $userLogin, 'user_email' => $userEmail, 'user_pass' => $userPass, 'user_url' => $userUrl, 'first_name' => $firstName, 'last_name' => $lastName, 'nickname' => $nickname, 'description' => $description, 'role' => 'customer'); $user_id = wp_insert_user($_userdata); if (is_wp_error($user_id)) { $reg_errors->add('insert_user', 'Registraci nelze dokončit. Kontaktujte prosím správce webu.'); return $reg_errors; } // Woocomerce data if (array_key_exists('billing_first_name', $userdata)) { add_user_meta($user_id, $meta_key, $meta_value, $unique); } $description = array_key_exists('description', $userdata) ? sanitize_text_field($userdata['description']) : ''; return $user_id; }
function username_check($title, $action) { if ($action == 'between') { if (!isset($_GET['with']) || !username_exists($_GET['with'])) { $title = "<div id='fep-error'>" . __("No Message found", 'fep') . "</div>"; } } return $title; }
/** * Process registration form submission * * @since 1.0 */ public function process_registration($data) { if (!isset($_POST['affwp_register_nonce']) || !wp_verify_nonce($_POST['affwp_register_nonce'], 'affwp-register-nonce')) { return; } do_action('affwp_pre_process_register_form'); if (!is_user_logged_in()) { // Loop through required fields and show error message foreach ($this->required_fields() as $field_name => $value) { if (empty($_POST[$field_name])) { $this->add_error($value['error_id'], $value['error_message']); } } if (username_exists($data['affwp_user_login'])) { $this->add_error('username_unavailable', __('Username already taken', 'affiliate-wp')); } if (!validate_username($data['affwp_user_login'])) { if (is_multisite()) { $this->add_error('username_invalid', __('Invalid username. Only lowercase letters (a-z) and numbers are allowed', 'affiliate-wp')); } else { $this->add_error('username_invalid', __('Invalid username', 'affiliate-wp')); } } if (email_exists($data['affwp_user_email'])) { $this->add_error('email_unavailable', __('Email address already taken', 'affiliate-wp')); } if (empty($data['affwp_user_email']) || !is_email($data['affwp_user_email'])) { $this->add_error('email_invalid', __('Invalid email', 'affiliate-wp')); } if (!empty($data['affwp_payment_email']) && $data['affwp_payment_email'] != $data['affwp_user_email'] && !is_email($data['affwp_payment_email'])) { $this->add_error('payment_email_invalid', __('Invalid payment email', 'affiliate-wp')); } if (!empty($_POST['affwp_user_pass']) && empty($_POST['affwp_user_pass2']) || $_POST['affwp_user_pass'] !== $_POST['affwp_user_pass2']) { $this->add_error('password_mismatch', __('Passwords do not match', 'affiliate-wp')); } } $terms_of_use = affiliate_wp()->settings->get('terms_of_use'); if (!empty($terms_of_use) && empty($_POST['affwp_tos'])) { $this->add_error('empty_tos', __('Please agree to our terms of use', 'affiliate-wp')); } if (!empty($_POST['affwp_honeypot'])) { $this->add_error('spam', __('Nice try honey bear, don\'t touch our honey', 'affiliate-wp')); } if (affwp_is_affiliate()) { $this->add_error('already_registered', __('You are already registered as an affiliate', 'affiliate-wp')); } do_action('affwp_process_register_form'); // only log the user in if there are no errors if (empty($this->errors)) { $this->register_user(); $redirect = apply_filters('affwp_register_redirect', $data['affwp_redirect']); if ($redirect) { wp_redirect($redirect); exit; } } }
protected function maybe_create($display_name, $role) { $slug = sanitize_title($display_name); $id = username_exists($slug); if (!$id || $id == null) { $id = $this->create($display_name, $role); } return $id; }
function um_add_user_frontend($args) { global $ultimatemember; unset($args['user_id']); extract($args); if (isset($username) && !isset($args['user_login'])) { $user_login = $username; } if (!empty($first_name) && !empty($last_name) && !isset($user_login)) { if (um_get_option('permalink_base') == 'name') { $user_login = rawurlencode(strtolower(str_replace(" ", ".", $first_name . " " . $last_name))); } else { if (um_get_option('permalink_base') == 'name_dash') { $user_login = rawurlencode(strtolower(str_replace(" ", "-", $first_name . " " . $last_name))); } else { if (um_get_option('permalink_base') == 'name_plus') { $user_login = strtolower(str_replace(" ", "+", $first_name . " " . $last_name)); } else { $user_login = strtolower(str_replace(" ", "", $first_name . " " . $last_name)); } } } // if full name exists $count = 1; while (username_exists($user_login)) { $user_login .= $count; $count++; } } if (!isset($user_login) && isset($user_email) && $user_email) { $user_login = $user_email; } $unique_userID = $ultimatemember->query->count_users() + 1; if (!isset($user_login)) { $user_login = '******' . $unique_userID; } if (isset($username) && is_email($username)) { $user_email = $username; } if (!isset($user_password)) { $user_password = $ultimatemember->validation->generate(8); } if (!isset($user_email)) { $user_email = 'nobody' . $unique_userID . '@' . get_bloginfo('name'); } $creds['user_login'] = $user_login; $creds['user_password'] = $user_password; $creds['user_email'] = $user_email; $args['submitted'] = array_merge($args['submitted'], $creds); $args = array_merge($args, $creds); unset($args['user_id']); do_action('um_before_new_user_register', $args); $user_id = wp_create_user($user_login, $user_password, $user_email); do_action('um_after_new_user_register', $user_id, $args); return $user_id; }
public function check_username() { $username = sanitize_text_field($_POST['username']); if (username_exists($username)) { echo 'false'; } else { echo 'true'; } die; }