Skip to content

Commit 930dea3

Browse files
authored
AMP: check if the class exists before to use it (#12139)
Summary: After adding the AMP compat file that ships with Jetpack (this was done in D22313, D26814, D26819, D26921, and D26928), let's start using this class. This replaces D22154 and D23501, and allows us to start syncing any future changes that would rely on the Jetpack_AMP_Support class. Related Jetpack PRs: - #10945 - #11195, which reverted some of the changes in the PR above. - #12054 - #12053 - #12026 Discussion: - https://[private link] We'll need to test for issues like the ones that popped up on Jetpack at the time: #11169 We will also need to account for the fact that WordPress.com does not run the latest version of the AMP plugin. It runs an old version (0.6.2 vs. the current version on W.org 1.0.2), with its own version of some of the compatibility fixes that come with the class we've added (see [[ https://[private link].php | here ]]) and needs to be updated as per the discussions here: - https://[private link] (D14521) - https://[private link] Test Plan: * Create a post with a gallery * Add a Facebook sharing button to that post. * Try Liking that post. * Comment on one of the images in the gallery. * Load the post in an AMP view, and repeat the steps below. In all cases: - You should not see any js errors in the browser console. - You should not get any PHP notices in your debug log. Reviewers: zinigor Tags: #touches_jetpack_files Differential Revision: D26821-code This commit syncs r190790-wpcom.
1 parent 0d600fe commit 930dea3

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

modules/carousel/jetpack-carousel.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ function display_bail_message( $output = '' ) {
153153
}
154154

155155
function check_if_shortcode_processed_and_enqueue_assets( $output ) {
156-
if ( Jetpack_AMP_Support::is_amp_request() ) {
156+
if (
157+
class_exists( 'Jetpack_AMP_Support' )
158+
&& Jetpack_AMP_Support::is_amp_request()
159+
) {
157160
return $output;
158161
}
159162

@@ -208,7 +211,10 @@ function check_if_shortcode_processed_and_enqueue_assets( $output ) {
208211
* @return string $content Post content.
209212
*/
210213
function check_content_for_blocks( $content ) {
211-
if ( Jetpack_AMP_Support::is_amp_request() ) {
214+
if (
215+
class_exists( 'Jetpack_AMP_Support' )
216+
&& Jetpack_AMP_Support::is_amp_request()
217+
) {
212218
return $content;
213219
}
214220

@@ -354,7 +360,10 @@ function enqueue_assets() {
354360
}
355361

356362
function set_in_gallery( $output ) {
357-
if ( Jetpack_AMP_Support::is_amp_request() ) {
363+
if (
364+
class_exists( 'Jetpack_AMP_Support' )
365+
&& Jetpack_AMP_Support::is_amp_request()
366+
) {
358367
return $output;
359368
}
360369
$this->in_gallery = true;
@@ -372,7 +381,10 @@ function set_in_gallery( $output ) {
372381
* @return string Modified HTML content of the post
373382
*/
374383
function add_data_img_tags_and_enqueue_assets( $content ) {
375-
if ( Jetpack_AMP_Support::is_amp_request() ) {
384+
if (
385+
class_exists( 'Jetpack_AMP_Support' )
386+
&& Jetpack_AMP_Support::is_amp_request()
387+
) {
376388
return $content;
377389
}
378390

@@ -426,7 +438,10 @@ function add_data_img_tags_and_enqueue_assets( $content ) {
426438
}
427439

428440
function add_data_to_images( $attr, $attachment = null ) {
429-
if ( Jetpack_AMP_Support::is_amp_request() ) {
441+
if (
442+
class_exists( 'Jetpack_AMP_Support' )
443+
&& Jetpack_AMP_Support::is_amp_request()
444+
) {
430445
return $attr;
431446
}
432447

@@ -498,7 +513,10 @@ function add_data_to_images( $attr, $attachment = null ) {
498513

499514
function add_data_to_container( $html ) {
500515
global $post;
501-
if ( Jetpack_AMP_Support::is_amp_request() ) {
516+
if (
517+
class_exists( 'Jetpack_AMP_Support' )
518+
&& Jetpack_AMP_Support::is_amp_request()
519+
) {
502520
return $html;
503521
}
504522

modules/related-posts/jetpack-related-posts.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,12 +1604,15 @@ protected function _log_click( $post_id, $to_post_id, $link_position ) {
16041604
*/
16051605
protected function _enabled_for_request() {
16061606
$enabled = is_single()
1607-
&&
1608-
! is_admin()
1609-
&&
1610-
( !$this->_allow_feature_toggle() || $this->get_option( 'enabled' ) )
1611-
&&
1612-
! Jetpack_AMP_Support::is_amp_request();
1607+
&& ! is_admin()
1608+
&& ( ! $this->_allow_feature_toggle() || $this->get_option( 'enabled' ) );
1609+
1610+
if (
1611+
class_exists( 'Jetpack_AMP_Support' )
1612+
&& Jetpack_AMP_Support::is_amp_request()
1613+
) {
1614+
$enabled = false;
1615+
}
16131616

16141617
/**
16151618
* Filter the Enabled value to allow related posts to be shown on pages as well.

modules/sharedaddy/sharing-service.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,10 @@ function sharing_maybe_enqueue_scripts() {
575575
}
576576

577577
function sharing_add_footer() {
578-
if ( Jetpack_AMP_Support::is_amp_request() ) {
578+
if (
579+
class_exists( 'Jetpack_AMP_Support' )
580+
&& Jetpack_AMP_Support::is_amp_request()
581+
) {
579582
return;
580583
}
581584

0 commit comments

Comments
 (0)