本文整理汇总了PHP中sanitize_user_field函数的典型用法代码示例。如果您正苦于以下问题:PHP sanitize_user_field函数的具体用法?PHP sanitize_user_field怎么用?PHP sanitize_user_field使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sanitize_user_field函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sanitize_user_object
/**
* Sanitize every user field.
*
* If the context is 'raw', then the user object or array will get minimal santization of the int fields.
*
* @since 2.3.0
* @deprecated 3.3.0
*
* @param object|array $user The User Object or Array
* @param string $context Optional, default is 'display'. How to sanitize user fields.
* @return object|array The now sanitized User Object or Array (will be the same type as $user)
*/
function sanitize_user_object($user, $context = 'display')
{
_deprecated_function(__FUNCTION__, '3.3');
if (is_object($user)) {
if (!isset($user->ID)) {
$user->ID = 0;
}
if (!is_a($user, 'WP_User')) {
$vars = get_object_vars($user);
foreach (array_keys($vars) as $field) {
if (is_string($user->{$field}) || is_numeric($user->{$field})) {
$user->{$field} = sanitize_user_field($field, $user->{$field}, $user->ID, $context);
}
}
}
$user->filter = $context;
} else {
if (!isset($user['ID'])) {
$user['ID'] = 0;
}
foreach (array_keys($user) as $field) {
$user[$field] = sanitize_user_field($field, $user[$field], $user['ID'], $context);
}
$user['filter'] = $context;
}
return $user;
}
示例2: sanitize_user_object
/**
* Sanitize every user field.
*
* If the context is 'raw', then the user object or array will get minimal santization of the int fields.
*
* @since 2.3.0
* @uses sanitize_user_field() Used to sanitize the fields.
*
* @param object|array $user The User Object or Array
* @param string $context Optional, default is 'display'. How to sanitize user fields.
* @return object|array The now sanitized User Object or Array (will be the same type as $user)
*/
function sanitize_user_object($user, $context = 'display')
{
if (is_object($user)) {
if (!isset($user->ID)) {
$user->ID = 0;
}
if (isset($user->data)) {
$vars = get_object_vars($user->data);
} else {
$vars = get_object_vars($user);
}
foreach (array_keys($vars) as $field) {
if (is_string($user->{$field}) || is_numeric($user->{$field})) {
$user->{$field} = sanitize_user_field($field, $user->{$field}, $user->ID, $context);
}
}
$user->filter = $context;
} else {
if (!isset($user['ID'])) {
$user['ID'] = 0;
}
foreach (array_keys($user) as $field) {
$user[$field] = sanitize_user_field($field, $user[$field], $user['ID'], $context);
}
$user['filter'] = $context;
}
return $user;
}
示例3: __get
/**
* Magic method for accessing custom fields
*
* @since 3.3.0
*/
function __get($key)
{
if ('id' == $key) {
_deprecated_argument('WP_User->id', '2.1', __('Use <code>WP_User->ID</code> instead.'));
return $this->ID;
}
if (isset($this->data->{$key})) {
$value = $this->data->{$key};
} else {
if (isset(self::$back_compat_keys[$key])) {
$key = self::$back_compat_keys[$key];
}
$value = get_user_meta($this->ID, $key, true);
}
if ($this->filter) {
$value = sanitize_user_field($key, $value, $this->ID, $this->filter);
}
return $value;
}
示例4: render_form
/**
* Registration form.
*
* @see Affiliates_Registration::$defaults for accepted parameters
*
* @param array $options form options
* @return string rendered registration form
*/
public static function render_form($options = array())
{
wp_enqueue_style('affiliates');
self::$submit_button_label = __('Sign Up', AFFILIATES_PLUGIN_DOMAIN);
$output = '';
//
// Existing affiliate
//
if ($is_affiliate = affiliates_user_is_affiliate()) {
$output .= '<div class="affiliates-registration registered">';
$output .= '<p>';
$output .= __('You are already registered as an affiliate.', AFFILIATES_PLUGIN_DOMAIN);
$output .= '</p>';
if (isset($options['registered_profile_link_url'])) {
$output .= '<p>';
$output .= '<a href="' . esc_url($options['registered_profile_link_url']) . '">';
if (isset($options['registered_profile_link_text'])) {
$output .= wp_filter_kses($options['registered_profile_link_text']);
} else {
$output .= __('Access your profile', AFFILIATES_PLUGIN_DOMAIN);
}
$output .= '</a>';
$output .= '</p>';
}
$output .= '</div>';
return $output;
}
//
// Registration closed
//
if (!get_option('aff_registration', get_option('users_can_register', false))) {
$output .= '<p>' . __('Registration is currently closed.', AFFILIATES_PLUGIN_DOMAIN) . '</p>';
return $output;
}
require_once AFFILIATES_CORE_LIB . '/class-affiliates-settings.php';
require_once AFFILIATES_CORE_LIB . '/class-affiliates-settings-registration.php';
$registration_fields = Affiliates_Settings_Registration::get_fields();
//
// Gather user info
//
$user = null;
if ($is_logged_in = is_user_logged_in()) {
$user = wp_get_current_user();
if (isset($registration_fields['first_name']) && $registration_fields['first_name']['enabled']) {
$first_name = $user->first_name;
$first_name = sanitize_user_field('first_name', $first_name, $user->ID, 'display');
$registration_fields['first_name']['value'] = $first_name;
}
if (isset($registration_fields['last_name']) && $registration_fields['last_name']['enabled']) {
$last_name = $user->last_name;
$last_name = sanitize_user_field('last_name', $last_name, $user->ID, 'display');
$registration_fields['last_name']['value'] = $last_name;
}
if (isset($registration_fields['user_login']) && $registration_fields['user_login']['enabled']) {
$user_login = $user->user_login;
$user_login = sanitize_user_field('user_login', $user_login, $user->ID, 'display');
$registration_fields['user_login']['value'] = $user_login;
}
if (isset($registration_fields['user_email']) && $registration_fields['user_email']['enabled']) {
$user_email = $user->user_email;
$user_email = sanitize_user_field('email', $user_email, $user->ID, 'display');
$registration_fields['user_email']['value'] = $user_email;
}
if (isset($registration_fields['user_url']) && $registration_fields['user_url']['enabled']) {
$url = $user->user_url;
$url = sanitize_user_field('user_url', $url, $user->ID, 'display');
$registration_fields['user_url']['value'] = $url;
}
}
$submit_name = 'affiliates-registration-submit';
$nonce = 'affiliates-registration-nonce';
$nonce_action = 'affiliates-registration';
$send = false;
$captcha = '';
$error = false;
if (!empty($_POST[$submit_name])) {
if (!wp_verify_nonce($_POST[$nonce], $nonce_action)) {
$error = true;
// fail but don't give clues
}
$captcha = !empty($_POST[Affiliates_Utility::get_captcha_field_id()]) ? $_POST[Affiliates_Utility::get_captcha_field_id()] : null;
if (!Affiliates_Utility::captcha_validates($captcha)) {
$error = true;
// dumbot
}
// gather field values
foreach ($registration_fields as $name => $field) {
if ($field['enabled']) {
$value = isset($_POST[$name]) ? $_POST[$name] : '';
$value = Affiliates_Utility::filter($value);
if ($field['required'] && empty($value)) {
$error = true;
//.........这里部分代码省略.........
示例5: __get
/**
* Magic method for accessing custom fields.
*
* @since 3.3.0
* @access public
*
* @param string $key User meta key to retrieve.
* @return mixed Value of the given user meta key (if set). If `$key` is 'id', the user ID.
*/
public function __get( $key ) {
if ( 'id' == $key ) {
_deprecated_argument( 'WP_User->id', '2.1.0',
sprintf(
/* translators: %s: WP_User->ID */
__( 'Use %s instead.' ),
'<code>WP_User->ID</code>'
)
);
return $this->ID;
}
if ( isset( $this->data->$key ) ) {
$value = $this->data->$key;
} else {
if ( isset( self::$back_compat_keys[ $key ] ) )
$key = self::$back_compat_keys[ $key ];
$value = get_user_meta( $this->ID, $key, true );
}
if ( $this->filter ) {
$value = sanitize_user_field( $key, $value, $this->ID, $this->filter );
}
return $value;
}
示例6: render_form
/**
* Fields:
*
* - first_name
* - last_name
* - user_login
* - email
* - url
*
* first name + last name => affiliate name
*
* Form options :
* - terms_post_id
* - redirect_to
* - is_widget
*
* @param array $options form options
* @return string rendered registration form
*/
static function render_form($options = array())
{
$output = '';
$ext = '';
// currently not relevant
if ($is_logged_in = is_user_logged_in()) {
$user = wp_get_current_user();
// sanitize_user_object is deprecated in WP 3.3 beta3
//$user = sanitize_user_object( $user );
$first_name = $user->first_name;
$first_name = sanitize_user_field('first_name', $first_name, $user->ID, 'display');
$last_name = $user->last_name;
$last_name = sanitize_user_field('last_name', $last_name, $user->ID, 'display');
$user_login = $user->user_login;
$user_login = sanitize_user_field('user_login', $user_login, $user->ID, 'display');
$email = $user->user_email;
$email = sanitize_user_field('email', $email, $user->ID, 'display');
$url = $user->user_url;
$url = sanitize_user_field('user_url', $url, $user->ID, 'display');
} else {
$user = null;
}
if ($is_affiliate = affiliates_user_is_affiliate()) {
$output .= '<div class="affiliates-registration registered">';
$output .= '<p>';
$output .= __('You are already registered as an affiliate.', AFFILIATES_PLUGIN_DOMAIN);
$output .= '</p>';
if (isset($options['registered_profile_link_url'])) {
$output .= '<p>';
$output .= '<a href="' . esc_url($options['registered_profile_link_url']) . '">';
if (isset($options['registered_profile_link_text'])) {
$output .= wp_filter_kses($options['registered_profile_link_text']);
} else {
$output .= __('Access your profile', AFFILIATES_PLUGIN_DOMAIN);
}
$output .= '</a>';
$output .= '</p>';
}
$output .= '</div>';
return $output;
}
if (!get_option('aff_registration', get_option('users_can_register', false))) {
$output .= '<p>' . __('Registration is currently closed.', AFFILIATES_PLUGIN_DOMAIN) . '</p>';
return $output;
}
$method = 'post';
$action = "";
$submit_name = 'affiliates-registration-submit';
$nonce = 'affiliates-registration-nonce';
$nonce_action = 'affiliates-registration';
$send = false;
$first_name_class = ' class="required" ';
$last_name_class = ' class="required" ';
$user_login_class = ' class="required" ';
$email_class = ' class="required" ';
$url_class = '';
if (isset($options['terms_post_id'])) {
$terms_post = get_post($options['terms_post_id']);
if ($terms_post) {
$terms_post_link = '<a target="_blank" href="' . esc_url(get_permalink($terms_post->ID)) . '">' . get_the_title($terms_post->ID) . '</a>';
$terms = sprintf(__('By signing up, you indicate that you have read and agree to the %s.', AFFILIATES_PLUGIN_DOMAIN), $terms_post_link);
}
}
$captcha = '';
$error = false;
if (!empty($_POST[$submit_name])) {
if (!wp_verify_nonce($_POST[$nonce], $nonce_action)) {
$error = true;
// fail but don't give clues
}
$captcha = $_POST[Affiliates_Utility::get_captcha_field_id()];
if (!Affiliates_Utility::captcha_validates($captcha)) {
$error = true;
// dumbot
}
if (!$is_logged_in) {
$first_name = isset($_POST['first_name']) ? Affiliates_Utility::filter($_POST['first_name']) : '';
$last_name = isset($_POST['last_name']) ? Affiliates_Utility::filter($_POST['last_name']) : '';
$user_login = isset($_POST['user_login']) ? Affiliates_Utility::filter($_POST['user_login']) : '';
$email = isset($_POST['email']) ? Affiliates_Utility::filter($_POST['email']) : '';
$url = isset($_POST['url']) ? Affiliates_Utility::filter($_POST['url']) : '';
//.........这里部分代码省略.........
示例7: sanitize_user_object
/**
* Sanitize every user field.
*
* If the context is 'raw', then the user object or array will get minimal santization of the int fields.
*
* @since 2.3.0
* @uses sanitize_user_field() Used to sanitize the fields.
*
* @param object|array $user The User Object or Array
* @param string $context Optional, default is 'display'. How to sanitize user fields.
* @return object|array The now sanitized User Object or Array (will be the same type as $user)
*/
function sanitize_user_object($user, $context = 'display') {
if ( is_object($user) ) {
if ( !isset($user->ID) )
$user->ID = 0;
if ( isset($user->data) )
$vars = get_object_vars( $user->data );
else
$vars = get_object_vars($user);
foreach ( array_keys($vars) as $field ) {
if ( is_array($user->$field) )
continue;
$user->$field = sanitize_user_field($field, $user->$field, $user->ID, $context);
}
$user->filter = $context;
} else {
if ( !isset($user['ID']) )
$user['ID'] = 0;
foreach ( array_keys($user) as $field )
$user[$field] = sanitize_user_field($field, $user[$field], $user['ID'], $context);
$user['filter'] = $context;
}
return $user;
}