Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'save_post', 'plugin_foo_save_post', 10, 2 );
- add_action( 'wp_restore_post_revision', 'plugin_foo_restore_revision', 10, 2 );
- function plugin_foo_restore_revision( $post_id, $revision_id ) {
- $post = get_post( $post_id );
- $revision = get_post( $revision_id );
- if ( post_type_supports( $post->post_type, 'my_feature' ) ) {
- $meta = get_metadata( 'post', $revision->ID, 'my_feature', true );
- if ( !empty( $meta ) )
- update_metadata( 'post', $post_id, 'my_feature', $meta );
- }
- }
- function plugin_foo_save_post( $post_id, $post ) {
- if ( $parent_id = wp_is_post_revision( $post_id ) ) {
- $parent = get_post( $parent_id );
- if ( post_type_supports( $parent->post_type, 'my_feature' ) ) {
- $meta = get_post_meta( $parent->ID, 'my_feature', true );
- if ( !empty( $meta ) )
- add_metadata( 'post', $post_id, 'my_feature', $meta );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement