Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-add_metadata_preview_filter - corrects meta for previews #37

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions wp-post-meta-revisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,7 @@ public function __construct() {
// When revisioned post meta has changed, trigger a revision save.
add_filter( 'wp_save_post_revision_post_has_changed', array( $this, '_wp_check_revisioned_meta_fields_have_changed' ), 10, 3 );

}

/**
* Add the revisioned meta to get_post_metadata for preview meta data.
*
* @since 4.5.0
*/
public function _add_metadata_preview_filter() {
// Add the revisioned meta to get_post_metadata for preview meta data.
add_filter( 'get_post_metadata', array( $this, '_wp_preview_meta_filter' ), 10, 4 );
}

Expand Down Expand Up @@ -191,6 +184,11 @@ public function _wp_restore_post_revision_meta( $post_id, $revision_id ) {
*/
public function _wp_preview_meta_filter( $value, $object_id, $meta_key, $single ) {

// Only filter previews.
if ( ! is_preview() ) {
return $value;
}

$post = get_post();
if (
empty( $post ) ||
Expand All @@ -207,6 +205,7 @@ public function _wp_preview_meta_filter( $value, $object_id, $meta_key, $single
return $value;
}

// Return the autosave revisioned meta.
return get_post_meta( $preview->ID, $meta_key, $single );
}
}
Expand Down