update_user_status

函式
update_user_status ( $id, $pref, $value, $deprecated = null )
引數
  • (int) $id The user ID.
    Required:
  • (string) $pref The column in the wp_users table to update the user's status in (presumably user_status, spam, or deleted).
    Required:
  • (int) $value The new status for the user.
    Required:
  • (null) $deprecated Deprecated as of 3.0.2 and should not be used.
    Required:
    Default: null
返回值
  • (int) The initially passed $value.
相關
  • wp_update_user()
定義位置
相關方法
update_user_metaupdate_usermetaupdate_blog_statusupdate_user_cachesupdate_user_option
引入
3.0.0
棄用
5.3.0

update_user_status: 這個函式更新一個使用者的狀態。它接收使用者ID和要更新的狀態。

更新一個使用者在資料庫中的狀態。

以前在核心中用於將使用者標記為垃圾郵件或多站點中的”ham”(非垃圾郵件)。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function update_user_status( $id, $pref, $value, $deprecated = null ) {
global $wpdb;
_deprecated_function( __FUNCTION__, '5.3.0', 'wp_update_user()' );
if ( null !== $deprecated ) {
_deprecated_argument( __FUNCTION__, '3.0.2' );
}
$wpdb->update( $wpdb->users, array( sanitize_key( $pref ) => $value ), array( 'ID' => $id ) );
$user = new WP_User( $id );
clean_user_cache( $user );
if ( 'spam' === $pref ) {
if ( $value == 1 ) {
/** This filter is documented in wp-includes/user.php */
do_action( 'make_spam_user', $id );
} else {
/** This filter is documented in wp-includes/user.php */
do_action( 'make_ham_user', $id );
}
}
return $value;
}
function update_user_status( $id, $pref, $value, $deprecated = null ) { global $wpdb; _deprecated_function( __FUNCTION__, '5.3.0', 'wp_update_user()' ); if ( null !== $deprecated ) { _deprecated_argument( __FUNCTION__, '3.0.2' ); } $wpdb->update( $wpdb->users, array( sanitize_key( $pref ) => $value ), array( 'ID' => $id ) ); $user = new WP_User( $id ); clean_user_cache( $user ); if ( 'spam' === $pref ) { if ( $value == 1 ) { /** This filter is documented in wp-includes/user.php */ do_action( 'make_spam_user', $id ); } else { /** This filter is documented in wp-includes/user.php */ do_action( 'make_ham_user', $id ); } } return $value; }
function update_user_status( $id, $pref, $value, $deprecated = null ) {
	global $wpdb;

	_deprecated_function( __FUNCTION__, '5.3.0', 'wp_update_user()' );

	if ( null !== $deprecated ) {
		_deprecated_argument( __FUNCTION__, '3.0.2' );
	}

	$wpdb->update( $wpdb->users, array( sanitize_key( $pref ) => $value ), array( 'ID' => $id ) );

	$user = new WP_User( $id );
	clean_user_cache( $user );

	if ( 'spam' === $pref ) {
		if ( $value == 1 ) {
			/** This filter is documented in wp-includes/user.php */
			do_action( 'make_spam_user', $id );
		} else {
			/** This filter is documented in wp-includes/user.php */
			do_action( 'make_ham_user', $id );
		}
	}

	return $value;
}

常見問題

FAQs
檢視更多 >