Introduce WP_User::exists(). see #20372
git-svn-id: http://svn.automattic.com/wordpress/trunk@20378 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
f06fb15878
commit
de41bc288b
|
@ -742,7 +742,7 @@ function wp_ajax_replyto_comment( $action ) {
|
||||||
wp_die( __('ERROR: you are replying to a comment on a draft post.') );
|
wp_die( __('ERROR: you are replying to a comment on a draft post.') );
|
||||||
|
|
||||||
$user = wp_get_current_user();
|
$user = wp_get_current_user();
|
||||||
if ( $user->ID ) {
|
if ( $user->exists() ) {
|
||||||
$user_ID = $user->ID;
|
$user_ID = $user->ID;
|
||||||
$comment_author = $wpdb->escape($user->display_name);
|
$comment_author = $wpdb->escape($user->display_name);
|
||||||
$comment_author_email = $wpdb->escape($user->user_email);
|
$comment_author_email = $wpdb->escape($user->user_email);
|
||||||
|
|
|
@ -54,7 +54,7 @@ $comment_content = ( isset($_POST['comment']) ) ? trim($_POST['comment']) :
|
||||||
|
|
||||||
// If the user is logged in
|
// If the user is logged in
|
||||||
$user = wp_get_current_user();
|
$user = wp_get_current_user();
|
||||||
if ( $user->ID ) {
|
if ( $user->exists() ) {
|
||||||
if ( empty( $user->display_name ) )
|
if ( empty( $user->display_name ) )
|
||||||
$user->display_name=$user->user_login;
|
$user->display_name=$user->user_login;
|
||||||
$comment_author = $wpdb->escape($user->display_name);
|
$comment_author = $wpdb->escape($user->display_name);
|
||||||
|
@ -73,7 +73,7 @@ if ( $user->ID ) {
|
||||||
|
|
||||||
$comment_type = '';
|
$comment_type = '';
|
||||||
|
|
||||||
if ( get_option('require_name_email') && !$user->ID ) {
|
if ( get_option('require_name_email') && !$user->exists() ) {
|
||||||
if ( 6 > strlen($comment_author_email) || '' == $comment_author )
|
if ( 6 > strlen($comment_author_email) || '' == $comment_author )
|
||||||
wp_die( __('<strong>ERROR</strong>: please fill the required fields (name, email).') );
|
wp_die( __('<strong>ERROR</strong>: please fill the required fields (name, email).') );
|
||||||
elseif ( !is_email($comment_author_email))
|
elseif ( !is_email($comment_author_email))
|
||||||
|
|
|
@ -598,6 +598,18 @@ class WP_User {
|
||||||
$this->data->$key = $value;
|
$this->data->$key = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user exists in the database.
|
||||||
|
*
|
||||||
|
* @since 3.4.0
|
||||||
|
* @access public
|
||||||
|
*
|
||||||
|
* @return bool True if user exists in the database, false if not.
|
||||||
|
*/
|
||||||
|
function exists() {
|
||||||
|
return ! empty( $this->ID );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the value of a property or meta key.
|
* Retrieve the value of a property or meta key.
|
||||||
*
|
*
|
||||||
|
@ -1259,7 +1271,7 @@ function user_can( $user, $capability ) {
|
||||||
if ( ! is_object( $user ) )
|
if ( ! is_object( $user ) )
|
||||||
$user = new WP_User( $user );
|
$user = new WP_User( $user );
|
||||||
|
|
||||||
if ( ! $user || ! $user->ID )
|
if ( ! $user || ! $user->exists() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$args = array_slice( func_get_args(), 2 );
|
$args = array_slice( func_get_args(), 2 );
|
||||||
|
@ -1356,7 +1368,7 @@ function is_super_admin( $user_id = false ) {
|
||||||
else
|
else
|
||||||
$user = wp_get_current_user();
|
$user = wp_get_current_user();
|
||||||
|
|
||||||
if ( empty( $user->ID ) )
|
if ( ! $user->exists() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( is_multisite() ) {
|
if ( is_multisite() ) {
|
||||||
|
|
|
@ -1517,7 +1517,7 @@ function comment_form( $args = array(), $post_id = null ) {
|
||||||
|
|
||||||
$commenter = wp_get_current_commenter();
|
$commenter = wp_get_current_commenter();
|
||||||
$user = wp_get_current_user();
|
$user = wp_get_current_user();
|
||||||
$user_identity = ! empty( $user->ID ) ? $user->display_name : '';
|
$user_identity = $user->exists() ? $user->display_name : '';
|
||||||
|
|
||||||
$req = get_option( 'require_name_email' );
|
$req = get_option( 'require_name_email' );
|
||||||
$aria_req = ( $req ? " aria-required='true'" : '' );
|
$aria_req = ( $req ? " aria-required='true'" : '' );
|
||||||
|
|
|
@ -579,7 +579,7 @@ function update_comment_meta($comment_id, $meta_key, $meta_value, $prev_value =
|
||||||
* @since 3.4.0
|
* @since 3.4.0
|
||||||
*/
|
*/
|
||||||
function wp_set_comment_cookies($comment, $user) {
|
function wp_set_comment_cookies($comment, $user) {
|
||||||
if ( $user->ID )
|
if ( $user->exists() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$comment_cookie_lifetime = apply_filters('comment_cookie_lifetime', 30000000);
|
$comment_cookie_lifetime = apply_filters('comment_cookie_lifetime', 30000000);
|
||||||
|
|
|
@ -49,7 +49,7 @@ function is_site_admin( $user_login = '' ) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
$user = get_user_by( 'login', $user_login );
|
$user = get_user_by( 'login', $user_login );
|
||||||
if ( empty( $user->ID ) )
|
if ( ! $user->exists() )
|
||||||
return false;
|
return false;
|
||||||
$user_id = $user->ID;
|
$user_id = $user->ID;
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,7 +185,7 @@ function add_user_to_blog( $blog_id, $user_id, $role ) {
|
||||||
|
|
||||||
$user = new WP_User($user_id);
|
$user = new WP_User($user_id);
|
||||||
|
|
||||||
if ( empty( $user->ID ) ) {
|
if ( ! $user->exists() ) {
|
||||||
restore_current_blog();
|
restore_current_blog();
|
||||||
return new WP_Error('user_does_not_exist', __('That user does not exist.'));
|
return new WP_Error('user_does_not_exist', __('That user does not exist.'));
|
||||||
}
|
}
|
||||||
|
@ -247,7 +247,7 @@ function remove_user_from_blog($user_id, $blog_id = '', $reassign = '') {
|
||||||
|
|
||||||
// wp_revoke_user($user_id);
|
// wp_revoke_user($user_id);
|
||||||
$user = new WP_User($user_id);
|
$user = new WP_User($user_id);
|
||||||
if ( empty( $user->ID ) ) {
|
if ( ! $user->exists() ) {
|
||||||
restore_current_blog();
|
restore_current_blog();
|
||||||
return new WP_Error('user_does_not_exist', __('That user does not exist.'));
|
return new WP_Error('user_does_not_exist', __('That user does not exist.'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -709,7 +709,7 @@ if ( !function_exists('is_user_logged_in') ) :
|
||||||
function is_user_logged_in() {
|
function is_user_logged_in() {
|
||||||
$user = wp_get_current_user();
|
$user = wp_get_current_user();
|
||||||
|
|
||||||
if ( empty( $user->ID ) )
|
if ( ! $user->exists() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -259,7 +259,7 @@ function get_user_option( $option, $user = 0, $deprecated = '' ) {
|
||||||
else
|
else
|
||||||
$user = new WP_User( $user );
|
$user = new WP_User( $user );
|
||||||
|
|
||||||
if ( ! isset( $user->ID ) )
|
if ( ! $user->exists() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( $user->has_prop( $wpdb->prefix . $option ) ) // Blog specific
|
if ( $user->has_prop( $wpdb->prefix . $option ) ) // Blog specific
|
||||||
|
@ -940,7 +940,7 @@ function setup_userdata($for_user_id = '') {
|
||||||
$user_ID = (int) $user->ID;
|
$user_ID = (int) $user->ID;
|
||||||
$user_level = (int) isset($user->user_level) ? $user->user_level : 0;
|
$user_level = (int) isset($user->user_level) ? $user->user_level : 0;
|
||||||
|
|
||||||
if ( 0 == $user->ID ) {
|
if ( ! $user->exists() ) {
|
||||||
$user_login = $user_email = $user_url = $user_pass_md5 = $user_identity = '';
|
$user_login = $user_email = $user_url = $user_pass_md5 = $user_identity = '';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue