From 2d420332168f35dd994495a28e55f6a86e02e793 Mon Sep 17 00:00:00 2001 From: Joey Blake Date: Fri, 24 Jan 2020 16:25:40 -0500 Subject: [PATCH] Fix post revision meta saving check when post_template conditional is set. Post_Template_Condition.php checks for existence of _wp_page_template in post_meta before saving. When the post is a revision there may not be a post_meta entry for _wp_page_template, so we need to check the parent post to ensure revision metadata is saved. Fixes #829 --- core/Container/Condition/Post_Template_Condition.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/Container/Condition/Post_Template_Condition.php b/core/Container/Condition/Post_Template_Condition.php index ad4f13259..e1b0b0be3 100644 --- a/core/Container/Condition/Post_Template_Condition.php +++ b/core/Container/Condition/Post_Template_Condition.php @@ -20,6 +20,12 @@ public function is_fulfilled( $environment ) { $is_page_for_posts = intval( $post_id ) === intval( get_option( 'page_for_posts' ) ); $post_template = get_post_meta( $post_id, '_wp_page_template', true ); + + // If this is a revision, there may not be a _wp_page_template record, so look up the parent template. + if ( ! $post_template && 'revision' === get_post_type( $post_id ) ) { + $post_template = get_post_meta( $environment['post']->post_parent, '_wp_page_template', true ); + } + if ( ! $post_template || $is_page_for_posts ) { $post_template = 'default'; } @@ -30,4 +36,4 @@ public function is_fulfilled( $environment ) { $this->get_value() ); } -} \ No newline at end of file +}