-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add initial support for themes to control the editor #24275
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -536,39 +536,54 @@ function gutenberg_experimental_global_styles_normalize_schema( $tree ) { | |
| } | ||
|
|
||
| /** | ||
| * Returns the stylesheet resulting of merging | ||
| * core's, theme's, and user's origins. | ||
| * Takes data from the different origins (core, theme, and user) | ||
| * and returns the merged result. | ||
| * | ||
| * @return string | ||
| * @return array Merged trees. | ||
| */ | ||
| function gutenberg_experimental_global_styles_get_stylesheet() { | ||
| $gs_merged = array(); | ||
| $gs_core = gutenberg_experimental_global_styles_get_core(); | ||
| $gs_theme = gutenberg_experimental_global_styles_get_theme(); | ||
| $gs_user = gutenberg_experimental_global_styles_get_user(); | ||
| function gutenberg_experimental_global_styles_get_merged_origins() { | ||
| $core = gutenberg_experimental_global_styles_get_core(); | ||
| $theme = gutenberg_experimental_global_styles_get_theme(); | ||
| $user = gutenberg_experimental_global_styles_get_user(); | ||
| $merged = gutenberg_experimental_global_styles_merge_trees( $core, $theme, $user ); | ||
|
|
||
| $gs_merged = gutenberg_experimental_global_styles_merge_trees( $gs_core, $gs_theme, $gs_user ); | ||
|
|
||
| $stylesheet = gutenberg_experimental_global_styles_resolver( $gs_merged ); | ||
| if ( empty( $stylesheet ) ) { | ||
| return; | ||
| } | ||
| return $stylesheet; | ||
| return $merged; | ||
| } | ||
|
|
||
| /** | ||
| * Fetches the preferences for each origin (core, theme, user) | ||
| * and enqueues the resulting stylesheet. | ||
| */ | ||
| function gutenberg_experimental_global_styles_enqueue_assets() { | ||
|
|
||
| $stylesheet = gutenberg_experimental_global_styles_get_stylesheet(); | ||
| $merged = gutenberg_experimental_global_styles_get_merged_origins(); | ||
| $stylesheet = gutenberg_experimental_global_styles_resolver( $merged ); | ||
| if ( empty( $stylesheet ) ) { | ||
| return; | ||
| } | ||
|
|
||
| wp_register_style( 'global-styles', false, array(), true, true ); | ||
| wp_add_inline_style( 'global-styles', $stylesheet ); | ||
| wp_enqueue_style( 'global-styles' ); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the default config for editor features, | ||
| * or an empty array if none found. | ||
| * | ||
| * @param array $config Config to extract values from. | ||
| * @return array Default features config for the editor. | ||
| */ | ||
| function gutenberg_experimental_global_styles_get_editor_features( $config ) { | ||
| if ( | ||
| empty( $config['global']['features'] ) || | ||
| ! is_array( $config['global']['features'] ) | ||
| ) { | ||
| return array(); | ||
| } | ||
|
|
||
| return $config['global']['features']; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really think we should pass just the "global" features to the editor, we should pass all the features config (per block as well) and handle it in useFeature properly.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, that's my next step. |
||
| } | ||
|
|
||
| /** | ||
| * Adds the necessary data for the Global Styles client UI to the block settings. | ||
| * | ||
|
|
@@ -591,7 +606,11 @@ function gutenberg_experimental_global_styles_settings( $settings ) { | |
| // Add the styles for the editor via the settings | ||
| // so they get processed as if they were added via add_editor_styles: | ||
| // they will get the editor wrapper class. | ||
| $settings['styles'][] = array( 'css' => gutenberg_experimental_global_styles_get_stylesheet() ); | ||
| $merged = gutenberg_experimental_global_styles_get_merged_origins(); | ||
| $stylesheet = gutenberg_experimental_global_styles_resolver( $merged ); | ||
| $settings['styles'][] = array( 'css' => $stylesheet ); | ||
|
|
||
| $settings['__experimentalFeatures'] = gutenberg_experimental_global_styles_get_editor_features( $merged ); | ||
|
|
||
| return $settings; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.