Skip to content

Commit

Permalink
Eliminate unnecessary additional loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
nerrad committed Jul 27, 2022
1 parent c9b5570 commit 9be9c6b
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions lib/experimental/class-wp-theme-json-resolver-gutenberg.php
Expand Up @@ -150,25 +150,22 @@ public static function get_plugin_theme_data() {
if ( null === static::$plugins ) {
$plugins_data = array();
$active_plugin_paths = wp_get_active_and_valid_plugins();
$plugin_json = new WP_Theme_JSON_Gutenberg();
foreach ( $active_plugin_paths as $path ) {
$config = static::read_json_file( dirname( $path ) . '/theme.json' );
if ( ! empty( $config ) ) {
$plugin_meta_data = get_plugin_data( $path, false, false );
if ( isset( $plugin_meta_data['TextDomain'] ) ) {
$config = static::translate( $config, $plugin_meta_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( $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_meta_data = get_plugin_data( $plugin_path, false, false );
if ( isset( $plugin_meta_data['TextDomain'] ) ) {
$plugin_config = static::translate( $plugin_config, $plugin_meta_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

0 comments on commit 9be9c6b

Please sign in to comment.