| 1 |
<?php |
| 2 |
/** |
| 3 |
* Experimental editor features config functionality. |
| 4 |
* |
| 5 |
* @package gutenberg |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Returns the default config for editor features, |
| 10 |
* or an empty array if none found. |
| 11 |
* |
| 12 |
* @return array Default features config for the editor. |
| 13 |
*/ |
| 14 |
function gutenberg_experimental_get_editor_features_config() { |
| 15 |
$empty_config = array(); |
| 16 |
$config_path = __DIR__ . '/experimental-default-theme.json'; |
| 17 |
if ( ! file_exists( $config_path ) ) { |
| 18 |
return $empty_config; |
| 19 |
} |
| 20 |
|
| 21 |
$theme_config = json_decode( |
| 22 |
@file_get_contents( $config_path ), |
| 23 |
true |
| 24 |
); |
| 25 |
if ( |
| 26 |
empty( $theme_config['global']['features'] ) || |
| 27 |
! is_array( $theme_config['global']['features'] ) |
| 28 |
) { |
| 29 |
return $empty_config; |
| 30 |
} |
| 31 |
|
| 32 |
return $theme_config['global']['features']; |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
/** |
| 37 |
* Extends editor settings with the features loaded from default config. |
| 38 |
* |
| 39 |
* @param array $settings Default editor settings. |
| 40 |
* |
| 41 |
* @return array Filtered editor settings. |
| 42 |
*/ |
| 43 |
function gutenberg_extend_settings_editor_features( $settings ) { |
| 44 |
$editor_features = gutenberg_experimental_get_editor_features_config(); |
| 45 |
$settings['__experimentalFeatures'] = $editor_features; |
| 46 |
|
| 47 |
return $settings; |
| 48 |
} |
| 49 |
add_filter( 'block_editor_settings', 'gutenberg_extend_settings_editor_features' ); |
| 50 |
|