From c7d3e267b8a7aebc28b23efa74b2971602852315 Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Thu, 26 Aug 2021 12:59:02 +0000 Subject: [PATCH] Coding Standards: Use static closures when not using `$this`. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a closure does not use `$this`, it can be made `static` for improved performance. Static closures are supported in PHP since PHP 5.4. ​ Props jrf, hellofromTonya, swissspidy, SergeyBiryukov. See #53359. Built from https://develop.svn.wordpress.org/trunk@51657 git-svn-id: http://core.svn.wordpress.org/trunk@51263 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit-form-blocks.php | 2 +- wp-admin/includes/class-wp-community-events.php | 2 +- wp-admin/includes/class-wp-site-health-auto-updates.php | 2 +- wp-admin/includes/update-core.php | 2 +- wp-admin/options-privacy.php | 2 +- wp-admin/privacy-policy-guide.php | 2 +- .../twentytwenty/classes/class-twentytwenty-customize.php | 2 +- .../classes/class-twenty-twenty-one-customize.php | 2 +- .../classes/class-twenty-twenty-one-dark-mode.php | 6 +++--- wp-includes/block-supports/duotone.php | 2 +- wp-includes/block-supports/layout.php | 2 +- wp-includes/block-template.php | 2 +- wp-includes/class-wp-theme-json.php | 2 +- wp-includes/formatting.php | 4 ++-- wp-includes/rest-api.php | 2 +- wp-includes/rest-api/endpoints/class-wp-rest-controller.php | 2 +- .../rest-api/endpoints/class-wp-rest-plugins-controller.php | 4 ++-- .../endpoints/class-wp-rest-widget-types-controller.php | 2 +- .../rest-api/endpoints/class-wp-rest-widgets-controller.php | 2 +- wp-includes/script-loader.php | 2 +- wp-includes/update.php | 2 +- wp-includes/user.php | 2 +- wp-includes/version.php | 2 +- 23 files changed, 27 insertions(+), 27 deletions(-) diff --git a/wp-admin/edit-form-blocks.php b/wp-admin/edit-form-blocks.php index fa4b8a9dd1..7e335fa49b 100644 --- a/wp-admin/edit-form-blocks.php +++ b/wp-admin/edit-form-blocks.php @@ -31,7 +31,7 @@ $current_screen->is_block_editor( true ); // 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/wp-admin/includes/class-wp-community-events.php b/wp-admin/includes/class-wp-community-events.php index 8ccf490e29..cf995eeac8 100644 --- a/wp-admin/includes/class-wp-community-events.php +++ b/wp-admin/includes/class-wp-community-events.php @@ -474,7 +474,7 @@ class WP_Community_Events { $future_wordcamps = array_filter( $future_events, - function( $wordcamp ) { + static function( $wordcamp ) { return 'wordcamp' === $wordcamp['type']; } ); diff --git a/wp-admin/includes/class-wp-site-health-auto-updates.php b/wp-admin/includes/class-wp-site-health-auto-updates.php index d1c133524d..4afaeac1c4 100644 --- a/wp-admin/includes/class-wp-site-health-auto-updates.php +++ b/wp-admin/includes/class-wp-site-health-auto-updates.php @@ -41,7 +41,7 @@ class WP_Site_Health_Auto_Updates { $tests = array_filter( $tests ); $tests = array_map( - function( $test ) { + static function( $test ) { $test = (object) $test; if ( empty( $test->severity ) ) { diff --git a/wp-admin/includes/update-core.php b/wp-admin/includes/update-core.php index 77ede74c77..32664bf6ff 100644 --- a/wp-admin/includes/update-core.php +++ b/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/wp-admin/options-privacy.php b/wp-admin/options-privacy.php index 3e4902daf4..0b0ca77ee9 100644 --- a/wp-admin/options-privacy.php +++ b/wp-admin/options-privacy.php @@ -20,7 +20,7 @@ if ( isset( $_GET['tab'] ) && 'policyguide' === $_GET['tab'] ) { add_filter( 'admin_body_class', - function( $body_class ) { + static function( $body_class ) { $body_class .= ' privacy-settings '; return $body_class; diff --git a/wp-admin/privacy-policy-guide.php b/wp-admin/privacy-policy-guide.php index e5d558e639..6581bb412a 100644 --- a/wp-admin/privacy-policy-guide.php +++ b/wp-admin/privacy-policy-guide.php @@ -19,7 +19,7 @@ if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) { add_filter( 'admin_body_class', - function( $body_class ) { + static function( $body_class ) { $body_class .= ' privacy-settings '; return $body_class; diff --git a/wp-content/themes/twentytwenty/classes/class-twentytwenty-customize.php b/wp-content/themes/twentytwenty/classes/class-twentytwenty-customize.php index d41b494584..ca666df11d 100644 --- a/wp-content/themes/twentytwenty/classes/class-twentytwenty-customize.php +++ b/wp-content/themes/twentytwenty/classes/class-twentytwenty-customize.php @@ -186,7 +186,7 @@ if ( ! class_exists( 'TwentyTwenty_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/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-customize.php b/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-customize.php index b880a03afb..4a0fe6f7af 100644 --- a/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-customize.php +++ b/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-customize.php @@ -92,7 +92,7 @@ if ( ! class_exists( 'Twenty_Twenty_One_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/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-dark-mode.php b/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-dark-mode.php index 4034eaae25..4de201c1b9 100644 --- a/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-dark-mode.php +++ b/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-dark-mode.php @@ -153,7 +153,7 @@ class Twenty_Twenty_One_Dark_Mode { 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 @@ class Twenty_Twenty_One_Dark_Mode { array( 'capability' => 'edit_theme_options', 'default' => false, - 'sanitize_callback' => function( $value ) { + 'sanitize_callback' => static function( $value ) { return (bool) $value; }, ) @@ -188,7 +188,7 @@ class Twenty_Twenty_One_Dark_Mode { '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/wp-includes/block-supports/duotone.php b/wp-includes/block-supports/duotone.php index 3e81c33e07..04aac0ef1e 100644 --- a/wp-includes/block-supports/duotone.php +++ b/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/wp-includes/block-supports/layout.php b/wp-includes/block-supports/layout.php index 16e070a7d3..be1da09899 100644 --- a/wp-includes/block-supports/layout.php +++ b/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/wp-includes/block-template.php b/wp-includes/block-template.php index d745c0536a..945b96b027 100644 --- a/wp-includes/block-template.php +++ b/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/wp-includes/class-wp-theme-json.php b/wp-includes/class-wp-theme-json.php index a35ee1b795..d394bd3301 100644 --- a/wp-includes/class-wp-theme-json.php +++ b/wp-includes/class-wp-theme-json.php @@ -636,7 +636,7 @@ class WP_Theme_JSON { $declaration_block = array_reduce( $declarations, - function ( $carry, $element ) { + static function ( $carry, $element ) { return $carry .= $element['name'] . ': ' . $element['value'] . ';'; }, '' ); diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 966e042ddb..df02acb7d6 100644 --- a/wp-includes/formatting.php +++ b/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/wp-includes/rest-api.php b/wp-includes/rest-api.php index 675c545ce1..fb83e38f4c 100644 --- a/wp-includes/rest-api.php +++ b/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/wp-includes/rest-api/endpoints/class-wp-rest-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-controller.php index b1cb4be457..b3f41c6a6a 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-controller.php @@ -597,7 +597,7 @@ abstract class WP_REST_Controller { // 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/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php index 3a7bf0ff95..4da8e7aa18 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php @@ -381,7 +381,7 @@ class WP_REST_Plugins_Controller extends WP_REST_Controller { $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 @@ class WP_REST_Plugins_Controller extends WP_REST_Controller { $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/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php index db88950faa..c137302f31 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php @@ -85,7 +85,7 @@ class WP_REST_Widget_Types_Controller extends WP_REST_Controller { '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/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php index 3b425a6b8b..4c54620f50 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php @@ -792,7 +792,7 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller { '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/wp-includes/script-loader.php b/wp-includes/script-loader.php index 1e2f1d5fae..608e7936e3 100644 --- a/wp-includes/script-loader.php +++ b/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/wp-includes/update.php b/wp-includes/update.php index 79e3b3ea33..85d0d4c9a8 100644 --- a/wp-includes/update.php +++ b/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/wp-includes/user.php b/wp-includes/user.php index 7c1c2c1f55..94598e8493 100644 --- a/wp-includes/user.php +++ b/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/wp-includes/version.php b/wp-includes/version.php index 453ea6d939..2c617aa00f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-51655'; +$wp_version = '5.9-alpha-51657'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.