Skip to content

Instantly share code, notes, and snippets.

@brasofilo
Forked from johnbillion/gist:5225514
Created August 28, 2014 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brasofilo/a79aedb18fb55510ab4d to your computer and use it in GitHub Desktop.
Save brasofilo/a79aedb18fb55510ab4d to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Post Meta Revisions
Description: Revisions for the 'foo' post meta field
Version: 1.0
Author: John Blackbourn
Plugin URI: http://lud.icro.us/post-meta-revisions-wordpress
*/
function pmr_fields( $fields ) {
$fields['foo'] = 'Foo';
return $fields;
}
function pmr_field( $value, $field ) {
global $revision;
return get_metadata( 'post', $revision->ID, $field, true );
}
function pmr_restore_revision( $post_id, $revision_id ) {
$post = get_post( $post_id );
$revision = get_post( $revision_id );
$meta = get_metadata( 'post', $revision->ID, 'foo', true );
if ( false === $meta )
delete_post_meta( $post_id, 'foo' );
else
update_post_meta( $post_id, 'foo', $meta );
}
function pmr_save_post( $post_id, $post ) {
if ( $parent_id = wp_is_post_revision( $post_id ) ) {
$meta = get_post_meta( $parent_id, 'foo', true );
if ( false !== $meta )
add_metadata( 'post', $post_id, 'foo', $meta );
}
}
add_filter( '_wp_post_revision_field_foo', 'pmr_field', 10, 2 );
add_action( 'save_post', 'pmr_save_post', 10, 2 );
add_action( 'wp_restore_post_revision', 'pmr_restore_revision', 10, 2 );
add_filter( '_wp_post_revision_fields', 'pmr_fields' );
?>
@meek2100
Copy link

brasofilo,
This unrelated to this gist, but not sure how to reach out to you any other way.

Could you take a look at my questions on one of your old answers on StackExchange?
https://wordpress.stackexchange.com/questions/51920/set-custom-name-for-generated-thumbnails/383694#383694

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment