2014-01-19 81 views

回答

1

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; 
} 

最高優先級是最後執行的掛鉤。

相關問題