Skip to content

Commit 91fbc2f

Browse files
committed
Updated documentation to use proper reference syntax for WP_Block_Parser::next_token(). Improved logic in wp_strip_custom_css_from_blocks to access token data directly from the $next_token array. Adjusted filter priorities in wp_custom_css_kses_init_filters and wp_custom_css_force_filtered_html_on_import_filter to ensure correct execution order during content processing.
1 parent 14c87de commit 91fbc2f

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/wp-includes/block-supports/custom-css.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function wp_register_custom_css_support( $block_type ) {
127127
/**
128128
* Strips `style.css` attributes from all blocks in post content.
129129
*
130-
* Uses WP_Block_Parser::next_token() to scan block tokens and surgically
130+
* Uses {@see WP_Block_Parser::next_token()} to scan block tokens and surgically
131131
* replace only the attribute JSON that changed — no parse_blocks() +
132132
* serialize_blocks() round-trip needed.
133133
*
@@ -152,12 +152,13 @@ function wp_strip_custom_css_from_blocks( $content ) {
152152

153153
while ( $parser->offset < $end ) {
154154
$next_token = $parser->next_token();
155-
list( $token_type, , $attrs, $start_offset, $token_length ) = $next_token;
156155

157-
if ( 'no-more-tokens' === $token_type ) {
156+
if ( 'no-more-tokens' === $next_token[0] ) {
158157
break;
159158
}
160159

160+
list( $token_type, , $attrs, $start_offset, $token_length ) = $next_token;
161+
161162
$parser->offset = $start_offset + $token_length;
162163

163164
if ( 'block-opener' !== $token_type && 'void-block' !== $token_type ) {
@@ -214,6 +215,7 @@ function wp_strip_custom_css_from_blocks( $content ) {
214215

215216
/**
216217
* Adds the filters to strip custom CSS from block content on save.
218+
* Priority of 8 to run before wp_filter_global_styles_post (priority 9) and wp_filter_post_kses (priority 10).
217219
*
218220
* @since 7.0.0
219221
* @access private
@@ -225,6 +227,7 @@ function wp_custom_css_kses_init_filters() {
225227

226228
/**
227229
* Removes the filters that strip custom CSS from block content on save.
230+
* Priority of 8 to run before wp_filter_global_styles_post (priority 9) and wp_filter_post_kses (priority 10).
228231
*
229232
* @since 7.0.0
230233
* @access private
@@ -250,7 +253,8 @@ function wp_custom_css_kses_init() {
250253
/**
251254
* Initializes custom CSS content filters when imported data should be filtered.
252255
*
253-
* This filter is the last being executed on force_filtered_html_on_import.
256+
* Runs at priority 999 on {@see 'force_filtered_html_on_import'} to ensure it
257+
* fires after general KSES initialization, independently of user capabilities.
254258
* If the input of the filter is true it means we are in an import situation and should
255259
* enable the custom CSS filters, independently of the user capabilities.
256260
*
@@ -267,6 +271,7 @@ function wp_custom_css_force_filtered_html_on_import_filter( $arg ) {
267271
return $arg;
268272
}
269273

274+
// Run before wp_filter_global_styles_post (priority 9) and wp_filter_post_kses (priority 10).
270275
add_action( 'init', 'wp_custom_css_kses_init', 20 );
271276
add_action( 'set_current_user', 'wp_custom_css_kses_init' );
272277
add_filter( 'force_filtered_html_on_import', 'wp_custom_css_force_filtered_html_on_import_filter', 999 );

0 commit comments

Comments
 (0)