Skip to content

Commit

Permalink
implement simpler initial approach avoiding caching of results.
Browse files Browse the repository at this point in the history
  • Loading branch information
nerrad committed Jul 22, 2022
1 parent d332866 commit bacee38
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 99 deletions.

This file was deleted.

36 changes: 32 additions & 4 deletions lib/experimental/class-wp-theme-json-resolver-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,36 @@ public static function get_block_data() {
return new WP_Theme_JSON_Gutenberg( $config, 'core' );
}

/**
* Returns any plugin provided theme data from all plugins merged together.
*
* Note: The current merge strategy merges in order of plugins returned by
* `wp_get_active_and_valid_plugins()`. This means the data from the last
* plugin in the list will override any equivalent properties from those
* earlier in the list.
*/
public static function get_plugin_theme_data() {
if ( null === static::$plugins ) {
$plugin_registry = WP_Plugin_Theme_Data_Registry::get_instance();
static::$plugins = $plugin_registry->get_theme_data();
$plugins_data = array();
$active_plugin_paths = wp_get_active_and_valid_plugins();
foreach ( $active_plugin_paths as $path ) {
$config = static::read_json_file( $path );
if ( ! empty( $config ) ) {
$plugins_data[ $path ] = $config;
}
}
// have configs from plugins, now let's register and merge.
$plugin_json = new WP_Theme_JSON_Gutenberg();
foreach ( $plugins_data as $plugin_path => $plugin_config ) {
$plugin_data = get_plugin_data( $plugin_path, false, false );
if ( isset( $plugin_data['TextDomain'] ) ) {
$plugin_config = static::translate( $plugin_config, $plugin_data['TextDomain'] );
}
// TODO, this is where we could potentially introduce different merge
// strategies for plugin provided data.
$plugin_json->merge( new WP_Theme_JSON_Gutenberg( $plugin_config ) );
}
static::$plugins = $plugin_json;
}
return static::$plugins;
}
Expand Down Expand Up @@ -196,8 +222,10 @@ public static function get_merged_data( $origin = 'custom' ) {
$result->merge( static::get_core_data() );
$result->merge( static::get_block_data() );
$result->merge( static::get_theme_data() );
// TODO merge in plugin data.
// $result->merge( static::get_plugin_theme_data() );.

// TODO: This is where we could potentially introduce new strategies for
// merging plugin provided data.
$result->merge( static::get_plugin_theme_data() );

if ( 'custom' === $origin ) {
$result->merge( static::get_user_data() );
Expand Down

0 comments on commit bacee38

Please sign in to comment.