wp_list_post_revisions

函式
wp_list_post_revisions ( $post = 0, $type = 'all' )
引數
  • (int|WP_Post) $post Optional. Post ID or WP_Post object. Default is global $post.
    Required:
  • (string) $type 'all' (default), 'revision' or 'autosave'
    Required:
    Default: 'all'
定義位置
相關方法
wp_is_post_revisionwp_get_post_revisionswp_get_post_revisionwp_delete_post_revision_wp_put_post_revision
引入
2.6.0
棄用
-

wp_list_post_revisions: 這個函式使用一組你可以自定義的引數,檢索並顯示一個特定文章的修訂列表。你可以使用這個函式來顯示一個特定文章的修訂列表,允許使用者比較和恢復該文章的先前版本。

顯示兩個字串之間的差異的人類可讀的HTML表示。

差異可用於獲取版本之間的變化。輸出是HTML,所以主要用途是顯示變化。如果兩個字串是相等的,那麼將返回一個空字串。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_list_post_revisions( $post = 0, $type = 'all' ) {
$post = get_post( $post );
if ( ! $post ) {
return;
}
// $args array with (parent, format, right, left, type) deprecated since 3.6.
if ( is_array( $type ) ) {
$type = ! empty( $type['type'] ) ? $type['type'] : $type;
_deprecated_argument( __FUNCTION__, '3.6.0' );
}
$revisions = wp_get_post_revisions( $post->ID );
if ( ! $revisions ) {
return;
}
$rows = '';
foreach ( $revisions as $revision ) {
if ( ! current_user_can( 'read_post', $revision->ID ) ) {
continue;
}
$is_autosave = wp_is_post_autosave( $revision );
if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) {
continue;
}
$rows .= "t<li>" . wp_post_revision_title_expanded( $revision ) . "</li>n";
}
echo "<div class='hide-if-js'><p>" . __( 'JavaScript must be enabled to use this feature.' ) . "</p></div>n";
echo "<ul class='post-revisions hide-if-no-js'>n";
echo $rows;
echo '</ul>';
}
function wp_list_post_revisions( $post = 0, $type = 'all' ) { $post = get_post( $post ); if ( ! $post ) { return; } // $args array with (parent, format, right, left, type) deprecated since 3.6. if ( is_array( $type ) ) { $type = ! empty( $type['type'] ) ? $type['type'] : $type; _deprecated_argument( __FUNCTION__, '3.6.0' ); } $revisions = wp_get_post_revisions( $post->ID ); if ( ! $revisions ) { return; } $rows = ''; foreach ( $revisions as $revision ) { if ( ! current_user_can( 'read_post', $revision->ID ) ) { continue; } $is_autosave = wp_is_post_autosave( $revision ); if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) { continue; } $rows .= "t<li>" . wp_post_revision_title_expanded( $revision ) . "</li>n"; } echo "<div class='hide-if-js'><p>" . __( 'JavaScript must be enabled to use this feature.' ) . "</p></div>n"; echo "<ul class='post-revisions hide-if-no-js'>n"; echo $rows; echo '</ul>'; }
function wp_list_post_revisions( $post = 0, $type = 'all' ) {
	$post = get_post( $post );

	if ( ! $post ) {
		return;
	}

	// $args array with (parent, format, right, left, type) deprecated since 3.6.
	if ( is_array( $type ) ) {
		$type = ! empty( $type['type'] ) ? $type['type'] : $type;
		_deprecated_argument( __FUNCTION__, '3.6.0' );
	}

	$revisions = wp_get_post_revisions( $post->ID );

	if ( ! $revisions ) {
		return;
	}

	$rows = '';
	foreach ( $revisions as $revision ) {
		if ( ! current_user_can( 'read_post', $revision->ID ) ) {
			continue;
		}

		$is_autosave = wp_is_post_autosave( $revision );
		if ( ( 'revision' === $type && $is_autosave ) || ( 'autosave' === $type && ! $is_autosave ) ) {
			continue;
		}

		$rows .= "t<li>" . wp_post_revision_title_expanded( $revision ) . "</li>n";
	}

	echo "<div class='hide-if-js'><p>" . __( 'JavaScript must be enabled to use this feature.' ) . "</p></div>n";

	echo "<ul class='post-revisions hide-if-no-js'>n";
	echo $rows;
	echo '</ul>';
}

常見問題

FAQs
檢視更多 >