Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
baa9ab4
Add initial backports
glendaviesnz Jan 31, 2023
b314cf3
Test that invalid CSS is rejected
glendaviesnz Feb 1, 2023
f0a244b
Add tests for global styles custom CSS
glendaviesnz Feb 1, 2023
cecd9ca
fix function name
glendaviesnz Feb 1, 2023
5a11f8a
Fix class naming issue
glendaviesnz Feb 1, 2023
bd7fe93
Fix linting issue
glendaviesnz Feb 1, 2023
76d3f99
Add tests for global custom CSS
glendaviesnz Feb 1, 2023
c446376
add debugging to unit test
glendaviesnz Feb 1, 2023
8f7afa8
check for array or object
glendaviesnz Feb 1, 2023
1f74f52
Remove debugging
glendaviesnz Feb 1, 2023
6787594
Add in check for edit-css capabilities
glendaviesnz Feb 1, 2023
e4d53a2
Add tests for custom CSS user capabilities
glendaviesnz Feb 1, 2023
400d437
Fix permissions issue on multisite test
glendaviesnz Feb 1, 2023
eec32b6
Put permissions assignment in the right place!
glendaviesnz Feb 1, 2023
c9fcd81
Set permissions in tests instead of setup to prevent changing permiss…
glendaviesnz Feb 1, 2023
7450db9
Fixes from code review
glendaviesnz Feb 1, 2023
d6c6e65
Remove unnecessary description
glendaviesnz Feb 1, 2023
20442c9
But make user definition that was removed by mistake
glendaviesnz Feb 1, 2023
d055fa5
Change ordering of $request[styles] assignment to $config[styles]
glendaviesnz Feb 1, 2023
d37e7f2
Change cache key and add doc comments
glendaviesnz Feb 1, 2023
d71a7fe
match cache key to method name
glendaviesnz Feb 1, 2023
b658684
Move check for theme.json to top of function
glendaviesnz Feb 1, 2023
6a986eb
Merge branch 'trunk' into backport/global-styles-custom-css
felixarntz Feb 2, 2023
7261356
Update inline comment.
felixarntz Feb 2, 2023
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
Fixes from code review
  • Loading branch information
glendaviesnz committed Feb 1, 2023
commit 7450db95cb06607175b5cc684892d40a3dd48b6d
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public function update_item( $request ) {
* @since 6.2.0 Added validation of styles.css property.
*
* @param WP_REST_Request $request Request object.
* @return stdClass Changes to pass to wp_update_post.
* @return stdClass|WP_Error Prepared item on success. WP_Error on when the custom CSS is not valid.
*/
protected function prepare_item_for_database( $request ) {
$changes = new stdClass();
Expand All @@ -318,9 +318,11 @@ protected function prepare_item_for_database( $request ) {
$config = array();
if ( isset( $request['styles'] ) ) {
$config['styles'] = $request['styles'];
$validate_custom_css = $this->validate_custom_css( $request['styles']['css'] );
if ( is_wp_error( $validate_custom_css ) ) {
return $validate_custom_css;
if ( isset( $config['styles']['css'] ) ) {
$css_validation_result = $this->validate_custom_css( $config['styles']['css'] );
if ( is_wp_error( $css_validation_result ) ) {
return $css_validation_result;
}
}
} elseif ( isset( $existing_config['styles'] ) ) {
$config['styles'] = $existing_config['styles'];
Expand Down Expand Up @@ -681,7 +683,7 @@ private function validate_custom_css( $css ) {
if ( preg_match( '#</?\w+#', $css ) ) {
return new WP_Error(
'rest_custom_css_illegal_markup',
__( 'Markup is not allowed in CSS.', 'gutenberg' ),
__( 'Markup is not allowed in CSS.' ),
array( 'status' => 400 )
);
}
Expand Down
3 changes: 1 addition & 2 deletions tests/phpunit/tests/theme/wpThemeJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -4540,7 +4540,7 @@ public function test_get_custom_css_handles_global_custom_css() {
)
);
$custom_css = 'body { color:purple; }';
$this->assertEquals( $custom_css, $theme_json->get_custom_css() );
$this->assertSame( $custom_css, $theme_json->get_custom_css() );
}

/**
Expand All @@ -4550,7 +4550,6 @@ public function test_get_custom_css_handles_global_custom_css() {
*
* @dataProvider data_custom_css_for_user_caps
*
*
* @param string $user_property The property name for current user.
* @param array $expected Expected results.
*/
Expand Down