diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index 0f77106decd..23834f345e6 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 ) ) { + $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' ); 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 ); }