From ae959efd0e73a429936e82a35d8fab2901448fcc Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 14 Apr 2021 11:04:43 -0700 Subject: [PATCH 1/3] Undo erroneous addition of is_callable() check in d0d21373128 --- src/Infrastructure/ServiceBasedPlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Infrastructure/ServiceBasedPlugin.php b/src/Infrastructure/ServiceBasedPlugin.php index abf6ba12380..fd301acad56 100644 --- a/src/Infrastructure/ServiceBasedPlugin.php +++ b/src/Infrastructure/ServiceBasedPlugin.php @@ -293,7 +293,7 @@ protected function register_service( $id, $class ) { $this->service_container->put( $id, $service ); - if ( $service instanceof CliCommand && is_callable( $service ) && defined( 'WP_CLI' ) && WP_CLI ) { + if ( $service instanceof CliCommand && defined( 'WP_CLI' ) && WP_CLI ) { WP_CLI::add_command( $service::get_command_name(), $service ); } From 5b84bc73d6441fa3ee7d1057b6063830b1e04c2b Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 14 Apr 2021 11:07:25 -0700 Subject: [PATCH 2/3] Avoid failing validation requests when response is redirect --- includes/class-amp-theme-support.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index 0f77106decd..22581a9064b 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -1809,7 +1809,18 @@ public static function prepare_response( $response, $args = [] ) { $response ) ) ) { - if ( AMP_Validation_Manager::$is_validate_request ) { + // Detect whether redirect happened and prevent failing a validation request when that happens, + // since \AMP_Validation_Manager::validate_url() follows redirects. + $sent_location_header = false; + foreach ( headers_list() as $sent_header ) { + if ( preg_match( '#^location:#i', $sent_header, $matches ) ) { + $sent_location_header = true; + break; + } + } + $did_redirect = $status_code >= 300 && $status_code < 400 && $sent_location_header; + + if ( AMP_Validation_Manager::$is_validate_request && ! $did_redirect ) { if ( ! headers_sent() ) { status_header( 400 ); header( 'Content-Type: application/json; charset=utf-8' ); From f634910a05b3c8c36795c579ce5808a0323e52e9 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 14 Apr 2021 11:54:11 -0700 Subject: [PATCH 3/3] Remove unused $matches Co-authored-by: Alain Schlesser --- includes/class-amp-theme-support.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index 22581a9064b..23834f345e6 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -1813,7 +1813,7 @@ public static function prepare_response( $response, $args = [] ) { // since \AMP_Validation_Manager::validate_url() follows redirects. $sent_location_header = false; foreach ( headers_list() as $sent_header ) { - if ( preg_match( '#^location:#i', $sent_header, $matches ) ) { + if ( preg_match( '#^location:#i', $sent_header ) ) { $sent_location_header = true; break; }