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

Make responsive embeds a theme option #10477

Merged
merged 12 commits into from
Oct 18, 2018
Merged

Conversation

notnownikki
Copy link
Member

@notnownikki notnownikki commented Oct 10, 2018

Description

Fixes: #10109

This adds a new style, wp-embed-responsive to the <body> if the theme has opted in to responsive-embeds.

This allows the editor to keep the styles in the saved html and allows themes to either opt in, supply their own responsive solution, use the gutenberg provided aspect ratio styles for their own responsive solution, or to ignore them completely.

How has this been tested?

Make a new post and embed a video from youtube, e.g. https://www.youtube.com/watch?v=lXMskKTw3Bc

Check that the published post renders fine, and the body does not have the wp-embed-responsive class.

Opt the theme in to responsive-embeds

Check the body has the wp-embed-responsive class and the video is responsive.

Types of changes

Bug fix

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@notnownikki notnownikki added this to the 4.1 milestone Oct 10, 2018
@notnownikki notnownikki requested review from jasmussen and a team October 10, 2018 14:01
@notnownikki notnownikki changed the title Update/embed responsive opt in Make responsive embeds a theme option Oct 10, 2018
@jasmussen
Copy link
Contributor

Very nice work.

I can confirm that for a theme that hasn't opted in, embeds are untouched, and that when opting in by pasting add_theme_support( 'responsive-embeds' ); into functions.php, the responsive magic happens again.

Although it would be nice if we could offer this without opt-in, I think this is the safe, and right approach. Perhaps we can remove the opt-in in a future version, and make it on by default? One can dream. And let's be sure to enable this in the Twenty themes as a "best practice", CC: @kjellr.

We have 3 todo's:

  1. We should update the theme support document as part of this PR. https://github.com/WordPress/gutenberg/blob/master/docs/extensibility/theme-support.md

Under "opt-in" features we could add:

Responsive Embeds:

The new editor can make sure video embeds (YouTube, Vimeo) scale responsively according to viewport and aspect ratio. This will work without issue in most themes, especially themes that don't already provide some responsive mechanims. If you'd like to offer this in your theme, you can opt into this feature by calling:

add_theme_support( 'responsive-embeds' );

  1. We should hide this toggle if a theme hasn't opted in:

screenshot 2018-10-11 at 09 32 39

Question about that: is it sufficient to apply display: none; to that option, or might screenreaders pick it up regardless? I think it should be fine, but we should make sure.

  1. I think the body class approach is the right one, but want to make sure with @pento or @mtias. And if it is, is wp-embed-responsive the right classname? Should it be something along the lines of has-responsive-embeds? @tofumatt any thoughts?

Thanks so much for working on this Nikki!

@notnownikki
Copy link
Member Author

display: none should stop screenreaders reading it, from working on the category filter, I know the label had to be visible for the reader to read it.

I'm not sure how to access the theme options from Gutenberg though. It's probably (hopefully) straightforward?

@notnownikki
Copy link
Member Author

Ah, ignore me, I haven't had coffee yet. Just need to modify the rest api to add in info about this theme option. Simple :)

@notnownikki
Copy link
Member Author

So I didn't go with display: none here. If the theme doesn't support the option, the toggle doesn't render at all. That's fine, because the toggle isn't required for anything apart from switching the responsive classes on/off on an individual block, so things work as expected.

@jasmussen
Copy link
Contributor

That's wonderful. So does this also retire the body classname, or is that still necessary? Could this classname be on the block itself intead of the body tag?

@notnownikki
Copy link
Member Author

@jasmussen the classname is still needed to make the aspect ratio styles match, and the difference between a theme that supports and a theme that doesn't is that the one that does has the classname added to the body. That way, a theme can just ignore our aspect ratio styles if it doesn't support our method of responsiveness, or it could use them to apply its own method. Does that make sense?

@jasmussen
Copy link
Contributor

Yes that does make sense, thanks for the clarification. And I'm not sure the following is possible, but I'll ask regardless. Instead of adding wp-embed-responsive as a class to the body, can we add it on a per-block basis?

For example right now, a random YouTube video I embed has these classes:

wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio

Could we either add an additional class to that list when the theme has opted-in, or perhaps even coopt the wp-has-aspect-ratio class to only show up when a theme has opted in, just to be sanitary in how many classes we add?

A theme would still be able to provide custom aspect-ratio based responsiveness based on the presence of the wp-embed-aspect-16-9, even if it hasn't opted into Guten-provided responsiveness.

@notnownikki
Copy link
Member Author

The problem with doing it at the block level is that we'd either need to republish every post with responsive blocks in them if the theme option changes, or parse the blocks and add the classnames based on the theme option, which is expensive to do.

@jasmussen
Copy link
Contributor

Given the feature has only been in one version, and that there's a fix (update post), I think that's actually fine.

@notnownikki
Copy link
Member Author

With this PR, we don't even need to update the posts published with the previous version. Because the stylesheet changes only to match the responsive content if the body element as the classname, then it'll just get switched off without any further changes needed. And as soon as the theme opts in, all published posts will benefit without having to republish anything.

@jasmussen
Copy link
Contributor

Yes I understand, and I've verified this works as well. If this is what we have to go with, that's fine.

My concern is that we are stuffing additional css classes into an already loaded element. And this class would be present on every single WordPress page and post, regardless of whether it included an embed or not.

It seems like it we could add this class at the block level, even if it requires updating currently published posts, this would be better for the next decade of WordPress. I just want to be sure we're looking at the long term and picking the best solution, not just the near term.

Given there are three ways to fix the additional whitespace for currently published posts affected, the toggle, removing css classes, and soon just updating the post, this seems like a small price to pay for a leaner body element.

@notnownikki
Copy link
Member Author

I'm not sure that people who have a decade's worth of posts would agree there :) Loading each one into the editor to republish if they want to switch to a theme that supports responsive embeds?

If we could only output the body classname if the current post has an embed with an aspect ratio, would that be ok?

@jasmussen
Copy link
Contributor

I'm not sure that people who have a decade's worth of posts would agree there :) Loading each one into the editor to republish if they want to switch to a theme that supports responsive embeds?

But how would they? Old posts aren't affected by this are they?

Already now older posts would need to be converted to blocks, that seems outside the scope of this issue.

@notnownikki
Copy link
Member Author

But how would they? Old posts aren't affected by this are they?

As you said, we want to plan ahead for the next decade. If someone is using a theme that doesn't opt in for the next decade, and then wants to opt in, then they'd have that problem.

@jasmussen
Copy link
Contributor

If someone is using a theme that doesn't opt in for the next decade, and then wants to opt in, then they'd have that problem.

Oh I see, right. Solid point, I'm daft.

@notnownikki
Copy link
Member Author

So if we only output the class on pages that have an embed, that means parsing the post to determine if the class should be there, and that's going to be a tough sell to systems people who run WordPress at scale, when we could include a few extra characters in the body element and save all those CPU cycles.

@jasmussen
Copy link
Contributor

Yep. Probably every page is okay. But now that I finally understood the point, I think this is open to wider feedback.

@chrisvanpatten
Copy link
Contributor

I wish HTML had a better method of handling these sort of pseudo-"feature flags" but since it doesn't, a body class seems like a reasonable approach for the time being.

lib/rest-api.php Outdated Show resolved Hide resolved
Copy link
Contributor

@desrosj desrosj left a comment

Choose a reason for hiding this comment

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

This looks good to me. I opened https://core.trac.wordpress.org/ticket/45125 to update core. The tests are failing, but it appears to be a problem upstream as well.

@notnownikki
Copy link
Member Author

Oh boy, that splitting-merging.test.js is a race condition that gets triggered sometimes. It's on my list to look at a workaround at least. Rerunning.

@notnownikki
Copy link
Member Author

@danielbachhuber I think everything has been resolved now.

@Soean
Copy link
Member

Soean commented Oct 18, 2018

The docs are missing, I opened an issue: #10759

@desrosj desrosj deleted the update/embed-responsive-opt-in branch October 18, 2018 21:39
@mtias mtias added the Customization Issues related to Phase 2: Customization efforts label Oct 19, 2018
BinaryMoon added a commit to BinaryMoon/granule that referenced this pull request Oct 21, 2018
@rickcurran
Copy link

Hi, is this change going to make it into a full release? I've encountered the issue with embedded WordPress pages (such as embedding a WordPress plugin url in a page as on my page here: https://suburbia.org.uk/projects), I've had to manually disable the responsiveness on all embeds on this page to stop the gap appearing below them. But it appears this default responsive setting is incorrect at least for this type of embedded page, at least on the standard 2017 theme anyway.

@notnownikki
Copy link
Member Author

Yes, this will be in the 4.1 release.

@timhibberd
Copy link

@notnownikki - Do you know when this enhancement will get migrated into the core (V5.0)? I will be honest...as a theme designer I am having trouble trying to keep up with the changes in two places and when to raise an issue here and when to raise an issue in Trac for the core Gutenberg. I am working with the bleeding edge core 5.0 (no Gutenberg plug-in installed) and I am finding the wp-embed-responsive class is being attached to the body for the (backend) admin edit view of a page but not the (front-end) display view of a page. Is the theme supposed to add the wp-embed-responsive class to the body in the page display view or is the core supposed to do that and its omission is just a bug?

Thanks in advance. Much appreciated :-)

@notnownikki
Copy link
Member Author

@timhibberd I'm not sure on how things are getting merged into 5.0, to be honest. If you're seeing wp-embed-responsive in the admin (as it should be, so the editor is nice on smaller screens and mobile) but not on the front end, then that would suggest this has been merged and the theme would need to opt in to this option.

@pento you would know better than me how these merges are handled, would you be able to comment here please?

@timhibberd
Copy link

Cheers @notnownikki - much appreciated. The Gutenberg express train is picking up steam and its leaving some of us hanging on to keep from falling off :-) Hopefully @pento can guide me w.r.t. what changes are made to the GB plug-in, what changes are made to the GB in core V5 and how they are being kept in synch.

Regarding the theme opting in to wp-embed-responsive, my theme IS opting in via the add_theme_support( 'responsive-embeds' ); instruction. My problem is that the core is not attaching the class to the body.

So I don't know who to report this to GB plug-in or V5.0 core because I don't know where the center of truth is any more. It is possible that this feature has not yet been merged into the core V5 Beta nightly build stream. I can't tell from the Responsive Trac ticket if / when it is being merged.

@danielbachhuber
Copy link
Member

@timhibberd The wp-embed-responsive class is added to the <body> tag currently on the 5.0 branch:

image

Notably, core development is happening on the 5.0 branch, not trunk. See this post for more details.

The wp-embed-responsive body class is also added by the Gutenberg plugin as of version 4.1.

You'll want to check that you're running Gutenberg's latest version and the latest nightly WordPress build. If both of those are correct, it might be that your theme registration isn't working as expected.

@timhibberd
Copy link

Cheers @danielbachhuber. I saw that post previously but the WordPress beta documentation says to use bleeding edge via WordPress Beta Tester plugin (which pulls the release from the trunk). So I was somewhat confused as to which instruction was accurate. So I assume the WordPress Beta Tester plugin should be left in "Point release nightlies" mode.

image

Also, if I pull the nightly build (wordpress-latest.zip) from the "nightly build" link on the Beta testing page (https://make.wordpress.org/core/handbook/testing/beta/ ) I get 5.1-alpha-43678 but if I do an update from the WordPress Beta Tester plugin set to "Point release nightlies" mode I get 5.0-beta1-43832.

Are we leaping past 5.0 and going right to 5.1?

So I'm just finding the process a bit muddled w.r.t what GB is in the core vs. what gb is in the plug-in and whether I need to pull the nightly GB plug-in release to match up with the nightly core 5.1 release and whether I still need the GB plug-in installed to test my theme on core v5.x.

Thanks for clarifying that the core is adding the wp-embed-responsive body class to the user page view and not just the admin page view. At least I know now that is the correct end-state I am testing for.

Much appreciated :-)

@danielbachhuber
Copy link
Member

I saw that post previously but the WordPress beta documentation says to use bleeding edge via WordPress Beta Tester plugin (which pulls the release from the trunk). So I was somewhat confused as to which instruction was accurate. So I assume the WordPress Beta Tester plugin should be left in "Point release nightlies" mode.

To be honest, I'm not totally sure of the current state of the WordPress Beta Tester plugin right now. Might be worth popping into #core on Slack to ask.

Are we leaping past 5.0 and going right to 5.1?

Nope, we're shipping 5.0.

So I'm just finding the process a bit muddled w.r.t what GB is in the core vs. what gb is in the plug-in and whether I need to pull the nightly GB plug-in release to match up with the nightly core 5.1 release and whether I still need the GB plug-in installed to test my theme on core v5.x.

You can install the WordPress 5.0-betas to test against what will be released in 5.0. For theme development, this should be sufficient. Alternatively, if you want to test against the bleeding edge, you can install the Gutenberg nightly build (or any of the stable Gutenberg releases).

@timhibberd
Copy link

Much appreciated @danielbachhuber. I got it sorted with your adept guidance. I am the custodian of the abandoned MySiteMyWay theme suite (forked as BackStop Themes in Gitlab.com). The process of modernising those themes is a gradual process. I'm Gutenising them at present. It turned out, on detailed re-examination that the original theme designers created their own html body statement in isolation and did not append the default WP body classes. Once I knew the core was definitely adding them it was simple to sort out. Thanks again for your help. Whenever I see your comments in WordPress they are always spot on. Thanks for being there when people need you...your WP knowledge & advice is invaluable :-)

@danielbachhuber
Copy link
Member

@timhibberd You're welcome :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Embed Affects the Embed Block Core REST API Task Task for Core REST API efforts Customization Issues related to Phase 2: Customization efforts REST API Interaction Related to REST API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Giant space above all Youtube video in Posts
10 participants