Skip to content

Commit 1b3bf19

Browse files
authored
Merge branch 'WordPress:trunk' into trunk
2 parents dd2558f + 9aafa93 commit 1b3bf19

5 files changed

Lines changed: 83 additions & 37 deletions

File tree

src/wp-includes/class-wp-theme-json.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ class WP_Theme_JSON {
415415
* Added support for `dimensions.width` and `dimensions.height`.
416416
* Added support for `typography.textIndent`.
417417
* @since 7.1.0 Added `viewport` property.
418-
* Added support for `background.gradient`.
418+
* Added support for `background.gradient` and `blockVisibility.allowEditing`.
419419
* @var array
420420
*/
421421
const VALID_SETTINGS = array(
@@ -474,6 +474,9 @@ class WP_Theme_JSON {
474474
'fixed' => null,
475475
'sticky' => null,
476476
),
477+
'blockVisibility' => array(
478+
'allowEditing' => true,
479+
),
477480
'spacing' => array(
478481
'customSpacingSize' => null,
479482
'defaultSpacingSizes' => null,
@@ -1330,7 +1333,9 @@ protected static function sanitize( $input, $valid_block_names, $valid_element_n
13301333
*/
13311334
foreach ( $valid_block_names as $block ) {
13321335
$schema_settings_blocks[ $block ] = static::VALID_SETTINGS;
1336+
// `viewport` and `blockVisibility` are global-only settings and cannot be set per block for now.
13331337
unset( $schema_settings_blocks[ $block ]['viewport'] );
1338+
unset( $schema_settings_blocks[ $block ]['blockVisibility'] );
13341339
$schema_styles_blocks[ $block ] = $styles_non_top_level;
13351340
$schema_styles_blocks[ $block ]['elements'] = $schema_styles_elements;
13361341

src/wp-includes/script-loader.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,10 +2230,7 @@ function _print_scripts() {
22302230

22312231
if ( $concat ) {
22322232
if ( ! empty( $wp_scripts->print_code ) ) {
2233-
echo "\n<script>\n";
2234-
echo $wp_scripts->print_code;
2235-
echo sprintf( "\n//# sourceURL=%s\n", rawurlencode( 'js-inline-concat-' . $concat ) );
2236-
echo "</script>\n";
2233+
wp_print_inline_script_tag( $wp_scripts->print_code . "\n//# sourceURL=" . rawurlencode( 'js-inline-concat-' . $concat ) );
22372234
}
22382235

22392236
$concat = str_split( $concat, 128 );
@@ -2244,7 +2241,7 @@ function _print_scripts() {
22442241
}
22452242

22462243
$src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}" . $concatenated . '&ver=' . $wp_scripts->default_version;
2247-
echo "<script src='" . esc_attr( $src ) . "'></script>\n";
2244+
wp_print_script_tag( array( 'src' => $src ) );
22482245
}
22492246

22502247
if ( ! empty( $wp_scripts->print_html ) ) {

tests/phpunit/tests/dependencies/scripts.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,6 +2275,9 @@ public function test_protocols() {
22752275

22762276
/**
22772277
* Test script concatenation.
2278+
*
2279+
* @global WP_Scripts $wp_scripts
2280+
* @global string $wp_version
22782281
*/
22792282
public function test_script_concatenation() {
22802283
global $wp_scripts, $wp_version;
@@ -2289,9 +2292,9 @@ public function test_script_concatenation() {
22892292
wp_print_scripts();
22902293
$print_scripts = get_echo( '_print_scripts' );
22912294

2292-
$expected = "<script src='/wp-admin/load-scripts.php?c=0&amp;load%5Bchunk_0%5D=one,two,three&amp;ver={$wp_version}'></script>\n";
2295+
$expected = "<script src=\"/wp-admin/load-scripts.php?c=0&#038;load%5Bchunk_0%5D=one,two,three&#038;ver={$wp_version}\"></script>\n";
22932296

2294-
$this->assertSame( $expected, $print_scripts );
2297+
$this->assertEqualHTML( $expected, $print_scripts );
22952298
}
22962299

22972300
/**
@@ -4310,6 +4313,10 @@ public function test_source_url_encoding() {
43104313

43114314
/**
43124315
* @ticket 63887
4316+
*
4317+
* @global WP_Scripts $wp_scripts
4318+
* @global bool $concatenate_scripts
4319+
* @global string $wp_version
43134320
*/
43144321
public function test_source_url_with_concat() {
43154322
global $wp_scripts, $concatenate_scripts, $wp_version;
@@ -4328,14 +4335,13 @@ public function test_source_url_with_concat() {
43284335
$print_scripts = get_echo( '_print_scripts' );
43294336

43304337
$expected = <<<HTML
4338+
<script>
4339+
var one = {"key":"val"};var two = {"key":"val"};
4340+
//# sourceURL=js-inline-concat-one%2Ctwo
4341+
</script>
4342+
<script src="/wp-admin/load-scripts.php?c=0&#038;load%5Bchunk_0%5D=one,two&#038;ver={$wp_version}"></script>
43314343
4332-
<script>
4333-
var one = {"key":"val"};var two = {"key":"val"};
4334-
//# sourceURL=js-inline-concat-one%2Ctwo
4335-
</script>
4336-
<script src="/wp-admin/load-scripts.php?c=0&load%5Bchunk_0%5D=one,two&ver={$wp_version}"></script>
4337-
4338-
HTML;
4344+
HTML;
43394345

43404346
$this->assertEqualHTML( $expected, $print_scripts );
43414347
}

tests/phpunit/tests/html-api/wpHtmlProcessorWebPlatformTests.php

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,21 @@ class Tests_HtmlApi_WebPlatformTests extends WP_UnitTestCase {
2727
* Skip specific tests that may not be supported or have known issues.
2828
*/
2929
const SKIP_TESTS = array(
30-
'noscript01/line0014' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
31-
'tests14/line0022' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
32-
'tests14/line0055' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
33-
'tests19/line0488' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
34-
'tests19/line0500' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
35-
'tests19/line1079' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
36-
'tests2/line0207' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
37-
'tests2/line0686' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
38-
'tests2/line0697' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
39-
'tests2/line0709' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
40-
'webkit01/line0231' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
41-
'webkit02/line0692' => 'Unimplemented: The parser does not implement the "maybe clone an option into selectedcontent" algorithm.',
42-
'webkit02/line0732' => 'Unimplemented: The parser does not implement the "maybe clone an option into selectedcontent" algorithm.',
43-
'webkit02/line0748' => 'Unimplemented: The parser does not implement the "maybe clone an option into selectedcontent" algorithm.',
30+
'noscript01/line0014' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
31+
'tests14/line0022' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
32+
'tests14/line0055' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
33+
'tests19/line0488' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
34+
'tests19/line0500' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
35+
'tests19/line1079' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
36+
'tests2/line0207' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
37+
'tests2/line0686' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
38+
'tests2/line0697' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
39+
'tests2/line0709' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
40+
'webkit01/line0231' => 'Unimplemented: This parser does not add missing attributes to existing HTML or BODY tags.',
41+
'webkit02/line0692' => 'Unimplemented: The parser does not implement the "maybe clone an option into selectedcontent" algorithm.',
42+
'webkit02/line0732' => 'Unimplemented: The parser does not implement the "maybe clone an option into selectedcontent" algorithm.',
43+
'webkit02/line0748' => 'Unimplemented: The parser does not implement the "maybe clone an option into selectedcontent" algorithm.',
44+
'processing-instructions/line0999' => 'Temporarily disabled invalid test.',
4445
);
4546

4647
/**
@@ -463,13 +464,20 @@ public static function parse_web_platform_test_file( $filename ) {
463464

464465
fclose( $handle );
465466

466-
// Return the last result when reaching the end of the file.
467-
return array(
468-
$test_line_number,
469-
$test_context_element,
470-
// Remove the trailing newline
471-
substr( $test_html, 0, -1 ),
472-
$test_dom,
473-
);
467+
// Yield the last result when reaching the end of the file.
468+
if ( $state && ! $test_script_flag ) {
469+
// Other tests include the blank line separating them from the next test.
470+
if ( ! str_ends_with( $test_dom, "\n\n" ) ) {
471+
$test_dom .= "\n";
472+
}
473+
474+
yield array(
475+
$test_line_number,
476+
$test_context_element,
477+
// Remove the trailing newline
478+
substr( $test_html, 0, -1 ),
479+
$test_dom,
480+
);
481+
}
474482
}
475483
}

tests/phpunit/tests/theme/wpThemeJson.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,36 @@ public function test_get_settings() {
103103
$this->assertEqualSetsWithIndex( $expected, $actual );
104104
}
105105

106+
/**
107+
* @ticket 65592
108+
*/
109+
public function test_get_block_visibility_settings() {
110+
// Test that the value passes through the full sanitization pipeline,
111+
// including remove_insecure_properties (called when saving global styles).
112+
$theme_json_data = array(
113+
'version' => WP_Theme_JSON::LATEST_SCHEMA,
114+
'settings' => array(
115+
'blockVisibility' => array(
116+
'allowEditing' => false,
117+
),
118+
'blocks' => array(
119+
'core/group' => array(
120+
'blockVisibility' => array(
121+
'allowEditing' => true,
122+
),
123+
),
124+
),
125+
),
126+
);
127+
$sanitized = WP_Theme_JSON::remove_insecure_properties( $theme_json_data );
128+
$theme_json = new WP_Theme_JSON( $sanitized );
129+
$actual = $theme_json->get_settings();
130+
131+
$this->assertFalse( $actual['blockVisibility']['allowEditing'] );
132+
// The setting is global-only: block-scoped values are stripped during sanitization.
133+
$this->assertArrayNotHasKey( 'blockVisibility', $actual['blocks']['core/group'] ?? array() );
134+
}
135+
106136
/**
107137
* @ticket 53397
108138
*/

0 commit comments

Comments
 (0)