Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Access valid_origins via static keyword so children can override it
  • Loading branch information
oandregal committed Feb 11, 2022
commit 1e9f4483779a046c89017bf6a6aa77a78cd99380
20 changes: 14 additions & 6 deletions lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class WP_Theme_JSON_5_9 {
* One of 'default', 'theme', or 'custom'. Default 'theme'.
*/
public function __construct( $theme_json = array(), $origin = 'theme' ) {
if ( ! in_array( $origin, self::VALID_ORIGINS, true ) ) {
if ( ! in_array( $origin, static::VALID_ORIGINS, true ) ) {
$origin = 'theme';
}

Expand Down Expand Up @@ -616,10 +616,14 @@ public function get_settings() {
* 'variables': only the CSS Custom Properties for presets & custom ones.
* 'styles': only the styles section in theme.json.
* 'presets': only the classes for the presets.
* @param array $origins A list of origins to include. By default it includes self::VALID_ORIGINS.
* @param array $origins A list of origins to include. By default it includes VALID_ORIGINS.
* @return string Stylesheet.
*/
public function get_stylesheet( $types = array( 'variables', 'styles', 'presets' ), $origins = self::VALID_ORIGINS ) {
public function get_stylesheet( $types = array( 'variables', 'styles', 'presets' ), $origins = null ) {
if ( $origins === null ) {
$origins = static::VALID_ORIGINS;
}

if ( is_string( $types ) ) {
// Dispatch error and map old arguments to new ones.
_deprecated_argument( __FUNCTION__, '5.9' );
Expand Down Expand Up @@ -1054,7 +1058,11 @@ private static function get_settings_values_by_slug( $settings, $preset_metadata
* @param array $origins List of origins to process.
* @return array Array of presets where the key and value are both the slug.
*/
private static function get_settings_slugs( $settings, $preset_metadata, $origins = self::VALID_ORIGINS ) {
private static function get_settings_slugs( $settings, $preset_metadata, $origins = null ) {
if ( $origins === null ) {
$origins = static::VALID_ORIGINS;
}

$preset_per_origin = _wp_array_get( $settings, $preset_metadata['path'], array() );

$result = array();
Expand Down Expand Up @@ -1460,7 +1468,7 @@ public function merge( $incoming ) {
foreach ( static::PRESETS_METADATA as $preset ) {
$override_preset = self::should_override_preset( $this->theme_json, $node['path'], $preset['override'] );

foreach ( self::VALID_ORIGINS as $origin ) {
foreach ( static::VALID_ORIGINS as $origin ) {
$base_path = array_merge( $node['path'], $preset['path'] );
$path = array_merge( $base_path, array( $origin ) );
$content = _wp_array_get( $incoming_data, $path, null );
Expand Down Expand Up @@ -1719,7 +1727,7 @@ public static function remove_insecure_properties( $theme_json ) {
private static function remove_insecure_settings( $input ) {
$output = array();
foreach ( static::PRESETS_METADATA as $preset_metadata ) {
foreach ( self::VALID_ORIGINS as $origin ) {
foreach ( static::VALID_ORIGINS as $origin ) {
$path_with_origin = array_merge( $preset_metadata['path'], array( $origin ) );
$presets = _wp_array_get( $input, $path_with_origin, null );
if ( null === $presets ) {
Expand Down