wp_list_post_revisions [ WordPress Function ]
| Parameters: |
|
| Uses: | |
| Returns: |
|
| Defined at: |
|
Display list of a post's revisions.
Can output either a UL with edit links or a TABLE with diff interface, and restore action links.
Second argument controls parameters: (bool) parent : include the parent (the "Current Revision") in the list. (string) format : 'list' or 'form-table'. 'list' outputs UL, 'form-table' outputs TABLE with UI. (int) right : what revision is currently being viewed - used in form-table format. (int) left : what revision is currently being diffed against right - used in form-table format.
Source
<?php
function wp_list_post_revisions( $post_id = 0, $args = null ) {
if ( !$post = get_post( $post_id ) )
return;
$defaults = array( 'parent' => false, 'right' => false, 'left' => false, 'format' => 'list', 'type' => 'all' );
extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );
switch ( $type ) {
case 'autosave' :
if ( !$autosave = wp_get_post_autosave( $post->ID ) )
return;
$revisions = array( $autosave );
break;
case 'revision' : // just revisions - remove autosave later
case 'all' :
default :
if ( !$revisions = wp_get_post_revisions( $post->ID ) )
return;
break;
}
/* translators: post revision: 1: when, 2: author name */
$titlef = _x( '%1$s by %2$s', 'post revision' );
if ( $parent )
array_unshift( $revisions, $post );
$rows = $right_checked = '';
$class = false;
$can_edit_post = current_user_can( 'edit_post', $post->ID );
foreach ( $revisions as $revision ) {
if ( !current_user_can( 'read_post', $revision->ID ) )
continue;
if ( 'revision' === $type && wp_is_post_autosave( $revision ) )
continue;
$date = wp_post_revision_title( $revision );
$name = get_the_author_meta( 'display_name', $revision->post_author );
if ( 'form-table' == $format ) {
if ( $left )
$left_checked = $left == $revision->ID ? ' checked="checked"' : '';
else
$left_checked = $right_checked ? ' checked="checked"' : ''; // [sic] (the next one)
$right_checked = $right == $revision->ID ? ' checked="checked"' : '';
$class = $class ? '' : " class='alternate'";
if ( $post->ID != $revision->ID && $can_edit_post )
$actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'action' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>';
else
$actions = '';
$rows .= "<tr$class>\n";
$rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked /></th>\n";
$rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='right' value='$revision->ID'$right_checked /></th>\n";
$rows .= "\t<td>$date</td>\n";
$rows .= "\t<td>$name</td>\n";
$rows .= "\t<td class='action-links'>$actions</td>\n";
$rows .= "</tr>\n";
} else {
$title = sprintf( $titlef, $date, $name );
$rows .= "\t<li>$title</li>\n";
}
}
if ( 'form-table' == $format ) : ?>
<form action="revision.php" method="get">
<div class="tablenav">
<div class="alignleft">
<input type="submit" class="button-secondary" value="<?php esc_attr_e( 'Compare Revisions' ); ?>" />
<input type="hidden" name="action" value="diff" />
<input type="hidden" name="post_type" value="<?php echo esc_attr($post->post_type); ?>" />
</div>
</div>
<br class="clear" />
<table class="widefat post-revisions" cellspacing="0" id="post-revisions">
<col />
<col />
<col style="width: 33%" />
<col style="width: 33%" />
<col style="width: 33%" />
<thead>
<tr>
<th scope="col"><?php /* translators: column name in revisons */ _ex( 'Old', 'revisions column name' ); ?></th>
<th scope="col"><?php /* translators: column name in revisons */ _ex( 'New', 'revisions column name' ); ?></th>
<th scope="col"><?php /* translators: column name in revisons */ _ex( 'Date Created', 'revisions column name' ); ?></th>
<th scope="col"><?php _e( 'Author' ); ?></th>
<th scope="col" class="action-links"><?php _e( 'Actions' ); ?></th>
</tr>
</thead>
<tbody>
<?php echo $rows; ?>
</tbody>
</table>
</form>
<?php
else :
echo "<ul class='post-revisions'>\n";
echo $rows;
echo "</ul>";
endif;
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- wp_list_post_revisions (WordPress Function) - WPSeek.com
WordPress lookup for wp_list_post_revisions, a WordPress Function. wpseek. com is a WordPress-centric search tool for developers and theme authors.
wpseek.com - WordPress › Support » Can I use wp_list_post_revisions() to display ...
Posted 1 year ago #. I would like to have a wikipedia-style list of revisions for visitors to view, with diffs. I know that I can use wp_list_post_revisions() to display a ...
wordpress.org - (PHP notice for undefined variable in wp_list_post_revisions())
I'm using wp_list_post_revisions() in a function, and noticed a bug related to ... 1) Call wp_list_post_revisions(), within the loop, with the following arguments: ...
core.trac.wordpress.org - WordPress Plugin – Post Revision Display | D'Arcy Norman dot net
Oct 7, 2008 ... On a tip from Otto42, I poked around with the wp_list_post_revisions() function. Looks exactly like what I need. So it was pretty simple to write a ...
www.darcynorman.net