| 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( 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA ), $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 |
* Return theme JSON object. |
| 74 |
* |
| 75 |
* @since 18.5.0 |
| 76 |
* |
| 77 |
* @return WP_Theme_JSON |
| 78 |
*/ |
| 79 |
public function get_theme_json() { |
| 80 |
return $this->theme_json; |
| 81 |
} |
| 82 |
} |
| 83 |
|