Make WordPress Core

Opened 10 months ago

Closed 6 months ago

#64544 closed enhancement (fixed)

Core GB backport - individual block custom CSS

Reported by: glendaviesnz Owned by: ellatrix
Priority: normal Milestone: 7.0
Component: General Version: 7.0
Severity: normal Keywords: has-patch gutenberg-merge fixed-major dev-reviewed
Cc: Focuses:

Description

Custom CSS for individual blocks is about to be merged to the Gutenberg plugin via ​https://github.com/WordPress/gutenberg/pull/73959 which involves updates to lib php files which need to be included in the next WP release.

Change History (32)

This ticket was mentioned in ​PR #10777 on ​WordPress/wordpress-develop by ​@glendaviesnz.


10 months ago
#1

  • Keywords has-patch added; needs-patch removed

This is a backport of ​https://github.com/WordPress/gutenberg/pull/73959 which adds block level custom CSS support.

Trac ticket: [](https://core.trac.wordpress.org/ticket/64544)

#2 @wildworks
10 months ago

  • Keywords gutenberg-merge added

​@glendaviesnz commented on ​PR #10777:


9 months ago
#3

@Mamaduka I have added the change from ​https://github.com/WordPress/gutenberg/pull/74969

​@Mamaduka commented on ​PR #10777:


9 months ago
#4

Thank you, @glendaviesnz!

​@glendaviesnz commented on ​PR #10777:


9 months ago
#5

@scruffian, @aaronrobertshaw I am not sure why all the tests are failing - it seems unrelated to this PR - have tried a rebase.

​@scruffian commented on ​PR #10777:


9 months ago
#6

A couple of reasons!

  1. Change WP_Theme_JSON_Gutenberg to WP_Theme_JSON in src/wp-includes/block-supports/custom-css.php:43
  2. Add static keyword to the method signature in src/wp-includes/class-wp-theme-json.php:1514

​@aaronrobertshaw commented on ​PR #10777:


9 months ago
#7

@scruffian is on the money regarding the test failures.

One other nit is that I believe core tests required a @ticket XXXX annotation so it is easier to see when a specific test was added.

​@shimotomoki commented on ​PR #10777:


9 months ago
#8

@glendaviesnz Could you please also add these changes?🙏
​https://github.com/WordPress/gutenberg/pull/75052

​@glendaviesnz commented on ​PR #10777:


9 months ago
#10

@scruffian, @aaronrobertshaw I think it is ready for another review

#11 @ellatrix
9 months ago

  • Owner set to ellatrix
  • Resolution → fixed
  • Status new → closed

In 61678:

Gutenberg PHP merge: block level custom CSS.

Merges/syncs PHP changes from ​https://github.com/WordPress/gutenberg/pull/73959.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/10777.

Props glendaviesnz, shailu25, scruffian, aaronrobertshaw, mamaduka, shimotomoki.
Fixes #64544.

#12 @sabernhardt
9 months ago

  • Milestone Awaiting Review → 7.0

#13 @jonsurrell
9 months ago

@glendaviesnz [61678] re-introduces some behavior around CSS restrictions that was improved in [61486] (#64418) (source):

<?php
// Validate CSS doesn't contain HTML markup (same validation as global styles REST API).
if ( preg_match( '#</?\w+#', $custom_css ) ) {
        return $parsed_block;
}

Restrictions on CSS (style tag contents) were relaxed to allow more content. It would be nice to maintain that consistency. The previous restrictions referred to in the comment were unnecessarily restrictive and rejected many safe and valid CSS strings.

This CSS validation logic is duplicated ​in client-side logic in Gutenberg that disallows many valid CSS strings.

#14 follow-up: @jonsurrell
9 months ago

  • Resolution fixed
  • Status closed → reopened

Reopening based on this comment, that may be considered follow-up, but I want to prevent it from being overlooked.

​The updated validation logic can be found here.

#15 in reply to: ↑ 14 ; follow-up: @glendaviesnz
9 months ago

Replying to jonsurrell:

Reopening based on this comment, that may be considered follow-up, but I want to prevent it from being overlooked.

It looks like that changed after the original GB PR was merged. I think this can be a follow-up, it only affects the new block-level custom CSS. I won't have time to take a look for about 2 weeks, so if anyone thinks it should be fixed earlier to get into 7.0 feel free to open a PR.

#16 in reply to: ↑ 15 @jonsurrell
9 months ago

Replying to glendaviesnz:

I think this can be a follow-up, it only affects the new block-level custom CSS.

Thanks, that seems fine. This problems addressed in [61486] are not as typical in CSS for a specific block.

This ticket was mentioned in ​Slack in #core by audrasjb. ​View the logs.


8 months ago

#18 @audrasjb
8 months ago

  • Version → trunk

This ticket was mentioned in ​Slack in #core by mukeshpanchal27. ​View the logs.


8 months ago

#20 @joedolson
8 months ago

  • Resolution → fixed
  • Status reopened → closed

Closing this, as the bug is tracked in #64771.

This ticket was mentioned in ​PR #11686 on ​WordPress/wordpress-develop by ​@mukesh27.


6 months ago
#21

Performance regression for #10777

Trac ticket: https://core.trac.wordpress.org/ticket/64544

By checking $block['attrs']['className'] first, it ensure that for the 90% of blocks that don't have custom CSS, the function returns in microseconds without ever triggering the preg_match.

## Use of AI Tools

N/A

​@westonruter commented on ​PR #11686:


6 months ago
#22

@mukeshpanchal27 please review my additions

​@mukesh27 commented on ​PR #11686:


6 months ago
#24

@mukeshpanchal27 please review my additions

Thanks @westonruter, The changes look good to me.

#26 @westonruter
6 months ago

In 62359:

Block Supports: Improve performance and hardening of block-level custom CSS rendering.

Short-circuits the custom CSS support filter before the more expensive lookups so blocks without custom CSS return faster.

Replaces the regex class name parsing in wp_render_custom_css_class_name() with a cheap str_contains() guard followed by an HTML spec-compliant strtok() walk over the className tokens. This avoids the regex engine for the common case where no wp-custom-css- class is present, and correctly handles tab/form-feed/CR/LF separators as well as classes such as my-wp-custom-css-* that merely contain the prefix as a substring after a hyphen.

Also hardens both functions against malformed parsed blocks (non-string className, missing keys), tightens @phpstan-param array shapes, and corrects the block_has_support() @param to allow WP_Block_Type|null. Lastly, a @return Generator<int, non-empty-string> phpdoc tag is added to WP_HTML_Tag_Processor::class_list().

Developed in ​https://github.com/WordPress/wordpress-develop/pull/11686 and ​https://github.com/WordPress/gutenberg/pull/78217

Follow-up to r61678.

Props mukesh27, westonruter, ramonopoly, jonsurrell.
See #64544, #64238.

#27 follow-up: @westonruter
6 months ago

  • Keywords fixed-major dev-feedback added
  • Resolution fixed
  • Status closed → reopened

Re-opening for merging r62359 into the 7.0 branch.

​@westonruter commented on ​PR #11686:


6 months ago
#28

Committed in 20b5d10 (62359)

This ticket was mentioned in ​Slack in #core-performance by westonruter. ​View the logs.


6 months ago

#30 @ellatrix
6 months ago

  • Keywords dev-reviewed added; dev-feedback removed

#31 @ellatrix
6 months ago

In 62376:

Block Supports: Improve performance and hardening of block-level custom CSS rendering.

Short-circuits the custom CSS support filter before the more expensive lookups so blocks without custom CSS return faster.

Replaces the regex class name parsing in wp_render_custom_css_class_name() with a cheap str_contains() guard followed by an HTML spec-compliant strtok() walk over the className tokens. This avoids the regex engine for the common case where no wp-custom-css- class is present, and correctly handles tab/form-feed/CR/LF separators as well as classes such as my-wp-custom-css-* that merely contain the prefix as a substring after a hyphen.

Also hardens both functions against malformed parsed blocks (non-string className, missing keys), tightens @phpstan-param array shapes, and corrects the block_has_support() @param to allow WP_Block_Type|null. Lastly, a @return Generator<int, non-empty-string> phpdoc tag is added to WP_HTML_Tag_Processor::class_list().

Developed in ​https://github.com/WordPress/wordpress-develop/pull/11686 and ​https://github.com/WordPress/gutenberg/pull/78217

Follow-up to r61678.

Reviewed by ellatrix.
Merges [62359] to the 7.0 branch.
Props mukesh27, westonruter, ramonopoly, jonsurrell.
See #64544, #64238.

#32 in reply to: ↑ 27 @ellatrix
6 months ago

  • Resolution → fixed
  • Status reopened → closed

Replying to westonruter:

Re-opening for merging r62359 into the 7.0 branch.

Backported, so closing.

Note: See TracTickets for help on using tickets.