Skip to content

Commit

Permalink
Use static closures when not using $this (#50723)
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter authored May 31, 2023
1 parent 172366a commit d665608
Show file tree
Hide file tree
Showing 26 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ function gutenberg_restore_group_inner_container( $block_content, $block ) {
);
$updated_content = preg_replace_callback(
$replace_regex,
function( $matches ) {
static function( $matches ) {
return $matches[1] . '<div class="wp-block-group__inner-container">' . $matches[2] . '</div>' . $matches[3];
},
$block_content
Expand Down
2 changes: 1 addition & 1 deletion lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function gutenberg_register_core_block_assets( $block_name ) {
if ( ! $stylesheet_removed ) {
add_action(
'wp_enqueue_scripts',
function() {
static function() {
wp_dequeue_style( 'wp-block-library-theme' );
}
);
Expand Down
2 changes: 1 addition & 1 deletion lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -2365,7 +2365,7 @@ static function( $split_selector ) use ( $clean_style_variation_selector ) {
$pseudo_matches = array_values(
array_filter(
$element_pseudo_allowed,
function( $pseudo_selector ) use ( $selector ) {
static function( $pseudo_selector ) use ( $selector ) {
return str_contains( $selector, $pseudo_selector );
}
)
Expand Down
2 changes: 1 addition & 1 deletion lib/compat/wordpress-6.2/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static function () use ( $style ) {

add_filter(
'block_editor_settings_all',
function( $settings ) {
static function( $settings ) {
// We must override what core is passing now.
$settings['__unstableIsBlockBasedTheme'] = wp_is_block_theme();
return $settings;
Expand Down
2 changes: 1 addition & 1 deletion lib/compat/wordpress-6.3/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function _gutenberg_get_iframed_editor_assets() {

add_filter(
'block_editor_settings_all',
function( $settings ) {
static function( $settings ) {
// We must override what core is passing now.
$settings['__unstableResolvedAssets'] = _gutenberg_get_iframed_editor_assets();
return $settings;
Expand Down
2 changes: 1 addition & 1 deletion lib/experimental/fonts-api/fonts-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function wp_print_fonts( $handles = false ) {
*/
add_filter(
'mime_types',
function( $mime_types ) {
static function( $mime_types ) {
// Webfonts formats.
$mime_types['woff2'] = 'font/woff2';
$mime_types['woff'] = 'font/woff';
Expand Down
2 changes: 1 addition & 1 deletion lib/experimental/navigation-theme-opt-in.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function gutenberg_remove_block_nav_menu_items( $menu_items ) {

return array_filter(
$menu_items,
function( $menu_item ) {
static function( $menu_item ) {
return 'block' !== $menu_item->type;
}
);
Expand Down
2 changes: 1 addition & 1 deletion lib/global-styles-and-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function gutenberg_add_global_styles_for_blocks() {
$result = array_values(
array_filter(
$metadata['path'],
function ( $item ) {
static function ( $item ) {
if ( strpos( $item, 'core/' ) !== false ) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function render_block_core_comments_pagination_next( $attributes, $content, $blo
$label = isset( $attributes['label'] ) && ! empty( $attributes['label'] ) ? $attributes['label'] : $default_label;
$pagination_arrow = get_comments_pagination_arrow( $block, 'next' );

$filter_link_attributes = function() {
$filter_link_attributes = static function() {
return get_block_wrapper_attributes();
};
add_filter( 'next_comments_link_attributes', $filter_link_attributes );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function render_block_core_comments_pagination_previous( $attributes, $content,
$label = $pagination_arrow . $label;
}

$filter_link_attributes = function() {
$filter_link_attributes = static function() {
return get_block_wrapper_attributes();
};
add_filter( 'previous_comments_link_attributes', $filter_link_attributes );
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/file/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function render_block_core_file( $attributes, $content ) {
$pattern = '@<object.+(?<attribute>aria-label="(?<filename>[^"]+)?")@i';
$content = preg_replace_callback(
$pattern,
function ( $matches ) {
static function ( $matches ) {
$filename = ! empty( $matches['filename'] ) ? $matches['filename'] : '';
$has_filename = ! empty( $filename ) && 'PDF embed' !== $filename;
$label = $has_filename ?
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function block_core_navigation_render_submenu_icon() {
function block_core_navigation_filter_out_empty_blocks( $parsed_blocks ) {
$filtered = array_filter(
$parsed_blocks,
function( $block ) {
static function( $block ) {
return isset( $block['blockName'] );
}
);
Expand Down Expand Up @@ -783,7 +783,7 @@ function block_core_navigation_get_classic_menu_fallback() {
// Otherwise return the most recently created classic menu.
usort(
$classic_nav_menus,
function( $a, $b ) {
static function( $a, $b ) {
return $b->term_id - $a->term_id;
}
);
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/post-excerpt/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function render_block_core_post_excerpt( $attributes, $content, $block ) {
}

$more_text = ! empty( $attributes['moreText'] ) ? '<a class="wp-block-post-excerpt__more-link" href="' . esc_url( get_the_permalink( $block->context['postId'] ) ) . '">' . wp_kses_post( $attributes['moreText'] ) . '</a>' : '';
$filter_excerpt_more = function( $more ) use ( $more_text ) {
$filter_excerpt_more = static function( $more ) use ( $more_text ) {
return empty( $more_text ) ? $more : '';
};
/**
Expand Down Expand Up @@ -87,7 +87,7 @@ function register_block_core_post_excerpt() {
defined( 'REST_REQUEST' ) && REST_REQUEST ) {
add_filter(
'excerpt_length',
function() {
static function() {
return 100;
},
PHP_INT_MAX
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/query-pagination-next/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function render_block_core_query_pagination_next( $attributes, $content, $block

// Check if the pagination is for Query that inherits the global context.
if ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] ) {
$filter_link_attributes = function() use ( $wrapper_attributes ) {
$filter_link_attributes = static function() use ( $wrapper_attributes ) {
return $wrapper_attributes;
};
add_filter( 'next_posts_link_attributes', $filter_link_attributes );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function render_block_core_query_pagination_previous( $attributes, $content, $bl
// Check if the pagination is for Query that inherits the global context
// and handle appropriately.
if ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] ) {
$filter_link_attributes = function() use ( $wrapper_attributes ) {
$filter_link_attributes = static function() use ( $wrapper_attributes ) {
return $wrapper_attributes;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/site-logo/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @return string The render.
*/
function render_block_core_site_logo( $attributes ) {
$adjust_width_height_filter = function ( $image ) use ( $attributes ) {
$adjust_width_height_filter = static function ( $image ) use ( $attributes ) {
if ( empty( $attributes['width'] ) || empty( $image ) || ! $image[1] || ! $image[2] ) {
return $image;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/plugins/block-context.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function gutenberg_test_register_context_blocks() {
'postId',
'postType',
),
'render_callback' => function( $attributes, $content, $block ) {
'render_callback' => static function( $attributes, $content, $block ) {
$ordered_context = array(
$block->context['gutenberg/recordId'],
$block->context['postId'],
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-tests/plugins/iframed-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

add_action(
'setup_theme',
function() {
static function() {
add_theme_support( 'block-templates' );
}
);

add_action(
'init',
function() {
static function() {
wp_register_script(
'iframed-block-jquery-test',
plugin_dir_url( __FILE__ ) . 'iframed-block/jquery.test.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

add_action(
'enqueue_block_assets',
function() {
static function() {
wp_enqueue_style(
'iframed-enqueue-block-assets',
plugin_dir_url( __FILE__ ) . 'iframed-enqueue-block-assets/style.css',
Expand Down
6 changes: 3 additions & 3 deletions packages/e2e-tests/plugins/iframed-inline-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

add_action(
'setup_theme',
function() {
static function() {
add_theme_support( 'block-templates' );
}
);

add_action(
'init',
function() {
static function() {
wp_register_script(
'iframed-inline-styles-editor-script',
plugin_dir_url( __FILE__ ) . 'iframed-inline-styles/editor.js',
Expand All @@ -40,7 +40,7 @@ function() {

add_action(
'enqueue_block_editor_assets',
function() {
static function() {
wp_enqueue_style(
'iframed-inline-styles-compat-style',
plugin_dir_url( __FILE__ ) . 'iframed-inline-styles/compat-style.css',
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-tests/plugins/iframed-masonry-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

add_action(
'setup_theme',
function() {
static function() {
add_theme_support( 'block-templates' );
}
);

add_action(
'init',
function() {
static function() {
wp_register_script(
'iframed-masonry-block-editor',
plugin_dir_url( __FILE__ ) . 'iframed-masonry-block/editor.js',
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-tests/plugins/iframed-multiple-stylesheets.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

add_action(
'setup_theme',
function() {
static function() {
add_theme_support( 'block-templates' );
}
);

add_action(
'init',
function() {
static function() {
wp_register_script(
'iframed-multiple-stylesheets-editor-script',
plugin_dir_url( __FILE__ ) . 'iframed-multiple-stylesheets/editor.js',
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-tests/plugins/marquee-function-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function marquee_greeting_init() {
wp_register_sidebar_widget(
'marquee_greeting',
'Marquee Greeting',
function() {
static function() {
$greeting = get_option( 'marquee_greeting', 'Hello!' );
printf( '<marquee>%s</marquee>', esc_html( $greeting ) );
}
Expand All @@ -23,7 +23,7 @@ function() {
wp_register_widget_control(
'marquee_greeting',
'Marquee Greeting',
function() {
static function() {
if ( isset( $_POST['marquee-greeting'] ) ) {
update_option(
'marquee_greeting',
Expand Down
8 changes: 4 additions & 4 deletions phpunit/class-block-context-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function test_provides_block_context() {
'gutenberg/contextWithAssigned',
'gutenberg/contextWithoutDefault',
),
'render_callback' => function( $attributes, $content, $block ) use ( &$provided_context ) {
'render_callback' => static function( $attributes, $content, $block ) use ( &$provided_context ) {
$provided_context[] = $block->context;

return '';
Expand Down Expand Up @@ -142,7 +142,7 @@ public function test_provides_default_context() {
'gutenberg/test-context-consumer',
array(
'uses_context' => array( 'postId', 'postType' ),
'render_callback' => function( $attributes, $content, $block ) use ( &$provided_context ) {
'render_callback' => static function( $attributes, $content, $block ) use ( &$provided_context ) {
$provided_context[] = $block->context;

return '';
Expand Down Expand Up @@ -173,15 +173,15 @@ public function test_default_context_is_filterable() {
'gutenberg/test-context-consumer',
array(
'uses_context' => array( 'example' ),
'render_callback' => function( $attributes, $content, $block ) use ( &$provided_context ) {
'render_callback' => static function( $attributes, $content, $block ) use ( &$provided_context ) {
$provided_context[] = $block->context;

return '';
},
)
);

$filter_block_context = function( $context ) {
$filter_block_context = static function( $context ) {
$context['example'] = 'ok';
return $context;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function data_get_items_query_args() {
private static function capture_http_urls() {
add_filter(
'pre_http_request',
function ( $preempt, $args, $url ) {
static function ( $preempt, $args, $url ) {
if ( 'api.wordpress.org' !== wp_parse_url( $url, PHP_URL_HOST ) ) {
return $preempt;
}
Expand Down
2 changes: 1 addition & 1 deletion phpunit/fonts-api/wp-fonts-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ protected function get_reflection_method( $method_name ) {
protected function setup_registration_mocks( array $inputs, WP_Fonts $wp_fonts ) {
$mocks = array();

$build_mock = function ( $font_family, $is_font_family = false ) use ( &$mocks, $wp_fonts ) {
$build_mock = static function ( $font_family, $is_font_family = false ) use ( &$mocks, $wp_fonts ) {
$mock = new stdClass();
$mock->deps = array();
$mock->extra = array( 'is_font_family' => $is_font_family );
Expand Down

0 comments on commit d665608

Please sign in to comment.