Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




wp_restore_post_revision [ WordPress Function ]

wp_restore_post_revision ( $revision_id, $fields = null )
Parameters:
  • (int|object) $revision_id Revision ID or revision object.
  • (array) $fields Optional. What fields to restore from. Defaults to all.
Uses:
Returns:
  • (mixed) Null if error, false if no fields to restore, (int) post ID if success.
Defined at:



Restores a post to the specified revision.

Can restore a past revision using all fields of the post revision, or only selected fields.

Source


<?php
function wp_restore_post_revision$revision_id$fields null ) {
    if ( !
$revision wp_get_post_revision$revision_idARRAY_A ) )
        return 
$revision;

    if ( !
is_array$fields ) )
        
$fields array_keys_wp_post_revision_fields() );

    
$update = array();
    foreach( 
array_intersectarray_keys$revision ), $fields ) as $field )
        
$update[$field] = $revision[$field];

    if ( !
$update )
        return 
false;

    
$update['ID'] = $revision['post_parent'];

    
$update add_magic_quotes$update ); //since data is from db

    
$post_id wp_update_post$update );
    if ( 
is_wp_error$post_id ) )
        return 
$post_id;

    if ( 
$post_id )
        
do_action'wp_restore_post_revision'$post_id$revision['ID'] );

    return 
$post_id;
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

Gebruikersdiscussies [ wordpress.org ]

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics