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

Prevent shortcode with WP_Query from overriding post shown for editing on edit post screen #1107

Merged
merged 2 commits into from
May 1, 2018
Merged
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
24 changes: 14 additions & 10 deletions includes/utils/class-amp-validation-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,16 +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();
}

// 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 );
Expand All @@ -562,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;
}
Expand Down