0
有兩種限制WordPress修訂的方法; WP_POST_REVISIONS和wp_revisions_to_keep()。哪個具有更高的優先級?即使閱讀食譜後,我也無法理解。哪種方法具有更高的優先級?
有兩種限制WordPress修訂的方法; WP_POST_REVISIONS和wp_revisions_to_keep()。哪個具有更高的優先級?即使閱讀食譜後,我也無法理解。哪種方法具有更高的優先級?
WP_POST_REVISIONS
是恆定的,而不是函數。如果你已經設置WP_POST_REVISIONS
像這樣:define('WP_POST_REVISIONS', 3);
那麼當你調用函數wp_revisions_to_keep
時(假設沒有過濾器正在修改該值),你會得到3。如果沒有設置WP_POST_REVISIONS
,那麼它將存儲每個修訂,當您撥打wp_revisions_to_keep
時,您將獲得-1
。這是wp_revisions_to_keep的源代碼。
/**
* Determine how many revisions to retain for a given post.
* By default, an infinite number of revisions are stored if a post type supports revisions.
*
* @since 3.6.0
*
* @uses post_type_supports()
* @uses apply_filters() Calls 'wp_revisions_to_keep' hook on the number of revisions.
*
* @param object $post The post object.
* @return int The number of revisions to keep.
*/
function wp_revisions_to_keep($post) {
$num = WP_POST_REVISIONS;
if (true === $num)
$num = -1;
else
$num = intval($num);
if (! post_type_supports($post->post_type, 'revisions'))
$num = 0;
return (int) apply_filters('wp_revisions_to_keep', $num, $post);
}
由此看來,很明顯,功能wp_revisions_to_keep()
使用裏面WP_POST_REVISIONS。但是,要100%確定您的建議修訂版數量正常,則應該將函數掛接到wp_revisions_to_keep
。像這樣的東西: -
add_filter('wp_revisions_to_keep', 'custom_revisions_number', 10, 2);
function custom_revisions_number($num, $post) {
$num = 5; // <---- change this accordingly.
return $num;
}
最高優先級是最後執行的掛鉤。