Coding Standards: Use static closures when not using $this.

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.

git-svn-id: https://develop.svn.wordpress.org/trunk@51657 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Tonya Mork
2021-08-26 12:57:08 +00:00
parent d87fa561ab
commit e83a341cc0
54 changed files with 95 additions and 95 deletions
+1 -1
View File
@@ -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";
}
);
@@ -474,7 +474,7 @@ class WP_Community_Events {
$future_wordcamps = array_filter(
$future_events,
function( $wordcamp ) {
static function( $wordcamp ) {
return 'wordcamp' === $wordcamp['type'];
}
);
@@ -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 ) ) {
+1 -1
View File
@@ -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' );
}
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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;