Skip to content

Commit

Permalink
Add initial support for themes to control the editor (#24275)
Browse files Browse the repository at this point in the history
  • Loading branch information
nosolosw authored Jul 30, 2020
1 parent 90df863 commit e4a41c8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 68 deletions.
49 changes: 0 additions & 49 deletions lib/editor-features.php

This file was deleted.

55 changes: 37 additions & 18 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

/**
* Adds the necessary data for the Global Styles client UI to the block settings.
*
Expand All @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,4 @@ function gutenberg_is_experiment_enabled( $name ) {
require dirname( __FILE__ ) . '/customizer.php';
require dirname( __FILE__ ) . '/edit-site-page.php';
require dirname( __FILE__ ) . '/edit-site-export.php';
require dirname( __FILE__ ) . '/editor-features.php';
require dirname( __FILE__ ) . '/global-styles.php';

0 comments on commit e4a41c8

Please sign in to comment.