Skip to content

Commit

Permalink
AMP: check if the class exists before to use it (#12139)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jeherve authored Apr 24, 2019
1 parent 0d600fe commit 930dea3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
30 changes: 24 additions & 6 deletions modules/carousel/jetpack-carousel.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ function display_bail_message( $output = '' ) {
}

function check_if_shortcode_processed_and_enqueue_assets( $output ) {
if ( Jetpack_AMP_Support::is_amp_request() ) {
if (
class_exists( 'Jetpack_AMP_Support' )
&& Jetpack_AMP_Support::is_amp_request()
) {
return $output;
}

Expand Down Expand Up @@ -208,7 +211,10 @@ function check_if_shortcode_processed_and_enqueue_assets( $output ) {
* @return string $content Post content.
*/
function check_content_for_blocks( $content ) {
if ( Jetpack_AMP_Support::is_amp_request() ) {
if (
class_exists( 'Jetpack_AMP_Support' )
&& Jetpack_AMP_Support::is_amp_request()
) {
return $content;
}

Expand Down Expand Up @@ -354,7 +360,10 @@ function enqueue_assets() {
}

function set_in_gallery( $output ) {
if ( Jetpack_AMP_Support::is_amp_request() ) {
if (
class_exists( 'Jetpack_AMP_Support' )
&& Jetpack_AMP_Support::is_amp_request()
) {
return $output;
}
$this->in_gallery = true;
Expand All @@ -372,7 +381,10 @@ function set_in_gallery( $output ) {
* @return string Modified HTML content of the post
*/
function add_data_img_tags_and_enqueue_assets( $content ) {
if ( Jetpack_AMP_Support::is_amp_request() ) {
if (
class_exists( 'Jetpack_AMP_Support' )
&& Jetpack_AMP_Support::is_amp_request()
) {
return $content;
}

Expand Down Expand Up @@ -426,7 +438,10 @@ function add_data_img_tags_and_enqueue_assets( $content ) {
}

function add_data_to_images( $attr, $attachment = null ) {
if ( Jetpack_AMP_Support::is_amp_request() ) {
if (
class_exists( 'Jetpack_AMP_Support' )
&& Jetpack_AMP_Support::is_amp_request()
) {
return $attr;
}

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

function add_data_to_container( $html ) {
global $post;
if ( Jetpack_AMP_Support::is_amp_request() ) {
if (
class_exists( 'Jetpack_AMP_Support' )
&& Jetpack_AMP_Support::is_amp_request()
) {
return $html;
}

Expand Down
15 changes: 9 additions & 6 deletions modules/related-posts/jetpack-related-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -1604,12 +1604,15 @@ protected function _log_click( $post_id, $to_post_id, $link_position ) {
*/
protected function _enabled_for_request() {
$enabled = is_single()
&&
! is_admin()
&&
( !$this->_allow_feature_toggle() || $this->get_option( 'enabled' ) )
&&
! Jetpack_AMP_Support::is_amp_request();
&& ! is_admin()
&& ( ! $this->_allow_feature_toggle() || $this->get_option( 'enabled' ) );

if (
class_exists( 'Jetpack_AMP_Support' )
&& Jetpack_AMP_Support::is_amp_request()
) {
$enabled = false;
}

/**
* Filter the Enabled value to allow related posts to be shown on pages as well.
Expand Down
5 changes: 4 additions & 1 deletion modules/sharedaddy/sharing-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,10 @@ function sharing_maybe_enqueue_scripts() {
}

function sharing_add_footer() {
if ( Jetpack_AMP_Support::is_amp_request() ) {
if (
class_exists( 'Jetpack_AMP_Support' )
&& Jetpack_AMP_Support::is_amp_request()
) {
return;
}

Expand Down

0 comments on commit 930dea3

Please sign in to comment.