Skip to content

Commit

Permalink
AMP: only check for is_amp_endpoint if the wp action happened.
Browse files Browse the repository at this point in the history
This reverts some of the changes to Carousel that were made in #10945.
Instead, we try to defer the is_amp_endpoint until wp is loaded,
to avoid the problems raised in #11169.
  • Loading branch information
jeherve committed Jan 23, 2019
1 parent 1505875 commit 29a3558
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
22 changes: 12 additions & 10 deletions 3rd-party/class.jetpack-amp-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,18 @@ static function is_amp_canonical() {
}

static function is_amp_request() {
$is_amp_request = ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() );

/**
* Returns true if the current request should return valid AMP content.
*
* @since 6.2.0
*
* @param boolean $is_amp_request Is this request supposed to return valid AMP content?
*/
return apply_filters( 'jetpack_is_amp_request', $is_amp_request );
if ( did_action( 'wp' ) ) {
$is_amp_request = ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() );

/**
* Returns true if the current request should return valid AMP content.
*
* @since 6.2.0
*
* @param boolean $is_amp_request Is this request supposed to return valid AMP content?
*/
return apply_filters( 'jetpack_is_amp_request', $is_amp_request );
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions modules/carousel/jetpack-carousel.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Jetpack_Carousel {
public $single_image_gallery_enabled_media_file = false;

function __construct() {
add_action( 'wp', array( $this, 'init' ), 99 );
add_action( 'init', array( $this, 'init' ) );
}

function init() {
Expand All @@ -44,7 +44,7 @@ function init() {

if ( is_admin() ) {
// Register the Carousel-related related settings
$this->register_settings();
add_action( 'admin_init', array( $this, 'register_settings' ), 5 );
if ( ! $this->in_jetpack ) {
if ( 0 == $this->test_1or0_option( get_option( 'carousel_enable_it' ), true ) ) {
return; // Carousel disabled, abort early, but still register setting so user can switch it back on
Expand Down Expand Up @@ -217,7 +217,7 @@ function check_content_for_blocks( $content ) {
if ( Jetpack_AMP_Support::is_amp_request() ) {
return $content;
}

if (
function_exists( 'has_block' )
&& ( has_block( 'gallery', $content ) || has_block( 'jetpack/tiled-gallery', $content ) )
Expand Down

0 comments on commit 29a3558

Please sign in to comment.