-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make global styles data filterable (#44015)
Use a WP_Theme_JSON_Data structure in the filters so consumers don't edit directly the theme.json array, whose format could be updated forcing consumers to update their code if they edit directly.
- Loading branch information
Showing
4 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/** | ||
* API to update a theme.json structure. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* Class to update with a theme.json structure. | ||
*/ | ||
class WP_Theme_JSON_Data { | ||
|
||
/** | ||
* Container of the data to update. | ||
* | ||
* @var WP_Theme_JSON | ||
*/ | ||
private $theme_json = null; | ||
|
||
/** | ||
* The origin of the data: default, theme, user, etc. | ||
* | ||
* @var string | ||
*/ | ||
private $origin = null; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param array $data Array following the theme.json specification. | ||
* @param string $origin The origin of the data: default, theme, user. | ||
*/ | ||
public function __construct( $data = array(), $origin = 'theme' ) { | ||
$this->origin = $origin; | ||
$this->theme_json = new WP_Theme_JSON_Gutenberg( $data, $this->origin ); | ||
} | ||
|
||
/** | ||
* Updates the theme.json with the the given data. | ||
* | ||
* @param array $new_data Array following the theme.json specification. | ||
* | ||
* @return WP_Theme_JSON_Data the modified data. | ||
*/ | ||
public function update_with( $new_data ) { | ||
$this->theme_json->merge( new WP_Theme_JSON_Gutenberg( $new_data, $this->origin ) ); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Returns the underlying data. | ||
* | ||
* @return array | ||
*/ | ||
public function get_data() { | ||
return $this->theme_json->get_raw_data(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters