From 73707c8d3d3e5959e86e623fea46baa55f65eb8c Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Tue, 18 Jul 2017 15:56:41 -0400 Subject: [PATCH 1/3] re-add_metadata_preview_filter --- wp-post-meta-revisions.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/wp-post-meta-revisions.php b/wp-post-meta-revisions.php index de02b12..389996f 100644 --- a/wp-post-meta-revisions.php +++ b/wp-post-meta-revisions.php @@ -32,6 +32,10 @@ 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 ); + if ( is_preview() ) { + _add_metadata_preview_filter(); + } + } /** @@ -188,7 +192,7 @@ public function _wp_preview_meta_filter( $value, $object_id, $meta_key, $single if ( empty( $post ) || $post->ID != $object_id || ! in_array( $meta_key, $this->_wp_post_revision_meta_keys() ) - || 'revision' == $post->post_type ) + || 'revision' === $post->post_type ) { return $value; } From d6e23a43f52da5746e38ea6121b75f196f8a8459 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Fri, 2 Feb 2018 10:51:02 -0500 Subject: [PATCH 2/3] clean up preview hook placement --- wp-post-meta-revisions.php | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/wp-post-meta-revisions.php b/wp-post-meta-revisions.php index de4952b..e2851b2 100644 --- a/wp-post-meta-revisions.php +++ b/wp-post-meta-revisions.php @@ -32,19 +32,9 @@ 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 ); - if ( is_preview() ) { - _add_metadata_preview_filter(); - } - - } - - /** - * 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 ); + $this->_add_metadata_preview_filter(); } /** @@ -195,6 +185,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 ) || @@ -211,6 +206,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 ); } } From 14e4949ec1d209c12c8266af6cbcbafe9f7859b2 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Fri, 2 Feb 2018 10:57:13 -0500 Subject: [PATCH 3/3] remove unused setup call --- wp-post-meta-revisions.php | 1 - 1 file changed, 1 deletion(-) diff --git a/wp-post-meta-revisions.php b/wp-post-meta-revisions.php index e2851b2..4ba404c 100644 --- a/wp-post-meta-revisions.php +++ b/wp-post-meta-revisions.php @@ -34,7 +34,6 @@ public function __construct() { // 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 ); - $this->_add_metadata_preview_filter(); } /**