Skip to content

Commit d5792c7

Browse files
committed
General: Use static on closures whenever $this is not used to avoid memory leaks.
Props westonruter, jrf, spacedmonkey. Fixes #58323. git-svn-id: https://develop.svn.wordpress.org/trunk@55822 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 5db3125 commit d5792c7

File tree

21 files changed

+29
-29
lines changed

21 files changed

+29
-29
lines changed

‎src/wp-admin/includes/file.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2685,7 +2685,7 @@ function wp_opcache_invalidate_directory( $dir ) {
26852685
* with sub-directories represented as nested arrays.
26862686
* @param string $path Absolute path to the directory.
26872687
*/
2688-
$invalidate_directory = function( $dirlist, $path ) use ( &$invalidate_directory ) {
2688+
$invalidate_directory = static function( $dirlist, $path ) use ( &$invalidate_directory ) {
26892689
$path = trailingslashit( $path );
26902690

26912691
foreach ( $dirlist as $name => $details ) {

‎src/wp-includes/blocks.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
485485
*
486486
* @return string Returns the block content.
487487
*/
488-
$settings['render_callback'] = function( $attributes, $content, $block ) use ( $template_path ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
488+
$settings['render_callback'] = static function( $attributes, $content, $block ) use ( $template_path ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
489489
ob_start();
490490
require $template_path;
491491
return ob_get_clean();

‎src/wp-includes/class-wp-query.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4826,7 +4826,7 @@ protected function generate_cache_key( array $args, $sql ) {
48264826
* $value is passed by reference to allow it to be modified.
48274827
* array_walk_recursive() does not return an array.
48284828
*/
4829-
function ( &$value ) use ( $wpdb, $placeholder ) {
4829+
static function ( &$value ) use ( $wpdb, $placeholder ) {
48304830
if ( is_string( $value ) && str_contains( $value, $placeholder ) ) {
48314831
$value = $wpdb->remove_placeholder_escape( $value );
48324832
}

‎src/wp-includes/kses.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ function wp_kses_attr( $element, $attr, $allowed_html, $allowed_protocols ) {
11771177
// Check if there are attributes that are required.
11781178
$required_attrs = array_filter(
11791179
$allowed_html[ $element_low ],
1180-
function( $required_attr_limits ) {
1180+
static function( $required_attr_limits ) {
11811181
return isset( $required_attr_limits['required'] ) && true === $required_attr_limits['required'];
11821182
}
11831183
);

‎src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ public function get_item_schema() {
792792
),
793793
'context' => array( 'view', 'edit', 'embed' ),
794794
'arg_options' => array(
795-
'sanitize_callback' => function ( $value ) {
795+
'sanitize_callback' => static function ( $value ) {
796796
return array_map( 'sanitize_html_class', wp_parse_list( $value ) );
797797
},
798798
),
@@ -873,7 +873,7 @@ public function get_item_schema() {
873873
),
874874
'context' => array( 'view', 'edit', 'embed' ),
875875
'arg_options' => array(
876-
'sanitize_callback' => function ( $value ) {
876+
'sanitize_callback' => static function ( $value ) {
877877
return array_map( 'sanitize_html_class', wp_parse_list( $value ) );
878878
},
879879
),

‎src/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ public function get_item_schema() {
534534
),
535535
'context' => array( 'view', 'edit' ),
536536
'arg_options' => array(
537-
'validate_callback' => function ( $locations, $request, $param ) {
537+
'validate_callback' => static function ( $locations, $request, $param ) {
538538
$valid = rest_validate_request_arg( $locations, $request, $param );
539539

540540
if ( true !== $valid ) {

‎src/wp-includes/script-loader.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,7 +2405,7 @@ function wp_common_block_scripts_and_styles() {
24052405
function wp_filter_out_block_nodes( $nodes ) {
24062406
return array_filter(
24072407
$nodes,
2408-
function( $node ) {
2408+
static function( $node ) {
24092409
return ! in_array( 'blocks', $node['path'], true );
24102410
},
24112411
ARRAY_FILTER_USE_BOTH
@@ -2635,7 +2635,7 @@ function enqueue_block_styles_assets() {
26352635
if ( wp_should_load_separate_core_block_assets() ) {
26362636
add_filter(
26372637
'render_block',
2638-
function( $html, $block ) use ( $block_name, $style_properties ) {
2638+
static function( $html, $block ) use ( $block_name, $style_properties ) {
26392639
if ( $block['blockName'] === $block_name ) {
26402640
wp_enqueue_style( $style_properties['style_handle'] );
26412641
}

‎tests/performance/wp-content/mu-plugins/server-timing.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
add_action(
44
'template_redirect',
5-
function() {
5+
static function() {
66

77
global $timestart;
88

@@ -15,7 +15,7 @@ function() {
1515

1616
add_action(
1717
'shutdown',
18-
function() use ( $server_timing_values, $template_start ) {
18+
static function() use ( $server_timing_values, $template_start ) {
1919

2020
global $timestart;
2121

‎tests/phpunit/tests/admin/wpSiteHealth.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ public function test_object_cache_default_thresholds_non_multisite() {
421421
// Set thresholds so high they should never be exceeded.
422422
add_filter(
423423
'site_status_persistent_object_cache_thresholds',
424-
function() {
424+
static function() {
425425
return array(
426426
'alloptions_count' => PHP_INT_MAX,
427427
'alloptions_bytes' => PHP_INT_MAX,
@@ -472,7 +472,7 @@ public function test_object_cache_thresholds_check_can_be_bypassed() {
472472
public function test_object_cache_thresholds( $threshold, $count ) {
473473
add_filter(
474474
'site_status_persistent_object_cache_thresholds',
475-
function ( $thresholds ) use ( $threshold, $count ) {
475+
static function ( $thresholds ) use ( $threshold, $count ) {
476476
return array_merge( $thresholds, array( $threshold => $count ) );
477477
}
478478
);

‎tests/phpunit/tests/blocks/editor.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public function test_get_default_block_editor_settings_max_upload_file_size() {
302302
// Force the return value of wp_max_upload_size() to be 500.
303303
add_filter(
304304
'upload_size_limit',
305-
function() {
305+
static function() {
306306
return 500;
307307
}
308308
);

0 commit comments

Comments
 (0)