mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
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
This commit is contained in:
@@ -421,7 +421,7 @@ class Tests_Admin_wpSiteHealth extends WP_UnitTestCase {
|
||||
// Set thresholds so high they should never be exceeded.
|
||||
add_filter(
|
||||
'site_status_persistent_object_cache_thresholds',
|
||||
function() {
|
||||
static function() {
|
||||
return array(
|
||||
'alloptions_count' => PHP_INT_MAX,
|
||||
'alloptions_bytes' => PHP_INT_MAX,
|
||||
@@ -472,7 +472,7 @@ class Tests_Admin_wpSiteHealth extends WP_UnitTestCase {
|
||||
public function test_object_cache_thresholds( $threshold, $count ) {
|
||||
add_filter(
|
||||
'site_status_persistent_object_cache_thresholds',
|
||||
function ( $thresholds ) use ( $threshold, $count ) {
|
||||
static function ( $thresholds ) use ( $threshold, $count ) {
|
||||
return array_merge( $thresholds, array( $threshold => $count ) );
|
||||
}
|
||||
);
|
||||
|
||||
@@ -302,7 +302,7 @@ class Tests_Blocks_Editor extends WP_UnitTestCase {
|
||||
// Force the return value of wp_max_upload_size() to be 500.
|
||||
add_filter(
|
||||
'upload_size_limit',
|
||||
function() {
|
||||
static function() {
|
||||
return 500;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -436,7 +436,7 @@ END
|
||||
)
|
||||
);
|
||||
|
||||
$commenter_filter = function () {
|
||||
$commenter_filter = static function () {
|
||||
return array(
|
||||
'comment_author_email' => 'unapproved@example.org',
|
||||
);
|
||||
|
||||
@@ -693,7 +693,7 @@ class Tests_Blocks_wpBlock extends WP_UnitTestCase {
|
||||
$this->registry->register(
|
||||
'core/outer',
|
||||
array(
|
||||
'render_callback' => function( $block_attributes, $content ) {
|
||||
'render_callback' => static function( $block_attributes, $content ) {
|
||||
return $content;
|
||||
},
|
||||
)
|
||||
@@ -702,7 +702,7 @@ class Tests_Blocks_wpBlock extends WP_UnitTestCase {
|
||||
$this->registry->register(
|
||||
'core/inner',
|
||||
array(
|
||||
'render_callback' => function() {
|
||||
'render_callback' => static function() {
|
||||
return 'b';
|
||||
},
|
||||
)
|
||||
|
||||
@@ -1473,7 +1473,7 @@ JS;
|
||||
wp_set_script_translations( 'common' );
|
||||
|
||||
$print_scripts = get_echo(
|
||||
function() {
|
||||
static function() {
|
||||
wp_print_scripts();
|
||||
_print_scripts();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class Tests_General_wpPreloadResources extends WP_UnitTestCase {
|
||||
* @ticket 42438
|
||||
*/
|
||||
public function test_preload_resources( $expected, $preload_resources ) {
|
||||
$callback = function () use ( $preload_resources ) {
|
||||
$callback = static function () use ( $preload_resources ) {
|
||||
return $preload_resources;
|
||||
};
|
||||
|
||||
|
||||
@@ -1923,7 +1923,7 @@ HTML;
|
||||
);
|
||||
|
||||
return array_map(
|
||||
function ( $datum ) {
|
||||
static function ( $datum ) {
|
||||
$datum[] = array(
|
||||
'p' => array(
|
||||
'dir' => array(
|
||||
|
||||
@@ -2348,7 +2348,7 @@ EOF;
|
||||
|
||||
add_filter(
|
||||
'wp_content_img_tag',
|
||||
function( $filtered_image ) {
|
||||
static function( $filtered_image ) {
|
||||
return "<span>$filtered_image</span>";
|
||||
}
|
||||
);
|
||||
@@ -2372,7 +2372,7 @@ EOF;
|
||||
|
||||
add_filter(
|
||||
'wp_content_img_tag',
|
||||
function( $filtered_image ) {
|
||||
static function( $filtered_image ) {
|
||||
return "<span>$filtered_image</span>";
|
||||
}
|
||||
);
|
||||
@@ -3761,7 +3761,7 @@ EOF;
|
||||
add_filter( 'wp_img_tag_add_decoding_attr', '__return_false' );
|
||||
add_filter(
|
||||
'wp_get_attachment_image_attributes',
|
||||
function( $attr ) {
|
||||
static function( $attr ) {
|
||||
unset( $attr['srcset'], $attr['sizes'], $attr['decoding'] );
|
||||
return $attr;
|
||||
}
|
||||
|
||||
@@ -538,7 +538,7 @@ class Tests_Pluggable_wpMail extends WP_UnitTestCase {
|
||||
* Tests that AltBody is reset between each wp_mail call.
|
||||
*/
|
||||
public function test_wp_mail_resets_properties() {
|
||||
$wp_mail_set_text_message = function ( $phpmailer ) {
|
||||
$wp_mail_set_text_message = static function ( $phpmailer ) {
|
||||
$phpmailer->AltBody = 'user1';
|
||||
};
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ class Tests_Query_Stickies extends WP_UnitTestCase {
|
||||
$post_ids = self::factory()->post->create_many( $sticky_count, array( 'post_date' => $post_date ) );
|
||||
add_filter(
|
||||
'pre_option_sticky_posts',
|
||||
function () use ( $post_ids ) {
|
||||
static function () use ( $post_ids ) {
|
||||
return $post_ids;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -937,7 +937,7 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
|
||||
* @ticket 56566
|
||||
*/
|
||||
public function test_link_embedding_returning_wp_error() {
|
||||
$return_wp_error = function() {
|
||||
$return_wp_error = static function() {
|
||||
return new WP_Error( 'some-error', 'This is not valid!' );
|
||||
};
|
||||
add_filter( 'rest_pre_dispatch', $return_wp_error );
|
||||
@@ -2188,7 +2188,7 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
|
||||
array(
|
||||
array(
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => function() {
|
||||
'callback' => static function() {
|
||||
return new \WP_REST_Response( INF );
|
||||
},
|
||||
'permission_callback' => '__return_true',
|
||||
|
||||
@@ -1384,7 +1384,7 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
'wp/v2',
|
||||
sprintf( '/themes/(?P<stylesheet>%s)//test', WP_REST_Themes_Controller::PATTERN ),
|
||||
array(
|
||||
'callback' => function ( WP_REST_Request $request ) {
|
||||
'callback' => static function ( WP_REST_Request $request ) {
|
||||
return $request['stylesheet'];
|
||||
},
|
||||
'permission_callback' => '__return_true',
|
||||
|
||||
@@ -600,7 +600,7 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase {
|
||||
$global_styles_query_count = 0;
|
||||
add_filter(
|
||||
'query',
|
||||
function( $query ) use ( &$global_styles_query_count ) {
|
||||
static function( $query ) use ( &$global_styles_query_count ) {
|
||||
if ( preg_match( '#post_type = \'wp_global_styles\'#', $query ) ) {
|
||||
$global_styles_query_count++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user