Skip to content

Commit d8b1bc9

Browse files
Merge branch 'trunk' into ticket/64145
2 parents 408b270 + 82d47f1 commit d8b1bc9

File tree

13 files changed

+227
-45
lines changed

13 files changed

+227
-45
lines changed

src/wp-includes/abilities-api.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,16 @@
254254
* @type array<string, mixed> $meta {
255255
* Optional. Additional metadata for the ability.
256256
*
257-
* @type array<string, bool|null> $annotations Optional. Annotation metadata for the ability. Provides
258-
* additional semantic information about the ability's
259-
* characteristics and behavior.
257+
* @type array<string, bool|null> $annotations {
258+
* Optional. Semantic annotations describing the ability's behavioral characteristics.
259+
* These annotations are hints for tooling and documentation.
260+
*
261+
* @type bool|null $readonly Optional. If true, the ability does not modify its environment.
262+
* @type bool|null $destructive Optional. If true, the ability may perform destructive updates to its environment.
263+
* If false, the ability performs only additive updates.
264+
* @type bool|null $idempotent Optional. If true, calling the ability repeatedly with the same arguments
265+
* will have no additional effect on its environment.
266+
* }
260267
* @type bool $show_in_rest Optional. Whether to expose this ability in the REST API.
261268
* When true, the ability can be invoked via HTTP requests.
262269
* Default false.

src/wp-includes/abilities-api/class-wp-abilities-registry.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,16 @@ final class WP_Abilities_Registry {
6161
* @type array<string, mixed> $meta {
6262
* Optional. Additional metadata for the ability.
6363
*
64-
* @type array<string, null|bool> $annotations Optional. Annotation metadata for the ability.
64+
* @type array<string, bool|null> $annotations {
65+
* Optional. Semantic annotations describing the ability's behavioral characteristics.
66+
* These annotations are hints for tooling and documentation.
67+
*
68+
* @type bool|null $readonly Optional. If true, the ability does not modify its environment.
69+
* @type bool|null $destructive Optional. If true, the ability may perform destructive updates to its environment.
70+
* If false, the ability performs only additive updates.
71+
* @type bool|null $idempotent Optional. If true, calling the ability repeatedly with the same arguments
72+
* will have no additional effect on its environment.
73+
* }
6574
* @type bool $show_in_rest Optional. Whether to expose this ability in the REST API. Default false.
6675
* }
6776
* @type string $ability_class Optional. Custom class to instantiate instead of WP_Ability.

src/wp-includes/abilities-api/class-wp-ability.php

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class WP_Ability {
3333
* They are not guaranteed to provide a faithful description of ability behavior.
3434
*
3535
* @since 6.9.0
36-
* @var array<string, (null|bool)>
36+
* @var array<string, bool|null>
3737
*/
3838
protected static $default_annotations = array(
3939
// If true, the ability does not modify its environment.
@@ -150,7 +150,16 @@ class WP_Ability {
150150
* @type array<string, mixed> $meta {
151151
* Optional. Additional metadata for the ability.
152152
*
153-
* @type array<string, null|bool> $annotations Optional. Annotation metadata for the ability.
153+
* @type array<string, bool|null> $annotations {
154+
* Optional. Semantic annotations describing the ability's behavioral characteristics.
155+
* These annotations are hints for tooling and documentation.
156+
*
157+
* @type bool|null $readonly Optional. If true, the ability does not modify its environment.
158+
* @type bool|null $destructive Optional. If true, the ability may perform destructive updates to its environment.
159+
* If false, the ability performs only additive updates.
160+
* @type bool|null $idempotent Optional. If true, calling the ability repeatedly with the same arguments
161+
* will have no additional effect on its environment.
162+
* }
154163
* @type bool $show_in_rest Optional. Whether to expose this ability in the REST API. Default false.
155164
* }
156165
* }
@@ -205,7 +214,16 @@ public function __construct( string $name, array $args ) {
205214
* @type array<string, mixed> $meta {
206215
* Optional. Additional metadata for the ability.
207216
*
208-
* @type array<string, null|bool> $annotations Optional. Annotation metadata for the ability.
217+
* @type array<string, bool|null> $annotations {
218+
* Optional. Semantic annotations describing the ability's behavioral characteristics.
219+
* These annotations are hints for tooling and documentation.
220+
*
221+
* @type bool|null $readonly Optional. If true, the ability does not modify its environment.
222+
* @type bool|null $destructive Optional. If true, the ability may perform destructive updates to its environment.
223+
* If false, the ability performs only additive updates.
224+
* @type bool|null $idempotent Optional. If true, calling the ability repeatedly with the same arguments
225+
* will have no additional effect on its environment.
226+
* }
209227
* @type bool $show_in_rest Optional. Whether to expose this ability in the REST API. Default false.
210228
* }
211229
* }
@@ -224,7 +242,16 @@ public function __construct( string $name, array $args ) {
224242
* @type array<string, mixed> $meta {
225243
* Additional metadata for the ability.
226244
*
227-
* @type array<string, null|bool> $annotations Optional. Annotation metadata for the ability.
245+
* @type array<string, bool|null> $annotations {
246+
* Semantic annotations describing the ability's behavioral characteristics.
247+
* These annotations are hints for tooling and documentation.
248+
*
249+
* @type bool|null $readonly If true, the ability does not modify its environment.
250+
* @type bool|null $destructive If true, the ability may perform destructive updates to its environment.
251+
* If false, the ability performs only additive updates.
252+
* @type bool|null $idempotent If true, calling the ability repeatedly with the same arguments
253+
* will have no additional effect on its environment.
254+
* }
228255
* @type bool $show_in_rest Whether to expose this ability in the REST API. Default false.
229256
* }
230257
* }
@@ -498,6 +525,14 @@ protected function invoke_callback( callable $callback, $input = null ) {
498525
* @return bool|WP_Error Whether the ability has the necessary permission.
499526
*/
500527
public function check_permissions( $input = null ) {
528+
if ( ! is_callable( $this->permission_callback ) ) {
529+
return new WP_Error(
530+
'ability_invalid_permission_callback',
531+
/* translators: %s ability name. */
532+
sprintf( __( 'Ability "%s" does not have a valid permission callback.' ), esc_html( $this->name ) )
533+
);
534+
}
535+
501536
return $this->invoke_callback( $this->permission_callback, $input );
502537
}
503538

src/wp-includes/class-wp-block-templates-registry.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,8 @@ public function register( $template_name, $args = array() ) {
6060
}
6161

6262
if ( $error_message ) {
63-
_doing_it_wrong(
64-
__METHOD__,
65-
$error_message,
66-
'6.7.0'
67-
);
63+
_doing_it_wrong( __METHOD__, $error_message, '6.7.0' );
64+
6865
return new WP_Error( $error_code, $error_message );
6966
}
7067

@@ -221,14 +218,12 @@ public function is_registered( $template_name ) {
221218
*/
222219
public function unregister( $template_name ) {
223220
if ( ! $this->is_registered( $template_name ) ) {
224-
_doing_it_wrong(
225-
__METHOD__,
226-
/* translators: %s: Template name. */
227-
sprintf( __( 'Template "%s" is not registered.' ), $template_name ),
228-
'6.7.0'
229-
);
230221
/* translators: %s: Template name. */
231-
return new WP_Error( 'template_not_registered', __( 'Template "%s" is not registered.' ) );
222+
$error_message = sprintf( __( 'Template "%s" is not registered.' ), $template_name );
223+
224+
_doing_it_wrong( __METHOD__, $error_message, '6.7.0' );
225+
226+
return new WP_Error( 'template_not_registered', $error_message );
232227
}
233228

234229
$unregistered_template = $this->registered_templates[ $template_name ];

src/wp-includes/class-wp.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,9 @@ public function send_headers() {
588588
/**
589589
* Fires once the requested HTTP headers for caching, content type, etc. have been sent.
590590
*
591+
* The {@see 'wp_send_late_headers'} action may be used to send headers after rendering the template into an
592+
* output buffer.
593+
*
591594
* @since 2.1.0
592595
*
593596
* @param WP $wp Current WordPress environment instance (passed by reference).

src/wp-includes/comment.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4128,7 +4128,9 @@ function wp_create_initial_comment_meta() {
41284128
'enum' => array( 'resolved', 'reopen' ),
41294129
),
41304130
),
4131+
'auth_callback' => function ( $allowed, $meta_key, $object_id ) {
4132+
return current_user_can( 'edit_comment', $object_id );
4133+
},
41314134
)
41324135
);
41334136
}
4134-
add_action( 'init', 'wp_create_initial_comment_meta' );

src/wp-includes/default-filters.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
add_action( 'added_comment_meta', 'wp_cache_set_comments_last_changed' );
152152
add_action( 'updated_comment_meta', 'wp_cache_set_comments_last_changed' );
153153
add_action( 'deleted_comment_meta', 'wp_cache_set_comments_last_changed' );
154+
add_action( 'init', 'wp_create_initial_comment_meta' );
154155

155156
// Places to balance tags on input.
156157
foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' ) as $filter ) {
@@ -422,7 +423,7 @@
422423
add_action( 'do_all_pings', 'generic_ping', 10, 0 );
423424
add_action( 'do_robots', 'do_robots' );
424425
add_action( 'do_favicon', 'do_favicon' );
425-
add_action( 'wp_before_include_template', 'wp_start_template_enhancement_output_buffer' );
426+
add_action( 'wp_before_include_template', 'wp_start_template_enhancement_output_buffer', 1000 ); // Late priority to let `wp_template_enhancement_output_buffer` filters and `wp_send_late_headers` actions be registered.
426427
add_action( 'set_comment_cookies', 'wp_set_comment_cookies', 10, 3 );
427428
add_action( 'sanitize_comment_cookies', 'sanitize_comment_cookies' );
428429
add_action( 'init', 'smilies_init', 5 );

src/wp-includes/rest-api/search/class-wp-rest-post-format-search-handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function search_items( WP_REST_Request $request ) {
100100
* @type string $title Optional. Post format name.
101101
* @type string $url Optional. Post format permalink URL.
102102
* @type string $type Optional. String 'post-format'.
103-
*}
103+
* }
104104
*/
105105
public function prepare_item( $id, array $fields ) {
106106
$data = array();

src/wp-includes/template.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -844,16 +844,17 @@ function wp_should_output_buffer_template_for_enhancement(): bool {
844844
* Filters whether the template should be output-buffered for enhancement.
845845
*
846846
* By default, an output buffer is only started if a {@see 'wp_template_enhancement_output_buffer'} filter has been
847-
* added. For this default to apply, a filter must be added by the time the template is included at the
848-
* {@see 'wp_before_include_template'} action. This allows template responses to be streamed as much as possible
849-
* when no template enhancements are registered to apply. This filter allows a site to opt in to adding such
850-
* template enhancement filters during the rendering of the template.
847+
* added or if a plugin has added a {@see 'wp_send_late_headers'} action. For this default to apply, either of the
848+
* hooks must be added by the time the template is included at the {@see 'wp_before_include_template'} action. This
849+
* allows template responses to be streamed unless the there is code which depends on an output buffer being opened.
850+
* This filter allows a site to opt in to adding such template enhancement filters later during the rendering of the
851+
* template.
851852
*
852853
* @since 6.9.0
853854
*
854855
* @param bool $use_output_buffer Whether an output buffer is started.
855856
*/
856-
return (bool) apply_filters( 'wp_should_output_buffer_template_for_enhancement', has_filter( 'wp_template_enhancement_output_buffer' ) );
857+
return (bool) apply_filters( 'wp_should_output_buffer_template_for_enhancement', has_filter( 'wp_template_enhancement_output_buffer' ) || has_action( 'wp_send_late_headers' ) );
857858
}
858859

859860
/**
@@ -957,6 +958,8 @@ function wp_finalize_template_enhancement_output_buffer( string $output, int $ph
957958

958959
// If the content type is not HTML, short-circuit since it is not relevant for enhancement.
959960
if ( ! $is_html_content_type ) {
961+
/** This action is documented in wp-includes/template.php */
962+
do_action( 'wp_send_late_headers', $output );
960963
return $output;
961964
}
962965

@@ -977,5 +980,25 @@ function wp_finalize_template_enhancement_output_buffer( string $output, int $ph
977980
* @param string $filtered_output HTML template enhancement output buffer.
978981
* @param string $output Original HTML template output buffer.
979982
*/
980-
return (string) apply_filters( 'wp_template_enhancement_output_buffer', $filtered_output, $output );
983+
$filtered_output = (string) apply_filters( 'wp_template_enhancement_output_buffer', $filtered_output, $output );
984+
985+
/**
986+
* Fires at the last moment HTTP headers may be sent.
987+
*
988+
* This happens immediately before the template enhancement output buffer is flushed. This is in contrast with
989+
* the {@see 'send_headers'} action which fires after the initial headers have been sent before the template
990+
* has begun rendering, and thus does not depend on output buffering. This action does not fire if the "template
991+
* enhancement output buffer" was not started. This output buffer is automatically started if this action is added
992+
* before {@see wp_start_template_enhancement_output_buffer()} runs at the {@see 'wp_before_include_template'}
993+
* action with priority 1000. Before this point, the output buffer will also be started automatically if there was a
994+
* {@see 'wp_template_enhancement_output_buffer'} filter added, or if the
995+
* {@see 'wp_should_output_buffer_template_for_enhancement'} filter is made to return `true`.
996+
*
997+
* @since 6.9.0
998+
*
999+
* @param string $output Output buffer.
1000+
*/
1001+
do_action( 'wp_send_late_headers', $filtered_output );
1002+
1003+
return $filtered_output;
9811004
}

src/wp-login.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ function wp_login_viewport_meta() {
13181318
$redirect_to = admin_url();
13191319
}
13201320

1321-
$reauth = empty( $_REQUEST['reauth'] ) ? false : true;
1321+
$reauth = ! empty( $_REQUEST['reauth'] );
13221322

13231323
$user = wp_signon( array(), $secure_cookie );
13241324

0 commit comments

Comments
 (0)