Skip to content
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

Force videopress to use html5 player for AMP #1125

Merged
merged 9 commits into from
May 10, 2018

Conversation

yurynix
Copy link
Contributor

@yurynix yurynix commented May 7, 2018

Videopress embed uses an iframe and a script tag,
script tag is not allowed in AMP, so it's stripped and a warning is generated.

screen shot 2018-05-07 at 10 19 17

This PR tries to force html5 player, so the player would be actually a <video /> tag
that would be converted to <amp-video />.

@yurynix
Copy link
Contributor Author

yurynix commented May 7, 2018

Despite the code in this PR, I still see the validation warning, I'm not sure why...

@yurynix
Copy link
Contributor Author

yurynix commented May 7, 2018

Ok, got it, it's because of this validation, so shortcodes are processed, but there is no way to hook to it for allowing modification for AMP.

Maybe do_action( 'pre_amp_render_post', $post_id ); ?

@yurynix yurynix changed the title [WIP] Force videopress to use html5 player for AMP Force videopress to use html5 player for AMP May 7, 2018
@yurynix yurynix requested a review from mjangda May 7, 2018 11:18
Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Eventually the Jetpack-specific code will be merged into Jetpack code itself per #1021.

}

if ( isset( $_GET[ AMP_Validation_Utils::VALIDATE_QUERY_VAR ] ) ) { // WPCS: CSRF ok.
add_filter( 'videopress_shortcode_options', 'amp_videopress_enable_freedom_mode' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be necessary now that you have b6a4671 right?

@@ -590,6 +590,7 @@ public static function print_edit_form_validation_status( $post ) {

// If no results from URL are available, validate post content outside frontend context.
if ( empty( $validation_errors ) && post_type_supports( $post->post_type, 'editor' ) ) {
do_action( 'pre_amp_render_post', $post->ID );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have the phpdoc added to it on the line before:

/** This action is documented in amp.php */

Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To ensure that this change applies when amp theme support is present, there should be also something like this:

add_action( 'template_redirect', function() {
    if ( is_amp_endpoint() ) {
        amp_jetpack_mods();
    }
}, 9 );

This could be used instead of the pre_amp_render_post action.

@yurynix
Copy link
Contributor Author

yurynix commented May 7, 2018

@westonruter Thank you for the review, I'll address your comments tomorrow unless someone beats me to it.

I'm not really clear what you meant by your comment here though:
#1125 (review)

Why hooking to template_redirect action is better than pre_amp_render_post?
Sorry if that's obvious, It's my first time around that repo.

@westonruter
Copy link
Member

@yurynix In v0.7 we've added amp theme support where you can have the entire theme be served as AMP, not just the post templates. For example, you could have your blog index template be served as AMP now (see example site: https://ampdemo.xwp.io/). In that case, there is no $post to be passed as the arg for the pre_amp_render_post action. But you can see from the source that the pre_amp_render_post action actually runs at template_redirect (priority 10) anyway:

https://github.com/Automattic/amp-wp/blob/7439d2ab5eebd0ee071749a849fda946a2eff4be/amp.php#L326-L383

So by doing amp_jetpack_mods() at template_redirect priority 9, then this ensures that the mods are present whether WordPress is serving the old AMP post templates or whether amp theme support is present.

@westonruter
Copy link
Member

@yurynix also, you may want to rebase your commits onto the 0.7 branch so that the changes could be included in 0.7.1.

@@ -590,6 +590,7 @@ public static function print_edit_form_validation_status( $post ) {

// If no results from URL are available, validate post content outside frontend context.
if ( empty( $validation_errors ) && post_type_supports( $post->post_type, 'editor' ) ) {
do_action( 'pre_amp_render_post', $post->ID );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this changes can be reverted because this entire if statement is going to be removed in #1132

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saw that now, we can drop my last 2 commits, sorry for the noise.

@westonruter westonruter force-pushed the add/force-videopress-use-html5 branch from b6a4671 to 145991d Compare May 8, 2018 00:54
@westonruter westonruter changed the base branch from develop to 0.7 May 8, 2018 00:54
@westonruter
Copy link
Member

@yurynix I've rebased onto 0.7 so please reset your branch to the remote. I've also made the changes I described. Please test to confirm it works as expected.

@westonruter westonruter added this to the v0.7.1 milestone May 8, 2018
@yurynix
Copy link
Contributor Author

yurynix commented May 8, 2018

Thank you for all the explanation and the work here @westonruter .
I've taken it to a spin now, and while it indeed generates the html5 player on AMP page,
the issue of the editor warning is still present.

This is caused because of the code that validates the output don't call redirect_template action, it only registers content embed handlers.

Which may be this workaround should be, a content embed handler, so I've pushed a commit to do just that, ideally, it should live in the Jetpack plugin with the rest of the workarounds.

@westonruter westonruter force-pushed the add/force-videopress-use-html5 branch from d7668fb to 3903e1a Compare May 9, 2018 14:23
@westonruter
Copy link
Member

@yurynix I dropped your two commits as requested, and I merged 0.7 into this branch. Could you confirm it works as expected now?

@yurynix
Copy link
Contributor Author

yurynix commented May 10, 2018

I've tested it and it works great 👍
Thanks.

@westonruter westonruter merged commit 4dd1023 into 0.7 May 10, 2018
@westonruter westonruter deleted the add/force-videopress-use-html5 branch May 10, 2018 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants