diff --git a/src/wp-admin/edit-form-blocks.php b/src/wp-admin/edit-form-blocks.php
index fa4b8a9dd17e..7e335fa49b9c 100644
--- a/src/wp-admin/edit-form-blocks.php
+++ b/src/wp-admin/edit-form-blocks.php
@@ -31,7 +31,7 @@
// Default to is-fullscreen-mode to avoid jumps in the UI.
add_filter(
'admin_body_class',
- function( $classes ) {
+ static function( $classes ) {
return "$classes is-fullscreen-mode";
}
);
diff --git a/src/wp-admin/includes/class-wp-community-events.php b/src/wp-admin/includes/class-wp-community-events.php
index 8ccf490e29a1..cf995eeac861 100644
--- a/src/wp-admin/includes/class-wp-community-events.php
+++ b/src/wp-admin/includes/class-wp-community-events.php
@@ -474,7 +474,7 @@ protected function trim_events( array $events ) {
$future_wordcamps = array_filter(
$future_events,
- function( $wordcamp ) {
+ static function( $wordcamp ) {
return 'wordcamp' === $wordcamp['type'];
}
);
diff --git a/src/wp-admin/includes/class-wp-site-health-auto-updates.php b/src/wp-admin/includes/class-wp-site-health-auto-updates.php
index d1c133524d6e..4afaeac1c48b 100644
--- a/src/wp-admin/includes/class-wp-site-health-auto-updates.php
+++ b/src/wp-admin/includes/class-wp-site-health-auto-updates.php
@@ -41,7 +41,7 @@ public function run_tests() {
$tests = array_filter( $tests );
$tests = array_map(
- function( $test ) {
+ static function( $test ) {
$test = (object) $test;
if ( empty( $test->severity ) ) {
diff --git a/src/wp-admin/includes/update-core.php b/src/wp-admin/includes/update-core.php
index 77ede74c779f..32664bf6ff30 100644
--- a/src/wp-admin/includes/update-core.php
+++ b/src/wp-admin/includes/update-core.php
@@ -1658,7 +1658,7 @@ function _upgrade_422_find_genericons_files_in_folder( $directory ) {
$dirs = glob( $directory . '*', GLOB_ONLYDIR );
$dirs = array_filter(
$dirs,
- function( $dir ) {
+ static function( $dir ) {
// Skip any node_modules directories.
return false === strpos( $dir, 'node_modules' );
}
diff --git a/src/wp-admin/options-privacy.php b/src/wp-admin/options-privacy.php
index 3e4902daf4bf..0b0ca77ee9e2 100644
--- a/src/wp-admin/options-privacy.php
+++ b/src/wp-admin/options-privacy.php
@@ -20,7 +20,7 @@
add_filter(
'admin_body_class',
- function( $body_class ) {
+ static function( $body_class ) {
$body_class .= ' privacy-settings ';
return $body_class;
diff --git a/src/wp-admin/privacy-policy-guide.php b/src/wp-admin/privacy-policy-guide.php
index e5d558e639af..6581bb412a62 100644
--- a/src/wp-admin/privacy-policy-guide.php
+++ b/src/wp-admin/privacy-policy-guide.php
@@ -19,7 +19,7 @@
add_filter(
'admin_body_class',
- function( $body_class ) {
+ static function( $body_class ) {
$body_class .= ' privacy-settings ';
return $body_class;
diff --git a/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-customize.php b/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-customize.php
index d41b494584a7..ca666df11d38 100644
--- a/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-customize.php
+++ b/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-customize.php
@@ -186,7 +186,7 @@ public static function register( $wp_customize ) {
'settings' => 'accent_hue',
'description' => __( 'Apply a custom color for links, buttons, featured images.', 'twentytwenty' ),
'mode' => 'hue',
- 'active_callback' => function() use ( $wp_customize ) {
+ 'active_callback' => static function() use ( $wp_customize ) {
return ( 'custom' === $wp_customize->get_setting( 'accent_hue_active' )->value() );
},
)
diff --git a/src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-customize.php b/src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-customize.php
index b880a03afbe3..4a0fe6f7af50 100644
--- a/src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-customize.php
+++ b/src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-customize.php
@@ -92,7 +92,7 @@ public function register( $wp_customize ) {
array(
'capability' => 'edit_theme_options',
'default' => 'excerpt',
- 'sanitize_callback' => function( $value ) {
+ 'sanitize_callback' => static function( $value ) {
return 'excerpt' === $value || 'full' === $value ? $value : 'excerpt';
},
)
diff --git a/src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-dark-mode.php b/src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-dark-mode.php
index 4034eaae25db..4de201c1b92a 100644
--- a/src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-dark-mode.php
+++ b/src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-dark-mode.php
@@ -153,7 +153,7 @@ public function customizer_controls( $wp_customize ) {
array(
'section' => 'colors',
'priority' => 100,
- 'active_callback' => function() {
+ 'active_callback' => static function() {
return 127 >= Twenty_Twenty_One_Custom_Colors::get_relative_luminance_from_hex( get_theme_mod( 'background_color', 'D1E4DD' ) );
},
)
@@ -165,7 +165,7 @@ public function customizer_controls( $wp_customize ) {
array(
'capability' => 'edit_theme_options',
'default' => false,
- 'sanitize_callback' => function( $value ) {
+ 'sanitize_callback' => static function( $value ) {
return (bool) $value;
},
)
@@ -188,7 +188,7 @@ public function customizer_controls( $wp_customize ) {
'label' => esc_html__( 'Dark Mode support', 'twentytwentyone' ),
'priority' => 110,
'description' => $description,
- 'active_callback' => function( $value ) {
+ 'active_callback' => static function( $value ) {
return 127 < Twenty_Twenty_One_Custom_Colors::get_relative_luminance_from_hex( get_theme_mod( 'background_color', 'D1E4DD' ) );
},
)
diff --git a/src/wp-includes/block-supports/duotone.php b/src/wp-includes/block-supports/duotone.php
index 3e81c33e0713..04aac0ef1e65 100644
--- a/src/wp-includes/block-supports/duotone.php
+++ b/src/wp-includes/block-supports/duotone.php
@@ -361,7 +361,7 @@ function wp_render_duotone_support( $block_content, $block ) {
$selectors = explode( ',', $duotone_support );
$selectors_scoped = array_map(
- function ( $selector ) use ( $duotone_id ) {
+ static function ( $selector ) use ( $duotone_id ) {
return '.' . $duotone_id . ' ' . trim( $selector );
},
$selectors
diff --git a/src/wp-includes/block-supports/layout.php b/src/wp-includes/block-supports/layout.php
index 16e070a7d3d1..be1da09899da 100644
--- a/src/wp-includes/block-supports/layout.php
+++ b/src/wp-includes/block-supports/layout.php
@@ -131,7 +131,7 @@ function wp_restore_group_inner_container( $block_content, $block ) {
$replace_regex = '/(^\s*
]*wp-block-group[^>]*>)(.*)(<\/div>\s*$)/ms';
$updated_content = preg_replace_callback(
$replace_regex,
- function( $matches ) {
+ static function( $matches ) {
return $matches[1] . '
' . $matches[2] . '
' . $matches[3];
},
$block_content
diff --git a/src/wp-includes/block-template.php b/src/wp-includes/block-template.php
index d745c0536a11..945b96b02742 100644
--- a/src/wp-includes/block-template.php
+++ b/src/wp-includes/block-template.php
@@ -124,7 +124,7 @@ function resolve_block_template( $template_type, $template_hierarchy ) {
usort(
$templates,
- function ( $template_a, $template_b ) use ( $slug_priorities ) {
+ static function ( $template_a, $template_b ) use ( $slug_priorities ) {
return $slug_priorities[ $template_a->slug ] - $slug_priorities[ $template_b->slug ];
}
);
diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php
index a35ee1b7958a..d394bd3301ca 100644
--- a/src/wp-includes/class-wp-theme-json.php
+++ b/src/wp-includes/class-wp-theme-json.php
@@ -636,7 +636,7 @@ private static function to_ruleset( $selector, $declarations ) {
$declaration_block = array_reduce(
$declarations,
- function ( $carry, $element ) {
+ static function ( $carry, $element ) {
return $carry .= $element['name'] . ': ' . $element['value'] . ';'; },
''
);
diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php
index b80c40cdda60..4f01c511b03a 100644
--- a/src/wp-includes/formatting.php
+++ b/src/wp-includes/formatting.php
@@ -3113,7 +3113,7 @@ function wp_rel_nofollow( $text ) {
$text = stripslashes( $text );
$text = preg_replace_callback(
'|
|i',
- function( $matches ) {
+ static function( $matches ) {
return wp_rel_callback( $matches, 'nofollow' );
},
$text
@@ -3147,7 +3147,7 @@ function wp_rel_ugc( $text ) {
$text = stripslashes( $text );
$text = preg_replace_callback(
'||i',
- function( $matches ) {
+ static function( $matches ) {
return wp_rel_callback( $matches, 'nofollow ugc' );
},
$text
diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php
index 675c545ce18e..fb83e38f4cb1 100644
--- a/src/wp-includes/rest-api.php
+++ b/src/wp-includes/rest-api.php
@@ -3227,7 +3227,7 @@ function rest_get_endpoint_args_for_schema( $schema, $method = WP_REST_Server::C
function rest_convert_error_to_response( $error ) {
$status = array_reduce(
$error->get_all_error_data(),
- function ( $status, $error_data ) {
+ static function ( $status, $error_data ) {
return is_array( $error_data ) && isset( $error_data['status'] ) ? $error_data['status'] : $status;
},
500
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php
index b1cb4be45745..b3f41c6a6a03 100644
--- a/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php
+++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php
@@ -597,7 +597,7 @@ public function get_fields_for_response( $request ) {
// Return the list of all requested fields which appear in the schema.
return array_reduce(
$requested_fields,
- function( $response_fields, $field ) use ( $fields ) {
+ static function( $response_fields, $field ) use ( $fields ) {
if ( in_array( $field, $fields, true ) ) {
$response_fields[] = $field;
return $response_fields;
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php
index 3a7bf0ff95b3..4da8e7aa18d9 100644
--- a/src/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php
+++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php
@@ -381,7 +381,7 @@ public function create_item( $request ) {
$installed_locales = apply_filters( 'plugins_update_check_locales', $installed_locales );
$language_packs = array_map(
- function( $item ) {
+ static function( $item ) {
return (object) $item;
},
$api->language_packs
@@ -389,7 +389,7 @@ function( $item ) {
$language_packs = array_filter(
$language_packs,
- function( $pack ) use ( $installed_locales ) {
+ static function( $pack ) use ( $installed_locales ) {
return in_array( $pack->language, $installed_locales, true );
}
);
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php
index db88950faa48..c137302f31ae 100644
--- a/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php
+++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php
@@ -85,7 +85,7 @@ public function register_routes() {
'form_data' => array(
'description' => __( 'Serialized widget form data to encode into instance settings.' ),
'type' => 'string',
- 'sanitize_callback' => function( $string ) {
+ 'sanitize_callback' => static function( $string ) {
$array = array();
wp_parse_str( $string, $array );
return $array;
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php
index 3b425a6b8b64..4c54620f509f 100644
--- a/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php
+++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php
@@ -792,7 +792,7 @@ public function get_item_schema() {
'type' => 'string',
'context' => array(),
'arg_options' => array(
- 'sanitize_callback' => function( $string ) {
+ 'sanitize_callback' => static function( $string ) {
$array = array();
wp_parse_str( $string, $array );
return $array;
diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php
index 1e2f1d5faeaa..608e7936e365 100644
--- a/src/wp-includes/script-loader.php
+++ b/src/wp-includes/script-loader.php
@@ -2692,7 +2692,7 @@ function wp_maybe_inline_styles() {
// Reorder styles array based on size.
usort(
$styles,
- function( $a, $b ) {
+ static function( $a, $b ) {
return ( $a['size'] <= $b['size'] ) ? -1 : 1;
}
);
diff --git a/src/wp-includes/update.php b/src/wp-includes/update.php
index 79e3b3ea33d5..85d0d4c9a86d 100644
--- a/src/wp-includes/update.php
+++ b/src/wp-includes/update.php
@@ -517,7 +517,7 @@ function wp_update_plugins( $extra_stats = array() ) {
}
}
- $sanitize_plugin_update_payload = function( &$item ) {
+ $sanitize_plugin_update_payload = static function( &$item ) {
$item = (object) $item;
unset( $item->translations, $item->compatibility );
diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php
index 7c1c2c1f5534..94598e84935a 100644
--- a/src/wp-includes/user.php
+++ b/src/wp-includes/user.php
@@ -3459,7 +3459,7 @@ function wp_user_personal_data_exporter( $email_address ) {
// Remove items that use reserved names.
$extra_data = array_filter(
$_extra_data,
- function( $item ) use ( $reserved_names ) {
+ static function( $item ) use ( $reserved_names ) {
return ! in_array( $item['name'], $reserved_names, true );
}
);
diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php
index be836f67075d..744e3670e061 100644
--- a/tests/phpunit/includes/abstract-testcase.php
+++ b/tests/phpunit/includes/abstract-testcase.php
@@ -719,14 +719,14 @@ public function assertDiscardWhitespace( $expected, $actual, $message = '' ) {
public function assertSameIgnoreEOL( $expected, $actual, $message = '' ) {
$expected = map_deep(
$expected,
- function ( $value ) {
+ static function ( $value ) {
return str_replace( "\r\n", "\n", $value );
}
);
$actual = map_deep(
$actual,
- function ( $value ) {
+ static function ( $value ) {
return str_replace( "\r\n", "\n", $value );
}
);
diff --git a/tests/phpunit/includes/plural-form-function.php b/tests/phpunit/includes/plural-form-function.php
index 714381339d15..a5cdf703e3b9 100644
--- a/tests/phpunit/includes/plural-form-function.php
+++ b/tests/phpunit/includes/plural-form-function.php
@@ -7,7 +7,7 @@
* @param string $expression
*/
function tests_make_plural_form_function( $nplurals, $expression ) {
- $closure = function ( $n ) use ( $nplurals, $expression ) {
+ $closure = static function ( $n ) use ( $nplurals, $expression ) {
$expression = str_replace( 'n', $n, $expression );
// phpcs:ignore Squiz.PHP.Eval -- This is test code, not production.
diff --git a/tests/phpunit/tests/actions/closures.php b/tests/phpunit/tests/actions/closures.php
index d1a458e27300..bd8b88d97fa1 100644
--- a/tests/phpunit/tests/actions/closures.php
+++ b/tests/phpunit/tests/actions/closures.php
@@ -12,7 +12,7 @@ class Tests_Actions_Closures extends WP_UnitTestCase {
*/
function test_action_closure() {
$tag = 'test_action_closure';
- $closure = function( $a, $b ) {
+ $closure = static function( $a, $b ) {
$GLOBALS[ $a ] = $b;
};
add_action( $tag, $closure, 10, 2 );
@@ -25,7 +25,7 @@ function test_action_closure() {
$this->assertSame( $GLOBALS[ $context[0] ], $context[1] );
$tag2 = 'test_action_closure_2';
- $closure2 = function() {
+ $closure2 = static function() {
$GLOBALS['closure_no_args'] = true;
};
add_action( $tag2, $closure2 );
diff --git a/tests/phpunit/tests/admin/includesListTable.php b/tests/phpunit/tests/admin/includesListTable.php
index 014475b28255..ac2e153e2fb1 100644
--- a/tests/phpunit/tests/admin/includesListTable.php
+++ b/tests/phpunit/tests/admin/includesListTable.php
@@ -360,7 +360,7 @@ public function test_bulk_action_menu_supports_options_and_optgroups() {
add_filter(
'bulk_actions-edit-comments',
- function() {
+ static function() {
return array(
'delete' => 'Delete',
'Change State' => array(
diff --git a/tests/phpunit/tests/block-template-utils.php b/tests/phpunit/tests/block-template-utils.php
index b528067dc4ad..c52c25a99fe7 100644
--- a/tests/phpunit/tests/block-template-utils.php
+++ b/tests/phpunit/tests/block-template-utils.php
@@ -70,7 +70,7 @@ function test_get_block_template_from_post() {
function test_get_block_templates() {
function get_template_ids( $templates ) {
return array_map(
- function( $template ) {
+ static function( $template ) {
return $template->id;
},
$templates
diff --git a/tests/phpunit/tests/blocks/context.php b/tests/phpunit/tests/blocks/context.php
index b23b8da3ae66..f39b378c65aa 100644
--- a/tests/phpunit/tests/blocks/context.php
+++ b/tests/phpunit/tests/blocks/context.php
@@ -115,7 +115,7 @@ function test_provides_block_context() {
'gutenberg/contextWithAssigned',
'gutenberg/contextWithoutDefault',
),
- 'render_callback' => function( $attributes, $content, $block ) use ( &$provided_context ) {
+ 'render_callback' => static function( $attributes, $content, $block ) use ( &$provided_context ) {
$provided_context[] = $block->context;
return '';
@@ -155,7 +155,7 @@ function test_provides_default_context() {
'gutenberg/test-context-consumer',
array(
'uses_context' => array( 'postId', 'postType' ),
- 'render_callback' => function( $attributes, $content, $block ) use ( &$provided_context ) {
+ 'render_callback' => static function( $attributes, $content, $block ) use ( &$provided_context ) {
$provided_context[] = $block->context;
return '';
@@ -188,7 +188,7 @@ function test_default_context_is_filterable() {
'gutenberg/test-context-consumer',
array(
'uses_context' => array( 'example' ),
- 'render_callback' => function( $attributes, $content, $block ) use ( &$provided_context ) {
+ 'render_callback' => static function( $attributes, $content, $block ) use ( &$provided_context ) {
$provided_context[] = $block->context;
return '';
@@ -196,7 +196,7 @@ function test_default_context_is_filterable() {
)
);
- $filter_block_context = function( $context ) {
+ $filter_block_context = static function( $context ) {
$context['example'] = 'ok';
return $context;
};
diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php
index 1f3104d09b3a..ee98bca81b72 100644
--- a/tests/phpunit/tests/blocks/register.php
+++ b/tests/phpunit/tests/blocks/register.php
@@ -510,7 +510,7 @@ function test_has_blocks() {
* @ticket 49615
*/
public function test_filter_block_registration() {
- $filter_registration = function( $args, $name ) {
+ $filter_registration = static function( $args, $name ) {
$args['attributes'] = array( $name => array( 'type' => 'boolean' ) );
return $args;
};
@@ -528,7 +528,7 @@ public function test_filter_block_registration() {
* @ticket 52138
*/
public function test_filter_block_registration_metadata() {
- $filter_metadata_registration = function( $metadata ) {
+ $filter_metadata_registration = static function( $metadata ) {
$metadata['apiVersion'] = 3;
return $metadata;
};
@@ -546,7 +546,7 @@ public function test_filter_block_registration_metadata() {
* @ticket 52138
*/
public function test_filter_block_registration_metadata_settings() {
- $filter_metadata_registration = function( $settings, $metadata ) {
+ $filter_metadata_registration = static function( $settings, $metadata ) {
$settings['api_version'] = $metadata['apiVersion'] + 1;
return $settings;
};
diff --git a/tests/phpunit/tests/blocks/supportedStyles.php b/tests/phpunit/tests/blocks/supportedStyles.php
index b3e50800dd6c..bdbf91aa2eb1 100644
--- a/tests/phpunit/tests/blocks/supportedStyles.php
+++ b/tests/phpunit/tests/blocks/supportedStyles.php
@@ -712,7 +712,7 @@ public function test_render_block_suppresses_warnings_without_at_suppression() {
// Custom error handler's see Warnings even if they are suppressed by the @ symbol.
$errors = array();
set_error_handler(
- function ( $errno = 0, $errstr = '' ) use ( &$errors ) {
+ static function ( $errno = 0, $errstr = '' ) use ( &$errors ) {
$errors[] = $errstr;
return false;
}
diff --git a/tests/phpunit/tests/blocks/wpBlock.php b/tests/phpunit/tests/blocks/wpBlock.php
index a50fc7e878f9..e44a96d8b0ba 100644
--- a/tests/phpunit/tests/blocks/wpBlock.php
+++ b/tests/phpunit/tests/blocks/wpBlock.php
@@ -275,7 +275,7 @@ function test_render_static_block_type_returns_own_content() {
$this->registry->register(
'core/dynamic',
array(
- 'render_callback' => function() {
+ 'render_callback' => static function() {
return 'b';
},
)
@@ -296,7 +296,7 @@ function test_render_passes_block_for_render_callback() {
$this->registry->register(
'core/greeting',
array(
- 'render_callback' => function( $attributes, $content, $block ) {
+ 'render_callback' => static function( $attributes, $content, $block ) {
return sprintf( 'Hello from %s', $block->name );
},
)
@@ -366,7 +366,7 @@ function test_passes_attributes_to_render_callback() {
'default' => '!',
),
),
- 'render_callback' => function( $block_attributes ) {
+ 'render_callback' => static function( $block_attributes ) {
return sprintf(
'Hello %s%s',
$block_attributes['toWhom'],
@@ -391,7 +391,7 @@ function test_passes_content_to_render_callback() {
$this->registry->register(
'core/outer',
array(
- 'render_callback' => function( $block_attributes, $content ) {
+ 'render_callback' => static function( $block_attributes, $content ) {
return $content;
},
)
@@ -399,7 +399,7 @@ function test_passes_content_to_render_callback() {
$this->registry->register(
'core/inner',
array(
- 'render_callback' => function() {
+ 'render_callback' => static function() {
return 'b';
},
)
diff --git a/tests/phpunit/tests/canonical.php b/tests/phpunit/tests/canonical.php
index 3069ba840027..d5198ee558d4 100644
--- a/tests/phpunit/tests/canonical.php
+++ b/tests/phpunit/tests/canonical.php
@@ -247,7 +247,7 @@ public function test_pre_redirect_guess_404_permalink() {
// Test short-circuit filter.
add_filter(
'pre_redirect_guess_404_permalink',
- function() {
+ static function() {
return 'wp';
}
);
diff --git a/tests/phpunit/tests/category/walkerCategory.php b/tests/phpunit/tests/category/walkerCategory.php
index ac49a3021643..92d5c3f30913 100644
--- a/tests/phpunit/tests/category/walkerCategory.php
+++ b/tests/phpunit/tests/category/walkerCategory.php
@@ -38,7 +38,7 @@ public function test_start_el_with_empty_attributes( $value, $expected ) {
add_filter(
'category_list_link_attributes',
- function( $atts ) use ( $value ) {
+ static function( $atts ) use ( $value ) {
$atts['data-test'] = $value;
return $atts;
}
diff --git a/tests/phpunit/tests/comment/commentsTemplate.php b/tests/phpunit/tests/comment/commentsTemplate.php
index c0cee5dc743d..7135118485a8 100644
--- a/tests/phpunit/tests/comment/commentsTemplate.php
+++ b/tests/phpunit/tests/comment/commentsTemplate.php
@@ -993,7 +993,7 @@ public function test_comments_template_top_level_query_args( $expected, $query_a
add_filter(
'comments_template_query_args',
- function ( $args ) use ( &$offset, $query_args ) {
+ static function ( $args ) use ( &$offset, $query_args ) {
$offset = $args['offset'];
return array_merge( $args, $query_args );
@@ -1003,7 +1003,7 @@ function ( $args ) use ( &$offset, $query_args ) {
if ( ! empty( $top_level_query_args ) ) {
add_filter(
'comments_template_top_level_query_args',
- function ( $args ) use ( $top_level_query_args ) {
+ static function ( $args ) use ( $top_level_query_args ) {
return array_merge( $args, $top_level_query_args );
}
);
diff --git a/tests/phpunit/tests/cron.php b/tests/phpunit/tests/cron.php
index 9b9c475954ca..26453c01111d 100644
--- a/tests/phpunit/tests/cron.php
+++ b/tests/phpunit/tests/cron.php
@@ -1055,7 +1055,7 @@ public function test_cron_array_error_is_returned_when_scheduling_single_event()
// Force update_option() to fail by setting the new value to match the existing:
add_filter(
'pre_update_option_cron',
- function() {
+ static function() {
return get_option( 'cron' );
}
);
@@ -1075,7 +1075,7 @@ public function test_cron_array_error_is_returned_when_scheduling_event() {
// Force update_option() to fail by setting the new value to match the existing:
add_filter(
'pre_update_option_cron',
- function() {
+ static function() {
return get_option( 'cron' );
}
);
@@ -1098,7 +1098,7 @@ public function test_cron_array_error_is_returned_when_unscheduling_hook() {
// Force update_option() to fail by setting the new value to match the existing:
add_filter(
'pre_update_option_cron',
- function() {
+ static function() {
return get_option( 'cron' );
}
);
@@ -1122,7 +1122,7 @@ public function test_cron_array_error_is_returned_when_unscheduling_event() {
// Force update_option() to fail by setting the new value to match the existing:
add_filter(
'pre_update_option_cron',
- function() {
+ static function() {
return get_option( 'cron' );
}
);
diff --git a/tests/phpunit/tests/dependencies/wpInlineScriptTag.php b/tests/phpunit/tests/dependencies/wpInlineScriptTag.php
index d2c2185d4847..1e517b637dda 100644
--- a/tests/phpunit/tests/dependencies/wpInlineScriptTag.php
+++ b/tests/phpunit/tests/dependencies/wpInlineScriptTag.php
@@ -80,7 +80,7 @@ public function test_get_inline_script_tag_unescaped_src() {
public function test_print_script_tag_prints_get_inline_script_tag() {
add_filter(
'wp_inline_script_attributes',
- function ( $attributes ) {
+ static function ( $attributes ) {
if ( isset( $attributes['id'] ) && 'utils-js-extra' === $attributes['id'] ) {
$attributes['async'] = true;
}
diff --git a/tests/phpunit/tests/dependencies/wpScriptTag.php b/tests/phpunit/tests/dependencies/wpScriptTag.php
index ba80c8cabfbb..f009bb5790c5 100644
--- a/tests/phpunit/tests/dependencies/wpScriptTag.php
+++ b/tests/phpunit/tests/dependencies/wpScriptTag.php
@@ -64,7 +64,7 @@ function test_get_script_tag_type_not_set() {
function test_print_script_tag_prints_get_script_tag() {
add_filter(
'wp_script_attributes',
- function ( $attributes ) {
+ static function ( $attributes ) {
if ( isset( $attributes['id'] ) && 'utils-js-extra' === $attributes['id'] ) {
$attributes['async'] = true;
}
diff --git a/tests/phpunit/tests/https-detection.php b/tests/phpunit/tests/https-detection.php
index 6ed466af6a19..1ae5af13091e 100644
--- a/tests/phpunit/tests/https-detection.php
+++ b/tests/phpunit/tests/https-detection.php
@@ -117,7 +117,7 @@ public function test_pre_wp_update_https_detection_errors() {
// Override to enforce no errors being detected.
add_filter(
'pre_wp_update_https_detection_errors',
- function() {
+ static function() {
return new WP_Error();
}
);
@@ -127,7 +127,7 @@ function() {
// Override to enforce an error being detected.
add_filter(
'pre_wp_update_https_detection_errors',
- function() {
+ static function() {
return new WP_Error(
'ssl_verification_failed',
'Bad SSL certificate.'
@@ -345,7 +345,7 @@ private function get_sample_html_string( $head_tag = '' ) {
* @return callable Filter callback.
*/
private function filter_set_url_scheme( $scheme ) {
- return function( $url ) use ( $scheme ) {
+ return static function( $url ) use ( $scheme ) {
return set_url_scheme( $url, $scheme );
};
}
diff --git a/tests/phpunit/tests/https-migration.php b/tests/phpunit/tests/https-migration.php
index dccf40b60285..d06e1f0fba05 100644
--- a/tests/phpunit/tests/https-migration.php
+++ b/tests/phpunit/tests/https-migration.php
@@ -161,7 +161,7 @@ public function test_wp_should_replace_insecure_home_url_integration() {
private function force_wp_is_using_https( $enabled ) {
$scheme = $enabled ? 'https' : 'http';
- $replace_scheme = function( $url ) use ( $scheme ) {
+ $replace_scheme = static function( $url ) use ( $scheme ) {
return str_replace( array( 'http://', 'https://' ), $scheme . '://', $url );
};
@@ -172,7 +172,7 @@ private function force_wp_is_using_https( $enabled ) {
private function force_option( $option, $value ) {
add_filter(
"option_$option",
- function() use ( $value ) {
+ static function() use ( $value ) {
return $value;
}
);
diff --git a/tests/phpunit/tests/image/intermediateSize.php b/tests/phpunit/tests/image/intermediateSize.php
index d2098c49e12b..cf5b3888fed9 100644
--- a/tests/phpunit/tests/image/intermediateSize.php
+++ b/tests/phpunit/tests/image/intermediateSize.php
@@ -69,7 +69,7 @@ function test_make_intermediate_size_successful() {
function test_image_editor_output_format_filter() {
add_filter(
'image_editor_output_format',
- function() {
+ static function() {
return array( 'image/jpeg' => 'image/webp' );
}
);
diff --git a/tests/phpunit/tests/l10n/loadScriptTextdomain.php b/tests/phpunit/tests/l10n/loadScriptTextdomain.php
index b9b6ef0c3f70..0cce2a1f2e02 100644
--- a/tests/phpunit/tests/l10n/loadScriptTextdomain.php
+++ b/tests/phpunit/tests/l10n/loadScriptTextdomain.php
@@ -49,7 +49,7 @@ public function data_test_resolve_relative_path() {
'default',
array(
'site_url',
- function ( $site_url ) {
+ static function ( $site_url ) {
return $site_url . '/wp';
},
),
@@ -62,7 +62,7 @@ function ( $site_url ) {
'internationalized-plugin',
array(
'plugins_url',
- function () {
+ static function () {
return 'https://plugins.example.com';
},
),
@@ -75,7 +75,7 @@ function () {
'internationalized-plugin',
array(
'content_url',
- function () {
+ static function () {
return 'https://content.example.com';
},
),
@@ -88,7 +88,7 @@ function () {
'internationalized-plugin',
array(
'content_url',
- function () {
+ static function () {
return '/';
},
),
@@ -101,7 +101,7 @@ function () {
'internationalized-plugin',
array(
'plugins_url',
- function () {
+ static function () {
return '/';
},
),
@@ -114,7 +114,7 @@ function () {
'default',
array(
'site_url',
- function () {
+ static function () {
return '/wp';
},
),
diff --git a/tests/phpunit/tests/menu/walker-nav-menu.php b/tests/phpunit/tests/menu/walker-nav-menu.php
index 83523644e537..1811284b50b7 100644
--- a/tests/phpunit/tests/menu/walker-nav-menu.php
+++ b/tests/phpunit/tests/menu/walker-nav-menu.php
@@ -94,7 +94,7 @@ public function test_start_el_with_empty_attributes( $value, $expected ) {
add_filter(
'nav_menu_link_attributes',
- function( $atts ) use ( $value ) {
+ static function( $atts ) use ( $value ) {
$atts['data-test'] = $value;
return $atts;
}
diff --git a/tests/phpunit/tests/post/revisions.php b/tests/phpunit/tests/post/revisions.php
index 3e0899ca999d..840597c4a9ab 100644
--- a/tests/phpunit/tests/post/revisions.php
+++ b/tests/phpunit/tests/post/revisions.php
@@ -594,7 +594,7 @@ public function test_wp_revisions_to_keep_filter() {
add_filter(
'wp_revisions_to_keep',
- function () use ( $expected ) {
+ static function () use ( $expected ) {
return $expected;
}
);
@@ -619,7 +619,7 @@ public function test_wp_post_type_revisions_to_keep_filter() {
add_filter(
'wp_revisions_to_keep',
- function () use ( $generic ) {
+ static function () use ( $generic ) {
return $generic;
}
);
@@ -630,7 +630,7 @@ function () use ( $generic ) {
add_filter(
"wp_{$post->post_type}_revisions_to_keep",
- function () use ( $expected ) {
+ static function () use ( $expected ) {
return $expected;
}
);
diff --git a/tests/phpunit/tests/post/walkerPage.php b/tests/phpunit/tests/post/walkerPage.php
index f0ad198d7899..6b71bb021667 100644
--- a/tests/phpunit/tests/post/walkerPage.php
+++ b/tests/phpunit/tests/post/walkerPage.php
@@ -33,7 +33,7 @@ public function test_start_el_with_empty_attributes( $value, $expected ) {
add_filter(
'page_menu_link_attributes',
- function( $atts ) use ( $value ) {
+ static function( $atts ) use ( $value ) {
$atts['data-test'] = $value;
return $atts;
}
diff --git a/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php b/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php
index ac07737b4d79..cbfe965fa1a3 100644
--- a/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php
+++ b/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php
@@ -937,7 +937,7 @@ public function test_introspect_item_password_invalid() {
$this->setup_app_password_authenticated_request();
add_action(
'application_password_did_authenticate',
- function() {
+ static function() {
$GLOBALS['wp_rest_application_password_uuid'] = 'invalid_uuid';
}
);
diff --git a/tests/phpunit/tests/rest-api/rest-block-renderer-controller.php b/tests/phpunit/tests/rest-api/rest-block-renderer-controller.php
index 6d76a2f5d69b..454bc6da35e1 100644
--- a/tests/phpunit/tests/rest-api/rest-block-renderer-controller.php
+++ b/tests/phpunit/tests/rest-api/rest-block-renderer-controller.php
@@ -435,7 +435,7 @@ public function test_get_item() {
public function test_get_item_with_pre_render_block_filter() {
wp_set_current_user( self::$user_id );
- $pre_render_filter = function( $output, $block ) {
+ $pre_render_filter = static function( $output, $block ) {
if ( $block['blockName'] === self::$block_name ) {
return 'Alternate content.
';
}
diff --git a/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php b/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php
index c21ba712f631..4a12e663b539 100644
--- a/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php
+++ b/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php
@@ -272,7 +272,7 @@ public function test_get_items_prepare_filter() {
// Test that filter changes uncached values.
add_filter(
'rest_prepare_block_pattern',
- function( $response ) {
+ static function( $response ) {
return 'initial value';
}
);
@@ -286,7 +286,7 @@ function( $response ) {
// Test that filter changes cached values (the previous request primed the cache).
add_filter(
'rest_prepare_block_pattern',
- function( $response ) {
+ static function( $response ) {
return 'modified the cache';
},
11
diff --git a/tests/phpunit/tests/rest-api/rest-post-meta-fields.php b/tests/phpunit/tests/rest-api/rest-post-meta-fields.php
index 1e506c282aae..85671eff5498 100644
--- a/tests/phpunit/tests/rest-api/rest-post-meta-fields.php
+++ b/tests/phpunit/tests/rest-api/rest-post-meta-fields.php
@@ -2708,7 +2708,7 @@ public function test_boolean_meta_update_to_false_stores_0() {
'single' => true,
'type' => 'boolean',
'show_in_rest' => true,
- 'sanitize_callback' => function( $value ) {
+ 'sanitize_callback' => static function( $value ) {
return $value ? '1' : '0';
},
)
diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php
index ba6dc53c0b2d..b35921a73db1 100644
--- a/tests/phpunit/tests/rest-api/rest-posts-controller.php
+++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php
@@ -2137,7 +2137,7 @@ public function test_prepare_item_limit_fields() {
*/
public function test_prepare_item_filters_content_when_needed() {
$filter_count = 0;
- $filter_content = function() use ( &$filter_count ) {
+ $filter_content = static function() use ( &$filter_count ) {
$filter_count++;
return 'Filtered content.
';
};
@@ -2173,7 +2173,7 @@ public function test_prepare_item_filters_content_when_needed() {
*/
public function test_prepare_item_skips_content_filter_if_not_needed() {
$filter_count = 0;
- $filter_content = function() use ( &$filter_count ) {
+ $filter_content = static function() use ( &$filter_count ) {
$filter_count++;
return 'Filtered content.
';
};
diff --git a/tests/phpunit/tests/rest-api/rest-request.php b/tests/phpunit/tests/rest-api/rest-request.php
index 55b3b188d017..836cb6159dbf 100644
--- a/tests/phpunit/tests/rest-api/rest-request.php
+++ b/tests/phpunit/tests/rest-api/rest-request.php
@@ -475,7 +475,7 @@ public function test_sanitize_params_error_multiple_messages() {
array(
'args' => array(
'failparam' => array(
- 'sanitize_callback' => function () {
+ 'sanitize_callback' => static function () {
$error = new WP_Error( 'invalid', 'Invalid.' );
$error->add( 'invalid', 'Super Invalid.' );
$error->add( 'broken', 'Broken.' );
@@ -510,7 +510,7 @@ public function test_sanitize_params_provides_detailed_errors() {
array(
'args' => array(
'failparam' => array(
- 'sanitize_callback' => function () {
+ 'sanitize_callback' => static function () {
return new WP_Error( 'invalid', 'Invalid.', 'mydata' );
},
),
@@ -738,7 +738,7 @@ public function test_invalid_params_error_multiple_messages() {
array(
'args' => array(
'failparam' => array(
- 'validate_callback' => function () {
+ 'validate_callback' => static function () {
$error = new WP_Error( 'invalid', 'Invalid.' );
$error->add( 'invalid', 'Super Invalid.' );
$error->add( 'broken', 'Broken.' );
@@ -773,7 +773,7 @@ public function test_invalid_params_provides_detailed_errors() {
array(
'args' => array(
'failparam' => array(
- 'validate_callback' => function () {
+ 'validate_callback' => static function () {
return new WP_Error( 'invalid', 'Invalid.', 'mydata' );
},
),
diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php
index 3c1e4107edb9..03d1cf21faf1 100644
--- a/tests/phpunit/tests/rest-api/rest-server.php
+++ b/tests/phpunit/tests/rest-api/rest-server.php
@@ -1392,7 +1392,7 @@ public function test_does_not_echo_body_for_null_responses() {
'/test',
array(
'methods' => array( 'GET' ),
- 'callback' => function () {
+ 'callback' => static function () {
return new WP_REST_Response();
},
'permission_callback' => '__return_true',
@@ -1414,7 +1414,7 @@ public function test_does_not_echo_body_for_responses_with_204_status() {
'/test',
array(
'methods' => array( 'GET' ),
- 'callback' => function () {
+ 'callback' => static function () {
return new WP_REST_Response( 'data', 204 );
},
'permission_callback' => '__return_true',
@@ -1505,7 +1505,7 @@ public function test_get_routes_no_namespace_overriding() {
'/test',
array(
'methods' => array( 'GET' ),
- 'callback' => function() {
+ 'callback' => static function() {
return new WP_REST_Response( 'data', 204 );
},
'permission_callback' => '__return_true',
@@ -1516,7 +1516,7 @@ public function test_get_routes_no_namespace_overriding() {
'/test',
array(
'methods' => array( 'GET' ),
- 'callback' => function() {
+ 'callback' => static function() {
return new WP_REST_Response( 'data', 204 );
},
'permission_callback' => '__return_true',
@@ -1928,7 +1928,7 @@ static function() {
'/test/(?P[\d+])',
array(
'methods' => array( 'POST', 'DELETE' ),
- 'callback' => function ( WP_REST_Request $request ) {
+ 'callback' => static function ( WP_REST_Request $request ) {
return new WP_REST_Response( 'test' );
},
'permission_callback' => '__return_true',
diff --git a/tests/phpunit/tests/rest-api/rest-widget-types-controller.php b/tests/phpunit/tests/rest-api/rest-widget-types-controller.php
index cd84b91c488b..fd0b3007ec3b 100644
--- a/tests/phpunit/tests/rest-api/rest-widget-types-controller.php
+++ b/tests/phpunit/tests/rest-api/rest-widget-types-controller.php
@@ -149,7 +149,7 @@ public function test_get_items_removes_duplicates() {
$data = $response->get_data();
$text_widgets = array_filter(
$data,
- function( $widget ) {
+ static function( $widget ) {
return 'text' === $widget['id'];
}
);
@@ -177,7 +177,7 @@ public function test_get_widget_legacy() {
wp_register_sidebar_widget(
$widget_id,
'WP legacy widget',
- function() {}
+ static function() {}
);
wp_set_current_user( self::$admin_id );
$request = new WP_REST_Request( 'GET', '/wp/v2/widget-types/' . $widget_id );
@@ -208,7 +208,7 @@ public function test_get_widgets_decodes_html_entities() {
wp_register_sidebar_widget(
$widget_id,
'‘Legacy ‑ Archive ‑ Widget’',
- function() {},
+ static function() {},
array(
'description' => '“A great & interesting archive of your site’s posts!”',
)
diff --git a/tests/phpunit/tests/rest-api/rest-widgets-controller.php b/tests/phpunit/tests/rest-api/rest-widgets-controller.php
index 66f14739b92f..a44512cf5ab9 100644
--- a/tests/phpunit/tests/rest-api/rest-widgets-controller.php
+++ b/tests/phpunit/tests/rest-api/rest-widgets-controller.php
@@ -108,7 +108,7 @@ public function set_up() {
wp_register_widget_control(
'testwidget',
'WP test widget',
- function () {
+ static function () {
$settings = get_option( 'widget_testwidget' );
// check if anything's been sent.
@@ -127,7 +127,7 @@ function () {
wp_register_sidebar_widget(
'testwidget',
'WP test widget',
- function () {
+ static function () {
$settings = wp_parse_args(
get_option( 'widget_testwidget' ),
array(
diff --git a/tests/phpunit/tests/robots.php b/tests/phpunit/tests/robots.php
index 9d71480af226..60da725e75e6 100644
--- a/tests/phpunit/tests/robots.php
+++ b/tests/phpunit/tests/robots.php
@@ -43,7 +43,7 @@ public function test_wp_robots_renders_when_relevant() {
public function test_wp_robots_parses_directives_correctly() {
add_filter(
'wp_robots',
- function( array $robots ) {
+ static function( array $robots ) {
// Directives that should have values must use strings.
$robots['directive-with-value'] = 'yes';
$robots['directive-with-numeric-value'] = '1';