Skip to content

Commit

Permalink
Merge f634910 into 8dad6e3
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Apr 14, 2021
2 parents 8dad6e3 + f634910 commit ca1196e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion includes/class-amp-theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/ServiceBasedPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down

0 comments on commit ca1196e

Please sign in to comment.