Advertisement
Guest User

Post meta revisions

a guest
Dec 10th, 2010
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. add_action( 'save_post',                'plugin_foo_save_post', 10, 2 );
  2. add_action( 'wp_restore_post_revision', 'plugin_foo_restore_revision', 10, 2 );
  3.  
  4. function plugin_foo_restore_revision( $post_id, $revision_id ) {
  5.  
  6.     $post = get_post( $post_id );
  7.     $revision = get_post( $revision_id );
  8.  
  9.     if ( post_type_supports( $post->post_type, 'my_feature' ) ) {
  10.  
  11.         $meta = get_metadata( 'post', $revision->ID, 'my_feature', true );
  12.         if ( !empty( $meta ) )
  13.             update_metadata( 'post', $post_id, 'my_feature', $meta );
  14.  
  15.     }
  16.  
  17. }
  18.  
  19. function plugin_foo_save_post( $post_id, $post ) {
  20.  
  21.     if ( $parent_id = wp_is_post_revision( $post_id ) ) {
  22.  
  23.         $parent = get_post( $parent_id );
  24.  
  25.         if ( post_type_supports( $parent->post_type, 'my_feature' ) ) {
  26.             $meta = get_post_meta( $parent->ID, 'my_feature', true );
  27.             if ( !empty( $meta ) )
  28.                 add_metadata( 'post', $post_id, 'my_feature', $meta );
  29.         }
  30.  
  31.     }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement