General: Use static on closures whenever $this is not used to avoid memory leaks.

Props westonruter, jrf, spacedmonkey.
Fixes #58323.

Built from https://develop.svn.wordpress.org/trunk@55822


git-svn-id: http://core.svn.wordpress.org/trunk@55334 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2023-05-17 22:46:24 +00:00
parent 8db8a24e46
commit 4c2394eed5
8 changed files with 10 additions and 10 deletions

View File

@ -2685,7 +2685,7 @@ function wp_opcache_invalidate_directory( $dir ) {
* with sub-directories represented as nested arrays. * with sub-directories represented as nested arrays.
* @param string $path Absolute path to the directory. * @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 ); $path = trailingslashit( $path );
foreach ( $dirlist as $name => $details ) { foreach ( $dirlist as $name => $details ) {

View File

@ -485,7 +485,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
* *
* @return string Returns the block content. * @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(); ob_start();
require $template_path; require $template_path;
return ob_get_clean(); return ob_get_clean();

View File

@ -4826,7 +4826,7 @@ class WP_Query {
* $value is passed by reference to allow it to be modified. * $value is passed by reference to allow it to be modified.
* array_walk_recursive() does not return an array. * 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 ) ) { if ( is_string( $value ) && str_contains( $value, $placeholder ) ) {
$value = $wpdb->remove_placeholder_escape( $value ); $value = $wpdb->remove_placeholder_escape( $value );
} }

View File

@ -1177,7 +1177,7 @@ function wp_kses_attr( $element, $attr, $allowed_html, $allowed_protocols ) {
// Check if there are attributes that are required. // Check if there are attributes that are required.
$required_attrs = array_filter( $required_attrs = array_filter(
$allowed_html[ $element_low ], $allowed_html[ $element_low ],
function( $required_attr_limits ) { static function( $required_attr_limits ) {
return isset( $required_attr_limits['required'] ) && true === $required_attr_limits['required']; return isset( $required_attr_limits['required'] ) && true === $required_attr_limits['required'];
} }
); );

View File

@ -792,7 +792,7 @@ class WP_REST_Menu_Items_Controller extends WP_REST_Posts_Controller {
), ),
'context' => array( 'view', 'edit', 'embed' ), 'context' => array( 'view', 'edit', 'embed' ),
'arg_options' => array( 'arg_options' => array(
'sanitize_callback' => function ( $value ) { 'sanitize_callback' => static function ( $value ) {
return array_map( 'sanitize_html_class', wp_parse_list( $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' ), 'context' => array( 'view', 'edit', 'embed' ),
'arg_options' => array( 'arg_options' => array(
'sanitize_callback' => function ( $value ) { 'sanitize_callback' => static function ( $value ) {
return array_map( 'sanitize_html_class', wp_parse_list( $value ) ); return array_map( 'sanitize_html_class', wp_parse_list( $value ) );
}, },
), ),

View File

@ -534,7 +534,7 @@ class WP_REST_Menus_Controller extends WP_REST_Terms_Controller {
), ),
'context' => array( 'view', 'edit' ), 'context' => array( 'view', 'edit' ),
'arg_options' => array( 'arg_options' => array(
'validate_callback' => function ( $locations, $request, $param ) { 'validate_callback' => static function ( $locations, $request, $param ) {
$valid = rest_validate_request_arg( $locations, $request, $param ); $valid = rest_validate_request_arg( $locations, $request, $param );
if ( true !== $valid ) { if ( true !== $valid ) {

View File

@ -2405,7 +2405,7 @@ function wp_common_block_scripts_and_styles() {
function wp_filter_out_block_nodes( $nodes ) { function wp_filter_out_block_nodes( $nodes ) {
return array_filter( return array_filter(
$nodes, $nodes,
function( $node ) { static function( $node ) {
return ! in_array( 'blocks', $node['path'], true ); return ! in_array( 'blocks', $node['path'], true );
}, },
ARRAY_FILTER_USE_BOTH ARRAY_FILTER_USE_BOTH
@ -2635,7 +2635,7 @@ function enqueue_block_styles_assets() {
if ( wp_should_load_separate_core_block_assets() ) { if ( wp_should_load_separate_core_block_assets() ) {
add_filter( add_filter(
'render_block', 'render_block',
function( $html, $block ) use ( $block_name, $style_properties ) { static function( $html, $block ) use ( $block_name, $style_properties ) {
if ( $block['blockName'] === $block_name ) { if ( $block['blockName'] === $block_name ) {
wp_enqueue_style( $style_properties['style_handle'] ); wp_enqueue_style( $style_properties['style_handle'] );
} }

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.3-alpha-55821'; $wp_version = '6.3-alpha-55822';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.