block-supports
1 year ago
compat
1 year ago
experimental
1 year ago
README.md
1 year ago
block-editor-settings.php
1 year ago
blocks.php
1 year ago
class-wp-duotone-gutenberg.php
1 year ago
class-wp-theme-json-data-gutenberg.php
1 year ago
class-wp-theme-json-gutenberg.php
1 year ago
class-wp-theme-json-resolver-gutenberg.php
1 year ago
client-assets.php
1 year ago
demo.php
1 year ago
experiments-page.php
1 year ago
global-styles-and-settings.php
1 year ago
init.php
1 year ago
load.php
1 year ago
script-loader.php
1 year ago
theme-i18n.json
1 year ago
theme.json
1 year ago
upgrade.php
1 year ago
class-wp-theme-json-data-gutenberg.php
73 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WP_Theme_JSON_Data class |
| 4 | * |
| 5 | * @package gutenberg |
| 6 | * @since 6.1.0 |
| 7 | */ |
| 8 | |
| 9 | /** |
| 10 | * Class to provide access to update a theme.json structure. |
| 11 | */ |
| 12 | #[AllowDynamicProperties] |
| 13 | class WP_Theme_JSON_Data_Gutenberg { |
| 14 | |
| 15 | /** |
| 16 | * Container of the data to update. |
| 17 | * |
| 18 | * @since 6.1.0 |
| 19 | * @var WP_Theme_JSON |
| 20 | */ |
| 21 | private $theme_json = null; |
| 22 | |
| 23 | /** |
| 24 | * The origin of the data: default, theme, user, etc. |
| 25 | * |
| 26 | * @since 6.1.0 |
| 27 | * @var string |
| 28 | */ |
| 29 | private $origin = ''; |
| 30 | |
| 31 | /** |
| 32 | * Constructor. |
| 33 | * |
| 34 | * @since 6.1.0 |
| 35 | * |
| 36 | * @link https://developer.wordpress.org/block-editor/reference-guides/theme-json-reference/ |
| 37 | * |
| 38 | * @param array $data Array following the theme.json specification. |
| 39 | * @param string $origin The origin of the data: default, theme, user. |
| 40 | */ |
| 41 | public function __construct( $data = array(), $origin = 'theme' ) { |
| 42 | $this->origin = $origin; |
| 43 | $this->theme_json = new WP_Theme_JSON_Gutenberg( $data, $this->origin ); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Updates the theme.json with the the given data. |
| 48 | * |
| 49 | * @since 6.1.0 |
| 50 | * |
| 51 | * @param array $new_data Array following the theme.json specification. |
| 52 | * |
| 53 | * @return WP_Theme_JSON_Data_Gutenberg The own instance with access to the modified data. |
| 54 | */ |
| 55 | public function update_with( $new_data ) { |
| 56 | $this->theme_json->merge( new WP_Theme_JSON_Gutenberg( $new_data, $this->origin ) ); |
| 57 | return $this; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns an array containing the underlying data |
| 62 | * following the theme.json specification. |
| 63 | * |
| 64 | * @since 6.1.0 |
| 65 | * |
| 66 | * @return array |
| 67 | */ |
| 68 | public function get_data() { |
| 69 | return $this->theme_json->get_raw_data(); |
| 70 | } |
| 71 | |
| 72 | } |
| 73 |