From 15a90cc2ec77291e26c39ea6f6a045bbdf24820f Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 1 May 2018 09:26:39 -0700 Subject: [PATCH 1/2] Fix edit post form showing wrong post if content shortcode does subquery --- includes/utils/class-amp-validation-utils.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/utils/class-amp-validation-utils.php b/includes/utils/class-amp-validation-utils.php index 478d8a22db7..5609f7de369 100644 --- a/includes/utils/class-amp-validation-utils.php +++ b/includes/utils/class-amp-validation-utils.php @@ -547,6 +547,10 @@ public static function print_edit_form_validation_status( $post ) { self::$validation_errors ); self::reset_validation_results(); + + // Make sure original post is restored after applying shortcodes which could change it. + $GLOBALS['post'] = $post; // WPCS: override ok. + setup_postdata( $post ); } // Incorporate frontend validation status if there is a known URL for the post. From fab07e3f3e82a43ad740c34a7ef9571419065bf4 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 1 May 2018 09:32:06 -0700 Subject: [PATCH 2/2] Prevent duplicate validation errors from being reported --- includes/utils/class-amp-validation-utils.php | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/includes/utils/class-amp-validation-utils.php b/includes/utils/class-amp-validation-utils.php index 5609f7de369..d43b42989c6 100644 --- a/includes/utils/class-amp-validation-utils.php +++ b/includes/utils/class-amp-validation-utils.php @@ -539,20 +539,6 @@ public static function print_edit_form_validation_status( $post ) { $validation_status_post = null; $validation_errors = array(); - // Validate post content outside frontend context. - if ( post_type_supports( $post->post_type, 'editor' ) ) { - self::process_markup( $post->post_content ); - $validation_errors = array_merge( - $validation_errors, - self::$validation_errors - ); - self::reset_validation_results(); - - // Make sure original post is restored after applying shortcodes which could change it. - $GLOBALS['post'] = $post; // WPCS: override ok. - setup_postdata( $post ); - } - // Incorporate frontend validation status if there is a known URL for the post. if ( is_post_type_viewable( $post->post_type ) ) { $url = amp_get_permalink( $post->ID ); @@ -566,6 +552,20 @@ public static function print_edit_form_validation_status( $post ) { } } + // If no results from URL are available, validate post content outside frontend context. + if ( empty( $validation_errors ) && post_type_supports( $post->post_type, 'editor' ) ) { + self::process_markup( $post->post_content ); + $validation_errors = array_merge( + $validation_errors, + self::$validation_errors + ); + self::reset_validation_results(); + + // Make sure original post is restored after applying shortcodes which could change it. + $GLOBALS['post'] = $post; // WPCS: override ok. + setup_postdata( $post ); + } + if ( empty( $validation_errors ) ) { return; }