Make WordPress Core

Changeset 55822


Ignore:
Timestamp:
05/17/2023 10:44:21 PM (11 months ago)
Author:
westonruter
Message:

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

Props westonruter, jrf, spacedmonkey.
Fixes #58323.

Location:
trunk
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/file.php

    r55750 r55822  
    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
  • trunk/src/wp-includes/blocks.php

    r55762 r55822  
    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;
  • trunk/src/wp-includes/class-wp-query.php

    r55749 r55822  
    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 );
  • trunk/src/wp-includes/kses.php

    r55703 r55822  
    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        }
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php

    r53760 r55822  
    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                },
     
    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                },
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php

    r53760 r55822  
    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
  • trunk/src/wp-includes/script-loader.php

    r55820 r55822  
    24062406    return array_filter(
    24072407        $nodes,
    2408         function( $node ) {
     2408        static function( $node ) {
    24092409            return ! in_array( 'blocks', $node['path'], true );
    24102410        },
     
    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'] );
  • trunk/tests/performance/wp-content/mu-plugins/server-timing.php

    r55459 r55822  
    33add_action(
    44    'template_redirect',
    5     function() {
     5    static function() {
    66
    77        global $timestart;
     
    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;
  • trunk/tests/phpunit/tests/admin/wpSiteHealth.php

    r55029 r55822  
    422422        add_filter(
    423423            'site_status_persistent_object_cache_thresholds',
    424             function() {
     424            static function() {
    425425                return array(
    426426                    'alloptions_count' => PHP_INT_MAX,
     
    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            }
  • trunk/tests/phpunit/tests/blocks/editor.php

    r55457 r55822  
    303303        add_filter(
    304304            'upload_size_limit',
    305             function() {
     305            static function() {
    306306                return 500;
    307307            }
  • trunk/tests/phpunit/tests/blocks/renderCommentTemplate.php

    r55457 r55822  
    437437        );
    438438
    439         $commenter_filter = function () {
     439        $commenter_filter = static function () {
    440440            return array(
    441441                'comment_author_email' => 'unapproved@example.org',
  • trunk/tests/phpunit/tests/blocks/wpBlock.php

    r55457 r55822  
    694694            'core/outer',
    695695            array(
    696                 'render_callback' => function( $block_attributes, $content ) {
     696                'render_callback' => static function( $block_attributes, $content ) {
    697697                    return $content;
    698698                },
     
    703703            'core/inner',
    704704            array(
    705                 'render_callback' => function() {
     705                'render_callback' => static function() {
    706706                    return 'b';
    707707                },
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r55084 r55822  
    14741474
    14751475        $print_scripts = get_echo(
    1476             function() {
     1476            static function() {
    14771477                wp_print_scripts();
    14781478                _print_scripts();
  • trunk/tests/phpunit/tests/general/wpPreloadResources.php

    r53849 r55822  
    1515     */
    1616    public function test_preload_resources( $expected, $preload_resources ) {
    17         $callback = function () use ( $preload_resources ) {
     17        $callback = static function () use ( $preload_resources ) {
    1818            return $preload_resources;
    1919        };
  • trunk/tests/phpunit/tests/kses.php

    r55564 r55822  
    19241924
    19251925        return array_map(
    1926             function ( $datum ) {
     1926            static function ( $datum ) {
    19271927                $datum[] = array(
    19281928                    'p' => array(
  • trunk/tests/phpunit/tests/media.php

    r55821 r55822  
    23492349        add_filter(
    23502350            'wp_content_img_tag',
    2351             function( $filtered_image ) {
     2351            static function( $filtered_image ) {
    23522352                return "<span>$filtered_image</span>";
    23532353            }
     
    23732373        add_filter(
    23742374            'wp_content_img_tag',
    2375             function( $filtered_image ) {
     2375            static function( $filtered_image ) {
    23762376                return "<span>$filtered_image</span>";
    23772377            }
     
    37623762        add_filter(
    37633763            'wp_get_attachment_image_attributes',
    3764             function( $attr ) {
     3764            static function( $attr ) {
    37653765                unset( $attr['srcset'], $attr['sizes'], $attr['decoding'] );
    37663766                return $attr;
  • trunk/tests/phpunit/tests/pluggable/wpMail.php

    r55087 r55822  
    539539     */
    540540    public function test_wp_mail_resets_properties() {
    541         $wp_mail_set_text_message = function ( $phpmailer ) {
     541        $wp_mail_set_text_message = static function ( $phpmailer ) {
    542542            $phpmailer->AltBody = 'user1';
    543543        };
  • trunk/tests/phpunit/tests/query/stickies.php

    r52990 r55822  
    137137        add_filter(
    138138            'pre_option_sticky_posts',
    139             function () use ( $post_ids ) {
     139            static function () use ( $post_ids ) {
    140140                return $post_ids;
    141141            }
  • trunk/tests/phpunit/tests/rest-api/rest-server.php

    r55562 r55822  
    938938     */
    939939    public function test_link_embedding_returning_wp_error() {
    940         $return_wp_error = function() {
     940        $return_wp_error = static function() {
    941941            return new WP_Error( 'some-error', 'This is not valid!' );
    942942        };
     
    21892189                array(
    21902190                    'methods'             => \WP_REST_Server::READABLE,
    2191                     'callback'            => function() {
     2191                    'callback'            => static function() {
    21922192                        return new \WP_REST_Response( INF );
    21932193                    },
  • trunk/tests/phpunit/tests/rest-api/rest-themes-controller.php

    r55457 r55822  
    13851385            sprintf( '/themes/(?P<stylesheet>%s)//test', WP_REST_Themes_Controller::PATTERN ),
    13861386            array(
    1387                 'callback'            => function ( WP_REST_Request $request ) {
     1387                'callback'            => static function ( WP_REST_Request $request ) {
    13881388                    return $request['stylesheet'];
    13891389                },
  • trunk/tests/phpunit/tests/theme/wpThemeJsonResolver.php

    r55753 r55822  
    601601        add_filter(
    602602            'query',
    603             function( $query ) use ( &$global_styles_query_count ) {
     603            static function( $query ) use ( &$global_styles_query_count ) {
    604604                if ( preg_match( '#post_type = \'wp_global_styles\'#', $query ) ) {
    605605                    $global_styles_query_count++;
Note: See TracChangeset for help on using the changeset viewer.