Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove code no longer necessary #28188

Merged
merged 2 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion lib/class-wp-theme-json-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ private static function get_user_origin() {
$config = $decoded_data;
}
}
self::$user = new WP_Theme_JSON( $config, true );
self::$user = new WP_Theme_JSON( $config );

return self::$user;
}
Expand Down
52 changes: 10 additions & 42 deletions lib/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,9 @@ class WP_Theme_JSON {
/**
* Constructor.
*
* @param array $contexts A structure that follows the theme.json schema.
* @param boolean $should_escape_styles Whether the incoming styles should be escaped.
* @param array $contexts A structure that follows the theme.json schema.
*/
public function __construct( $contexts = array(), $should_escape_styles = false ) {
public function __construct( $contexts = array() ) {
$this->contexts = array();

if ( ! is_array( $contexts ) ) {
Expand All @@ -317,10 +316,10 @@ public function __construct( $contexts = array(), $should_escape_styles = false
// Process styles subtree.
$this->process_key( 'styles', $context, self::SCHEMA );
if ( isset( $context['styles'] ) ) {
$this->process_key( 'border', $context['styles'], self::SCHEMA['styles'], $should_escape_styles );
$this->process_key( 'color', $context['styles'], self::SCHEMA['styles'], $should_escape_styles );
$this->process_key( 'spacing', $context['styles'], self::SCHEMA['styles'], $should_escape_styles );
$this->process_key( 'typography', $context['styles'], self::SCHEMA['styles'], $should_escape_styles );
$this->process_key( 'border', $context['styles'], self::SCHEMA['styles'] );
$this->process_key( 'color', $context['styles'], self::SCHEMA['styles'] );
$this->process_key( 'spacing', $context['styles'], self::SCHEMA['styles'] );
$this->process_key( 'typography', $context['styles'], self::SCHEMA['styles'] );

if ( empty( $context['styles'] ) ) {
unset( $context['styles'] );
Expand Down Expand Up @@ -523,12 +522,11 @@ private static function get_blocks_metadata() {
* This function modifies the given input by removing
* the nodes that aren't valid per the schema.
*
* @param string $key Key of the subtree to normalize.
* @param array $input Whole tree to normalize.
* @param array $schema Schema to use for normalization.
* @param boolean $should_escape Whether the subproperties should be escaped.
* @param string $key Key of the subtree to normalize.
* @param array $input Whole tree to normalize.
* @param array $schema Schema to use for normalization.
*/
private static function process_key( $key, &$input, $schema, $should_escape = false ) {
private static function process_key( $key, &$input, $schema ) {
if ( ! isset( $input[ $key ] ) ) {
return;
}
Expand All @@ -548,36 +546,6 @@ private static function process_key( $key, &$input, $schema, $should_escape = fa
$schema[ $key ]
);

if ( $should_escape ) {
$subtree = $input[ $key ];
foreach ( $subtree as $property => $value ) {
$name = 'background-color';
if ( 'gradient' === $property ) {
$name = 'background';
}

if ( is_array( $value ) ) {
$result = array();
foreach ( $value as $subproperty => $subvalue ) {
$result_subproperty = safecss_filter_attr( "$name: $subvalue" );
if ( '' !== $result_subproperty ) {
$result[ $subproperty ] = $result_subproperty;
}
}

if ( empty( $result ) ) {
unset( $input[ $key ][ $property ] );
}
} else {
$result = safecss_filter_attr( "$name: $value" );

if ( '' === $result ) {
unset( $input[ $key ][ $property ] );
}
}
}
}

if ( 0 === count( $input[ $key ] ) ) {
unset( $input[ $key ] );
}
Expand Down
33 changes: 0 additions & 33 deletions phpunit/class-wp-theme-json-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,6 @@

class WP_Theme_JSON_Test extends WP_UnitTestCase {

function test_user_data_is_escaped() {
$theme_json = new WP_Theme_JSON(
array(
'global' => array(
'styles' => array(
'color' => array(
'background' => 'green',
'gradient' => 'linear-gradient(10deg,rgba(6,147,227,1) 0%,rgb(61,132,163) 37%,rgb(155,81,224) 100%)',
'link' => 'linear-gradient(10deg,rgba(6,147,227,1) 0%,rgb(61,132,163) 37%,rgb(155,81,224) 100%)',
'text' => 'var:preset|color|dark-gray',
),
),
),
),
true
);
$result = $theme_json->get_raw_data();

$expected = array(
'global' => array(
'styles' => array(
'color' => array(
'background' => 'green',
'gradient' => 'linear-gradient(10deg,rgba(6,147,227,1) 0%,rgb(61,132,163) 37%,rgb(155,81,224) 100%)',
'text' => 'var:preset|color|dark-gray',
),
),
),
);

$this->assertEqualSetsWithIndex( $expected, $result );
}

function test_contexts_not_valid_are_skipped() {
$theme_json = new WP_Theme_JSON(
array(
Expand Down