-
Notifications
You must be signed in to change notification settings - Fork 802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WordAds Block: AMP Support #12733
WordAds Block: AMP Support #12733
Conversation
Thank you for the great PR description! When this PR is ready for review, please apply the Scheduled Jetpack release: August 6, 2019. |
One question I have is: there's a few different AMP implementations available for self-hosted sites, does this one target one in particular, or is it more of a generic solution? We may need to consider supporting a handful of the most popular AMP options. Though I suppose if a different version of AMP is used our |
By "different AMP implementations" do you mean plugins other than the official one: https://wordpress.org/plugins/amp/ ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good, just a question about which AMP implementations we need to support.
modules/wordads/wordads.php
Outdated
@@ -496,6 +514,17 @@ function get_ad_snippet( $section_id, $height, $width, $location = '', $css = '' | |||
if ( ! empty( self::$ad_location_ids[ $location ] ) ) { | |||
$loc_id = self::$ad_location_ids[ $location ]; | |||
} | |||
if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to consider extracting this into a separate is_amp
function to include support for various versions of AMP solutions self-hosted sites might use.
Unless we're firm on only supporting the Jetpack_AMP_Support version, then nevermind :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted in #12733 (comment), let's see what Jetpack folks think?
Yeah, interesting point. This check https://github.com/Automattic/jetpack/blob/master/3rd-party/class.jetpack-amp-support.php#L56-L72 is already used pretty widely throughout Jetpack, but I'll leave it to @Automattic/jetpack-crew to comment on whether we might need to broaden support? |
There is an official one, and it is the one being directly supported: https://wordpress.org/plugins/amp/ This is what runs on WordPress.com Other plugins that want to shim support can do so via the filter exposed in |
Also, the AMP for WP plugin includes an old version of the official AMP plugin, so the same conditionals should work. |
Regardless of whether or not we add support for other versions, I think it makes sense to extract the check into a separate function -- which I did :) |
<amp-ad width="$width" height="$height" | ||
type="pubmine" | ||
data-siteid="$site_id" | ||
data-section="$amp_section_id"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should use esc_attr()
no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, added.
HTML; | ||
} | ||
|
||
$ad_number = count( $this->ads ) . '-' . uniqid(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using uniqid
breaks the AMP plugin's post-processor cache. Better to use https://developer.wordpress.org/reference/functions/wp_unique_id/ or a polyfill.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though I suppose this won't run in AMP anyway since it's after the return
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though I suppose this won't run in AMP anyway since it's after the return?
That's correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I think this update is now a solid enough first release while the other updates noted get worked on.
This is resolved in 877f0cd. For AMP requests, the unit will be inserted above the content, below the title. After discussing with @dbspringer we decided there wasn't any way to match the non-AMP positioning without using Javascript. This isn't precisely the same as the non-AMP placement, but is similar in spirit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting the following notice when trying to view a post in an AMP view:
PHP Notice: is_amp_endpoint was called <strong>incorrectly</strong>. is_amp_endpoint() was called before the parse_query hook was called. Please see <a href="https://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information. (This message was added in version 0.4.2.) in /var/www/html/wp-includes/functions.php on line 4773
[20-Jun-2019 13:49:11 UTC] PHP Stack trace:
[20-Jun-2019 13:49:11 UTC] PHP 1. {main}() /var/www/html/index.php:0
[20-Jun-2019 13:49:11 UTC] PHP 2. require() /var/www/html/index.php:17
[20-Jun-2019 13:49:11 UTC] PHP 3. require_once() /var/www/html/wp-blog-header.php:13
[20-Jun-2019 13:49:11 UTC] PHP 4. require_once() /var/www/html/wp-load.php:37
[20-Jun-2019 13:49:11 UTC] PHP 5. require_once() /var/www/html/wp-config.php:85
[20-Jun-2019 13:49:11 UTC] PHP 6. do_action() /var/www/html/wp-settings.php:525
[20-Jun-2019 13:49:11 UTC] PHP 7. WP_Hook->do_action() /var/www/html/wp-includes/plugin.php:465
[20-Jun-2019 13:49:11 UTC] PHP 8. WP_Hook->apply_filters() /var/www/html/wp-includes/class-wp-hook.php:310
[20-Jun-2019 13:49:11 UTC] PHP 9. WordAds->init() /var/www/html/wp-includes/class-wp-hook.php:286
[20-Jun-2019 13:49:11 UTC] PHP 10. WordAds->insert_adcode() /var/www/html/wp-content/plugins/jetpack/modules/wordads/wordads.php:156
[20-Jun-2019 13:49:11 UTC] PHP 11. WordAds::is_amp() /var/www/html/wp-content/plugins/jetpack/modules/wordads/wordads.php:235
[20-Jun-2019 13:49:11 UTC] PHP 12. Jetpack_AMP_Support::is_amp_request() /var/www/html/wp-content/plugins/jetpack/modules/wordads/wordads.php:78
[20-Jun-2019 13:49:11 UTC] PHP 13. is_amp_endpoint() /var/www/html/wp-content/plugins/jetpack/3rd-party/class.jetpack-amp-support.php:62
[20-Jun-2019 13:49:11 UTC] PHP 14. _doing_it_wrong() /var/www/html/wp-content/plugins/amp/includes/amp-helper-functions.php:275
[20-Jun-2019 13:49:11 UTC] PHP 15. trigger_error() /var/www/html/wp-includes/functions.php:4773
Previous art on that topic: #11195
@dbspringer any issue with skipping |
Yeah, totally fine 👍(I'm pretty sure AMP would just strip them out anyway) |
Rebasing to fix tests. |
39a9c8c
to
65ae218
Compare
Rebased. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am now getting the following errors when editing a post that contains Ad blocks:
Notice: Trying to get property 'blog_id' of non-object in wp-content/plugins/jetpack-dev/extensions/blocks/wordads/wordads.php on line 93
Notice: Trying to get property 'cloudflare' of non-object in wp-content/plugins/jetpack-dev/modules/wordads/wordads.php on line 566
Notice: Trying to get property 'blog_id' of non-object in wp-content/plugins/jetpack-dev/extensions/blocks/wordads/wordads.php on line 93
Notice: Trying to get property 'cloudflare' of non-object in wp-content/plugins/jetpack-dev/modules/wordads/wordads.php on line 566
Notice: Trying to get property 'blog_id' of non-object in wp-content/plugins/jetpack-dev/extensions/blocks/wordads/wordads.php on line 93
Notice: Trying to get property 'cloudflare' of non-object in wp-content/plugins/jetpack-dev/modules/wordads/wordads.php on line 566
Warning: Cannot modify header information - headers already sent by (output started at wp-content/plugins/jetpack-dev/extensions/blocks/wordads/wordads.php:93) in wp-includes/option.php on line 947
Warning: Cannot modify header information - headers already sent by (output started at wp-content/plugins/jetpack-dev/extensions/blocks/wordads/wordads.php:93) in wp-includes/option.php on line 948
$wordads->params
appears to be null
.
This can even cause a Fatal error if you hide one of the ads on mobile using the block option:
Fatal error: Uncaught Error: Call to a member function is_mobile() on null
in wp-content/plugins/jetpack-dev/extensions/blocks/wordads/wordads.php on line 83
This does not appear on Jetpack Stable.
Hmmm, this is tricky. Looks like the new Block fatals came about because of the change in the init action from |
Why do the fatals occur due to moving the logic from |
After discussing with @westonruter 2349a05 should resolve the issue by using different initialization hooks for API and non-API requests. |
For the most part it seems to work well now. I do, however, run into Fatals from AMP now:
@westonruter Does this ring a bell? |
@jeherve Humm. Are you getting any other error in the log? What is the When testing with @jeffersonrabb we didn't see this issue. |
If this is a memory issue, wouldn't we expect to see the same on Jetpack stable? |
64M, but I see that I have the same problem with I'll let someone else jump in and test this instead of me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tests well for me today. Merging.
* 7.7 changelog: initial set of changes * Changelog: add #13154 * Changelog: add #13134 * Changelog: add #12699 and many others * Changelog: add #13127 * Changelog: add #13167 * Changelog: add #13225 * Changelog: add #13179 * Changelog: add #13173 * Changelog: add #13232 * Changelog: add #13137 * Changelog: add #13172 * Changelog: add #13182 * Changelog: add #13200 * Changelog: add #13244 * Changelog: add #13267 * Changelog: add #13204 * changelog: add #13205 * Changelog: add #13183 * Changelog: add #13278 * Changelog: add #13162 * Changelog: add #13268 * Changelog: add #13286 * Changelog: add #13273 * Changelog: add #12474 * Changelog: add #13085 * Changelog: add #13266 * Changelog: add #13306 * Changelog: add #13311 * Changelog: add #13302 * Changelog: add #13196 * Changelog: add #12733 * Changelog: add #13261 * Changelog: add #13322 * Changelog: add #13333 * Changelog: add #13335
Changes proposed in this Pull Request:
This PR brings AMP compatibility to the Jetpack Ads block.
A couple of gotchas:
TheAdditional ad placements->Top of each page
option will lead to AMP incompatibility in TwentySeventeen, TwentyFifteen, and TwentyFourteen. This is due to https://github.com/Automattic/jetpack/blob/master/modules/wordads/wordads.php#L400-L402. I plan to address this in a separate PR since this doesn't directly relate to the block.Settings->Reading->Search Engine Visibility->Discourage search engines from indexing this site
is checked.Testing instructions:
https://jurassic.ninja/create/?branch=add/amp-ads-supporthttp://jurassic.ninja/create/?jetpack-beta&branch=add/amp-ads-support/wp-admin/admin.php?page=jetpack#/traffic
.Additional ad placements->Top of each page
(see note above)Proposed changelog entry for your changes: