wp_update_user_counts

函式
wp_update_user_counts ( $network_id = null )
引數
  • (int|null) $network_id ID of the network. Defaults to the current network.
    Required:
    Default: null
返回值
  • (bool) Whether the update was successful.
定義位置
相關方法
wp_maybe_update_user_countswp_update_term_countwp_update_network_user_countswp_update_network_countswp_schedule_update_user_counts
引入
6.0.0
棄用
-

wp_update_user_counts是一個函式,用於更新WordPress資料庫中某個使用者的文章和評論的數量: 這個函式用來跟蹤屬於某個特定使用者的文章和評論的數量,它通常在一個文章或評論被更新或刪除後執行。

更新網站上使用者的總數量。

function wp_update_user_counts( $network_id = null ) {
	global $wpdb;

	if ( ! is_multisite() && null !== $network_id ) {
		_doing_it_wrong(
			__FUNCTION__,
			sprintf(
				/* translators: %s: $network_id */
				__( 'Unable to pass %s if not using multisite.' ),
				'<code>$network_id</code>'
			),
			'6.0.0'
		);
	}

	$query = "SELECT COUNT(ID) as c FROM $wpdb->users";
	if ( is_multisite() ) {
		$query .= " WHERE spam = '0' AND deleted = '0'";
	}

	$count = $wpdb->get_var( $query );

	return update_network_option( $network_id, 'user_count', $count );
}

常見問題

FAQs
檢視更多 >