Skip to content

Commit e25b9c9

Browse files
committed
Merge branch 'trunk' into collaboration/table-awareness-object-cache
2 parents 78f875a + adf6443 commit e25b9c9

6 files changed

Lines changed: 454 additions & 202 deletions

File tree

Gruntfile.js

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,55 @@ module.exports = function(grunt) {
397397
'suggest*'
398398
],
399399
dest: WORKING_DIR + 'wp-includes/js/jquery/'
400+
},
401+
{
402+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/lodash.js' ]: [ './node_modules/lodash/lodash.js' ],
403+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/lodash.min.js' ]: [ './node_modules/lodash/lodash.min.js' ],
404+
},
405+
{
406+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/moment.js' ]: [ './node_modules/moment/moment.js' ],
407+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/moment.min.js' ]: [ './node_modules/moment/min/moment.min.js' ],
408+
},
409+
{
410+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/regenerator-runtime.js' ]: [ './node_modules/regenerator-runtime/runtime.js' ],
411+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/regenerator-runtime.min.js' ]: [ './node_modules/regenerator-runtime/runtime.js' ],
412+
},
413+
// React libraries: react, react-dom
414+
{
415+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/react.js' ]: [ './node_modules/react/umd/react.development.js' ],
416+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/react.min.js' ]: [ './node_modules/react/umd/react.production.min.js' ],
417+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/react-dom.js' ]: [ './node_modules/react-dom/umd/react-dom.development.js' ],
418+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/react-dom.min.js' ]: [ './node_modules/react-dom/umd/react-dom.production.min.js' ],
419+
},
420+
// Polyfills
421+
{
422+
// @wordpress/babel-preset-default
423+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/wp-polyfill.js' ]: [ './node_modules/@wordpress/babel-preset-default/build/polyfill.js' ],
424+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/wp-polyfill.min.js' ]: [ './node_modules/@wordpress/babel-preset-default/build/polyfill.min.js' ],
425+
// polyfill-library (DOMRect)
426+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/wp-polyfill-dom-rect.js' ]: [ './node_modules/polyfill-library/polyfills/__dist/DOMRect/raw.js' ],
427+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/wp-polyfill-dom-rect.min.js' ]: [ './node_modules/polyfill-library/polyfills/__dist/DOMRect/min.js' ],
428+
// element-closest
429+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/wp-polyfill-element-closest.js' ]: [ './node_modules/element-closest/browser.js' ],
430+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/wp-polyfill-element-closest.min.js' ]: [ './node_modules/element-closest/browser.js' ],
431+
// whatwg-fetch
432+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/wp-polyfill-fetch.js' ]: [ './node_modules/whatwg-fetch/dist/fetch.umd.js' ],
433+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/wp-polyfill-fetch.min.js' ]: [ './node_modules/whatwg-fetch/dist/fetch.umd.js' ],
434+
// formdata-polyfill
435+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/wp-polyfill-formdata.js' ]: [ './node_modules/formdata-polyfill/FormData.js' ],
436+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/wp-polyfill-formdata.min.js' ]: [ './node_modules/formdata-polyfill/formdata.min.js' ],
437+
// wicg-inert
438+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/wp-polyfill-inert.js' ]: [ './node_modules/wicg-inert/dist/inert.js' ],
439+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/wp-polyfill-inert.min.js' ]: [ './node_modules/wicg-inert/dist/inert.min.js' ],
440+
// polyfill-library (Node.prototype.contains)
441+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/wp-polyfill-node-contains.js' ]: [ './node_modules/polyfill-library/polyfills/__dist/Node.prototype.contains/raw.js' ],
442+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/wp-polyfill-node-contains.min.js' ]: [ './node_modules/polyfill-library/polyfills/__dist/Node.prototype.contains/min.js' ],
443+
// objectFitPolyfill
444+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/wp-polyfill-object-fit.js' ]: [ './node_modules/objectFitPolyfill/src/objectFitPolyfill.js' ],
445+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/wp-polyfill-object-fit.min.js' ]: [ './node_modules/objectFitPolyfill/dist/objectFitPolyfill.min.js' ],
446+
// core-js-url-browser
447+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/wp-polyfill-url.js' ]: [ './node_modules/core-js-url-browser/url.js' ],
448+
[ WORKING_DIR + 'wp-includes/js/dist/vendor/wp-polyfill-url.min.js' ]: [ './node_modules/core-js-url-browser/url.min.js' ],
400449
}
401450
].concat(
402451
// Copy tinymce.js only when building to /src.
@@ -1107,6 +1156,14 @@ module.exports = function(grunt) {
11071156
src: WORKING_DIR + 'wp-includes/js/dist/vendor/moment.js',
11081157
dest: WORKING_DIR + 'wp-includes/js/dist/vendor/moment.min.js'
11091158
},
1159+
'regenerator-runtime': {
1160+
src: WORKING_DIR + 'wp-includes/js/dist/vendor/regenerator-runtime.js',
1161+
dest: WORKING_DIR + 'wp-includes/js/dist/vendor/regenerator-runtime.min.js'
1162+
},
1163+
'wp-polyfill-fetch': {
1164+
src: WORKING_DIR + 'wp-includes/js/dist/vendor/wp-polyfill-fetch.js',
1165+
dest: WORKING_DIR + 'wp-includes/js/dist/vendor/wp-polyfill-fetch.min.js'
1166+
},
11101167
dynamic: {
11111168
expand: true,
11121169
cwd: WORKING_DIR,
@@ -1635,18 +1692,6 @@ module.exports = function(grunt) {
16351692
} );
16361693
} );
16371694

1638-
grunt.registerTask( 'copy-vendor-scripts', 'Copies vendor scripts from node_modules to wp-includes/js/dist/vendor/.', function() {
1639-
const done = this.async();
1640-
const buildDir = grunt.option( 'dev' ) ? 'src' : 'build';
1641-
grunt.util.spawn( {
1642-
cmd: 'node',
1643-
args: [ 'tools/vendors/copy-vendors.js', `--build-dir=${ buildDir }` ],
1644-
opts: { stdio: 'inherit' }
1645-
}, function( error ) {
1646-
done( ! error );
1647-
} );
1648-
} );
1649-
16501695
grunt.renameTask( 'watch', '_watch' );
16511696

16521697
grunt.registerTask( 'watch', function() {
@@ -1675,6 +1720,8 @@ module.exports = function(grunt) {
16751720
'uglify:imgareaselect',
16761721
'uglify:jqueryform',
16771722
'uglify:moment',
1723+
'uglify:regenerator-runtime',
1724+
'uglify:wp-polyfill-fetch',
16781725
'qunit:compiled'
16791726
] );
16801727

@@ -1817,7 +1864,9 @@ module.exports = function(grunt) {
18171864
'uglify:jquery-ui',
18181865
'uglify:imgareaselect',
18191866
'uglify:jqueryform',
1820-
'uglify:moment'
1867+
'uglify:moment',
1868+
'uglify:regenerator-runtime',
1869+
'uglify:wp-polyfill-fetch'
18211870
] );
18221871

18231872
grunt.registerTask( 'build:codemirror', [
@@ -1837,7 +1886,6 @@ module.exports = function(grunt) {
18371886
'clean:js',
18381887
'build:webpack',
18391888
'copy:js',
1840-
'copy-vendor-scripts',
18411889
'file_append',
18421890
'uglify:all',
18431891
'concat:tinymce',

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@
142142
"typecheck:php": "node ./tools/local-env/scripts/docker.js run --rm php composer phpstan",
143143
"gutenberg:copy": "node tools/gutenberg/copy.js",
144144
"gutenberg:verify": "node tools/gutenberg/utils.js",
145-
"gutenberg:download": "node tools/gutenberg/download.js && grunt build:gutenberg --dev",
146-
"vendor:copy": "node tools/vendors/copy-vendors.js"
145+
"gutenberg:download": "node tools/gutenberg/download.js && grunt build:gutenberg --dev"
147146
}
148147
}

src/wp-admin/menu.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272

7373
$menu[10] = array( __( 'Media' ), 'upload_files', 'upload.php', '', 'menu-top menu-icon-media', 'menu-media', 'dashicons-admin-media' );
7474

75-
$submenu['upload.php'][5] = array( __( 'Library' ), 'upload_files', 'upload.php' );
75+
$submenu['upload.php'][5] = array( _x( 'Library', 'media library menu item' ), 'upload_files', 'upload.php' );
7676
$submenu['upload.php'][10] = array( __( 'Add Media File' ), 'upload_files', 'media-new.php' );
7777
$submenu_index = 15;
7878

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

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,158 @@ function wp_register_custom_css_support( $block_type ) {
124124
}
125125
}
126126

127+
/**
128+
* Strips `style.css` attributes from all blocks in post content.
129+
*
130+
* Uses {@see WP_Block_Parser::next_token()} to scan block tokens and surgically
131+
* replace only the attribute JSON that changed — no parse_blocks() +
132+
* serialize_blocks() round-trip needed.
133+
*
134+
* @since 7.0.0
135+
* @access private
136+
*
137+
* @param string $content Post content to filter, expected to be escaped with slashes.
138+
* @return string Filtered post content with block custom CSS removed.
139+
*/
140+
function wp_strip_custom_css_from_blocks( $content ) {
141+
if ( ! has_blocks( $content ) ) {
142+
return $content;
143+
}
144+
145+
$unslashed = stripslashes( $content );
146+
147+
$parser = new WP_Block_Parser();
148+
$parser->document = $unslashed;
149+
$parser->offset = 0;
150+
$end = strlen( $unslashed );
151+
$replacements = array();
152+
153+
while ( $parser->offset < $end ) {
154+
$next_token = $parser->next_token();
155+
156+
if ( 'no-more-tokens' === $next_token[0] ) {
157+
break;
158+
}
159+
160+
list( $token_type, , $attrs, $start_offset, $token_length ) = $next_token;
161+
162+
$parser->offset = $start_offset + $token_length;
163+
164+
if ( 'block-opener' !== $token_type && 'void-block' !== $token_type ) {
165+
continue;
166+
}
167+
168+
if ( ! isset( $attrs['style']['css'] ) ) {
169+
continue;
170+
}
171+
172+
// Remove css and clean up empty style.
173+
unset( $attrs['style']['css'] );
174+
if ( empty( $attrs['style'] ) ) {
175+
unset( $attrs['style'] );
176+
}
177+
178+
// Locate the JSON portion within the token.
179+
$token_string = substr( $unslashed, $start_offset, $token_length );
180+
$json_rel_start = strcspn( $token_string, '{' );
181+
$json_rel_end = strrpos( $token_string, '}' );
182+
183+
$json_start = $start_offset + $json_rel_start;
184+
$json_length = $json_rel_end - $json_rel_start + 1;
185+
186+
// Re-encode attributes. If attrs is now empty, remove JSON and trailing space.
187+
if ( empty( $attrs ) ) {
188+
// Remove the trailing space after JSON.
189+
$replacements[] = array( $json_start, $json_length + 1, '' );
190+
} else {
191+
$replacements[] = array( $json_start, $json_length, serialize_block_attributes( $attrs ) );
192+
}
193+
}
194+
195+
if ( empty( $replacements ) ) {
196+
return $content;
197+
}
198+
199+
// Build the result by splicing replacements into the original string.
200+
$result = '';
201+
$was_at = 0;
202+
203+
foreach ( $replacements as $replacement ) {
204+
list( $offset, $length, $new_json ) = $replacement;
205+
$result .= substr( $unslashed, $was_at, $offset - $was_at ) . $new_json;
206+
$was_at = $offset + $length;
207+
}
208+
209+
if ( $was_at < $end ) {
210+
$result .= substr( $unslashed, $was_at );
211+
}
212+
213+
return addslashes( $result );
214+
}
215+
216+
/**
217+
* 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).
219+
*
220+
* @since 7.0.0
221+
* @access private
222+
*/
223+
function wp_custom_css_kses_init_filters() {
224+
add_filter( 'content_save_pre', 'wp_strip_custom_css_from_blocks', 8 );
225+
add_filter( 'content_filtered_save_pre', 'wp_strip_custom_css_from_blocks', 8 );
226+
}
227+
228+
/**
229+
* 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).
231+
*
232+
* @since 7.0.0
233+
* @access private
234+
*/
235+
function wp_custom_css_remove_filters() {
236+
remove_filter( 'content_save_pre', 'wp_strip_custom_css_from_blocks', 8 );
237+
remove_filter( 'content_filtered_save_pre', 'wp_strip_custom_css_from_blocks', 8 );
238+
}
239+
240+
/**
241+
* Registers the custom CSS content filters if the user does not have the edit_css capability.
242+
*
243+
* @since 7.0.0
244+
* @access private
245+
*/
246+
function wp_custom_css_kses_init() {
247+
wp_custom_css_remove_filters();
248+
if ( ! current_user_can( 'edit_css' ) ) {
249+
wp_custom_css_kses_init_filters();
250+
}
251+
}
252+
253+
/**
254+
* Initializes custom CSS content filters when imported data should be filtered.
255+
*
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.
258+
* If the input of the filter is true it means we are in an import situation and should
259+
* enable the custom CSS filters, independently of the user capabilities.
260+
*
261+
* @since 7.0.0
262+
* @access private
263+
*
264+
* @param mixed $arg Input argument of the filter.
265+
* @return mixed Input argument of the filter.
266+
*/
267+
function wp_custom_css_force_filtered_html_on_import_filter( $arg ) {
268+
if ( $arg ) {
269+
wp_custom_css_kses_init_filters();
270+
}
271+
return $arg;
272+
}
273+
274+
// Run before wp_filter_global_styles_post (priority 9) and wp_filter_post_kses (priority 10).
275+
add_action( 'init', 'wp_custom_css_kses_init', 20 );
276+
add_action( 'set_current_user', 'wp_custom_css_kses_init' );
277+
add_filter( 'force_filtered_html_on_import', 'wp_custom_css_force_filtered_html_on_import_filter', 999 );
278+
127279
// Register the block support.
128280
WP_Block_Supports::get_instance()->register(
129281
'custom-css',

0 commit comments

Comments
 (0)