wp_defer_comment_counting

函式
wp_defer_comment_counting ( $defer = null )
引數
  • (bool) $defer
    Required:
    Default: null
返回值
  • (bool)
定義位置
相關方法
wp_defer_term_countingwp_update_comment_countwp_update_comment_count_nowget_comment_countwp_set_comment_cookies
引入
2.5.0
棄用
-

wp_defer_comment_counting: 這個函式延遲了WordPress中評論的計數,這意味著它延遲了對文章評論數量的重新計算,直到它是絕對必要的。這有助於提高WordPress網站的效能,尤其是在處理大量評論時。預設情況下,每次新增、編輯或刪除評論時,WordPress都會更新評論。

決定是否推遲評論計數。

當設定$defer為true時,所有文章的評論計數將不會被更新,直到$defer被設定為false: 當$defer被設定為false時,那麼所有之前推遲更新的文章評論計數將被自動更新,而不需要再呼叫wp_update_comment_count()。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_defer_comment_counting( $defer = null ) {
static $_defer = false;
if ( is_bool( $defer ) ) {
$_defer = $defer;
// Flush any deferred counts.
if ( ! $defer ) {
wp_update_comment_count( null, true );
}
}
return $_defer;
}
function wp_defer_comment_counting( $defer = null ) { static $_defer = false; if ( is_bool( $defer ) ) { $_defer = $defer; // Flush any deferred counts. if ( ! $defer ) { wp_update_comment_count( null, true ); } } return $_defer; }
function wp_defer_comment_counting( $defer = null ) {
	static $_defer = false;

	if ( is_bool( $defer ) ) {
		$_defer = $defer;
		// Flush any deferred counts.
		if ( ! $defer ) {
			wp_update_comment_count( null, true );
		}
	}

	return $_defer;
}

常見問題

FAQs
檢視更多 >