Skip to content
2 changes: 1 addition & 1 deletion src/wp-admin/includes/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -2685,7 +2685,7 @@ function wp_opcache_invalidate_directory( $dir ) {
* with sub-directories represented as nested arrays.
* @param string $path Absolute path to the directory.
*/
$invalidate_directory = function( $dirlist, $path ) use ( &$invalidate_directory ) {
$invalidate_directory = static function( $dirlist, $path ) use ( &$invalidate_directory ) {
$path = trailingslashit( $path );

foreach ( $dirlist as $name => $details ) {
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
*
* @return string Returns the block content.
*/
$settings['render_callback'] = function( $attributes, $content, $block ) use ( $template_path ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$settings['render_callback'] = static function( $attributes, $content, $block ) use ( $template_path ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outside of the scope of this PR, but we may as well remove the // phpcs:ignore comment as the VariableAnalysis standard is not being used by Core, nor WPCS.

Isn't this also a Gutenberg file though ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this also a Gutenberg file though ?

Based on the filename it would seem so, but it seems to fundamentally be a different file from https://github.com/WordPress/gutenberg/blob/trunk/lib/blocks.php

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree we should look into // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable, but not in this ticket.

ob_start();
require $template_path;
return ob_get_clean();
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -4826,7 +4826,7 @@ protected function generate_cache_key( array $args, $sql ) {
* $value is passed by reference to allow it to be modified.
* array_walk_recursive() does not return an array.
*/
function ( &$value ) use ( $wpdb, $placeholder ) {
static function ( &$value ) use ( $wpdb, $placeholder ) {
if ( is_string( $value ) && str_contains( $value, $placeholder ) ) {
$value = $wpdb->remove_placeholder_escape( $value );
}
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/kses.php
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ function wp_kses_attr( $element, $attr, $allowed_html, $allowed_protocols ) {
// Check if there are attributes that are required.
$required_attrs = array_filter(
$allowed_html[ $element_low ],
function( $required_attr_limits ) {
static function( $required_attr_limits ) {
return isset( $required_attr_limits['required'] ) && true === $required_attr_limits['required'];
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ public function get_item_schema() {
),
'context' => array( 'view', 'edit', 'embed' ),
'arg_options' => array(
'sanitize_callback' => function ( $value ) {
'sanitize_callback' => static function ( $value ) {
return array_map( 'sanitize_html_class', wp_parse_list( $value ) );
},
),
Expand Down Expand Up @@ -873,7 +873,7 @@ public function get_item_schema() {
),
'context' => array( 'view', 'edit', 'embed' ),
'arg_options' => array(
'sanitize_callback' => function ( $value ) {
'sanitize_callback' => static function ( $value ) {
return array_map( 'sanitize_html_class', wp_parse_list( $value ) );
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public function get_item_schema() {
),
'context' => array( 'view', 'edit' ),
'arg_options' => array(
'validate_callback' => function ( $locations, $request, $param ) {
'validate_callback' => static function ( $locations, $request, $param ) {
$valid = rest_validate_request_arg( $locations, $request, $param );

if ( true !== $valid ) {
Expand Down
4 changes: 2 additions & 2 deletions src/wp-includes/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2405,7 +2405,7 @@ function wp_common_block_scripts_and_styles() {
function wp_filter_out_block_nodes( $nodes ) {
return array_filter(
$nodes,
function( $node ) {
static function( $node ) {
return ! in_array( 'blocks', $node['path'], true );
},
ARRAY_FILTER_USE_BOTH
Expand Down Expand Up @@ -2635,7 +2635,7 @@ function enqueue_block_styles_assets() {
if ( wp_should_load_separate_core_block_assets() ) {
add_filter(
'render_block',
function( $html, $block ) use ( $block_name, $style_properties ) {
static function( $html, $block ) use ( $block_name, $style_properties ) {
if ( $block['blockName'] === $block_name ) {
wp_enqueue_style( $style_properties['style_handle'] );
}
Expand Down
4 changes: 2 additions & 2 deletions tests/performance/wp-content/mu-plugins/server-timing.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

add_action(
'template_redirect',
function() {
static function() {

global $timestart;

Expand All @@ -15,7 +15,7 @@ function() {

add_action(
'shutdown',
function() use ( $server_timing_values, $template_start ) {
static function() use ( $server_timing_values, $template_start ) {

global $timestart;

Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/admin/wpSiteHealth.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public function test_object_cache_default_thresholds_non_multisite() {
// Set thresholds so high they should never be exceeded.
add_filter(
'site_status_persistent_object_cache_thresholds',
function() {
static function() {
return array(
'alloptions_count' => PHP_INT_MAX,
'alloptions_bytes' => PHP_INT_MAX,
Expand Down Expand Up @@ -472,7 +472,7 @@ public function test_object_cache_thresholds_check_can_be_bypassed() {
public function test_object_cache_thresholds( $threshold, $count ) {
add_filter(
'site_status_persistent_object_cache_thresholds',
function ( $thresholds ) use ( $threshold, $count ) {
static function ( $thresholds ) use ( $threshold, $count ) {
return array_merge( $thresholds, array( $threshold => $count ) );
}
);
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/blocks/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public function test_get_default_block_editor_settings_max_upload_file_size() {
// Force the return value of wp_max_upload_size() to be 500.
add_filter(
'upload_size_limit',
function() {
static function() {
return 500;
}
);
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/blocks/renderCommentTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public function test_build_comment_query_vars_from_block_with_comment_preview()
)
);

$commenter_filter = function () {
$commenter_filter = static function () {
return array(
'comment_author_email' => 'unapproved@example.org',
);
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/blocks/wpBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ public function test_block_filters_for_inner_blocks() {
$this->registry->register(
'core/outer',
array(
'render_callback' => function( $block_attributes, $content ) {
'render_callback' => static function( $block_attributes, $content ) {
return $content;
},
)
Expand All @@ -702,7 +702,7 @@ public function test_block_filters_for_inner_blocks() {
$this->registry->register(
'core/inner',
array(
'render_callback' => function() {
'render_callback' => static function() {
return 'b';
},
)
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/dependencies/scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,7 @@ public function test_wp_external_wp_i18n_print_order() {
wp_set_script_translations( 'common' );

$print_scripts = get_echo(
function() {
static function() {
wp_print_scripts();
_print_scripts();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/general/wpPreloadResources.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Tests_General_wpPreloadResources extends WP_UnitTestCase {
* @ticket 42438
*/
public function test_preload_resources( $expected, $preload_resources ) {
$callback = function () use ( $preload_resources ) {
$callback = static function () use ( $preload_resources ) {
return $preload_resources;
};

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/kses.php
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,7 @@ public function data_wp_kses_allowed_values_list() {
);

return array_map(
function ( $datum ) {
static function ( $datum ) {
$datum[] = array(
'p' => array(
'dir' => array(
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/tests/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -2348,7 +2348,7 @@ public function test_wp_filter_content_tags_filter_with_identical_image_tags_cus

add_filter(
'wp_content_img_tag',
function( $filtered_image ) {
static function( $filtered_image ) {
return "<span>$filtered_image</span>";
}
);
Expand All @@ -2372,7 +2372,7 @@ public function test_wp_filter_content_tags_filter_with_identical_image_tags_dis

add_filter(
'wp_content_img_tag',
function( $filtered_image ) {
static function( $filtered_image ) {
return "<span>$filtered_image</span>";
}
);
Expand Down Expand Up @@ -3761,7 +3761,7 @@ public function test_wp_filter_content_tags_does_not_lazy_load_first_featured_im
add_filter( 'wp_img_tag_add_decoding_attr', '__return_false' );
add_filter(
'wp_get_attachment_image_attributes',
function( $attr ) {
static function( $attr ) {
unset( $attr['srcset'], $attr['sizes'], $attr['decoding'] );
return $attr;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/pluggable/wpMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ public function test_wp_mail_can_be_shortcircuited() {
* Tests that AltBody is reset between each wp_mail call.
*/
public function test_wp_mail_resets_properties() {
$wp_mail_set_text_message = function ( $phpmailer ) {
$wp_mail_set_text_message = static function ( $phpmailer ) {
$phpmailer->AltBody = 'user1';
};

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/query/stickies.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function test_stickies_should_limit_query() {
$post_ids = self::factory()->post->create_many( $sticky_count, array( 'post_date' => $post_date ) );
add_filter(
'pre_option_sticky_posts',
function () use ( $post_ids ) {
static function () use ( $post_ids ) {
return $post_ids;
}
);
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/rest-api/rest-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ public function test_link_embedding_without_links() {
* @ticket 56566
*/
public function test_link_embedding_returning_wp_error() {
$return_wp_error = function() {
$return_wp_error = static function() {
return new WP_Error( 'some-error', 'This is not valid!' );
};
add_filter( 'rest_pre_dispatch', $return_wp_error );
Expand Down Expand Up @@ -2188,7 +2188,7 @@ public function test_json_encode_error_results_in_500_status_code() {
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => function() {
'callback' => static function() {
return new \WP_REST_Response( INF );
},
'permission_callback' => '__return_true',
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/rest-api/rest-themes-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ public function test_can_support_further_routes() {
'wp/v2',
sprintf( '/themes/(?P<stylesheet>%s)//test', WP_REST_Themes_Controller::PATTERN ),
array(
'callback' => function ( WP_REST_Request $request ) {
'callback' => static function ( WP_REST_Request $request ) {
return $request['stylesheet'];
},
'permission_callback' => '__return_true',
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/theme/wpThemeJsonResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ public function test_get_user_data_from_wp_global_styles_does_not_use_uncached_q
$global_styles_query_count = 0;
add_filter(
'query',
function( $query ) use ( &$global_styles_query_count ) {
static function( $query ) use ( &$global_styles_query_count ) {
if ( preg_match( '#post_type = \'wp_global_styles\'#', $query ) ) {
$global_styles_query_count++;
}
Expand Down