Skip to content

Commit 9d5d79a

Browse files
committed
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develop into replace-esprima-with-espree
2 parents bd2376c + dc62ecb commit 9d5d79a

21 files changed

Lines changed: 1120 additions & 188 deletions

src/wp-admin/includes/dashboard.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,24 @@ function wp_dashboard_right_now() {
309309
if ( $num_posts && $num_posts->publish ) {
310310
if ( 'post' === $post_type ) {
311311
/* translators: %s: Number of posts. */
312-
$text = _n( '%s Post', '%s Posts', $num_posts->publish );
312+
$text = _n( '%s Published post', '%s Published posts', $num_posts->publish );
313313
} else {
314314
/* translators: %s: Number of pages. */
315-
$text = _n( '%s Page', '%s Pages', $num_posts->publish );
315+
$text = _n( '%s Published page', '%s Published pages', $num_posts->publish );
316316
}
317317

318318
$text = sprintf( $text, number_format_i18n( $num_posts->publish ) );
319319
$post_type_object = get_post_type_object( $post_type );
320320

321321
if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {
322-
printf( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text );
322+
$url = add_query_arg(
323+
array(
324+
'post_status' => 'publish',
325+
'post_type' => $post_type,
326+
),
327+
admin_url( 'edit.php' )
328+
);
329+
printf( '<li class="%1$s-count"><a href="%1$s">%2$s</a></li>', esc_url( $url ), esc_html( $text ) );
323330
} else {
324331
printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text );
325332
}

src/wp-content/themes/twentytwentyfour/functions.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
* @since Twenty Twenty-Four 1.0
99
*/
1010

11-
/**
12-
* Register block styles.
13-
*/
14-
1511
if ( ! function_exists( 'twentytwentyfour_block_styles' ) ) :
1612
/**
1713
* Registers custom block styles.
@@ -146,10 +142,6 @@ function twentytwentyfour_block_styles() {
146142

147143
add_action( 'init', 'twentytwentyfour_block_styles' );
148144

149-
/**
150-
* Enqueue block stylesheets.
151-
*/
152-
153145
if ( ! function_exists( 'twentytwentyfour_block_stylesheets' ) ) :
154146
/**
155147
* Enqueues custom block stylesheets.
@@ -180,10 +172,6 @@ function twentytwentyfour_block_stylesheets() {
180172

181173
add_action( 'init', 'twentytwentyfour_block_stylesheets' );
182174

183-
/**
184-
* Register pattern categories.
185-
*/
186-
187175
if ( ! function_exists( 'twentytwentyfour_pattern_categories' ) ) :
188176
/**
189177
* Registers pattern categories.

src/wp-includes/block-supports/block-style-variations.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,13 @@ function wp_render_block_style_variation_support_styles( $parsed_block ) {
142142
);
143143

144144
$config = array(
145-
'version' => WP_Theme_JSON::LATEST_SCHEMA,
146-
'styles' => array(
145+
'version' => WP_Theme_JSON::LATEST_SCHEMA,
146+
'settings' => array(
147+
'spacing' => array(
148+
'blockGap' => true,
149+
),
150+
),
151+
'styles' => array(
147152
'elements' => $elements_data,
148153
'blocks' => $blocks_data,
149154
),

src/wp-includes/block-supports/block-visibility.php

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
*/
88

99
/**
10-
* Render nothing if the block is hidden.
10+
* Render nothing if the block is hidden, or add viewport visibility styles.
1111
*
1212
* @since 6.9.0
13+
* @since 7.0.0 Added support for viewport visibility.
1314
* @access private
1415
*
1516
* @param string $block_content Rendered block content.
@@ -23,10 +24,126 @@ function wp_render_block_visibility_support( $block_content, $block ) {
2324
return $block_content;
2425
}
2526

26-
if ( isset( $block['attrs']['metadata']['blockVisibility'] ) && false === $block['attrs']['metadata']['blockVisibility'] ) {
27+
$block_visibility = $block['attrs']['metadata']['blockVisibility'] ?? null;
28+
29+
if ( false === $block_visibility ) {
2730
return '';
2831
}
2932

33+
if ( is_array( $block_visibility ) && ! empty( $block_visibility ) ) {
34+
$viewport_config = $block_visibility['viewport'] ?? null;
35+
36+
if ( ! is_array( $viewport_config ) || empty( $viewport_config ) ) {
37+
return $block_content;
38+
}
39+
/*
40+
* Viewport size definitions are in several places in WordPress packages.
41+
* The following are taken from: https://github.com/WordPress/gutenberg/blob/trunk/packages/base-styles/_breakpoints.scss
42+
* The array is in a future, potential JSON format, and will be centralized
43+
* as the feature is developed.
44+
*
45+
* Viewport sizes as array items are defined sequentially. The first item's size is the max value.
46+
* Each subsequent item starts after the previous size (using > operator), and its size is the max.
47+
* The last item starts after the previous size (using > operator), and it has no max.
48+
*/
49+
$viewport_sizes = array(
50+
array(
51+
'name' => 'Mobile',
52+
'slug' => 'mobile',
53+
'size' => '480px',
54+
),
55+
array(
56+
'name' => 'Tablet',
57+
'slug' => 'tablet',
58+
'size' => '782px',
59+
),
60+
array(
61+
'name' => 'Desktop',
62+
'slug' => 'desktop',
63+
/*
64+
* Note: the last item in the $viewport_sizes array does not technically require a 'size' key,
65+
* as the last item's media query is calculated using `width > previous size`.
66+
* The last item is present for validating the attribute values, and in order to indicate
67+
* that this is the final viewport size, and to calculate the previous media query accordingly.
68+
*/
69+
),
70+
);
71+
72+
/*
73+
* Build media queries from viewport size definitions using the CSS range syntax.
74+
* Could be absorbed into the style engine,
75+
* as well as classname building, and declaration of the display property, if required.
76+
*/
77+
$viewport_media_queries = array();
78+
$previous_size = null;
79+
foreach ( $viewport_sizes as $index => $viewport_size ) {
80+
// First item: width <= size.
81+
if ( 0 === $index ) {
82+
$viewport_media_queries[ $viewport_size['slug'] ] = "@media (width <= {$viewport_size['size']})";
83+
} elseif ( count( $viewport_sizes ) - 1 === $index && $previous_size ) {
84+
// Last item: width > previous size.
85+
$viewport_media_queries[ $viewport_size['slug'] ] = "@media (width > $previous_size)";
86+
} else {
87+
// Middle items: previous size < width <= size.
88+
$viewport_media_queries[ $viewport_size['slug'] ] = "@media ({$previous_size} < width <= {$viewport_size['size']})";
89+
}
90+
91+
$previous_size = $viewport_size['size'] ?? null;
92+
}
93+
94+
$hidden_on = array();
95+
96+
// Collect which viewport the block is hidden on (only known viewport sizes).
97+
foreach ( $viewport_config as $viewport_config_size => $is_visible ) {
98+
if ( false === $is_visible && isset( $viewport_media_queries[ $viewport_config_size ] ) ) {
99+
$hidden_on[] = $viewport_config_size;
100+
}
101+
}
102+
103+
// If no viewport sizes have visibility set to false, return unchanged.
104+
if ( empty( $hidden_on ) ) {
105+
return $block_content;
106+
}
107+
108+
// Maintain consistent order of viewport sizes for class name generation.
109+
sort( $hidden_on );
110+
111+
$css_rules = array();
112+
$class_names = array();
113+
114+
foreach ( $hidden_on as $hidden_viewport_size ) {
115+
/*
116+
* If these values ever become user-defined,
117+
* they should be sanitized and kebab-cased.
118+
*/
119+
$visibility_class = 'wp-block-hidden-' . $hidden_viewport_size;
120+
$class_names[] = $visibility_class;
121+
$css_rules[] = array(
122+
'selector' => '.' . $visibility_class,
123+
'declarations' => array(
124+
'display' => 'none !important',
125+
),
126+
'rules_group' => $viewport_media_queries[ $hidden_viewport_size ],
127+
);
128+
}
129+
130+
wp_style_engine_get_stylesheet_from_css_rules(
131+
$css_rules,
132+
array(
133+
'context' => 'block-supports',
134+
'prettify' => false,
135+
)
136+
);
137+
138+
if ( ! empty( $block_content ) ) {
139+
$processor = new WP_HTML_Tag_Processor( $block_content );
140+
if ( $processor->next_tag() ) {
141+
$processor->add_class( implode( ' ', $class_names ) );
142+
$block_content = $processor->get_updated_html();
143+
}
144+
}
145+
}
146+
30147
return $block_content;
31148
}
32149

src/wp-includes/block-supports/elements.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function wp_render_elements_support_styles( $parsed_block ) {
116116
* `render_block_data` filter in 6.6.0 to avoid filtered attributes
117117
* breaking the application of the elements CSS class.
118118
*
119-
* @see https://github.com/WordPress/gutenberg/pull/59535
119+
* @link https://github.com/WordPress/gutenberg/pull/59535
120120
*
121121
* The change in filter means, the argument types for this function
122122
* have changed and require deprecating.

src/wp-includes/class-wp-http-requests-response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function set_data( $data ) {
155155
*
156156
* @since 4.6.0
157157
*
158-
* @return WP_HTTP_Cookie[] List of cookie objects.
158+
* @return WP_Http_Cookie[] List of cookie objects.
159159
*/
160160
public function get_cookies() {
161161
$cookies = array();

src/wp-includes/class-wp-http.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class WP_Http {
161161
* @type int|false $code HTTP response status code.
162162
* @type string|false $message HTTP response message.
163163
* }
164-
* @type WP_HTTP_Cookie[] $cookies Array of cookies set by the server.
164+
* @type WP_Http_Cookie[] $cookies Array of cookies set by the server.
165165
* @type string|null $filename Optional. Filename of the response.
166166
* @type WP_HTTP_Requests_Response|null $http_response Response object.
167167
* }
@@ -804,7 +804,7 @@ public static function processHeaders( $headers, $url = '' ) { // phpcs:ignore W
804804
*/
805805
public static function buildCookieHeader( &$r ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
806806
if ( ! empty( $r['cookies'] ) ) {
807-
// Upgrade any name => value cookie pairs to WP_HTTP_Cookie instances.
807+
// Upgrade any name => value cookie pairs to WP_Http_Cookie instances.
808808
foreach ( $r['cookies'] as $name => $value ) {
809809
if ( ! is_object( $value ) ) {
810810
$r['cookies'][ $name ] = new WP_Http_Cookie(

src/wp-includes/class-wp-post-type.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ final class WP_Post_Type {
303303
* and delete blocks.
304304
* - If set to 'insert', the user is able to move existing blocks but is unable to insert
305305
* new blocks and delete blocks.
306+
* - If set to 'contentOnly', the user is only able to edit the content of existing blocks.
306307
*
307308
* Default false.
308309
*

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ protected function get_layout_styles( $block_metadata, $options = array() ) {
16151615
$selector = $block_metadata['selector'] ?? '';
16161616
$has_block_gap_support = isset( $this->theme_json['settings']['spacing']['blockGap'] );
16171617
$has_fallback_gap_support = ! $has_block_gap_support; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback gap styles support.
1618-
$node = _wp_array_get( $this->theme_json, $block_metadata['path'], array() );
1618+
$node = $options['node'] ?? _wp_array_get( $this->theme_json, $block_metadata['path'], array() );
16191619
$layout_definitions = wp_get_layout_definitions();
16201620
$layout_selector_pattern = '/^[a-zA-Z0-9\-\.\,\ *+>:\(\)]*$/'; // Allow alphanumeric classnames, spaces, wildcard, sibling, child combinator and pseudo class selectors.
16211621

@@ -2356,18 +2356,6 @@ protected static function compute_style_properties( $styles, $settings = array()
23562356
continue;
23572357
}
23582358

2359-
/*
2360-
* Look up protected properties, keyed by value path.
2361-
* Skip protected properties that are explicitly set to `null`.
2362-
*/
2363-
$path_string = implode( '.', $value_path );
2364-
if (
2365-
isset( static::PROTECTED_PROPERTIES[ $path_string ] ) &&
2366-
_wp_array_get( $settings, static::PROTECTED_PROPERTIES[ $path_string ], null ) === null
2367-
) {
2368-
continue;
2369-
}
2370-
23712359
// Calculates fluid typography rules where available.
23722360
if ( 'font-size' === $css_property ) {
23732361
/*
@@ -2811,8 +2799,9 @@ public function get_styles_for_block( $block_metadata ) {
28112799
$is_root_selector = static::ROOT_BLOCK_SELECTOR === $selector;
28122800

28132801
// If there are style variations, generate the declarations for them, including any feature selectors the block may have.
2814-
$style_variation_declarations = array();
2815-
$style_variation_custom_css = array();
2802+
$style_variation_declarations = array();
2803+
$style_variation_custom_css = array();
2804+
$style_variation_layout_metadata = array();
28162805
if ( ! empty( $block_metadata['variations'] ) ) {
28172806
foreach ( $block_metadata['variations'] as $style_variation ) {
28182807
$style_variation_node = _wp_array_get( $this->theme_json, $style_variation['path'], array() );
@@ -2852,6 +2841,18 @@ static function ( $split_selector ) use ( $clean_style_variation_selector ) {
28522841
if ( isset( $style_variation_node['css'] ) ) {
28532842
$style_variation_custom_css[ $style_variation['selector'] ] = $this->process_blocks_custom_css( $style_variation_node['css'], $style_variation['selector'] );
28542843
}
2844+
2845+
// Store variation metadata and node for layout styles generation.
2846+
// Only store if the variation has blockGap defined.
2847+
if ( isset( $style_variation_node['spacing']['blockGap'] ) ) {
2848+
// Append block selector to the variation selector for proper targeting.
2849+
$variation_metadata_with_selector = $style_variation;
2850+
$variation_metadata_with_selector['selector'] = $style_variation['selector'] . $block_metadata['css'];
2851+
$style_variation_layout_metadata[ $style_variation['selector'] ] = array(
2852+
'metadata' => $variation_metadata_with_selector,
2853+
'node' => $style_variation_node,
2854+
);
2855+
}
28552856
}
28562857
}
28572858
/*
@@ -3004,6 +3005,10 @@ static function ( $pseudo_selector ) use ( $selector ) {
30043005
// 6. Generate and append the style variation rulesets.
30053006
foreach ( $style_variation_declarations as $style_variation_selector => $individual_style_variation_declarations ) {
30063007
$block_rules .= static::to_ruleset( ":root :where($style_variation_selector)", $individual_style_variation_declarations );
3008+
if ( isset( $style_variation_layout_metadata[ $style_variation_selector ] ) ) {
3009+
$variation_data = $style_variation_layout_metadata[ $style_variation_selector ];
3010+
$block_rules .= $this->get_layout_styles( $variation_data['metadata'], array( 'node' => $variation_data['node'] ) );
3011+
}
30073012
if ( isset( $style_variation_custom_css[ $style_variation_selector ] ) ) {
30083013
$block_rules .= $style_variation_custom_css[ $style_variation_selector ];
30093014
}
@@ -3079,7 +3084,7 @@ public function get_root_layout_rules( $selector, $block_metadata, $options = ar
30793084
$css .= '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';
30803085
}
30813086

3082-
// Block gap styles will be output unless explicitly set to `null`. See static::PROTECTED_PROPERTIES.
3087+
// Block gap styles will be output unless explicitly set to `null`.
30833088
if ( isset( $this->theme_json['settings']['spacing']['blockGap'] ) ) {
30843089
$block_gap_value = static::get_property_value( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ) );
30853090
$css .= ":where(.wp-site-blocks) > * { margin-block-start: $block_gap_value; margin-block-end: 0; }";

0 commit comments

Comments
 (0)