本文整理汇总了PHP中sanitize_user函数的典型用法代码示例。如果您正苦于以下问题:PHP sanitize_user函数的具体用法?PHP sanitize_user怎么用?PHP sanitize_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sanitize_user函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wp_authenticate
/**
* Our wp_authenticate pluggable check the captcha.
*
* It also removed the strange default behaviour or not showing
* an error message when only the username is provided
*/
function wp_authenticate($username, $password)
{
global $palo_options, $palo_textdomain;
$username = sanitize_user($username);
$password = trim($password);
$captcha_challenge;
$captcha_answer;
$user = apply_filters('authenticate', null, $username, $password);
/**
* Do nothing if no post data have been provided
*/
if (empty($_POST)) {
return $user;
}
/**
* Force errors on missing username or password
*/
if ($username == null || $password == null) {
$user = new WP_Error('authentication_failed', __('<strong>ERROR</strong>: Invalid username or incorrect password.', $palo_textdomain));
}
if (!palo_captcha_test()) {
if (!empty($user) && is_wp_error($user)) {
$user->add('palo_captcha', '<strong>' . __('ERROR', $palo_textdomain) . '</strong>: ' . __($palo_options['palo_captcha_error_msg'], $palo_textdomain));
} else {
$user = new WP_Error('palo_captcha', '<strong>' . __('ERROR', $palo_textdomain) . '</strong>: ' . __($palo_options['palo_captcha_error_msg'], $palo_textdomain));
}
}
if (!empty($user) && is_wp_error($user)) {
do_action('wp_login_failed', $username);
}
return $user;
}
示例2: rcl_get_login_user
function rcl_get_login_user()
{
global $wp_errors;
$pass = sanitize_text_field($_POST['user_pass']);
$login = sanitize_user($_POST['user_login']);
$member = isset($_POST['rememberme']) ? intval($_POST['rememberme']) : 0;
$url = esc_url($_POST['redirect_to']);
$wp_errors = new WP_Error();
if (!$pass || !$login) {
$wp_errors->add('rcl_login_empty', __('Fill in the required fields!', 'wp-recall'));
return $wp_errors;
}
if ($user = get_user_by('login', $login)) {
$user_data = get_userdata($user->ID);
$roles = $user_data->roles;
$role = array_shift($roles);
if ($role == 'need-confirm') {
$wp_errors->add('rcl_login_confirm', __('Your email is not confirmed!', 'wp-recall'));
return $wp_errors;
}
}
$creds = array();
$creds['user_login'] = $login;
$creds['user_password'] = $pass;
$creds['remember'] = $member;
$user = wp_signon($creds, false);
if (is_wp_error($user)) {
$wp_errors = $user;
return $wp_errors;
} else {
rcl_update_timeaction_user();
wp_redirect(rcl_get_authorize_url($user->ID));
exit;
}
}
示例3: non_strict_login
function non_strict_login($username, $raw_username, $strict)
{
if (!$strict) {
return $username;
}
return sanitize_user(stripslashes($raw_username), false);
}
示例4: ajax_register
function ajax_register()
{
// First check the nonce, if it fails the function will break
check_ajax_referer('ajax-register-nonce', 'security');
// Nonce is checked, get the POST data and sign user on
$info = array();
$info['user_nicename'] = $info['nickname'] = $info['display_name'] = $info['first_name'] = $info['user_login'] = sanitize_user($_POST['username']);
$info['user_pass'] = sanitize_text_field($_POST['password']);
$info['user_email'] = sanitize_email($_POST['email']);
// Register the user
$user_register = wp_insert_user($info);
if (is_wp_error($user_register)) {
$error = $user_register->get_error_codes();
if (in_array('empty_user_login', $error)) {
echo json_encode(array('loggedin' => false, 'message' => __('Xin lỗi, thông tin đăng nhập không hợp lệ.')));
} else {
if (in_array('existing_user_login', $error)) {
echo json_encode(array('loggedin' => false, 'message' => __('Xin lỗi, tên đăng nhập này đã tồn tại.')));
} else {
if (in_array('existing_user_email', $error)) {
echo json_encode(array('loggedin' => false, 'message' => __('Xin lỗi, thư điện tử này đã tồn tại.')));
}
}
}
// else echo json_encode(array('loggedin'=>false, 'message'=>__($user_register->get_error_messages($error))));
} else {
wp_insert_user($info);
echo json_encode(array('loggedin' => true, 'message' => __('Đăng ký thành công.')));
}
die;
}
示例5: get_userdatabylogin
function get_userdatabylogin($user_login)
{
global $wpdb;
$user_login = sanitize_user($user_login);
if (empty($user_login)) {
return false;
}
$userdata = wp_cache_get($user_login, 'userlogins');
if ($userdata) {
return $userdata;
}
if (!($user = $wpdb->get_row("SELECT * FROM {$wpdb->users} WHERE user_login = '{$user_login}'"))) {
return false;
}
$wpdb->hide_errors();
$metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM {$wpdb->usermeta} WHERE user_id = '{$user->ID}'");
$wpdb->show_errors();
if ($metavalues) {
foreach ($metavalues as $meta) {
@($value = unserialize($meta->meta_value));
if ($value === FALSE) {
$value = $meta->meta_value;
}
$user->{$meta->meta_key} = $value;
// We need to set user_level from meta, not row
if ($wpdb->prefix . 'user_level' == $meta->meta_key) {
$user->user_level = $meta->meta_value;
}
}
}
wp_cache_add($user->ID, $user, 'users');
wp_cache_add($user->user_login, $user, 'userlogins');
return $user;
}
示例6: wp_login
function wp_login($username, $password, $already_md5 = false)
{
global $wpdb, $error;
$username = sanitize_user($username);
if ('' == $username) {
return false;
}
if ('' == $password) {
$error = __('<strong>ERROR</strong>: The password field is empty.');
return false;
}
$login = get_userdatabylogin($username);
//$login = $wpdb->get_row("SELECT ID, user_login, user_pass FROM $wpdb->users WHERE user_login = '$username'");
if (!$login) {
$error = __('<strong>ERROR</strong>: Invalid username.');
return false;
} else {
// If the password is already_md5, it has been double hashed.
// Otherwise, it is plain text.
if ($already_md5 && md5($login->user_pass) == $password || $login->user_login == $username && $login->user_pass == md5($password)) {
return true;
} else {
$error = __('<strong>ERROR</strong>: Incorrect password.');
$pwd = '';
return false;
}
}
}
示例7: wpmem_login
/**
* Logs in the user
*
* Logs in the the user using wp_signon (since 2.5.2). If login
* is successful, it redirects and exits; otherwise "loginfailed"
* is returned.
*
* @since 0.1
*
* @uses apply_filters Calls 'wpmem_login_redirect' hook to get $redirect_to
*
* @uses wp_signon
* @uses wp_redirect Redirects to $redirect_to if login is successful
* @return string Returns "loginfailed" if the login fails
*/
function wpmem_login()
{
if (isset($_POST['redirect_to'])) {
$redirect_to = $_POST['redirect_to'];
} else {
$redirect_to = $_SERVER['PHP_SELF'];
}
$redirect_to = apply_filters('wpmem_login_redirect', $redirect_to);
if (isset($_POST['rememberme']) == 'forever') {
$rememberme = true;
} else {
$rememberme = false;
}
if ($_POST['log'] && $_POST['pwd']) {
$user_login = sanitize_user($_POST['log']);
$user_login = wpmem_login_check_for_email($user_login);
$creds = array();
$creds['user_login'] = $user_login;
$creds['user_password'] = $_POST['pwd'];
$creds['remember'] = $rememberme;
$user = wp_signon($creds, false);
if (!is_wp_error($user)) {
if (!$using_cookie) {
wp_setcookie($user_login, $user_pass, false, '', '', $rememberme);
}
wp_redirect($redirect_to);
exit;
} else {
return "loginfailed";
}
} else {
//login failed
return "loginfailed";
}
}
示例8: register
/**
* Checks post data and registers user
* @return string
*/
function register()
{
if (!empty($_REQUEST['register_ajax_widget'])) {
$return = array();
if ('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_REQUEST['user_login']) && !empty($_REQUEST['user_email'])) {
//require_once( ABSPATH . WPINC . '/registration.php');
// todo - recaptcha
$errors = register_new_user($_POST['user_login'], $_POST['user_email']);
if (!is_wp_error($errors)) {
//Success
// do they have an envato id?
if (isset($_REQUEST['envato_purchase_code']) && !empty($_REQUEST['envato_purchase_code'])) {
// add this based on tc plugin.
}
$user_data = get_userdata($errors);
$return['result'] = true;
$return['message'] = __(sprintf('Thank you %s. Registration is complete. Please check your e-mail.', $user_data->user_login));
} else {
//Something's wrong
$return['result'] = false;
$return['error'] = $errors->get_error_message() . "<br>Username: " . htmlspecialchars(sanitize_user($_POST['user_login'], true));
}
}
$return = json_encode($return);
if (isset($_REQUEST['callback']) && preg_match("/^jQuery[_a-zA-Z0-9]+\$/", $_REQUEST['callback'])) {
$return = $_GET['callback'] . "({$return})";
}
echo $return;
exit;
}
}
示例9: get_tweets_from_api
private function get_tweets_from_api($username, $args)
{
if (!class_exists('TwitterOAuth')) {
//you need to reference the TwitterOAuth class for this to work
$this->error = 'The TwitterOAuth class cannot be found. Please include twitteroauth.php!';
return false;
}
$twitter_oauth = new TwitterOAuth($this->consumer_key, $this->consumer_secret, $this->access_key, $this->access_secret);
//setup params
$params = array();
$params['screen_name'] = strip_tags(sanitize_user($username));
if (array_key_exists('limit', $args)) {
$params['count'] = intval($args['limit']);
}
if (array_key_exists('include_rts', $args)) {
$params['include_rts'] = $args['include_rts'];
}
if (array_key_exists('exclude_replies', $args)) {
$params['exclude_replies'] = $args['exclude_replies'];
}
$response = $twitter_oauth->get('statuses/user_timeline', $params);
if (is_wp_error($response)) {
$this->error = $response->get_error_message();
return false;
} else {
if (isset($response->errors)) {
$this->error = $response->errors;
return false;
} else {
return $response;
}
}
}
示例10: wp_authenticate
/**
* Replace WordPress built-in authentication function
*
* Replaces WP authentication function to allow for logging
* login errors and removing messages if needed
*
* @param string $username user name
* @param string $password user submitted password
*
* @return object WordPress user object
*
*/
function wp_authenticate($username, $password)
{
global $bwps, $bwpsoptions;
//if away mode is currently restricting login return to homepage
if ($bwps->checkaway()) {
wp_redirect(get_option('siteurl'));
}
$username = sanitize_user($username);
$password = trim($password);
$user = apply_filters('authenticate', null, $username, $password);
//if they're locked out due to too many bad logins display an error
if ($bwpsoptions['ll_enabled'] == 1 && $bwps->checklock($username)) {
do_action('wp_login_failed', $username);
return new WP_Error('incorrect_password', __('<strong>ERROR</strong>: We are sorry , your ability to login has been suspended due to too many recent failed login attempts. Please try again later.', $bwps->hook));
}
//if there is no valud user object
if ($user == null) {
if ($bwpsoptions['ll_enabled'] == 1) {
$bwps->logevent('1');
}
$user = new WP_Error('authentication_failed', __('<strong>ERROR</strong>: Invalid username or incorrect password.'));
}
$ignore_codes = array('empty_username', 'empty_password');
//log if bad logins
if (isset($_POST['wp-submit']) && $bwpsoptions['ll_enabled'] == 1 && is_wp_error($user)) {
$bwps->logevent('1', $username);
} elseif (is_wp_error($user) && !in_array($user->get_error_code(), $ignore_codes)) {
if ($bwpsoptions['ll_enabled'] == 1) {
$bwps->logevent('1', $username);
}
do_action('wp_login_failed', $username);
}
return $user;
//returns user object or error message
}
示例11: get_username_or_die
public static function get_username_or_die($user_id)
{
$user_data = Resource_Booking_Ajax_Common::get_user_data_or_die($user_id);
$username = $user_data->display_name != "" ? $user_data->display_name . " (" . $user_data->user_email . ")" : $user_data->user_email;
$username = sanitize_user($username, true);
return $username;
}
示例12: wppb_userdata_add_username
function wppb_userdata_add_username($userdata, $global_request)
{
if (isset($global_request['username'])) {
$userdata['user_login'] = sanitize_user(trim($global_request['username']));
}
return $userdata;
}
示例13: wpsc_add_new_user
/**
* WPSC add new user function, validates and adds a new user, for the
*
* @since 3.7
*
* @param string $user_login The user's username.
* @param string $password The user's password.
* @param string $user_email The user's email (optional).
* @return int The new user's ID.
*/
function wpsc_add_new_user($user_login, $user_pass, $user_email)
{
$errors = new WP_Error();
$user_login = sanitize_user($user_login);
$user_email = apply_filters('user_registration_email', $user_email);
// Check the username
if ($user_login == '') {
$errors->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.', 'wpsc'));
} elseif (!validate_username($user_login)) {
$errors->add('invalid_username', __('<strong>ERROR</strong>: This username is invalid. Please enter a valid username.', 'wpsc'));
$user_login = '';
} elseif (username_exists($user_login)) {
$errors->add('username_exists', __('<strong>ERROR</strong>: This username is already registered, please choose another one.', 'wpsc'));
}
// Check the e-mail address
if ($user_email == '') {
$errors->add('empty_email', __('<strong>ERROR</strong>: Please type your e-mail address.', 'wpsc'));
} elseif (!is_email($user_email)) {
$errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn’t correct.', 'wpsc'));
$user_email = '';
} elseif (email_exists($user_email)) {
$errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.', 'wpsc'));
}
if ($errors->get_error_code()) {
return $errors;
}
$user_id = wp_create_user($user_login, $user_pass, $user_email);
if (!$user_id) {
$errors->add('registerfail', sprintf(__('<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'wpsc'), get_option('admin_email')));
return $errors;
}
$user = wp_signon(array('user_login' => $user_login, 'user_password' => $user_pass, 'remember' => true));
wp_set_current_user($user->ID);
return $user;
}
示例14: ajax_register
/**
* AJAX Register.
*
* @since 1.0.0
*/
public function ajax_register()
{
// First check the nonce, if it fails the function will break
check_ajax_referer('vr-ajax-register-nonce', 'vr-secure-register');
// Nonce is checked, Get to work
$info = array();
$info['user_nicename'] = $info['nickname'] = $info['display_name'] = $info['first_name'] = $info['user_login'] = sanitize_user($_POST['register_username']);
$info['user_pass'] = sanitize_text_field($_POST['register_pwd']);
$info['user_email'] = sanitize_email($_POST['register_email']);
// Register the user
$user_register = wp_insert_user($info);
if (is_wp_error($user_register)) {
$error = $user_register->get_error_codes();
if (in_array('empty_user_login', $error)) {
echo json_encode(array('success' => false, 'message' => __($user_register->get_error_message('empty_user_login'))));
} elseif (in_array('existing_user_login', $error)) {
echo json_encode(array('success' => false, 'message' => __('This username already exists.', 'VRC')));
} elseif (in_array('existing_user_email', $error)) {
echo json_encode(array('success' => false, 'message' => __('This email is already registered.', 'VRC')));
}
} else {
/**
* Object: VR_Member class.
*
* @since 1.0.0
*/
$vr_member_object = new VR_Member();
$vr_member_object->ajax_user_authenticate($info['user_login'], $info['user_pass'], __('Registration', 'VRC'));
}
die;
}
示例15: confirm_email
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();
}
}
}