diff --git a/src/wp-admin/includes/file.php b/src/wp-admin/includes/file.php index 8e2b41411f..af88fe023f 100644 --- a/src/wp-admin/includes/file.php +++ b/src/wp-admin/includes/file.php @@ -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 ) { diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 159af66331..3bdcdcc452 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -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 ob_start(); require $template_path; return ob_get_clean(); diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php index c1f43cf271..6b9e9d0bb8 100644 --- a/src/wp-includes/class-wp-query.php +++ b/src/wp-includes/class-wp-query.php @@ -4826,7 +4826,7 @@ class WP_Query { * $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 ); } diff --git a/src/wp-includes/kses.php b/src/wp-includes/kses.php index 31dc1125ec..0ab8c3350d 100644 --- a/src/wp-includes/kses.php +++ b/src/wp-includes/kses.php @@ -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']; } ); diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php index c50dded161..59edfa5bcd 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php @@ -792,7 +792,7 @@ class WP_REST_Menu_Items_Controller extends WP_REST_Posts_Controller { ), '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 ) ); }, ), @@ -873,7 +873,7 @@ class WP_REST_Menu_Items_Controller extends WP_REST_Posts_Controller { ), '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 ) ); }, ), diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php index 775d805efe..18b2c8fcfd 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php @@ -534,7 +534,7 @@ class WP_REST_Menus_Controller extends WP_REST_Terms_Controller { ), '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 ) { diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index b611292dcb..786e18f6d4 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -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 @@ -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'] ); } diff --git a/tests/performance/wp-content/mu-plugins/server-timing.php b/tests/performance/wp-content/mu-plugins/server-timing.php index 267ca164d3..8d7e7ae3aa 100644 --- a/tests/performance/wp-content/mu-plugins/server-timing.php +++ b/tests/performance/wp-content/mu-plugins/server-timing.php @@ -2,7 +2,7 @@ add_action( 'template_redirect', - function() { + static function() { global $timestart; @@ -15,7 +15,7 @@ add_action( add_action( 'shutdown', - function() use ( $server_timing_values, $template_start ) { + static function() use ( $server_timing_values, $template_start ) { global $timestart; diff --git a/tests/phpunit/tests/admin/wpSiteHealth.php b/tests/phpunit/tests/admin/wpSiteHealth.php index 62697c576c..0d7ccb6112 100644 --- a/tests/phpunit/tests/admin/wpSiteHealth.php +++ b/tests/phpunit/tests/admin/wpSiteHealth.php @@ -421,7 +421,7 @@ class Tests_Admin_wpSiteHealth extends WP_UnitTestCase { // 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, @@ -472,7 +472,7 @@ class Tests_Admin_wpSiteHealth extends WP_UnitTestCase { 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 ) ); } ); diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index ef8f1cd795..0769cbc31c 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -302,7 +302,7 @@ class Tests_Blocks_Editor extends WP_UnitTestCase { // Force the return value of wp_max_upload_size() to be 500. add_filter( 'upload_size_limit', - function() { + static function() { return 500; } ); diff --git a/tests/phpunit/tests/blocks/renderCommentTemplate.php b/tests/phpunit/tests/blocks/renderCommentTemplate.php index 82b2cb91cb..a206fa5e2b 100644 --- a/tests/phpunit/tests/blocks/renderCommentTemplate.php +++ b/tests/phpunit/tests/blocks/renderCommentTemplate.php @@ -436,7 +436,7 @@ END ) ); - $commenter_filter = function () { + $commenter_filter = static function () { return array( 'comment_author_email' => 'unapproved@example.org', ); diff --git a/tests/phpunit/tests/blocks/wpBlock.php b/tests/phpunit/tests/blocks/wpBlock.php index ebf2f9aaf6..21057aa5a2 100644 --- a/tests/phpunit/tests/blocks/wpBlock.php +++ b/tests/phpunit/tests/blocks/wpBlock.php @@ -693,7 +693,7 @@ class Tests_Blocks_wpBlock extends WP_UnitTestCase { $this->registry->register( 'core/outer', array( - 'render_callback' => function( $block_attributes, $content ) { + 'render_callback' => static function( $block_attributes, $content ) { return $content; }, ) @@ -702,7 +702,7 @@ class Tests_Blocks_wpBlock extends WP_UnitTestCase { $this->registry->register( 'core/inner', array( - 'render_callback' => function() { + 'render_callback' => static function() { return 'b'; }, ) diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 10e447728a..78642c1178 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -1473,7 +1473,7 @@ JS; wp_set_script_translations( 'common' ); $print_scripts = get_echo( - function() { + static function() { wp_print_scripts(); _print_scripts(); } diff --git a/tests/phpunit/tests/general/wpPreloadResources.php b/tests/phpunit/tests/general/wpPreloadResources.php index 53fd2646a6..fe2a4e6fa5 100644 --- a/tests/phpunit/tests/general/wpPreloadResources.php +++ b/tests/phpunit/tests/general/wpPreloadResources.php @@ -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; }; diff --git a/tests/phpunit/tests/kses.php b/tests/phpunit/tests/kses.php index db5e26ec0b..3c6749799a 100644 --- a/tests/phpunit/tests/kses.php +++ b/tests/phpunit/tests/kses.php @@ -1923,7 +1923,7 @@ HTML; ); return array_map( - function ( $datum ) { + static function ( $datum ) { $datum[] = array( 'p' => array( 'dir' => array( diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index c971a4a2a9..92d09f8f1a 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -2348,7 +2348,7 @@ EOF; add_filter( 'wp_content_img_tag', - function( $filtered_image ) { + static function( $filtered_image ) { return "$filtered_image"; } ); @@ -2372,7 +2372,7 @@ EOF; add_filter( 'wp_content_img_tag', - function( $filtered_image ) { + static function( $filtered_image ) { return "$filtered_image"; } ); @@ -3761,7 +3761,7 @@ EOF; 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; } diff --git a/tests/phpunit/tests/pluggable/wpMail.php b/tests/phpunit/tests/pluggable/wpMail.php index cc6b3df1a1..f7af48bc06 100644 --- a/tests/phpunit/tests/pluggable/wpMail.php +++ b/tests/phpunit/tests/pluggable/wpMail.php @@ -538,7 +538,7 @@ class Tests_Pluggable_wpMail extends WP_UnitTestCase { * 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'; }; diff --git a/tests/phpunit/tests/query/stickies.php b/tests/phpunit/tests/query/stickies.php index 0070f4cb31..81a991c6d7 100644 --- a/tests/phpunit/tests/query/stickies.php +++ b/tests/phpunit/tests/query/stickies.php @@ -136,7 +136,7 @@ class Tests_Query_Stickies extends WP_UnitTestCase { $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; } ); diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php index 3a7bf78353..bb10b20bc6 100644 --- a/tests/phpunit/tests/rest-api/rest-server.php +++ b/tests/phpunit/tests/rest-api/rest-server.php @@ -937,7 +937,7 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { * @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 ); @@ -2188,7 +2188,7 @@ class Tests_REST_Server extends WP_Test_REST_TestCase { array( array( 'methods' => \WP_REST_Server::READABLE, - 'callback' => function() { + 'callback' => static function() { return new \WP_REST_Response( INF ); }, 'permission_callback' => '__return_true', diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index 995b11f51d..01e1a2b6ad 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -1384,7 +1384,7 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase { 'wp/v2', sprintf( '/themes/(?P%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', diff --git a/tests/phpunit/tests/theme/wpThemeJsonResolver.php b/tests/phpunit/tests/theme/wpThemeJsonResolver.php index 59ce83e887..7e928aa0c7 100644 --- a/tests/phpunit/tests/theme/wpThemeJsonResolver.php +++ b/tests/phpunit/tests/theme/wpThemeJsonResolver.php @@ -600,7 +600,7 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase { $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++; }