wp_restore_post_revision [ WordPress Functions ]
wp_restore_post_revision ( $revision_id, $fields = null )
| Parameters: |
|
| Uses: | |
| Returns: |
|
| Defined at: |
|
| Codex |
Similar Functions: wp_get_post_revision, wp_delete_post_revision, wp_save_post_revision, wp_is_post_revision, wp_get_post_revisions
Restores a post to the specified revision.
Can restore a past revision using all fields of the post revision, or only selected fields.
Source
function wp_restore_post_revision( $revision_id, $fields = null ) {
if ( !$revision = wp_get_post_revision( $revision_id, ARRAY_A ) )
return $revision;
if ( !is_array( $fields ) )
$fields = array_keys( _wp_post_revision_fields() );
$update = array();
foreach( array_intersect( array_keys( $revision ), $fields ) as $field ) {
$update[$field] = $revision[$field];
}
if ( !$update )
return false;
$update['ID'] = $revision['post_parent'];
$update = wp_slash( $update ); //since data is from db
$post_id = wp_update_post( $update );
if ( ! $post_id || is_wp_error( $post_id ) )
return $post_id;
// Add restore from details
$restore_details = array(
'restored_revision_id' => $revision_id,
'restored_by_user' => get_current_user_id(),
'restored_time' => time()
);
update_post_meta( $post_id, '_post_restored_from', $restore_details );
// Update last edit user
update_post_meta( $post_id, '_edit_last', get_current_user_id() );
do_action( 'wp_restore_post_revision', $post_id, $revision['ID'] );
return $post_id;
}Examples [ wp-snippets.com ]
Top Google Search Results
- wp_restore_post_revision (WordPress Function) - WPSeek.com
Jun 9, 2013 ... Restores a post to the specified revision. WordPress lookup for wp_restore_post_revision, a WordPress Function.
wpseek.com - wp_restore_post_revision Wordpress hook details -- Adam Brown ...
wp_restore_post_revision. WordPress version history for wp_restore_post_revision. This database has information for all major versions from WP 1.2.1 through ...
adambrown.info - wp_restore_post_revision | A HitchHackers guide through WordPress
Feb 12, 2011 ... function wp_restore_post_revision( $revision_id, $fields = null ) { if ( !$revision = wp_get_post_revision( $revision_id, ARRAY_A ) ) return ...
hitchhackerguide.com - Saving Post Meta Field Revisions in WordPress | Ludicrous
Apr 27, 2012 ... For this we hook into the wp_restore_post_revision action and update the meta field to the version stored at the revision we're reverting to.
lud.icro.us
