-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Rename theme support for wide images to align-wide
.
#4153
Conversation
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.
Nice work here!
docs/themes.md
Outdated
@@ -34,7 +37,7 @@ Different blocks have the possibility of customizing colors. Gutenberg provides | |||
|
|||
```php | |||
add_theme_support( 'gutenberg', array( | |||
'colors' => array( | |||
'colors' => array( |
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.
Should we do the same for the colors? I mean dropping the gutenberg
code name. Maybe something like add_theme_support( 'colors', $colors );
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.
Yeah, thinking that makes sense. Should that happen under a different issue?
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 fine doing it in the same PR, that way we can check for the "deprecated" theme support only once.
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. Ended up doing a first run with only wide images changes/warnings first. If that's close, I'll expand it to colors.
lib/client-assets.php
Outdated
@@ -817,7 +818,7 @@ function gutenberg_editor_scripts_and_styles( $hook ) { | |||
$allowed_block_types = apply_filters( 'allowed_block_types', true ); | |||
|
|||
$editor_settings = array( | |||
'wideImages' => ! empty( $gutenberg_theme_support[0]['wide-images'] ), | |||
'alignWide' => $align_wide, |
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 thinking for one Gutenberg release or two, we should support both and maybe warn the user (console.warn for instance) if we detect the usage of the old gutenberg
theme support?
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.
Sure, can do. Wasn't sure how much backcompat is expected at the moment.
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.
Yeah! not sure either, but keeping it for one or two releases seems reasonable to me. We're doing the same thing (warning) for the deprecated block attributes definition.
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 love the idea of supporting both for a few releases and maybe throwing a _doing_it_wrong
or similar for wideImages
editor/components/provider/index.js
Outdated
"See https://wordpress.org/gutenberg/handbook/reference/theme-support/" | ||
) ); | ||
} | ||
|
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.
Not sure if I'm doing this in the right spot. Feel free to point me in another direction if not.
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.
RE Travis errors:
Looks like I need to use a different quote style here, which is easy enough (whoops). That won't fix that it doesn't like that I'm outputting to the console, so going to dig a bit more on the other warning you referenced @youknowriad.
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.
Looks like in the other case (https://github.com/WordPress/gutenberg/blob/master/blocks/hooks/matchers.js#L12), the console warning is being ignored through a comment.
Pushed another commit that should help ESLint / Travis pass.
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.
Yep, it helps if you can install an eslint
plugin in your favorite IDE to catch the errors "live". You can also run npm run lint
locally.
That said, I wonder if this check should be done server-side instead,
if (! empty( $gutenberg_theme_support)) {
wp_add_inline_script(
'wp-editor',
'console.warn("message")'
);
}
and update the setting
$editor_settings = array(
'alignWide' => $align_wide || ! empty( $gutenberg_theme_support[0]['wide-images'] )
)
That way the client is consistent. What do you think?
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! For some reason, I (incorrectly) assumed that lint was run as part of build when using npm run dev
. Have been running it manually to check since learning otherwise, because some of the editing is in vim, and I don't have an eslint
plugin installed there yet.
I'd been assuming the client/JS side due to the console.warn()
suggestion, but have no problem at all with that route.
If we're going to solve it server-side, should it be with _doing_it_wrong
like @aaronjorbin suggested, or is sending the warning across via wp_add_inline_script()
more idiomatic and/or likely to be noticed by devs?
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.
If we're going to solve it server-side, should it be with _doing_it_wrong like @aaronjorbin suggested, or is sending the warning across via wp_add_inline_script() more idiomatic and/or likely to be noticed by devs?
Not strong opinion myself. I'd personally use console.warn
for consistency with the other "depreacted" API we have in Gutenberg. I don't know if plugins/theme authors are already familiar with the _doing_it_wrong
behavior in other parts of WordPress, in which case, it would be a better choice.
In other words, I'm personally ok with both. The important thing is that the user notices it. What do you think @aaronjorbin ?
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'll go ahead and put something together, and can always swap out the method upon feedback.
Another question: Any suggestions on the best naming for the colors
option, since I'm assuming add_theme_support( 'colors' );
isn't appropriate?
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.
editor-color-palette
perhaps?
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.
editor-color-palette
That sounds good.
This looks quite good so far! @getsource, let us know once you'd like another look (per #4153 (comment)). |
Noting that this change is also proposed in the implementation of #4069 (see "Implementation notes"). |
I think this is ready for another look. Added Re: @aduth's comment, if this, or part of this, is best done in a different pull request or issue, I'm fine with that. Just let me know so that I don't continue here. :) |
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.
Nice work 👍
docs/themes.md
Outdated
@@ -4,43 +4,42 @@ By default, blocks provide their styles to enable basic support for blocks in th | |||
|
|||
Some advanced block features require opt-in support in the theme itself as it's difficult for the block to provide these styles, they may require some architecting of the theme itself, in order to work well. | |||
|
|||
To opt-in for one of these features, we should call `add_theme_support( 'gutenberg', $features )` in the `functions.php` file of the theme. For example: | |||
To opt-in for one of these features, we should call `add_theme_support( 'feature-name', $optional-parameters )` in the `functions.php` file of the theme. For example: |
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.
Noting that this is a syntax error on $optional-parameters
(dashes aren't valid in variable name). I think we might want to drop the arguments here since they're a bit misleading (reader might not interpret 'feature-name'
as dummy text).
To opt in for one of these features, we should call
add_theme_support
in thefunctions.php
file of the theme:
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 for pointing that out! Wasn't sure what was optimal here.
Good suggestion, especially since there's a full example immediately below. Added a commit to make this change. I also removed the "we" wording, since it didn't seem to be used in other places in this doc, and it was a little confusing who it was referring to. If that's not wanted, I can revert it.
Changes theme support for wide images from being within the `gutenberg` theme support array with a `wide-images` bool to adding it with: `add_theme_support( 'align-wide' );` Additionally, updates documentation and variable names to match. See: #4113
Includes backcompat for declaring wide image support with `add_theme_support` and `wide-images` inside the gutenberg array. Issues a JS console warning with a link to documentation if it is not declared with `add_theme_support( 'align-wide' );`.
- When warning about `wide-images` usage, use single quotes for formatting. - Whitelist usage of `console` for `wide-images` warning.
- Moves the console warning to be generated on the server side - Moves `colors` out of the array as well, with `editor-color-palette` as a replacement theme support flag. - Updates docs to reflect both of these.
… the command more generic WordPress/gutenberg#4153
Let's formally deprecate it, I think: #13458 |
Description
Changes theme support for wide images from being within the
gutenberg
theme support array with awide-images
bool to adding it with:add_theme_support( 'align-wide' );
Additionally, updates documentation and related JS variable names to match.
How Has This Been Tested?
This was tested by adding theme support for
align-wide
to Twenty Seventeen.Caveat: The demo content still has a wide image included, and it displays this way whether or not
align-wide
is enabled in the theme. As far as I can tell, this was also the case with the previous name.Types of changes
This is a breaking change for themes that have been added wide image support using the previously supported method. They would need to change to the new naming for the wide and full image controls to display.
Fixes: #4113
Checklist: