Skip to content

Commit

Permalink
Fix post revision meta saving check when post_template conditional is…
Browse files Browse the repository at this point in the history
… 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 htmlburger#829
  • Loading branch information
joeyblake committed Jan 24, 2020
1 parent 7ee5c1e commit 2d42033
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/Container/Condition/Post_Template_Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand All @@ -30,4 +36,4 @@ public function is_fulfilled( $environment ) {
$this->get_value()
);
}
}
}

0 comments on commit 2d42033

Please sign in to comment.