From 7c254c5510f6e5227e320ea3118f411504f1fe1a Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Mon, 28 Aug 2023 21:51:44 +0000 Subject: [PATCH 001/105] Privacy: Improve docblocks for hooks and functions related to personal data export and erasure. See #58833 git-svn-id: https://develop.svn.wordpress.org/trunk@56482 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/ajax-actions.php | 23 +++++++++++++++-------- src/wp-includes/comment.php | 24 ++++++++++++++++++------ src/wp-includes/media.php | 9 +++++++-- src/wp-includes/user.php | 7 ++++++- 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index 3c5dab31b500b..16b827d7bd5d0 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -4939,8 +4939,8 @@ function wp_ajax_wp_privacy_export_personal_data() { * Array of personal data exporters. * * @type callable $callback Callable exporter function that accepts an - * email address and a page and returns an array - * of name => value pairs of personal data. + * email address and a page number and returns an + * array of name => value pairs of personal data. * @type string $exporter_friendly_name Translated user facing friendly name for the * exporter. * } @@ -5051,10 +5051,10 @@ function wp_ajax_wp_privacy_export_personal_data() { * * @since 4.9.6 * - * @param array $response The personal data for the given exporter and page. + * @param array $response The personal data for the given exporter and page number. * @param int $exporter_index The index of the exporter that provided this data. * @param string $email_address The email address associated with this personal data. - * @param int $page The page for this response. + * @param int $page The page number for this response. * @param int $request_id The privacy request post ID associated with this request. * @param bool $send_as_email Whether the final results of the export should be emailed to the user. * @param string $exporter_key The key (slug) of the exporter that provided this data. @@ -5128,8 +5128,8 @@ function wp_ajax_wp_privacy_erase_personal_data() { * @type array ...$0 { * Array of personal data exporters. * - * @type callable $callback Callable eraser that accepts an email address and - * a page and returns an array with boolean values for + * @type callable $callback Callable eraser that accepts an email address and a page + * number, and returns an array with boolean values for * whether items were removed or retained and any messages * from the eraser, as well as if additional pages are * available. @@ -5281,10 +5281,17 @@ function wp_ajax_wp_privacy_erase_personal_data() { * * @since 4.9.6 * - * @param array $response The personal data for the given exporter and page. + * @param array $response { + * The personal data for the given exporter and page number. + * + * @type bool $items_removed Whether items were actually removed or not. + * @type bool $items_retained Whether items were retained or not. + * @type string[] $messages An array of messages to add to the personal data export file. + * @type bool $done Whether the eraser is finished or not. + * } * @param int $eraser_index The index of the eraser that provided this data. * @param string $email_address The email address associated with this personal data. - * @param int $page The page for this response. + * @param int $page The page number for this response. * @param int $request_id The privacy request post ID associated with this request. * @param string $eraser_key The key (slug) of the eraser that provided this data. */ diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index 604ede7c876a7..b538b2c5c12ef 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -3684,8 +3684,8 @@ function wp_handle_comment_submission( $comment_data ) { * * @since 4.9.6 * - * @param array $exporters An array of personal data exporters. - * @return array An array of personal data exporters. + * @param array[] $exporters An array of personal data exporters. + * @return array[] An array of personal data exporters. */ function wp_register_comment_personal_data_exporter( $exporters ) { $exporters['wordpress-comments'] = array( @@ -3702,8 +3702,13 @@ function wp_register_comment_personal_data_exporter( $exporters ) { * @since 4.9.6 * * @param string $email_address The comment author email address. - * @param int $page Comment page. - * @return array An array of personal data. + * @param int $page Comment page number. + * @return array { + * An array of personal data. + * + * @type array[] $data An array of personal data arrays. + * @type bool $done Whether the exporter is finished. + * } */ function wp_comments_personal_data_exporter( $email_address, $page = 1 ) { // Limit us to 500 comments at a time to avoid timing out. @@ -3814,8 +3819,15 @@ function wp_register_comment_personal_data_eraser( $erasers ) { * @global wpdb $wpdb WordPress database abstraction object. * * @param string $email_address The comment author email address. - * @param int $page Comment page. - * @return array + * @param int $page Comment page number. + * @return array { + * Data removal results. + * + * @type bool $items_removed Whether items were actually removed. + * @type bool $items_retained Whether items were retained. + * @type string[] $messages An array of messages to add to the personal data export file. + * @type bool $done Whether the eraser is finished. + * } */ function wp_comments_personal_data_eraser( $email_address, $page = 1 ) { global $wpdb; diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index aeedcc22a95ba..e037a0608bac8 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -5359,8 +5359,13 @@ function wp_register_media_personal_data_exporter( $exporters ) { * @since 4.9.6 * * @param string $email_address The attachment owner email address. - * @param int $page Attachment page. - * @return array An array of personal data. + * @param int $page Attachment page number. + * @return array { + * An array of personal data. + * + * @type array[] $data An array of personal data arrays. + * @type bool $done Whether the exporter is finished. + * } */ function wp_media_personal_data_exporter( $email_address, $page = 1 ) { // Limit us to 50 attachments at a time to avoid timing out. diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php index 04e6aab999a1b..5f8fe3807154e 100644 --- a/src/wp-includes/user.php +++ b/src/wp-includes/user.php @@ -3807,7 +3807,12 @@ function wp_register_user_personal_data_exporter( $exporters ) { * @since 5.4.0 Added 'Session Tokens' group to the export data. * * @param string $email_address The user's email address. - * @return array An array of personal data. + * @return array { + * An array of personal data. + * + * @type array[] $data An array of personal data arrays. + * @type bool $done Whether the exporter is finished. + * } */ function wp_user_personal_data_exporter( $email_address ) { $email_address = trim( $email_address ); From 61cd1a5210f907926c769bf7b3103d2d1b83a9de Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 29 Aug 2023 13:44:54 +0000 Subject: [PATCH 002/105] External Libraries: Upgrade PHPMailer to version 6.8.1. This is a minor maintenance release. Note: WordPress core does not include PHPMailer's DSN class, as it is not particularly relevant for WP. References: * [https://github.com/PHPMailer/PHPMailer/releases/tag/v6.8.1 PHPMailer 6.8.1 release notes] * [https://github.com/PHPMailer/PHPMailer/compare/v6.8.0...v6.8.1 Full list of changes in PHPMailer 6.8.1] Follow-up to [50628], [50799], [51169], [51634], [51635], [52252], [52749], [52811], [53500], [53535], [53917], [54427], [54937], [55557]. Props jrf, Synchro. Fixes #59238. git-svn-id: https://develop.svn.wordpress.org/trunk@56484 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/PHPMailer/PHPMailer.php | 4 ++-- src/wp-includes/PHPMailer/SMTP.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/PHPMailer/PHPMailer.php b/src/wp-includes/PHPMailer/PHPMailer.php index 79cf323307987..011fa92068e95 100644 --- a/src/wp-includes/PHPMailer/PHPMailer.php +++ b/src/wp-includes/PHPMailer/PHPMailer.php @@ -750,7 +750,7 @@ class PHPMailer * * @var string */ - const VERSION = '6.8.0'; + const VERSION = '6.8.1'; /** * Error severity: message only, continue processing. @@ -795,7 +795,7 @@ class PHPMailer * The maximum line length supported by mail(). * * Background: mail() will sometimes corrupt messages - * with headers headers longer than 65 chars, see #818. + * with headers longer than 65 chars, see #818. * * @var int */ diff --git a/src/wp-includes/PHPMailer/SMTP.php b/src/wp-includes/PHPMailer/SMTP.php index fc4b781a5fdeb..2b63840304749 100644 --- a/src/wp-includes/PHPMailer/SMTP.php +++ b/src/wp-includes/PHPMailer/SMTP.php @@ -35,7 +35,7 @@ class SMTP * * @var string */ - const VERSION = '6.8.0'; + const VERSION = '6.8.1'; /** * SMTP line break constant. @@ -704,7 +704,7 @@ public function close() * Send an SMTP DATA command. * Issues a data command and sends the msg_data to the server, * finalizing the mail transaction. $msg_data is the message - * that is to be send with the headers. Each header needs to be + * that is to be sent with the headers. Each header needs to be * on a single line followed by a with the message headers * and the message body being separated by an additional . * Implements RFC 821: DATA . @@ -732,7 +732,7 @@ public function data($msg_data) $lines = explode("\n", str_replace(["\r\n", "\r"], "\n", $msg_data)); /* To distinguish between a complete RFC822 message and a plain message body, we check if the first field - * of the first line (':' separated) does not contain a space then it _should_ be a header and we will + * of the first line (':' separated) does not contain a space then it _should_ be a header, and we will * process all lines before a blank line as headers. */ From ec94944ae4b5af2c2dda675711b627d98a72a2b0 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 29 Aug 2023 15:33:43 +0000 Subject: [PATCH 003/105] Media: Prevent warning if `[caption]` shortcode is used without attributes. Props maltfield, aslamdoctor. Fixes #59206. git-svn-id: https://develop.svn.wordpress.org/trunk@56488 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/media.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index e037a0608bac8..d365e0b1e1915 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -2361,6 +2361,10 @@ function _wp_post_thumbnail_context_filter_remove() { * @return string HTML content to display the caption. */ function img_caption_shortcode( $attr, $content = '' ) { + if ( ! $attr ) { + $attr = array(); + } + // New-style shortcode with the caption inside the shortcode with the link and image tags. if ( ! isset( $attr['caption'] ) ) { if ( preg_match( '#((?:]+>\s*)?]+>(?:\s*)?)(.*)#is', $content, $matches ) ) { From ab5fd4d56a955c1b2c7800feb5f34218c6604a36 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 29 Aug 2023 15:39:13 +0000 Subject: [PATCH 004/105] Site Health: fix check name used for REST API permission checks. Updates the calls to permission validation calls for the `directory-sizes` and `page-cache` routes to actually match the route names. Follow-up to r54043 and r49154. Props szepeviktor. Fixes #59236 git-svn-id: https://develop.svn.wordpress.org/trunk@56489 602fd350-edb4-49c9-b593-d223f7449a82 --- .../endpoints/class-wp-rest-site-health-controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php index 43e6676eff0ea..18d67dc2dd7a0 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php @@ -153,7 +153,7 @@ public function register_routes() { 'methods' => 'GET', 'callback' => array( $this, 'get_directory_sizes' ), 'permission_callback' => function() { - return $this->validate_request_permission( 'debug_enabled' ) && ! is_multisite(); + return $this->validate_request_permission( 'directory_sizes' ) && ! is_multisite(); }, ) ); @@ -170,7 +170,7 @@ public function register_routes() { 'methods' => 'GET', 'callback' => array( $this, 'test_page_cache' ), 'permission_callback' => function () { - return $this->validate_request_permission( 'view_site_health_checks' ); + return $this->validate_request_permission( 'page_cache' ); }, ), ) From 3d2f4d5a88ab33e21f0ae97c277ddabb066c886b Mon Sep 17 00:00:00 2001 From: Joe McGill Date: Tue, 29 Aug 2023 22:03:25 +0000 Subject: [PATCH 005/105] Posts, Post Types: Reinstate missing sort_column options in get_pages(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes an issue introduced in [55569] that broke sort ordering by `post_modified_gmt` or `modified_gmt`. Props david.binda, azaozz, spacedmonkey, flixos90, joemcgill. Fixes #59226. git-svn-id: https://develop.svn.wordpress.org/trunk@56490 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post.php | 16 +++++++++++++- tests/phpunit/tests/post/getPages.php | 31 +++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 5367f51e06f06..0bd4fc7a9f1ce 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -6066,8 +6066,22 @@ function get_pages( $args = array() ) { $query_args['post_parent'] = $parent; } + /* + * Maintain backward compatibility for `sort_column` key. + * Additionally to `WP_Query`, it has been supporting the `post_modified_gmt` field, so this logic will translate + * it to `post_modified` which should result in the same order given the two dates in the fields match. + */ $orderby = wp_parse_list( $parsed_args['sort_column'] ); - $orderby = array_map( 'trim', $orderby ); + $orderby = array_map( + static function( $orderby_field ) { + $orderby_field = trim( $orderby_field ); + if ( 'post_modified_gmt' === $orderby_field || 'modified_gmt' === $orderby_field ) { + $orderby_field = str_replace( '_gmt', '', $orderby_field ); + } + return $orderby_field; + }, + $orderby + ); if ( $orderby ) { $query_args['orderby'] = array_fill_keys( $orderby, $parsed_args['sort_order'] ); } diff --git a/tests/phpunit/tests/post/getPages.php b/tests/phpunit/tests/post/getPages.php index 92de3356fa5c6..e72ba3e2ed8b9 100644 --- a/tests/phpunit/tests/post/getPages.php +++ b/tests/phpunit/tests/post/getPages.php @@ -1181,4 +1181,35 @@ public function test_get_pages_order() { 'Check that ORDER is post date.' ); } + + /** + * Tests that the legacy `post_modified_gmt` orderby values are translated to the proper `WP_Query` values. + * + * @ticket 59226 + */ + public function test_get_pages_order_by_post_modified_gmt() { + global $wpdb; + + get_pages( + array( + 'sort_column' => 'post_modified_gmt', + ) + ); + $this->assertStringContainsString( + "ORDER BY $wpdb->posts.post_modified ASC", + $wpdb->last_query, + 'Check that ORDER is post modified when using post_modified_gmt.' + ); + + get_pages( + array( + 'sort_column' => 'modified_gmt', + ) + ); + $this->assertStringContainsString( + "ORDER BY $wpdb->posts.post_modified ASC", + $wpdb->last_query, + 'Check that ORDER is post modified when using modified_gmt.' + ); + } } From e278fe3fcf262d1792a347a460bc004200a2490f Mon Sep 17 00:00:00 2001 From: Joe McGill Date: Tue, 29 Aug 2023 22:11:22 +0000 Subject: [PATCH 006/105] Posts, Post Types: Avoid redundant SQL query in get_pages(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This avoids an additional query by passing the query args directly to the `WP_Query::query()` method, rather than to the constructor and calling get_posts(), following [55569]. Props david.binda, azaozz, spacedmonkey, mukesh27, flixos90, SergeyBiryukov, joemcgill. Fixes #59224. git-svn-id: https://develop.svn.wordpress.org/trunk@56491 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 0bd4fc7a9f1ce..f71a0a061d391 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -6105,8 +6105,8 @@ static function( $orderby_field ) { */ $query_args = apply_filters( 'get_pages_query_args', $query_args, $parsed_args ); - $query = new WP_Query( $query_args ); - $pages = $query->get_posts(); + $pages = new WP_Query(); + $pages = $pages->query( $query_args ); if ( $child_of || $hierarchical ) { $pages = get_page_children( $child_of, $pages ); From c6088bb590ecf9d49dd03b81bc7175a7b9452ac1 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 30 Aug 2023 10:49:27 +0000 Subject: [PATCH 007/105] Tests: Correct uses of `ReflectionProperty::setValue()` for static properties. The single parameter signature, which was used for setting the value on a static property, is deprecated since PHP 8.3. A cross-version solution is to pass `null` as the first parameter. This commit updates all the instances that use the deprecated signature in WordPress core. Reference: [https://wiki.php.net/rfc/deprecate_functions_with_overloaded_signatures#reflectionpropertysetvalue PHP RFC: Deprecate functions with overloaded signatures: ReflectionProperty::setValue()]. Follow-up to [53152], [54493], [54799]. Props jrf, costdev, Tests: Correct uses of `ReflectionProperty::setValue()` for static properties. The single parameter signature, which was used for setting the value on a static property, is deprecated since PHP 8.3. A cross-version solution is to pass `null` as the first parameter. This commit updates all the instances that use the deprecated signature in WordPress core. Reference: [https://wiki.php.net/rfc/deprecate_functions_with_overloaded_signatures#reflectionpropertysetvalue PHP RFC: Deprecate functions with overloaded signatures: ReflectionProperty::setValue()]. Follow-up to [53152], [54493], [54799]. Props jrf, costdev, sc0ttkclark. See #59231. git-svn-id: https://develop.svn.wordpress.org/trunk@56492 602fd350-edb4-49c9-b593-d223f7449a82 --- .../rest-api/wpRestBlockPatternCategoriesController.php | 4 ++-- .../tests/rest-api/wpRestBlockPatternsController.php | 4 ++-- tests/phpunit/tests/theme/wpThemeJsonResolver.php | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/phpunit/tests/rest-api/wpRestBlockPatternCategoriesController.php b/tests/phpunit/tests/rest-api/wpRestBlockPatternCategoriesController.php index 77481112a0f87..63c2256b36ba3 100644 --- a/tests/phpunit/tests/rest-api/wpRestBlockPatternCategoriesController.php +++ b/tests/phpunit/tests/rest-api/wpRestBlockPatternCategoriesController.php @@ -65,7 +65,7 @@ public static function wpSetupBeforeClass( $factory ) { self::$registry_instance_property = new ReflectionProperty( 'WP_Block_Pattern_Categories_Registry', 'instance' ); self::$registry_instance_property->setAccessible( true ); $test_registry = new WP_Block_Pattern_Categories_Registry(); - self::$registry_instance_property->setValue( $test_registry ); + self::$registry_instance_property->setValue( null, $test_registry ); // Register some categories in the test registry. $test_registry->register( @@ -88,7 +88,7 @@ public static function wpTearDownAfterClass() { self::delete_user( self::$admin_id ); // Restore the original registry instance. - self::$registry_instance_property->setValue( self::$orig_registry ); + self::$registry_instance_property->setValue( null, self::$orig_registry ); self::$registry_instance_property->setAccessible( false ); self::$registry_instance_property = null; self::$orig_registry = null; diff --git a/tests/phpunit/tests/rest-api/wpRestBlockPatternsController.php b/tests/phpunit/tests/rest-api/wpRestBlockPatternsController.php index 5482e32cbede2..2dc3bb83a38ac 100644 --- a/tests/phpunit/tests/rest-api/wpRestBlockPatternsController.php +++ b/tests/phpunit/tests/rest-api/wpRestBlockPatternsController.php @@ -65,7 +65,7 @@ public static function wpSetUpBeforeClass( $factory ) { self::$registry_instance_property = new ReflectionProperty( 'WP_Block_Patterns_Registry', 'instance' ); self::$registry_instance_property->setAccessible( true ); $test_registry = new WP_Block_Pattern_Categories_Registry(); - self::$registry_instance_property->setValue( $test_registry ); + self::$registry_instance_property->setValue( null, $test_registry ); // Register some patterns in the test registry. $test_registry->register( @@ -106,7 +106,7 @@ public static function wpTearDownAfterClass() { self::delete_user( self::$admin_id ); // Restore the original registry instance. - self::$registry_instance_property->setValue( self::$orig_registry ); + self::$registry_instance_property->setValue( null, self::$orig_registry ); self::$registry_instance_property->setAccessible( false ); self::$registry_instance_property = null; self::$orig_registry = null; diff --git a/tests/phpunit/tests/theme/wpThemeJsonResolver.php b/tests/phpunit/tests/theme/wpThemeJsonResolver.php index 7e928aa0c7123..12c9f50f084f8 100644 --- a/tests/phpunit/tests/theme/wpThemeJsonResolver.php +++ b/tests/phpunit/tests/theme/wpThemeJsonResolver.php @@ -81,8 +81,8 @@ public static function set_up_before_class() { } public static function tear_down_after_class() { - static::$property_blocks_cache->setValue( WP_Theme_JSON_Resolver::class, static::$property_blocks_cache_orig_value ); - static::$property_core->setValue( WP_Theme_JSON_Resolver::class, static::$property_core_orig_value ); + static::$property_blocks_cache->setValue( null, static::$property_blocks_cache_orig_value ); + static::$property_core->setValue( null, static::$property_core_orig_value ); parent::tear_down_after_class(); } @@ -759,7 +759,7 @@ public function test_get_theme_data_does_not_parse_theme_json_if_not_present() { // Force-unset $i18n_schema property to "unload" translation schema. $property = new ReflectionProperty( $theme_json_resolver, 'i18n_schema' ); $property->setAccessible( true ); - $property->setValue( null ); + $property->setValue( null, null ); // A completely empty theme.json data set still has the 'version' key when parsed. $empty_theme_json = array( 'version' => WP_Theme_JSON::LATEST_SCHEMA ); From 973b4565ee4b7a9c08dfc8541e4951963f37f478 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 30 Aug 2023 15:37:33 +0000 Subject: [PATCH 008/105] HTML API: Stop processing HTML when encountering unsupported markup. It was a design goal of the HTML Processor to abort processing its input document when encountering unsupported markup. Unfortunately there was no test for this and so-far, the HTML Processor has paused, but continued processing in these situations. In this patch a new test ensures that the HTML Processor stops and refuses to move forward after encountering any unsupported markup. It also ensures that it doesn't report any current tag names since unsupported markup could imply that the read tag name is different than the parsed tag name. Props dmsnell. Fixes #59167. git-svn-id: https://develop.svn.wordpress.org/trunk@56493 602fd350-edb4-49c9-b593-d223f7449a82 --- .../html-api/class-wp-html-processor.php | 9 +++++ .../tests/html-api/wpHtmlProcessor.php | 34 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index 6e1723494c2e9..b5a20dbd82cdc 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -432,6 +432,11 @@ public function next_tag( $query = null ) { * @return bool Whether a tag was matched. */ public function step( $node_to_process = self::PROCESS_NEXT_NODE ) { + // Refuse to proceed if there was a previous error. + if ( null !== $this->last_error ) { + return false; + } + if ( self::PROCESS_NEXT_NODE === $node_to_process ) { $top_node = $this->state->stack_of_open_elements->current_node(); if ( $top_node && self::is_void( $top_node->node_name ) ) { @@ -744,6 +749,10 @@ private function bookmark_tag() { * @return string|null Name of currently matched tag in input HTML, or `null` if none found. */ public function get_tag() { + if ( null !== $this->last_error ) { + return null; + } + $tag_name = parent::get_tag(); switch ( $tag_name ) { diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessor.php b/tests/phpunit/tests/html-api/wpHtmlProcessor.php index 6a666c19cf27c..d6b818dd44c34 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessor.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessor.php @@ -42,6 +42,40 @@ public function test_warns_that_the_static_creator_methods_should_be_called_inst ); } + /** + * Once stepping to the end of the document, WP_HTML_Processor::get_tag + * should no longer report a tag. It should report `null` because there + * is no tag matched or open. + * + * @ticket 59167 + * + * @covers WP_HTML_Processor::get_tag + */ + public function test_get_tag_is_null_once_document_is_finished() { + $p = WP_HTML_Processor::createFragment( '
Test
' ); + $p->next_tag(); + $this->assertSame( 'DIV', $p->get_tag() ); + + $this->assertFalse( $p->next_tag() ); + $this->assertNull( $p->get_tag() ); + } + + /** + * Ensures that if the HTML Processor encounters inputs that it can't properly handle, + * that it stops processing the rest of the document. This prevents data corruption. + * + * @ticket 59167 + * + * @covers WP_HTML_Processor::next_tag + */ + public function test_stops_processing_after_unsupported_elements() { + $p = WP_HTML_Processor::createFragment( '

' ); + $p->next_tag( 'P' ); + $this->assertFalse( $p->next_tag(), 'Stepped into a tag after encountering X-NOT-SUPPORTED element when it should have aborted.' ); + $this->assertNull( $p->get_tag(), "Should have aborted processing, but still reported tag {$p->get_tag()} after properly failing to step into tag." ); + $this->assertFalse( $p->next_tag( 'P' ), 'Stepped into normal P element after X-NOT-SUPPORTED element when it should have aborted.' ); + } + /** * Ensures that the HTML Processor maintains its internal state through seek calls. * From bc92bb0cbae3969dc53056efaed3593c66e2600a Mon Sep 17 00:00:00 2001 From: Colin Stewart Date: Wed, 30 Aug 2023 20:23:18 +0000 Subject: [PATCH 009/105] General: Replace two `esc_url_raw()` calls in core with `sanitize_url()`. This aims to improve performance by calling `sanitize_url()` directly, instead of the `esc_url_raw()` wrapper. As of WordPress 6.1, `sanitize_url()` is the recommended function for sanitizing a URL for database or redirect usage. This replaces the two remaining instances of `esc_url_raw()` with `sanitize_url()` in WordPress core. Follow-up to [53455], [53933], [54522]. Props rajinsharwar, SergeyBiryukov. Fixes #59247. git-svn-id: https://develop.svn.wordpress.org/trunk@56494 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 2 +- src/wp-includes/update.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index d2304f4d55c53..be03264455331 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -3613,7 +3613,7 @@ function wp_nonce_ays( $action ) { if ( wp_get_referer() ) { $wp_http_referer = remove_query_arg( 'updated', wp_get_referer() ); - $wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) ); + $wp_http_referer = wp_validate_redirect( sanitize_url( $wp_http_referer ) ); $html .= '

'; $html .= sprintf( diff --git a/src/wp-includes/update.php b/src/wp-includes/update.php index 7c4e31feefe99..c5349832ac2a4 100644 --- a/src/wp-includes/update.php +++ b/src/wp-includes/update.php @@ -754,7 +754,7 @@ function wp_update_themes( $extra_stats = array() ) { continue; } - $hostname = wp_parse_url( esc_url_raw( $theme_data['UpdateURI'] ), PHP_URL_HOST ); + $hostname = wp_parse_url( sanitize_url( $theme_data['UpdateURI'] ), PHP_URL_HOST ); /** * Filters the update response for a given theme hostname. From 98284ae792d95d4484c25b11d6f4fea4f6603cbc Mon Sep 17 00:00:00 2001 From: Jb Audras Date: Wed, 30 Aug 2023 22:07:13 +0000 Subject: [PATCH 010/105] HTTP API: Update `WP_Http` class to avoid PHP deprecation warnings. This changeset prevents a PHP 8.3 deprecation shown when enabling debug and calling `get_class()` without arguments. For more info about this deprecation, see https://wiki.php.net/rfc/deprecate_functions_with_overloaded_signatures#get_class_and_get_parent_class. Props ipajen, rajinsharwar, SergeyBiryukov, jrf. Fixes #58876. git-svn-id: https://develop.svn.wordpress.org/trunk@56495 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-http.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-http.php b/src/wp-includes/class-wp-http.php index e1d37878a140f..546ba96c1cdfb 100644 --- a/src/wp-includes/class-wp-http.php +++ b/src/wp-includes/class-wp-http.php @@ -326,11 +326,11 @@ public function request( $url, $args = array() ) { ); // Ensure redirects follow browser behavior. - $options['hooks']->register( 'requests.before_redirect', array( get_class(), 'browser_redirect_compatibility' ) ); + $options['hooks']->register( 'requests.before_redirect', array( static::class, 'browser_redirect_compatibility' ) ); // Validate redirected URLs. if ( function_exists( 'wp_kses_bad_protocol' ) && $parsed_args['reject_unsafe_urls'] ) { - $options['hooks']->register( 'requests.before_redirect', array( get_class(), 'validate_redirects' ) ); + $options['hooks']->register( 'requests.before_redirect', array( static::class, 'validate_redirects' ) ); } if ( $parsed_args['stream'] ) { From 39db9a677547c4cd1fa9f75b19223323ccfac7c7 Mon Sep 17 00:00:00 2001 From: Jb Audras Date: Wed, 30 Aug 2023 22:09:20 +0000 Subject: [PATCH 011/105] Editor: Add relative time strings for the `wp-date` inline script output. This changeset updates `wp_default_packages_inline_scripts()` to add relative time strings to the `wp-date` inline script, so the JS version of `human_time_diff` can output translated strings. Props ramonopoly, oandregal, swissspidy, manzoorwanijk, adrianduffell, Presskopp. Fixes #59219, #47373. git-svn-id: https://develop.svn.wordpress.org/trunk@56496 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/script-loader.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 3cbcb8996709b..85cb58f56bb13 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -329,6 +329,7 @@ function wp_default_packages_scripts( $scripts ) { * Adds inline scripts required for the WordPress JavaScript packages. * * @since 5.0.0 + * @since 6.4.0 Added relative time strings for the `wp-date` inline script output. * * @global WP_Locale $wp_locale WordPress date and time locale object. * @global wpdb $wpdb WordPress database abstraction object. @@ -430,6 +431,30 @@ function wp_default_packages_inline_scripts( $scripts ) { 'future' => __( '%s from now' ), /* translators: %s: Duration. */ 'past' => __( '%s ago' ), + /* translators: One second from or to a particular datetime, e.g., "a second ago" or "a second from now". */ + 's' => __( 'a second' ), + /* translators: %s: Duration in seconds from or to a particular datetime, e.g., "4 seconds ago" or "4 seconds from now". */ + 'ss' => __( '%d seconds' ), + /* translators: One minute from or to a particular datetime, e.g., "a minute ago" or "a minute from now". */ + 'm' => __( 'a minute' ), + /* translators: %s: Duration in minutes from or to a particular datetime, e.g., "4 minutes ago" or "4 minutes from now". */ + 'mm' => __( '%d minutes' ), + /* translators: %s: One hour from or to a particular datetime, e.g., "an hour ago" or "an hour from now". */ + 'h' => __( 'an hour' ), + /* translators: %s: Duration in hours from or to a particular datetime, e.g., "4 hours ago" or "4 hours from now". */ + 'hh' => __( '%d hours' ), + /* translators: %s: One day from or to a particular datetime, e.g., "a day ago" or "a day from now". */ + 'd' => __( 'a day' ), + /* translators: %s: Duration in days from or to a particular datetime, e.g., "4 days ago" or "4 days from now". */ + 'dd' => __( '%d days' ), + /* translators: %s: One month from or to a particular datetime, e.g., "a month ago" or "a month from now". */ + 'M' => __( 'a month' ), + /* translators: %s: Duration in months from or to a particular datetime, e.g., "4 months ago" or "4 months from now". */ + 'MM' => __( '%d months' ), + /* translators: %s: One year from or to a particular datetime, e.g., "a year ago" or "a year from now". */ + 'y' => __( 'a year' ), + /* translators: %s: Duration in years from or to a particular datetime, e.g., "4 years ago" or "4 years from now". */ + 'yy' => __( '%d years' ), ), 'startOfWeek' => (int) get_option( 'start_of_week', 0 ), ), From a023fbce186748782d89c6180009fd4df569fda8 Mon Sep 17 00:00:00 2001 From: Jb Audras Date: Wed, 30 Aug 2023 22:30:06 +0000 Subject: [PATCH 012/105] Upload: Add a MIME type exception for `.docx` generated by Google Docs. This changeset adds an exception to prevent permission issues on `.docx` generated by Google Docs. This is a temporary fix for an upstream bug on the `finfo_file()` PHP function which returns a redundant MIME type for these documents. Props winterstreet, jakariaistauk, mujuonly, mi5t4n, annashopina, audrasjb, azaozz, mikeschroder, oglekler. Fixes #57898. git-svn-id: https://develop.svn.wordpress.org/trunk@56497 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index be03264455331..dfe8af43350be 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -3150,6 +3150,11 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) { $real_mime = finfo_file( $finfo, $file ); finfo_close( $finfo ); + // finfo_file() returns redudant mime type for Google docs, see #57898. + if ( 'application/vnd.openxmlformats-officedocument.wordprocessingml.documentapplication/vnd.openxmlformats-officedocument.wordprocessingml.document' === $real_mime ) { + $real_mime = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; + } + // fileinfo often misidentifies obscure files as one of these types. $nonspecific_types = array( 'application/octet-stream', From 9879434020b7acf9c10dad2593b9658737c11516 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 31 Aug 2023 10:15:42 +0000 Subject: [PATCH 013/105] Build/Test Tools: Enable running the tests on PHP 8.3. PHP 8.3 is expected to be released at the end of November 2023. Enabling the tests to run in CI on PHP 8.3 allows WordPress core to start getting ready. Note: Xdebug-related tests will not be run on PHP 8.3 at this time as the Docker image for PHP 8.3 does not contain Xdebug yet. Once a stable release of Xdebug 3.3.0 is available, it can be added to the Docker image and the test step can then be enabled for PHP 8.3. Follow-up to [53922], [56492], [56495]. Props jrf, costdev. See #59231. git-svn-id: https://develop.svn.wordpress.org/trunk@56498 602fd350-edb4-49c9-b593-d223f7449a82 --- .github/workflows/phpunit-tests-run.yml | 1 + .github/workflows/phpunit-tests.yml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/phpunit-tests-run.yml b/.github/workflows/phpunit-tests-run.yml index 843a950481f19..af03911f4ac08 100644 --- a/.github/workflows/phpunit-tests-run.yml +++ b/.github/workflows/phpunit-tests-run.yml @@ -165,6 +165,7 @@ jobs: # __fakegroup__ is excluded to force PHPUnit to ignore the settings in phpunit.xml.dist. - name: Run (Xdebug) tests + if: ${{ inputs.php != '8.3' }} run: LOCAL_PHP_XDEBUG=true node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit -v --group xdebug --exclude-group __fakegroup__ - name: Ensure version-controlled files are not modified or deleted diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 9c399d51ed791..7edf91608093c 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -45,7 +45,7 @@ jobs: fail-fast: false matrix: os: [ ubuntu-latest ] - php: [ '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ] + php: [ '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ] db-type: [ 'mysql' ] db-version: [ '5.7', '8.0' ] multisite: [ false, true ] @@ -97,7 +97,7 @@ jobs: fail-fast: false matrix: os: [ ubuntu-latest ] - php: [ '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ] + php: [ '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ] db-type: [ 'mariadb' ] db-version: [ '10.4', '10.6', '10.11', '11.0' ] multisite: [ false, true ] From 54a177910a80083930ee1284f648c1db5bf2e5c0 Mon Sep 17 00:00:00 2001 From: Jb Audras Date: Thu, 31 Aug 2023 14:43:36 +0000 Subject: [PATCH 014/105] Coding Standards: Remove unused global variables in various `/wp-admin/includes/` files. Props upadalavipul. Fixes #59254. git-svn-id: https://develop.svn.wordpress.org/trunk@56499 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/class-wp-privacy-policy-content.php | 4 ---- src/wp-admin/includes/ms.php | 4 ---- src/wp-admin/includes/upgrade.php | 3 +-- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/wp-admin/includes/class-wp-privacy-policy-content.php b/src/wp-admin/includes/class-wp-privacy-policy-content.php index 46b10e15f6b66..aa72b21aa7470 100644 --- a/src/wp-admin/includes/class-wp-privacy-policy-content.php +++ b/src/wp-admin/includes/class-wp-privacy-policy-content.php @@ -130,12 +130,8 @@ public static function text_change_check() { * Outputs a warning when some privacy info has changed. * * @since 4.9.6 - * - * @global WP_Post $post Global post object. */ public static function policy_text_changed_notice() { - global $post; - $screen = get_current_screen()->id; if ( 'privacy' !== $screen ) { diff --git a/src/wp-admin/includes/ms.php b/src/wp-admin/includes/ms.php index c769375b4b017..1e38133a3f3d8 100644 --- a/src/wp-admin/includes/ms.php +++ b/src/wp-admin/includes/ms.php @@ -58,14 +58,10 @@ function check_upload_size( $file ) { * @since 3.0.0 * @since 5.1.0 Use wp_delete_site() internally to delete the site row from the database. * - * @global wpdb $wpdb WordPress database abstraction object. - * * @param int $blog_id Site ID. * @param bool $drop True if site's database tables should be dropped. Default false. */ function wpmu_delete_blog( $blog_id, $drop = false ) { - global $wpdb; - $blog_id = (int) $blog_id; $switch = false; diff --git a/src/wp-admin/includes/upgrade.php b/src/wp-admin/includes/upgrade.php index 23653d1c2b46c..39455ad425c30 100644 --- a/src/wp-admin/includes/upgrade.php +++ b/src/wp-admin/includes/upgrade.php @@ -625,10 +625,9 @@ function wp_new_blog_notification( $blog_title, $blog_url, $user_id, $password ) * * @global int $wp_current_db_version The old (current) database version. * @global int $wp_db_version The new database version. - * @global wpdb $wpdb WordPress database abstraction object. */ function wp_upgrade() { - global $wp_current_db_version, $wp_db_version, $wpdb; + global $wp_current_db_version, $wp_db_version; $wp_current_db_version = __get_option( 'db_version' ); From c29b095e762836e47df9080d670c2f6570d6cd12 Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Thu, 31 Aug 2023 21:47:40 +0000 Subject: [PATCH 015/105] Introduce font-face styles generator and printer. Introducing Font Face, a server-side `@font-face` styles generator and printer. tl;dr: * Introduces Font Face. * Deprecates `_wp_theme_json_webfonts_handler()`. **Introduce Font Face** From an array of fonts (i.e. each font-family and its font variations to be processed), it: 1. Validates each `font-face` declaration, i.e. the CSS property and value pairing. If validation fails, processing stops with no font-face styles printed. 3. Generates the `@font-face` CSS for each font-family. 4. Prints the CSS within a ` and open a + +CSS; + $this->expectOutputString( $expected_output ); + + wp_print_font_faces( $fonts ); + } + + public function test_should_print_fonts_in_merged_data() { + switch_theme( static::FONTS_THEME ); + + $expected = $this->get_expected_fonts_for_fonts_block_theme( 'font_face_styles' ); + $expected_output = $this->get_expected_styles_output( $expected ); + + $this->expectOutputString( $expected_output ); + wp_print_font_faces(); + } + + private function get_expected_styles_output( $styles ) { + $style_element = "\n"; + return sprintf( $style_element, $styles ); + } +} diff --git a/tests/phpunit/tests/theme/themeDir.php b/tests/phpunit/tests/theme/themeDir.php index ea721e5a4494c..73cf63539e58f 100644 --- a/tests/phpunit/tests/theme/themeDir.php +++ b/tests/phpunit/tests/theme/themeDir.php @@ -185,7 +185,7 @@ public function test_theme_list() { 'Block Theme [0.4.0]', 'Block Theme [1.0.0] in subdirectory', 'Block Theme Deprecated Path', - 'Webfonts theme', + 'Block Theme with defined Typography Fonts', 'Empty `fontFace` in theme.json - no webfonts defined', 'A theme with the Update URI header', ); From 13531cc3bdcdc912f4025089f14f6ac33469fc32 Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Thu, 31 Aug 2023 22:16:05 +0000 Subject: [PATCH 016/105] Tests: Remove webfonts tests. Removes the test file and `webfonts` directory for the stopgap code that was deprecated by [56500]. Follow-up to [56500], [53282]. Fixes #59165. git-svn-id: https://develop.svn.wordpress.org/trunk@56501 602fd350-edb4-49c9-b593-d223f7449a82 --- .../webfonts/wpThemeJsonWebfontsHandler.php | 138 ------------------ 1 file changed, 138 deletions(-) delete mode 100644 tests/phpunit/tests/webfonts/wpThemeJsonWebfontsHandler.php diff --git a/tests/phpunit/tests/webfonts/wpThemeJsonWebfontsHandler.php b/tests/phpunit/tests/webfonts/wpThemeJsonWebfontsHandler.php deleted file mode 100644 index 7202417ddee93..0000000000000 --- a/tests/phpunit/tests/webfonts/wpThemeJsonWebfontsHandler.php +++ /dev/null @@ -1,138 +0,0 @@ -orig_wp_styles = $wp_styles; - $wp_styles = null; - - $this->theme_root = realpath( DIR_TESTDATA . '/themedir1' ); - $this->orig_theme_dir = $GLOBALS['wp_theme_directories']; - - // /themes is necessary as theme.php functions assume /themes is the root if there is only one root. - $GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', $this->theme_root ); - - $theme_root_callback = function () { - return $this->theme_root; - }; - - add_filter( 'theme_root', $theme_root_callback ); - add_filter( 'stylesheet_root', $theme_root_callback ); - add_filter( 'template_root', $theme_root_callback ); - - // Clear caches. - wp_clean_themes_cache(); - unset( $GLOBALS['wp_themes'] ); - } - - public function tear_down() { - global $wp_styles; - $wp_styles = $this->orig_wp_styles; - - // Restore the original theme directory setup. - $GLOBALS['wp_theme_directories'] = $this->orig_theme_dir; - wp_clean_themes_cache(); - unset( $GLOBALS['wp_themes'] ); - - parent::tear_down(); - } - - /** - * @ticket 55567 - * @ticket 46370 - * @ticket 57430 - */ - public function test_font_face_generated_from_themejson() { - $this->setup_theme_and_test( 'webfonts-theme' ); - - $expected = << -@font-face{font-family:"Source Serif Pro";font-style:normal;font-weight:200 900;font-display:fallback;src:url('THEME_ROOT_URL/assets/fonts/SourceSerif4Variable-Roman.ttf.woff2') format('woff2');font-stretch:normal;}@font-face{font-family:"Source Serif Pro";font-style:italic;font-weight:200 900;font-display:fallback;src:url('THEME_ROOT_URL/assets/fonts/SourceSerif4Variable-Italic.ttf.woff2') format('woff2');font-stretch:normal;} - -EOF; - $expected = str_replace( 'THEME_ROOT_URL', get_stylesheet_directory_uri(), $expected ); - $expected = str_replace( "\r\n", "\n", $expected ); - - $this->assertStringContainsString( - $expected, - get_echo( 'wp_print_styles' ) - ); - } - - /** - * @dataProvider data_font_face_not_generated - * - * @ticket 55567 - * @ticket 46370 - */ - public function test_font_face_not_generated( $theme_name ) { - $this->setup_theme_and_test( $theme_name ); - - $actual = get_echo( 'wp_print_styles' ); - $this->assertStringNotContainsString( "' === strtolower( $piece ) ) ) { - $nested_code_pre--; + --$nested_code_pre; } if ( $nested_code_pre @@ -5354,7 +5354,7 @@ function wp_sprintf_l( $pattern, $args ) { $i = count( $args ); while ( $i ) { $arg = array_shift( $args ); - $i--; + --$i; if ( 0 === $i ) { $result .= $l['between_last_two'] . $arg; } else { diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 4a2a2b1779f2d..6963de3a3831d 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -2696,7 +2696,7 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) ); $number = $new_number; - $i++; + ++$i; } } } @@ -2769,7 +2769,7 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) ); $number = $new_number; - $i++; + ++$i; } } } @@ -7163,7 +7163,7 @@ function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pr $trace = debug_backtrace( false ); $caller = array(); $check_class = ! is_null( $ignore_class ); - $skip_frames++; // Skip this function. + ++$skip_frames; // Skip this function. if ( ! isset( $truncate_paths ) ) { $truncate_paths = array( @@ -7174,7 +7174,7 @@ function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pr foreach ( $trace as $call ) { if ( $skip_frames > 0 ) { - $skip_frames--; + --$skip_frames; } elseif ( isset( $call['class'] ) ) { if ( $check_class && $ignore_class === $call['class'] ) { continue; // Filter out calls. diff --git a/src/wp-includes/html-api/class-wp-html-tag-processor.php b/src/wp-includes/html-api/class-wp-html-tag-processor.php index 2e84b3d7193a0..541b5baf0bfbe 100644 --- a/src/wp-includes/html-api/class-wp-html-tag-processor.php +++ b/src/wp-includes/html-api/class-wp-html-tag-processor.php @@ -951,7 +951,7 @@ private function parse_next_tag() { if ( '/' === $this->html[ $at + 1 ] ) { $this->is_closing_tag = true; - $at++; + ++$at; } else { $this->is_closing_tag = false; } @@ -1020,7 +1020,7 @@ private function parse_next_tag() { * * See https://html.spec.whatwg.org/#parse-error-incorrectly-closed-comment */ - $closer_at--; // Pre-increment inside condition below reduces risk of accidental infinite looping. + --$closer_at; // Pre-increment inside condition below reduces risk of accidental infinite looping. while ( ++$closer_at < strlen( $html ) ) { $closer_at = strpos( $html, '--', $closer_at ); if ( false === $closer_at ) { @@ -1101,7 +1101,7 @@ private function parse_next_tag() { * See https://html.spec.whatwg.org/#parse-error-missing-end-tag-name */ if ( '>' === $html[ $at + 1 ] ) { - $at++; + ++$at; continue; } diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index d365e0b1e1915..dd98b5e622b7d 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -2552,7 +2552,7 @@ function gallery_shortcode( $attr ) { $post = get_post(); static $instance = 0; - $instance++; + ++$instance; if ( ! empty( $attr['ids'] ) ) { // 'ids' is explicitly ordered, unless you specify otherwise. @@ -2899,7 +2899,7 @@ function wp_playlist_shortcode( $attr ) { $post = get_post(); static $instance = 0; - $instance++; + ++$instance; if ( ! empty( $attr['ids'] ) ) { // 'ids' is explicitly ordered, unless you specify otherwise. @@ -3213,7 +3213,7 @@ function wp_audio_shortcode( $attr, $content = '' ) { $post_id = get_post() ? get_the_ID() : 0; static $instance = 0; - $instance++; + ++$instance; /** * Filters the default audio shortcode output. @@ -3432,7 +3432,7 @@ function wp_video_shortcode( $attr, $content = '' ) { $post_id = get_post() ? get_the_ID() : 0; static $instance = 0; - $instance++; + ++$instance; /** * Filters the default video shortcode output. diff --git a/src/wp-includes/ms-site.php b/src/wp-includes/ms-site.php index eaee99f5685c2..65e7d8d78d57d 100644 --- a/src/wp-includes/ms-site.php +++ b/src/wp-includes/ms-site.php @@ -877,7 +877,7 @@ function wp_uninitialize_site( $site_id ) { } @closedir( $dh ); } - $index++; + ++$index; } $stack = array_reverse( $stack ); // Last added directories are deepest. diff --git a/src/wp-includes/pomo/mo.php b/src/wp-includes/pomo/mo.php index dec51cee31310..1bbc40ab65aa2 100644 --- a/src/wp-includes/pomo/mo.php +++ b/src/wp-includes/pomo/mo.php @@ -129,7 +129,7 @@ public function export_to_file_handle( $fh ) { // Headers' msgid is an empty string. fwrite( $fh, pack( 'VV', 0, $current_addr ) ); - $current_addr++; + ++$current_addr; $originals_table = "\0"; $reader = new POMO_Reader(); diff --git a/src/wp-includes/pomo/plural-forms.php b/src/wp-includes/pomo/plural-forms.php index b072bfadac002..ae9c306d989a8 100644 --- a/src/wp-includes/pomo/plural-forms.php +++ b/src/wp-includes/pomo/plural-forms.php @@ -110,19 +110,19 @@ protected function parse( $str ) { // Ignore whitespace. case ' ': case "\t": - $pos++; + ++$pos; break; // Variable (n). case 'n': $output[] = array( 'var' ); - $pos++; + ++$pos; break; // Parentheses. case '(': $stack[] = $next; - $pos++; + ++$pos; break; case ')': @@ -144,7 +144,7 @@ protected function parse( $str ) { throw new Exception( 'Mismatched parentheses' ); } - $pos++; + ++$pos; break; // Operators. @@ -189,7 +189,7 @@ protected function parse( $str ) { $o2 = $stack[ $s_pos ]; if ( '?' !== $o2 ) { $output[] = array( 'op', array_pop( $stack ) ); - $s_pos--; + --$s_pos; continue; } @@ -202,7 +202,7 @@ protected function parse( $str ) { if ( ! $found ) { throw new Exception( 'Missing starting "?" ternary operator' ); } - $pos++; + ++$pos; break; // Default - number or invalid. @@ -264,7 +264,7 @@ public function execute( $n ) { $total = count( $this->tokens ); while ( $i < $total ) { $next = $this->tokens[ $i ]; - $i++; + ++$i; if ( 'var' === $next[0] ) { $stack[] = $n; continue; diff --git a/src/wp-includes/pomo/po.php b/src/wp-includes/pomo/po.php index 89d827c2550b9..7b9ec0b88bb2c 100644 --- a/src/wp-includes/pomo/po.php +++ b/src/wp-includes/pomo/po.php @@ -342,7 +342,7 @@ public function read_entry( $f, $lineno = 0 ) { $context = ''; $msgstr_index = 0; while ( true ) { - $lineno++; + ++$lineno; $line = PO::read_line( $f ); if ( ! $line ) { if ( feof( $f ) ) { @@ -365,7 +365,7 @@ public function read_entry( $f, $lineno = 0 ) { // The comment is the start of a new entry. if ( self::is_final( $context ) ) { PO::read_line( $f, 'put-back' ); - $lineno--; + --$lineno; break; } // Comments have to be at the beginning. @@ -377,7 +377,7 @@ public function read_entry( $f, $lineno = 0 ) { } elseif ( preg_match( '/^msgctxt\s+(".*")/', $line, $m ) ) { if ( self::is_final( $context ) ) { PO::read_line( $f, 'put-back' ); - $lineno--; + --$lineno; break; } if ( $context && 'comment' !== $context ) { @@ -388,7 +388,7 @@ public function read_entry( $f, $lineno = 0 ) { } elseif ( preg_match( '/^msgid\s+(".*")/', $line, $m ) ) { if ( self::is_final( $context ) ) { PO::read_line( $f, 'put-back' ); - $lineno--; + --$lineno; break; } if ( $context && 'msgctxt' !== $context && 'comment' !== $context ) { diff --git a/src/wp-includes/pomo/translations.php b/src/wp-includes/pomo/translations.php index d3a1d3cbd09a9..a5534a8ea9d02 100644 --- a/src/wp-includes/pomo/translations.php +++ b/src/wp-includes/pomo/translations.php @@ -261,7 +261,7 @@ public function parenthesize_plural_exression( $expression ) { switch ( $char ) { case '?': $res .= ' ? ('; - $depth++; + ++$depth; break; case ':': $res .= ') : ('; diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 5d7aee24ee663..2a8d6b41f6844 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -5073,7 +5073,7 @@ function wp_unique_post_slug( $slug, $post_id, $post_status, $post_type, $post_p do { $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_id ) ); - $suffix++; + ++$suffix; } while ( $post_name_check ); $slug = $alt_post_name; } @@ -5110,7 +5110,7 @@ function wp_unique_post_slug( $slug, $post_id, $post_status, $post_type, $post_p do { $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_id, $post_parent ) ); - $suffix++; + ++$suffix; } while ( $post_name_check ); $slug = $alt_post_name; } @@ -5166,7 +5166,7 @@ function wp_unique_post_slug( $slug, $post_id, $post_status, $post_type, $post_p do { $alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_id ) ); - $suffix++; + ++$suffix; } while ( $post_name_check ); $slug = $alt_post_name; } @@ -5758,7 +5758,7 @@ function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) { * ensuring each matches the post ancestry. */ while ( 0 != $p->post_parent && isset( $pages[ $p->post_parent ] ) ) { - $count++; + ++$count; $parent = $pages[ $p->post_parent ]; if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] ) { break; diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index 52a5705331798..3eb36552e618f 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -3090,7 +3090,7 @@ function wp_unique_term_slug( $slug, $term ) { $num = 2; do { $alt_slug = $slug . "-$num"; - $num++; + ++$num; $slug_check = $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $alt_slug ) ); } while ( $slug_check ); $slug = $alt_slug; diff --git a/src/wp-includes/theme-templates.php b/src/wp-includes/theme-templates.php index 114d7205d470c..2f233ca1d1946 100644 --- a/src/wp-includes/theme-templates.php +++ b/src/wp-includes/theme-templates.php @@ -90,7 +90,7 @@ function wp_filter_wp_template_unique_post_slug( $override_slug, $slug, $post_id $alt_post_name = _truncate_post_slug( $override_slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; $query_args['post_name__in'] = array( $alt_post_name ); $query = new WP_Query( $query_args ); - $suffix++; + ++$suffix; } while ( count( $query->posts ) > 0 ); $override_slug = $alt_post_name; } diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php index 5f8fe3807154e..aaba3a7e7e095 100644 --- a/src/wp-includes/user.php +++ b/src/wp-includes/user.php @@ -1316,11 +1316,11 @@ function count_users( $strategy = 'time', $site_id = null ) { continue; } if ( empty( $b_roles ) ) { - $avail_roles['none']++; + ++$avail_roles['none']; } foreach ( $b_roles as $b_role => $val ) { if ( isset( $avail_roles[ $b_role ] ) ) { - $avail_roles[ $b_role ]++; + ++$avail_roles[ $b_role ]; } else { $avail_roles[ $b_role ] = 1; } @@ -2177,7 +2177,7 @@ function wp_insert_user( $userdata ) { $base_length = 49 - mb_strlen( $suffix ); $alt_user_nicename = mb_substr( $user_nicename, 0, $base_length ) . "-$suffix"; $user_nicename_check = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1", $alt_user_nicename, $user_login ) ); - $suffix++; + ++$suffix; } $user_nicename = $alt_user_nicename; } diff --git a/src/wp-includes/widgets/class-wp-widget-calendar.php b/src/wp-includes/widgets/class-wp-widget-calendar.php index 6ab373fc42fe4..9103934173f8e 100644 --- a/src/wp-includes/widgets/class-wp-widget-calendar.php +++ b/src/wp-includes/widgets/class-wp-widget-calendar.php @@ -66,7 +66,7 @@ public function widget( $args, $instance ) { echo ''; echo $args['after_widget']; - self::$instance++; + ++self::$instance; } /** diff --git a/src/wp-includes/widgets/class-wp-widget-media.php b/src/wp-includes/widgets/class-wp-widget-media.php index ebca22ec66955..2352ae837b05a 100644 --- a/src/wp-includes/widgets/class-wp-widget-media.php +++ b/src/wp-includes/widgets/class-wp-widget-media.php @@ -373,7 +373,7 @@ public function display_media_state( $states, $post = null ) { $use_count = 0; foreach ( $this->get_settings() as $instance ) { if ( isset( $instance['attachment_id'] ) && $instance['attachment_id'] === $post->ID ) { - $use_count++; + ++$use_count; } } diff --git a/tests/phpunit/includes/factory/class-wp-unittest-generator-sequence.php b/tests/phpunit/includes/factory/class-wp-unittest-generator-sequence.php index 9391dd8bf7d9c..6412c15db7d8d 100644 --- a/tests/phpunit/includes/factory/class-wp-unittest-generator-sequence.php +++ b/tests/phpunit/includes/factory/class-wp-unittest-generator-sequence.php @@ -9,7 +9,7 @@ public function __construct( $template_string = '%s', $start = null ) { if ( $start ) { $this->next = $start; } else { - self::$incr++; + ++self::$incr; $this->next = self::$incr; } $this->template_string = $template_string; @@ -17,7 +17,7 @@ public function __construct( $template_string = '%s', $start = null ) { public function next() { $generated = sprintf( $this->template_string, $this->next ); - $this->next++; + ++$this->next; return $generated; } diff --git a/tests/phpunit/includes/testcase-rest-post-type-controller.php b/tests/phpunit/includes/testcase-rest-post-type-controller.php index 0fc03ef5ec621..cd8ccaefc7b14 100644 --- a/tests/phpunit/includes/testcase-rest-post-type-controller.php +++ b/tests/phpunit/includes/testcase-rest-post-type-controller.php @@ -193,7 +193,7 @@ protected function check_post_data( $post, $data, $context, $links ) { foreach ( $taxonomies as $key => $taxonomy ) { $this->assertSame( $taxonomy->name, $links['https://api.w.org/term'][ $num ]['attributes']['taxonomy'] ); $this->assertSame( add_query_arg( 'post', $data['id'], rest_url( 'wp/v2/' . $taxonomy->rest_base ) ), $links['https://api.w.org/term'][ $num ]['href'] ); - $num++; + ++$num; } } } diff --git a/tests/phpunit/includes/wp-profiler.php b/tests/phpunit/includes/wp-profiler.php index 293f85645d779..5c4ea902d095c 100644 --- a/tests/phpunit/includes/wp-profiler.php +++ b/tests/phpunit/includes/wp-profiler.php @@ -72,7 +72,7 @@ public function stop() { if ( isset( $this->profile[ $name ] ) ) { $this->profile[ $name ]['time'] += $time; - $this->profile[ $name ]['calls']++; + ++$this->profile[ $name ]['calls']; $this->profile[ $name ]['cache_cold_hits'] += ( $wp_object_cache->cold_cache_hits - $item['cache_cold_hits'] ); $this->profile[ $name ]['cache_warm_hits'] += ( $wp_object_cache->warm_cache_hits - $item['cache_warm_hits'] ); $this->profile[ $name ]['cache_misses'] += ( $wp_object_cache->cache_misses - $item['cache_misses'] ); @@ -113,9 +113,9 @@ public function log_filter( $tag ) { if ( $this->stack ) { global $wp_actions; if ( end( $wp_actions ) === $tag ) { - $this->stack[ count( $this->stack ) - 1 ]['actions'][ $tag ]++; + ++$this->stack[ count( $this->stack ) - 1 ]['actions'][ $tag ]; } else { - $this->stack[ count( $this->stack ) - 1 ]['filters'][ $tag ]++; + ++$this->stack[ count( $this->stack ) - 1 ]['filters'][ $tag ]; } } return $arg; @@ -123,7 +123,7 @@ public function log_filter( $tag ) { public function log_action( $tag ) { if ( $this->stack ) { - $this->stack[ count( $this->stack ) - 1 ]['actions'][ $tag ]++; + ++$this->stack[ count( $this->stack ) - 1 ]['actions'][ $tag ]; } } @@ -142,7 +142,7 @@ public function _query_summary( $queries, &$out ) { $sql = preg_replace( '/(WHERE \w+ =) \d+/', '$1 x', $sql ); $sql = preg_replace( '/(WHERE \w+ =) \'\[-\w]+\'/', '$1 \'xxx\'', $sql ); - $out[ $sql ]++; + ++$out[ $sql ]; } asort( $out ); return; @@ -153,9 +153,9 @@ public function _query_count( $queries ) { $out = array(); foreach ( $queries as $q ) { if ( empty( $q[2] ) ) { - $out['unknown']++; + ++$out['unknown']; } else { - $out[ $q[2] ]++; + ++$out[ $q[2] ]; } } return $out; diff --git a/tests/phpunit/tests/blocks/wpBlockList.php b/tests/phpunit/tests/blocks/wpBlockList.php index 2194bc5a98733..48b040e918f82 100644 --- a/tests/phpunit/tests/blocks/wpBlockList.php +++ b/tests/phpunit/tests/blocks/wpBlockList.php @@ -71,10 +71,10 @@ public function test_iterable() { foreach ( $blocks as $block ) { $this->assertSame( 'core/example', $block->name ); - $assertions++; + ++$assertions; foreach ( $block->inner_blocks as $inner_block ) { $this->assertSame( 'core/example', $inner_block->name ); - $assertions++; + ++$assertions; } } @@ -83,9 +83,9 @@ public function test_iterable() { $key = $blocks->key(); $block = $blocks->current(); $this->assertSame( 0, $key ); - $assertions++; + ++$assertions; $this->assertSame( 'core/example', $block->name ); - $assertions++; + ++$assertions; $blocks->next(); } diff --git a/tests/phpunit/tests/comment/metaCache.php b/tests/phpunit/tests/comment/metaCache.php index 5a6d716e914e8..828363e580544 100644 --- a/tests/phpunit/tests/comment/metaCache.php +++ b/tests/phpunit/tests/comment/metaCache.php @@ -243,7 +243,7 @@ public function test_comment_meta_should_be_lazy_loaded_in_comment_feed_queries( // First comment will cause the cache to be primed. $num_queries = get_num_queries(); $this->assertSame( 'bar', get_comment_meta( $comments[0], 'foo', 'bar' ) ); - $num_queries++; + ++$num_queries; $this->assertSame( $num_queries, get_num_queries() ); // Second comment from the results should not cause more queries. @@ -252,7 +252,7 @@ public function test_comment_meta_should_be_lazy_loaded_in_comment_feed_queries( // A comment from outside the results will not be primed. $this->assertSame( 'bar', get_comment_meta( $comments[4], 'foo', 'bar' ) ); - $num_queries++; + ++$num_queries; $this->assertSame( $num_queries, get_num_queries() ); } @@ -293,7 +293,7 @@ public function test_comment_meta_should_be_lazy_loaded_in_single_post_comment_f // First comment will cause the cache to be primed. $num_queries = get_num_queries(); $this->assertSame( 'bar', get_comment_meta( $comments[0], 'foo', 'bar' ) ); - $num_queries++; + ++$num_queries; $this->assertSame( $num_queries, get_num_queries() ); // Second comment from the results should not cause more queries. @@ -302,7 +302,7 @@ public function test_comment_meta_should_be_lazy_loaded_in_single_post_comment_f // A comment from outside the results will not be primed. $this->assertSame( 'bar', get_comment_meta( $comments[4], 'foo', 'bar' ) ); - $num_queries++; + ++$num_queries; $this->assertSame( $num_queries, get_num_queries() ); } diff --git a/tests/phpunit/tests/comment/query.php b/tests/phpunit/tests/comment/query.php index 65f9af6253e13..50cd9107960ca 100644 --- a/tests/phpunit/tests/comment/query.php +++ b/tests/phpunit/tests/comment/query.php @@ -4769,7 +4769,7 @@ public function test_updated_comment_should_invalidate_query_cache() { ) ); - $num_queries++; + ++$num_queries; $this->assertSame( $num_queries, get_num_queries() ); $this->assertSameSets( array( $c ), $q->comments ); } @@ -4805,7 +4805,7 @@ public function test_deleted_comment_should_invalidate_query_cache() { ) ); - $num_queries++; + ++$num_queries; $this->assertSame( $num_queries, get_num_queries() ); $this->assertSameSets( array(), $q->comments ); } @@ -4841,7 +4841,7 @@ public function test_trashed_comment_should_invalidate_query_cache() { ) ); - $num_queries++; + ++$num_queries; $this->assertSame( $num_queries, get_num_queries() ); $this->assertSameSets( array(), $q->comments ); } @@ -4879,7 +4879,7 @@ public function test_untrashed_comment_should_invalidate_query_cache() { ) ); - $num_queries++; + ++$num_queries; $this->assertSame( $num_queries, get_num_queries() ); $this->assertSameSets( array( $c ), $q->comments ); } @@ -4915,7 +4915,7 @@ public function test_spammed_comment_should_invalidate_query_cache() { ) ); - $num_queries++; + ++$num_queries; $this->assertSame( $num_queries, get_num_queries() ); $this->assertSameSets( array(), $q->comments ); } @@ -4953,7 +4953,7 @@ public function test_unspammed_comment_should_invalidate_query_cache() { ) ); - $num_queries++; + ++$num_queries; $this->assertSame( $num_queries, get_num_queries() ); $this->assertSameSets( array( $c ), $q->comments ); } diff --git a/tests/phpunit/tests/date/theDate.php b/tests/phpunit/tests/date/theDate.php index 2337ab61ec059..fffcb47ad5665 100644 --- a/tests/phpunit/tests/date/theDate.php +++ b/tests/phpunit/tests/date/theDate.php @@ -80,7 +80,7 @@ public function test_should_call_hooks() { } public function count_hook( $input ) { - $this->hooks_called[ current_filter() ]++; + ++$this->hooks_called[ current_filter() ]; return $input; } diff --git a/tests/phpunit/tests/feed/atom.php b/tests/phpunit/tests/feed/atom.php index 403f1152a46b2..dae234f51caf5 100644 --- a/tests/phpunit/tests/feed/atom.php +++ b/tests/phpunit/tests/feed/atom.php @@ -287,7 +287,7 @@ public function test_atom_enclosure_with_extended_url_length_type_parsing() { $this->assertSame( $enclosures[ $i ]['expected']['href'], $link['attributes']['href'] ); $this->assertEquals( $enclosures[ $i ]['expected']['length'], $link['attributes']['length'] ); $this->assertSame( $enclosures[ $i ]['expected']['type'], $link['attributes']['type'] ); - $i++; + ++$i; } } } diff --git a/tests/phpunit/tests/import/base.php b/tests/phpunit/tests/import/base.php index db83296c0afcb..d0fefb1a925ec 100644 --- a/tests/phpunit/tests/import/base.php +++ b/tests/phpunit/tests/import/base.php @@ -42,7 +42,7 @@ protected function _import_wp( $filename, $users = array(), $fetch_files = true $new[ $i ] = $map; } - $i++; + ++$i; } $_POST = array( diff --git a/tests/phpunit/tests/multisite/network.php b/tests/phpunit/tests/multisite/network.php index db1f35b6d0466..c7fb78e54778f 100644 --- a/tests/phpunit/tests/multisite/network.php +++ b/tests/phpunit/tests/multisite/network.php @@ -267,7 +267,7 @@ public function test_is_plugin_active_for_network_false() { } public function helper_deactivate_hook() { - $this->plugin_hook_count++; + ++$this->plugin_hook_count; } public function test_wp_schedule_update_network_counts() { diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php index 4b201cd912108..aa04499105464 100644 --- a/tests/phpunit/tests/multisite/site.php +++ b/tests/phpunit/tests/multisite/site.php @@ -422,7 +422,7 @@ public function test_wpmu_update_blogs_date() { public function test_get_blog_details_when_site_does_not_exist() { // Create an unused site so that we can then assume an invalid site ID. $blog_id = self::factory()->blog->create(); - $blog_id++; + ++$blog_id; // Prime the cache for an invalid site. get_blog_details( $blog_id ); diff --git a/tests/phpunit/tests/oembed/controller.php b/tests/phpunit/tests/oembed/controller.php index 238b1faf1fa49..821eeac7e3ab5 100644 --- a/tests/phpunit/tests/oembed/controller.php +++ b/tests/phpunit/tests/oembed/controller.php @@ -171,7 +171,7 @@ public function filter_oembed_result( $data, $url, $args ) { } $this->assertIsString( $url ); $this->assertIsArray( $args ); - $this->oembed_result_filter_count++; + ++$this->oembed_result_filter_count; return $data; } diff --git a/tests/phpunit/tests/pluggable/signatures.php b/tests/phpunit/tests/pluggable/signatures.php index 84a828d348307..81fd079621916 100644 --- a/tests/phpunit/tests/pluggable/signatures.php +++ b/tests/phpunit/tests/pluggable/signatures.php @@ -44,7 +44,7 @@ public function test_pluggable_function_signatures_match( $function_name ) { $this->assertSame( $name, $param_ref->getName(), $msg ); - $i++; + ++$i; } } diff --git a/tests/phpunit/tests/pomo/pluralForms.php b/tests/phpunit/tests/pomo/pluralForms.php index 0343302c689ef..439064f7c49de 100644 --- a/tests/phpunit/tests/pomo/pluralForms.php +++ b/tests/phpunit/tests/pomo/pluralForms.php @@ -21,7 +21,7 @@ protected static function parenthesize_plural_expression( $expression ) { switch ( $char ) { case '?': $res .= ' ? ('; - $depth++; + ++$depth; break; case ':': $res .= ') : ('; diff --git a/tests/phpunit/tests/post/getPageByPath.php b/tests/phpunit/tests/post/getPageByPath.php index 5d26b88d2de19..8db0274249bed 100644 --- a/tests/phpunit/tests/post/getPageByPath.php +++ b/tests/phpunit/tests/post/getPageByPath.php @@ -343,7 +343,7 @@ public function test_cache_should_not_match_post_in_different_post_type_with_sam $found = get_page_by_path( 'foo', OBJECT, 'wptests_pt' ); $this->assertSame( $p2, $found->ID ); - $num_queries++; + ++$num_queries; $this->assertSame( $num_queries, get_num_queries() ); } @@ -373,7 +373,7 @@ public function test_cache_should_be_invalidated_when_post_name_is_edited() { $found = get_page_by_path( 'bar' ); $this->assertSame( $page, $found->ID ); - $num_queries++; + ++$num_queries; $this->assertSame( $num_queries, get_num_queries() ); } diff --git a/tests/phpunit/tests/post/revisions.php b/tests/phpunit/tests/post/revisions.php index cc17ccd60d5df..8bdcb399b4a46 100644 --- a/tests/phpunit/tests/post/revisions.php +++ b/tests/phpunit/tests/post/revisions.php @@ -736,7 +736,7 @@ public function test_wp_get_post_revisions_url( $revisions ) { ) ); - $latest_revision_id++; + ++$latest_revision_id; } } @@ -784,7 +784,7 @@ public function test_wp_get_post_revisions_url_with_post_object( $revisions ) { ) ); - $latest_revision_id++; + ++$latest_revision_id; } } diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php index aca3c794f97fb..0e721258ed40a 100644 --- a/tests/phpunit/tests/rest-api/rest-attachments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-attachments-controller.php @@ -1983,11 +1983,11 @@ public function test_create_item_with_meta_values() { } public function filter_rest_insert_attachment( $attachment ) { - self::$rest_insert_attachment_count++; + ++self::$rest_insert_attachment_count; } public function filter_rest_after_insert_attachment( $attachment ) { - self::$rest_after_insert_attachment_count++; + ++self::$rest_after_insert_attachment_count; } /** diff --git a/tests/phpunit/tests/rest-api/rest-categories-controller.php b/tests/phpunit/tests/rest-api/rest-categories-controller.php index a6ad0cf7005b0..a9019f227d723 100644 --- a/tests/phpunit/tests/rest-api/rest-categories-controller.php +++ b/tests/phpunit/tests/rest-api/rest-categories-controller.php @@ -631,8 +631,8 @@ public function test_get_terms_pagination_headers() { // 3rd page. self::factory()->category->create(); - $total_categories++; - $total_pages++; + ++$total_categories; + ++$total_pages; $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); $request->set_param( 'page', 3 ); $response = rest_get_server()->dispatch( $request ); diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php index 9b4444f559554..ab8f672c5de8a 100644 --- a/tests/phpunit/tests/rest-api/rest-comments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-comments-controller.php @@ -828,8 +828,8 @@ public function test_get_comments_pagination_headers() { 'comment_post_ID' => self::$post_id, ) ); - $total_comments++; - $total_pages++; + ++$total_comments; + ++$total_pages; $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); $request->set_param( 'page', 3 ); $response = rest_get_server()->dispatch( $request ); diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index 2722cfa7349bd..92d1262195456 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -1662,8 +1662,8 @@ public function test_get_items_pagination_headers() { // 3rd page. self::factory()->post->create(); - $total_posts++; - $total_pages++; + ++$total_posts; + ++$total_pages; $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); $request->set_param( 'page', 3 ); $response = rest_get_server()->dispatch( $request ); @@ -2279,7 +2279,7 @@ public function test_prepare_item_limit_fields() { public function test_prepare_item_filters_content_when_needed() { $filter_count = 0; $filter_content = static function() use ( &$filter_count ) { - $filter_count++; + ++$filter_count; return '

Filtered content.

'; }; add_filter( 'the_content', $filter_content ); @@ -2315,7 +2315,7 @@ public function test_prepare_item_filters_content_when_needed() { public function test_prepare_item_skips_content_filter_if_not_needed() { $filter_count = 0; $filter_content = static function() use ( &$filter_count ) { - $filter_count++; + ++$filter_count; return '

Filtered content.

'; }; add_filter( 'the_content', $filter_content ); diff --git a/tests/phpunit/tests/rest-api/rest-sidebars-controller.php b/tests/phpunit/tests/rest-api/rest-sidebars-controller.php index 8dab4f6ba97f7..0bddf12df92b9 100644 --- a/tests/phpunit/tests/rest-api/rest-sidebars-controller.php +++ b/tests/phpunit/tests/rest-api/rest-sidebars-controller.php @@ -1012,7 +1012,7 @@ protected function remove_links( $data ) { if ( isset( $item['_links'] ) ) { unset( $data[ $count ]['_links'] ); } - $count++; + ++$count; } return $data; diff --git a/tests/phpunit/tests/rest-api/rest-tags-controller.php b/tests/phpunit/tests/rest-api/rest-tags-controller.php index d50bcedaaa3e3..6fb75eb93ec0e 100644 --- a/tests/phpunit/tests/rest-api/rest-tags-controller.php +++ b/tests/phpunit/tests/rest-api/rest-tags-controller.php @@ -415,7 +415,7 @@ public function test_get_terms_post_args_paging() { $i = 0; foreach ( $tags as $tag ) { $this->assertSame( $tag['name'], "Tag {$i}" ); - $i++; + ++$i; } $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); @@ -430,7 +430,7 @@ public function test_get_terms_post_args_paging() { foreach ( $tags as $tag ) { $this->assertSame( $tag['name'], "Tag {$i}" ); - $i++; + ++$i; } } @@ -599,8 +599,8 @@ public function test_get_terms_pagination_headers() { // 3rd page. self::factory()->tag->create(); - $total_tags++; - $total_pages++; + ++$total_tags; + ++$total_pages; $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); $request->set_param( 'page', 3 ); $response = rest_get_server()->dispatch( $request ); diff --git a/tests/phpunit/tests/rest-api/rest-users-controller.php b/tests/phpunit/tests/rest-api/rest-users-controller.php index 72c1f7d6e250e..f4dbc2d57f379 100644 --- a/tests/phpunit/tests/rest-api/rest-users-controller.php +++ b/tests/phpunit/tests/rest-api/rest-users-controller.php @@ -339,8 +339,8 @@ public function test_get_items_pagination_headers() { // 3rd page. self::factory()->user->create(); - $total_users++; - $total_pages++; + ++$total_users; + ++$total_pages; $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); $request->set_param( 'page', 3 ); $response = rest_get_server()->dispatch( $request ); diff --git a/tests/phpunit/tests/rest-api/rest-widgets-controller.php b/tests/phpunit/tests/rest-api/rest-widgets-controller.php index 22516737c338d..69672a722627c 100644 --- a/tests/phpunit/tests/rest-api/rest-widgets-controller.php +++ b/tests/phpunit/tests/rest-api/rest-widgets-controller.php @@ -1551,7 +1551,7 @@ protected function remove_links( $data ) { if ( is_array( $item ) && isset( $item['_links'] ) ) { unset( $data[ $count ]['_links'] ); } - $count++; + ++$count; } return $data; diff --git a/tests/phpunit/tests/rest-api/wpRestMenuItemsController.php b/tests/phpunit/tests/rest-api/wpRestMenuItemsController.php index 4687700cc798f..72dfab5f466e1 100644 --- a/tests/phpunit/tests/rest-api/wpRestMenuItemsController.php +++ b/tests/phpunit/tests/rest-api/wpRestMenuItemsController.php @@ -918,7 +918,7 @@ protected function check_menu_item_data( $post, $data, $context, $links ) { foreach ( $taxonomies as $taxonomy ) { $this->assertSame( $taxonomy->name, $links['https://api.w.org/term'][ $num ]['attributes']['taxonomy'] ); $this->assertSame( add_query_arg( 'post', $data['id'], rest_url( 'wp/v2/' . $taxonomy->rest_base ) ), $links['https://api.w.org/term'][ $num ]['href'] ); - $num++; + ++$num; } if ( 'post_type' === $data['type'] ) { diff --git a/tests/phpunit/tests/term/cache.php b/tests/phpunit/tests/term/cache.php index 8efd55da00d0c..ac418fbcfd5c0 100644 --- a/tests/phpunit/tests/term/cache.php +++ b/tests/phpunit/tests/term/cache.php @@ -73,12 +73,12 @@ public function test_hierachy_invalidation() { case 2: $parent = wp_insert_term( 'Child' . $i, $tax, array( 'parent' => $parent_id ) ); $parent_id = $parent['term_id']; - $children++; + ++$children; break; case 3: wp_insert_term( 'Grandchild' . $i, $tax, array( 'parent' => $parent_id ) ); $parent_id = 0; - $children++; + ++$children; break; } @@ -93,7 +93,7 @@ public function test_hierachy_invalidation() { if ( 0 === ( $i % 3 ) ) { $step = 1; } else { - $step++; + ++$step; } } @@ -418,7 +418,7 @@ public function test_get_term_by_does_not_prime_term_meta_cache() { $this->assertSame( $num_queries, get_num_queries() ); $term_meta = get_term_meta( $term_id, 'foo', true ); - $num_queries++; + ++$num_queries; $this->assertSame( $term_meta, 'bar' ); $this->assertSame( $num_queries, get_num_queries() ); } diff --git a/tests/phpunit/tests/term/getTerm.php b/tests/phpunit/tests/term/getTerm.php index 36567a7830884..ed6acab691fc5 100644 --- a/tests/phpunit/tests/term/getTerm.php +++ b/tests/phpunit/tests/term/getTerm.php @@ -233,7 +233,7 @@ public function test_shared_term_in_cache_should_be_ignored_when_specifying_a_di // Database should be hit again. $found = get_term( $terms[1]['term_id'], 'wptests_tax_2' ); - $num_queries++; + ++$num_queries; $this->assertSame( $num_queries, get_num_queries() ); $this->assertInstanceOf( 'WP_Term', $found ); diff --git a/tests/phpunit/tests/term/meta.php b/tests/phpunit/tests/term/meta.php index d46f35ae1dbd7..248d1909179d3 100644 --- a/tests/phpunit/tests/term/meta.php +++ b/tests/phpunit/tests/term/meta.php @@ -139,7 +139,7 @@ public function test_term_meta_should_be_lazy_loaded_for_all_terms_in_wp_query_l // First request will hit the database. $num_queries = get_num_queries(); $this->assertSame( 'bar', get_term_meta( $terms[0], 'foo', true ) ); - $num_queries++; + ++$num_queries; $this->assertSame( $num_queries, get_num_queries() ); // Second and third requests should be in cache. @@ -148,7 +148,7 @@ public function test_term_meta_should_be_lazy_loaded_for_all_terms_in_wp_query_l $this->assertSame( $num_queries, get_num_queries() ); // Querying a term not primed should result in a hit. - $num_queries++; + ++$num_queries; $this->assertSame( 'bar', get_term_meta( $orphan_term, 'foo', true ) ); $this->assertSame( $num_queries, get_num_queries() ); } @@ -208,11 +208,11 @@ public function test_lazy_load_term_meta_false() { // Requests will hit the database. $num_queries = get_num_queries(); $this->assertSame( 'bar', get_term_meta( $terms[0], 'foo', true ) ); - $num_queries++; + ++$num_queries; $this->assertSame( $num_queries, get_num_queries() ); $this->assertSame( 'bar', get_term_meta( $terms[1], 'foo', true ) ); - $num_queries++; + ++$num_queries; $this->assertSame( $num_queries, get_num_queries() ); } } diff --git a/tests/phpunit/tests/theme/wpThemeJsonResolver.php b/tests/phpunit/tests/theme/wpThemeJsonResolver.php index d75ff476b3e30..98f67fea5da4f 100644 --- a/tests/phpunit/tests/theme/wpThemeJsonResolver.php +++ b/tests/phpunit/tests/theme/wpThemeJsonResolver.php @@ -393,7 +393,7 @@ public function test_get_core_data( $should_fire_filter, $core_is_cached, $block $expected_filter_count = did_filter( 'wp_theme_json_data_default' ); $actual = WP_Theme_JSON_Resolver::get_core_data(); if ( $should_fire_filter ) { - $expected_filter_count++; + ++$expected_filter_count; } $this->assertSame( $expected_filter_count, did_filter( 'wp_theme_json_data_default' ), 'The filter "wp_theme_json_data_default" should fire the given number of times' ); diff --git a/tests/phpunit/tests/url.php b/tests/phpunit/tests/url.php index 1561d3a03cccc..4768e25b7770a 100644 --- a/tests/phpunit/tests/url.php +++ b/tests/phpunit/tests/url.php @@ -339,7 +339,7 @@ public function test_set_url_scheme() { $this->assertSame( $http_links[ $i ], set_url_scheme( $link, 'login' ) ); $this->assertSame( $http_links[ $i ], set_url_scheme( $link, 'rpc' ) ); - $i++; + ++$i; } force_ssl_admin( $forced_admin ); diff --git a/tests/phpunit/tests/widgets/wpWidgetText.php b/tests/phpunit/tests/widgets/wpWidgetText.php index cccdcbe957c74..a1570da63a550 100644 --- a/tests/phpunit/tests/widgets/wpWidgetText.php +++ b/tests/phpunit/tests/widgets/wpWidgetText.php @@ -303,7 +303,7 @@ public function test_widget() { */ public function do_example_shortcode() { $this->post_during_shortcode = get_post(); - $this->shortcode_render_count++; + ++$this->shortcode_render_count; return $this->example_shortcode_content; } From 2a13d9321c48a3f55aebc5682e944812b969aee8 Mon Sep 17 00:00:00 2001 From: Colin Stewart Date: Sun, 10 Sep 2023 07:31:47 +0000 Subject: [PATCH 061/105] Upgrade/Install: Fix broken `sprintf()` call when deleting a backup. In `WP_Upgrader::delete_temp_backup()`, a malformed `sprintf()` call did not pass the value, triggering a Warning in PHP 7 and a Fatal Error in PHP 8. This fixes the malformed `sprintf()` call by correctly passing the value. Follow-up to [55720]. Props akihiroharai, afragen. Fixes #59320. git-svn-id: https://develop.svn.wordpress.org/trunk@56550 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/class-wp-upgrader.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wp-admin/includes/class-wp-upgrader.php b/src/wp-admin/includes/class-wp-upgrader.php index 69ba518328c1c..1fbfa99e4cf45 100644 --- a/src/wp-admin/includes/class-wp-upgrader.php +++ b/src/wp-admin/includes/class-wp-upgrader.php @@ -1207,8 +1207,7 @@ public function delete_temp_backup() { if ( ! $wp_filesystem->delete( $temp_backup_dir, true ) ) { $errors->add( 'temp_backup_delete_failed', - sprintf( $this->strings['temp_backup_delete_failed'] ), - $args['slug'] + sprintf( $this->strings['temp_backup_delete_failed'], $args['slug'] ) ); continue; } From 858bd4b25f0ac021e64b2543cc990f9f9f1e5cb0 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 10 Sep 2023 09:02:49 +0000 Subject: [PATCH 062/105] Coding Standards: Correct spacing for spread operators. No space allowed between the operator and the variable it applies to. Note: This is enforced by WPCS 3.0.0. Follow-up to [46133]. Props jrf. See #59161, #58831. git-svn-id: https://develop.svn.wordpress.org/trunk@56551 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-customize-panel.php | 2 +- src/wp-includes/class-wp-customize-section.php | 2 +- src/wp-includes/class-wp-customize-setting.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/class-wp-customize-panel.php b/src/wp-includes/class-wp-customize-panel.php index f880afa8fe4a6..95b7aed468814 100644 --- a/src/wp-includes/class-wp-customize-panel.php +++ b/src/wp-includes/class-wp-customize-panel.php @@ -242,7 +242,7 @@ public function check_capabilities() { return false; } - if ( $this->theme_supports && ! current_theme_supports( ... (array) $this->theme_supports ) ) { + if ( $this->theme_supports && ! current_theme_supports( ...(array) $this->theme_supports ) ) { return false; } diff --git a/src/wp-includes/class-wp-customize-section.php b/src/wp-includes/class-wp-customize-section.php index 65dbe00961dd5..4e58e7d43e64d 100644 --- a/src/wp-includes/class-wp-customize-section.php +++ b/src/wp-includes/class-wp-customize-section.php @@ -264,7 +264,7 @@ final public function check_capabilities() { return false; } - if ( $this->theme_supports && ! current_theme_supports( ... (array) $this->theme_supports ) ) { + if ( $this->theme_supports && ! current_theme_supports( ...(array) $this->theme_supports ) ) { return false; } diff --git a/src/wp-includes/class-wp-customize-setting.php b/src/wp-includes/class-wp-customize-setting.php index 33b9436f859f6..99d0d2e51f199 100644 --- a/src/wp-includes/class-wp-customize-setting.php +++ b/src/wp-includes/class-wp-customize-setting.php @@ -836,7 +836,7 @@ final public function check_capabilities() { return false; } - if ( $this->theme_supports && ! current_theme_supports( ... (array) $this->theme_supports ) ) { + if ( $this->theme_supports && ! current_theme_supports( ...(array) $this->theme_supports ) ) { return false; } From aeba9d183d1b13616ac62e86e7ba310723ee6320 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 11 Sep 2023 04:51:09 +0000 Subject: [PATCH 063/105] Code Modernization: Use `dirname()` with the `$levels` parameter. PHP 7.0 introduced the `$levels` parameter to the `dirname()` function, which means nested calls to `dirname()` are no longer needed. Note: This is enforced by WPCS 3.0.0. Reference: [https://www.php.net/manual/en/function.dirname.php PHP Manual: dirname()]. Follow-up to [56141]. Props jrf. See #59161, #58831. git-svn-id: https://develop.svn.wordpress.org/trunk@56552 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/theme.php | 2 +- src/wp-admin/maint/repair.php | 2 +- tests/phpunit/includes/bootstrap.php | 4 ++-- tests/phpunit/tests/filesystem/base.php | 2 +- tests/phpunit/tests/pomo/pluralForms.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php index d98cb5de33dd3..b0b3c6d768e79 100644 --- a/src/wp-admin/includes/theme.php +++ b/src/wp-admin/includes/theme.php @@ -156,7 +156,7 @@ function get_page_templates( $post = null, $post_type = 'page' ) { * @return string */ function _get_template_edit_filename( $fullpath, $containingfolder ) { - return str_replace( dirname( dirname( $containingfolder ) ), '', $fullpath ); + return str_replace( dirname( $containingfolder, 2 ), '', $fullpath ); } /** diff --git a/src/wp-admin/maint/repair.php b/src/wp-admin/maint/repair.php index 554e466d76f3e..1c0f6ffa985eb 100644 --- a/src/wp-admin/maint/repair.php +++ b/src/wp-admin/maint/repair.php @@ -7,7 +7,7 @@ */ define( 'WP_REPAIRING', true ); -require_once dirname( dirname( __DIR__ ) ) . '/wp-load.php'; +require_once dirname( __DIR__, 2 ) . '/wp-load.php'; header( 'Content-Type: text/html; charset=utf-8' ); ?> diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index 43ba0b0c493b5..15ec06b081440 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -10,7 +10,7 @@ if ( ! file_exists( $config_file_path . '/wp-tests-config.php' ) ) { // Support the config file from the root of the develop repository. if ( basename( $config_file_path ) === 'phpunit' && basename( dirname( $config_file_path ) ) === 'tests' ) { - $config_file_path = dirname( dirname( $config_file_path ) ); + $config_file_path = dirname( $config_file_path, 2 ); } } $config_file_path .= '/wp-tests-config.php'; @@ -79,7 +79,7 @@ */ if ( ! class_exists( 'Yoast\PHPUnitPolyfills\Autoload' ) ) { // Default location of the autoloader for WP core test runs. - $phpunit_polyfills_autoloader = dirname( dirname( dirname( __DIR__ ) ) ) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php'; + $phpunit_polyfills_autoloader = dirname( __DIR__, 3 ) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php'; $phpunit_polyfills_error = false; // Allow for a custom installation location to be provided for plugin/theme integration tests. diff --git a/tests/phpunit/tests/filesystem/base.php b/tests/phpunit/tests/filesystem/base.php index 52ab59e3cdf6e..ceefeafa3e5c7 100644 --- a/tests/phpunit/tests/filesystem/base.php +++ b/tests/phpunit/tests/filesystem/base.php @@ -24,7 +24,7 @@ public function filter_fs_method( $method ) { return 'MockFS'; } public function filter_abstraction_file( $file ) { - return dirname( dirname( __DIR__ ) ) . '/includes/mock-fs.php'; + return dirname( __DIR__, 2 ) . '/includes/mock-fs.php'; } public function test_is_MockFS_sane() { diff --git a/tests/phpunit/tests/pomo/pluralForms.php b/tests/phpunit/tests/pomo/pluralForms.php index 439064f7c49de..b676735c59bac 100644 --- a/tests/phpunit/tests/pomo/pluralForms.php +++ b/tests/phpunit/tests/pomo/pluralForms.php @@ -43,7 +43,7 @@ protected static function parenthesize_plural_expression( $expression ) { * @group external-http */ public function test_regression( $lang, $nplurals, $expression ) { - require_once dirname( dirname( __DIR__ ) ) . '/includes/plural-form-function.php'; + require_once dirname( __DIR__, 2 ) . '/includes/plural-form-function.php'; $parenthesized = self::parenthesize_plural_expression( $expression ); $old_style = tests_make_plural_form_function( $nplurals, $parenthesized ); From 2453a6b57d9bfeb0a5a5d191044b42d24955995b Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Mon, 11 Sep 2023 05:25:41 +0000 Subject: [PATCH 064/105] Cron: Cast `doing_cron` transient to a float. Cast the `doing_cron` transient value to a float to prevent type errors if the transient is not set (in which case it returns `false`) or another unexpected type. Props fzhantw, ankitmaru. Fixes #58471. git-svn-id: https://develop.svn.wordpress.org/trunk@56553 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/cron.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/cron.php b/src/wp-includes/cron.php index c3a281a626dd5..4912d5f5035c8 100644 --- a/src/wp-includes/cron.php +++ b/src/wp-includes/cron.php @@ -863,7 +863,7 @@ function spawn_cron( $gmt_time = 0 ) { * Multiple processes on multiple web servers can run this code concurrently, * this lock attempts to make spawning as atomic as possible. */ - $lock = get_transient( 'doing_cron' ); + $lock = (float) get_transient( 'doing_cron' ); if ( $lock > $gmt_time + 10 * MINUTE_IN_SECONDS ) { $lock = 0; From 46c1f6fcf4b823d6563638ff72d4a48b081f34e9 Mon Sep 17 00:00:00 2001 From: Colin Stewart Date: Mon, 11 Sep 2023 10:31:22 +0000 Subject: [PATCH 065/105] External Libraries: Update the Requests library to version 2.0.8. This is a maintenance release with minor changes: - Only force close cURL connection when needed (cURL < 7.22). References: - [https://github.com/WordPress/Requests/releases/tag/v2.0.8 Requests 2.0.8 release notes] - [https://github.com/WordPress/Requests/compare/v2.0.6...v2.0.8 Full list of changes in Requests 2.0.8] Follow-up to [54997], [55007], [55046], [55225], [55296], [55629]. Props jrf, mukesh27, spacedmonkey, costdev. Fixes #59322. git-svn-id: https://develop.svn.wordpress.org/trunk@56554 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/Requests/src/Requests.php | 2 +- src/wp-includes/Requests/src/Transport/Curl.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/Requests/src/Requests.php b/src/wp-includes/Requests/src/Requests.php index 287bacaaa575b..edf37f2214983 100644 --- a/src/wp-includes/Requests/src/Requests.php +++ b/src/wp-includes/Requests/src/Requests.php @@ -148,7 +148,7 @@ class Requests { * * @var string */ - const VERSION = '2.0.6'; + const VERSION = '2.0.8'; /** * Selected transport name diff --git a/src/wp-includes/Requests/src/Transport/Curl.php b/src/wp-includes/Requests/src/Transport/Curl.php index 7316987b5faed..29034b25d5358 100644 --- a/src/wp-includes/Requests/src/Transport/Curl.php +++ b/src/wp-includes/Requests/src/Transport/Curl.php @@ -25,6 +25,7 @@ final class Curl implements Transport { const CURL_7_10_5 = 0x070A05; const CURL_7_16_2 = 0x071002; + const CURL_7_22_0 = 0x071600; /** * Raw HTTP data @@ -363,7 +364,7 @@ private function setup_handle($url, $headers, $data, $options) { $options['hooks']->dispatch('curl.before_request', [&$this->handle]); // Force closing the connection for old versions of cURL (<7.22). - if (!isset($headers['Connection'])) { + if ($this->version < self::CURL_7_22_0 && !isset($headers['Connection'])) { $headers['Connection'] = 'close'; } From 827a560adef5e5f1d9fea1788b58aab9c4752a10 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Mon, 11 Sep 2023 11:35:59 +0000 Subject: [PATCH 066/105] Taxonomy: Cache term objects in WP_Term_Query if query is filtered. When utilizing the `terms_clauses` or `get_terms_fields` filters within `WP_Term_Query` and the selected fields are modified, the entire term object is now cached. This adjustment is necessary because filters can broaden the selected fields beyond just the term ID. Fields linked to the term object, such as the count or parent, may undergo modifications when queried. Caching the complete object ensures the accurate storage of these modified fields within the cache. Props spacedmonkey, tnolte, peterwilsoncc. Fixes #58116. git-svn-id: https://develop.svn.wordpress.org/trunk@56555 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-term-query.php | 6 +- tests/phpunit/tests/term/query.php | 100 ++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-term-query.php b/src/wp-includes/class-wp-term-query.php index d1cc69d96ca49..65b35289a9a21 100644 --- a/src/wp-includes/class-wp-term-query.php +++ b/src/wp-includes/class-wp-term-query.php @@ -738,6 +738,8 @@ public function get_terms() { $order = isset( $clauses['order'] ) ? $clauses['order'] : ''; $limits = isset( $clauses['limits'] ) ? $clauses['limits'] : ''; + $fields_is_filtered = implode( ', ', $selects ) !== $fields; + if ( $where ) { $where = "WHERE $where"; } @@ -782,7 +784,7 @@ public function get_terms() { $cache = array_map( 'intval', $cache ); } elseif ( 'count' !== $_fields ) { if ( ( 'all_with_object_id' === $_fields && ! empty( $args['object_ids'] ) ) - || ( 'all' === $_fields && $args['pad_counts'] ) + || ( 'all' === $_fields && $args['pad_counts'] || $fields_is_filtered ) ) { $term_ids = wp_list_pluck( $cache, 'term_id' ); } else { @@ -884,6 +886,8 @@ public function get_terms() { $object->count = $term->count; $term_cache[] = $object; } + } elseif ( $fields_is_filtered ) { + $term_cache = $term_objects; } else { $term_cache = wp_list_pluck( $term_objects, 'term_id' ); } diff --git a/tests/phpunit/tests/term/query.php b/tests/phpunit/tests/term/query.php index 0e118a3c169a4..682e86a8dfced 100644 --- a/tests/phpunit/tests/term/query.php +++ b/tests/phpunit/tests/term/query.php @@ -698,6 +698,106 @@ public function test_query_should_return_zero_for_field_as_count_and_child_of_se $this->assertSame( 0, $q->query( $args ) ); } + /** + * If fields have filtered, cached results should work. + * + * @ticket 58116 + * @group cache + */ + public function test_query_filter_fields() { + $post_id = self::factory()->post->create(); + register_taxonomy( 'wptests_tax', 'post' ); + + $term_id = self::factory()->term->create( + array( + 'taxonomy' => 'wptests_tax', + ) + ); + wp_set_object_terms( $post_id, array( $term_id ), 'wptests_tax' ); + $post_draft_id = self::factory()->post->create( array( 'post_type' => 'draft' ) ); + wp_set_object_terms( $post_draft_id, array( $term_id ), 'wptests_tax' ); + + add_filter( 'terms_clauses', array( $this, 'filter_fields_terms_clauses' ), 10, 3 ); + + $args = array( + 'taxonomy' => 'wptests_tax', + 'hide_empty' => false, + 'post_type' => 'post', + 'post_status' => 'publish', + ); + + $q1 = new WP_Term_Query(); + $terms1 = $q1->query( $args ); + $q2 = new WP_Term_Query(); + $terms2 = $q2->query( $args ); + $this->assertSameSets( wp_list_pluck( $terms1, 'term_id' ), wp_list_pluck( $terms2, 'term_id' ), 'Term IDs are expected to match' ); + $this->assertSameSets( wp_list_pluck( $terms1, 'count' ), wp_list_pluck( $terms2, 'count' ), 'Term counts are expected to match' ); + } + + /** + * Filter `terms_clauses` to change the field requested. The filter is from example code given in #58116. + */ + public function filter_fields_terms_clauses( $clauses, $taxonomies, $args ) { + global $wpdb; + + // Set to query specific posts types if set. + if ( ! empty( $args['post_type'] ) ) { + $clauses['fields'] = 'DISTINCT t.term_id, tt.term_taxonomy_id, tt.taxonomy, tt.description, tt.parent, COUNT(p.post_type) AS count'; + $clauses['join'] .= ' LEFT JOIN ' . $wpdb->term_relationships . ' AS r ON r.term_taxonomy_id = tt.term_taxonomy_id LEFT JOIN ' . $wpdb->posts . ' AS p ON p.ID = r.object_id'; + $clauses['where'] .= " AND (p.post_type = '" . $args['post_type'] . "' OR p.post_type IS NULL)"; + $clauses['orderby'] = 'GROUP BY t.term_id ' . $clauses['orderby']; + } + + // Set to query posts with specific status. + if ( ! empty( $args['post_status'] ) ) { + $clauses['where'] .= " AND (p.post_status = '" . $args['post_status'] . "')"; + } + return $clauses; + } + + /** + * If fields have filtered, cached results should work. + * + * @ticket 58116 + * @group cache + */ + public function test_query_filter_select_fields() { + $post_id = self::factory()->post->create(); + register_taxonomy( 'wptests_tax', 'post' ); + + $term_id = self::factory()->term->create( + array( + 'taxonomy' => 'wptests_tax', + ) + ); + wp_set_object_terms( $post_id, array( $term_id ), 'wptests_tax' ); + $post_draft_id = self::factory()->post->create( array( 'post_type' => 'draft' ) ); + wp_set_object_terms( $post_draft_id, array( $term_id ), 'wptests_tax' ); + + add_filter( 'get_terms_fields', array( $this, 'filter_get_terms_fields' ) ); + + $args = array( + 'taxonomy' => 'wptests_tax', + 'hide_empty' => false, + 'post_type' => 'post', + 'post_status' => 'publish', + ); + + $q1 = new WP_Term_Query(); + $terms1 = $q1->query( $args ); + $q2 = new WP_Term_Query(); + $terms2 = $q2->query( $args ); + $this->assertSameSets( wp_list_pluck( $terms1, 'term_id' ), wp_list_pluck( $terms2, 'term_id' ), 'Term IDs are expected to match' ); + $this->assertSameSets( wp_list_pluck( $terms1, 'parent' ), wp_list_pluck( $terms2, 'parent' ), 'Term parent are expected to match' ); + } + + /** + * Filter `get_terms_fields` to change the field requested. + */ + public function filter_get_terms_fields( $select ) { + return array( 't.term_id', 'tt.parent' ); + } + /** * The terms property should be an empty array for fields not as count and parent set. * From cc775b9985b1dd9a0c8827df378b21e831b400a1 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 12 Sep 2023 00:04:15 +0000 Subject: [PATCH 067/105] Bundled Themes: Use `defer` loading strategy for theme scripts. * Add `defer` loading strategy for all frontend end-user theme scripts (excluding Customizer preview). * Move scripts to the `head` which relate to the initial page viewport to ensure they start loading earlier and execute sooner while still not blocking rendering. * Update Twenty Twenty's script loader (`TwentyTwenty_Script_Loader`) to support core's built-in script loading strategies (#12009), while also retaining backwards-compatibility for child themes that may set `async` and `defer` script data. * Update the main script loading strategy in Twenty Twenty from `async` to `defer` for better performance on repeat page views, since when an `async` script is cached it will block rendering. Props westonruter, flixos90, sabernhardt. Fixes #59316. git-svn-id: https://develop.svn.wordpress.org/trunk@56556 602fd350-edb4-49c9-b593-d223f7449a82 --- .../themes/twentyeleven/showcase.php | 11 +++++- .../themes/twentyfifteen/functions.php | 11 +++++- .../themes/twentyfourteen/functions.php | 22 ++++++++++- .../themes/twentynineteen/functions.php | 22 ++++++++++- .../themes/twentyseventeen/functions.php | 33 ++++++++++++++-- .../themes/twentysixteen/functions.php | 11 +++++- .../themes/twentythirteen/functions.php | 11 +++++- .../themes/twentytwelve/functions.php | 11 +++++- .../class-twentytwenty-script-loader.php | 39 ++++++++++++++++--- .../themes/twentytwenty/functions.php | 18 +++++++-- .../themes/twentytwentyone/functions.php | 5 ++- 11 files changed, 173 insertions(+), 21 deletions(-) diff --git a/src/wp-content/themes/twentyeleven/showcase.php b/src/wp-content/themes/twentyeleven/showcase.php index 0821040f76d99..a46fed329cd69 100644 --- a/src/wp-content/themes/twentyeleven/showcase.php +++ b/src/wp-content/themes/twentyeleven/showcase.php @@ -16,7 +16,16 @@ */ // Enqueue showcase script for the slider. -wp_enqueue_script( 'twentyeleven-showcase', get_template_directory_uri() . '/js/showcase.js', array( 'jquery' ), '20211130' ); +wp_enqueue_script( + 'twentyeleven-showcase', + get_template_directory_uri() . '/js/showcase.js', + array( 'jquery' ), + '20211130', + array( + 'in_footer' => false, // Because involves header. + 'strategy' => 'defer', + ) +); get_header(); ?> diff --git a/src/wp-content/themes/twentyfifteen/functions.php b/src/wp-content/themes/twentyfifteen/functions.php index 1132cff2dd58a..2b9cc816f80cf 100644 --- a/src/wp-content/themes/twentyfifteen/functions.php +++ b/src/wp-content/themes/twentyfifteen/functions.php @@ -454,7 +454,16 @@ function twentyfifteen_scripts() { wp_enqueue_script( 'twentyfifteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20141210' ); } - wp_enqueue_script( 'twentyfifteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20221101', array( 'in_footer' => true ) ); + wp_enqueue_script( + 'twentyfifteen-script', + get_template_directory_uri() . '/js/functions.js', + array( 'jquery' ), + '20221101', + array( + 'in_footer' => false, // Because involves header. + 'strategy' => 'defer', + ) + ); wp_localize_script( 'twentyfifteen-script', 'screenReaderText', diff --git a/src/wp-content/themes/twentyfourteen/functions.php b/src/wp-content/themes/twentyfourteen/functions.php index 6267c95f2ebab..d9688e0b87be5 100644 --- a/src/wp-content/themes/twentyfourteen/functions.php +++ b/src/wp-content/themes/twentyfourteen/functions.php @@ -367,7 +367,16 @@ function twentyfourteen_scripts() { } if ( is_front_page() && 'slider' === get_theme_mod( 'featured_content_layout' ) ) { - wp_enqueue_script( 'twentyfourteen-slider', get_template_directory_uri() . '/js/slider.js', array( 'jquery' ), '20150120', array( 'in_footer' => true ) ); + wp_enqueue_script( + 'twentyfourteen-slider', + get_template_directory_uri() . '/js/slider.js', + array( 'jquery' ), + '20150120', + array( + 'in_footer' => false, // Because involves header. + 'strategy' => 'defer', + ) + ); wp_localize_script( 'twentyfourteen-slider', 'featuredSliderDefaults', @@ -378,7 +387,16 @@ function twentyfourteen_scripts() { ); } - wp_enqueue_script( 'twentyfourteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20230526', array( 'in_footer' => true ) ); + wp_enqueue_script( + 'twentyfourteen-script', + get_template_directory_uri() . '/js/functions.js', + array( 'jquery' ), + '20230526', + array( + 'in_footer' => false, // Because involves header. + 'strategy' => 'defer', + ) + ); } add_action( 'wp_enqueue_scripts', 'twentyfourteen_scripts' ); diff --git a/src/wp-content/themes/twentynineteen/functions.php b/src/wp-content/themes/twentynineteen/functions.php index f53b3a2053f0b..33ce770581ba3 100644 --- a/src/wp-content/themes/twentynineteen/functions.php +++ b/src/wp-content/themes/twentynineteen/functions.php @@ -258,8 +258,26 @@ function twentynineteen_scripts() { wp_style_add_data( 'twentynineteen-style', 'rtl', 'replace' ); if ( has_nav_menu( 'menu-1' ) ) { - wp_enqueue_script( 'twentynineteen-priority-menu', get_theme_file_uri( '/js/priority-menu.js' ), array(), '20200129', array( 'in_footer' => true ) ); - wp_enqueue_script( 'twentynineteen-touch-navigation', get_theme_file_uri( '/js/touch-keyboard-navigation.js' ), array(), '20230621', array( 'in_footer' => true ) ); + wp_enqueue_script( + 'twentynineteen-priority-menu', + get_theme_file_uri( '/js/priority-menu.js' ), + array(), + '20200129', + array( + 'in_footer' => false, // Because involves header. + 'strategy' => 'defer', + ) + ); + wp_enqueue_script( + 'twentynineteen-touch-navigation', + get_theme_file_uri( '/js/touch-keyboard-navigation.js' ), + array(), + '20230621', + array( + 'in_footer' => true, + 'strategy' => 'defer', + ) + ); } wp_enqueue_style( 'twentynineteen-print-style', get_template_directory_uri() . '/print.css', array(), wp_get_theme()->get( 'Version' ), 'print' ); diff --git a/src/wp-content/themes/twentyseventeen/functions.php b/src/wp-content/themes/twentyseventeen/functions.php index 26a7a1a3c07e8..0afafbb8e8a13 100644 --- a/src/wp-content/themes/twentyseventeen/functions.php +++ b/src/wp-content/themes/twentyseventeen/functions.php @@ -479,14 +479,32 @@ function twentyseventeen_scripts() { // Skip-link fix is no longer enqueued by default. wp_register_script( 'twentyseventeen-skip-link-focus-fix', get_theme_file_uri( '/assets/js/skip-link-focus-fix.js' ), array(), '20161114', array( 'in_footer' => true ) ); - wp_enqueue_script( 'twentyseventeen-global', get_theme_file_uri( '/assets/js/global.js' ), array( 'jquery' ), '20211130', array( 'in_footer' => true ) ); + wp_enqueue_script( + 'twentyseventeen-global', + get_theme_file_uri( '/assets/js/global.js' ), + array( 'jquery' ), + '20211130', + array( + 'in_footer' => false, // Because involves header. + 'strategy' => 'defer', + ) + ); $twentyseventeen_l10n = array( 'quote' => twentyseventeen_get_svg( array( 'icon' => 'quote-right' ) ), ); if ( has_nav_menu( 'top' ) ) { - wp_enqueue_script( 'twentyseventeen-navigation', get_theme_file_uri( '/assets/js/navigation.js' ), array( 'jquery' ), '20210122', array( 'in_footer' => true ) ); + wp_enqueue_script( + 'twentyseventeen-navigation', + get_theme_file_uri( '/assets/js/navigation.js' ), + array( 'jquery' ), + '20210122', + array( + 'in_footer' => false, // Because involves header. + 'strategy' => 'defer', + ) + ); $twentyseventeen_l10n['expand'] = __( 'Expand child menu', 'twentyseventeen' ); $twentyseventeen_l10n['collapse'] = __( 'Collapse child menu', 'twentyseventeen' ); $twentyseventeen_l10n['icon'] = twentyseventeen_get_svg( @@ -499,7 +517,16 @@ function twentyseventeen_scripts() { wp_localize_script( 'twentyseventeen-global', 'twentyseventeenScreenReaderText', $twentyseventeen_l10n ); - wp_enqueue_script( 'jquery-scrollto', get_theme_file_uri( '/assets/js/jquery.scrollTo.js' ), array( 'jquery' ), '2.1.3', array( 'in_footer' => true ) ); + wp_enqueue_script( + 'jquery-scrollto', + get_theme_file_uri( '/assets/js/jquery.scrollTo.js' ), + array( 'jquery' ), + '2.1.3', + array( + 'in_footer' => true, + 'strategy' => 'defer', + ) + ); if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); diff --git a/src/wp-content/themes/twentysixteen/functions.php b/src/wp-content/themes/twentysixteen/functions.php index 0c4c9237ee002..80b5cb525a6fe 100644 --- a/src/wp-content/themes/twentysixteen/functions.php +++ b/src/wp-content/themes/twentysixteen/functions.php @@ -423,7 +423,16 @@ function twentysixteen_scripts() { wp_enqueue_script( 'twentysixteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20170530' ); } - wp_enqueue_script( 'twentysixteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20230629', array( 'in_footer' => true ) ); + wp_enqueue_script( + 'twentysixteen-script', + get_template_directory_uri() . '/js/functions.js', + array( 'jquery' ), + '20230629', + array( + 'in_footer' => false, // Because involves header. + 'strategy' => 'defer', + ) + ); wp_localize_script( 'twentysixteen-script', diff --git a/src/wp-content/themes/twentythirteen/functions.php b/src/wp-content/themes/twentythirteen/functions.php index 5ccf92453622f..92651857044f2 100644 --- a/src/wp-content/themes/twentythirteen/functions.php +++ b/src/wp-content/themes/twentythirteen/functions.php @@ -321,7 +321,16 @@ function twentythirteen_scripts_styles() { } // Loads JavaScript file with functionality specific to Twenty Thirteen. - wp_enqueue_script( 'twentythirteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20230526', array( 'in_footer' => true ) ); + wp_enqueue_script( + 'twentythirteen-script', + get_template_directory_uri() . '/js/functions.js', + array( 'jquery' ), + '20230526', + array( + 'in_footer' => false, // Because involves header. + 'strategy' => 'defer', + ) + ); // Add Source Sans Pro and Bitter fonts, used in the main stylesheet. $font_version = ( 0 === strpos( (string) twentythirteen_fonts_url(), get_template_directory_uri() . '/' ) ) ? '20230328' : null; diff --git a/src/wp-content/themes/twentytwelve/functions.php b/src/wp-content/themes/twentytwelve/functions.php index 0d7c4825e23ca..6f8de15a89a4d 100644 --- a/src/wp-content/themes/twentytwelve/functions.php +++ b/src/wp-content/themes/twentytwelve/functions.php @@ -188,7 +188,16 @@ function twentytwelve_scripts_styles() { } // Adds JavaScript for handling the navigation menu hide-and-show behavior. - wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20141205', array( 'in_footer' => true ) ); + wp_enqueue_script( + 'twentytwelve-navigation', + get_template_directory_uri() . '/js/navigation.js', + array( 'jquery' ), + '20141205', + array( + 'in_footer' => false, // Because involves header. + 'strategy' => 'defer', + ) + ); $font_url = twentytwelve_get_font_url(); if ( ! empty( $font_url ) ) { diff --git a/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-script-loader.php b/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-script-loader.php index f57811614b15e..086d53ed2c287 100644 --- a/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-script-loader.php +++ b/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-script-loader.php @@ -19,10 +19,32 @@ */ class TwentyTwenty_Script_Loader { + /** + * Migrates legacy async/defer script data which might be used by child themes. + * + * This method is used on the `print_scripts_array` filter. + * + * @since Twenty Twenty 2.0 + * + * @param string[] $to_do An array of script dependency handles. + * @return string[] Unchanged array of script dependency handles. + */ + public function migrate_legacy_strategy_script_data( $to_do ) { + foreach ( $to_do as $handle ) { + foreach ( array( 'async', 'defer' ) as $strategy ) { + if ( wp_scripts()->get_data( $handle, $strategy ) ) { + wp_script_add_data( $handle, 'strategy', $strategy ); + } + } + } + return $to_do; + } + /** * Adds async/defer attributes to enqueued / registered scripts. * - * If #12009 lands in WordPress, this function can no-op since it would be handled in core. + * Now that #12009 has landed in WordPress 6.3, this method is only used for older versions of WordPress. + * This method is used on the `script_loader_tag` filter. * * @since Twenty Twenty 1.0 * @@ -33,10 +55,17 @@ class TwentyTwenty_Script_Loader { * @return string Script HTML string. */ public function filter_script_loader_tag( $tag, $handle ) { - foreach ( array( 'async', 'defer' ) as $attr ) { - if ( ! wp_scripts()->get_data( $handle, $attr ) ) { - continue; - } + $strategies = array( + 'async' => (bool) wp_scripts()->get_data( $handle, 'async' ), + 'defer' => (bool) wp_scripts()->get_data( $handle, 'defer' ), + ); + $strategy = wp_scripts()->get_data( $handle, 'strategy' ); + if ( $strategy && isset( $strategies[ $strategy ] ) ) { + $strategies[ $strategy ] = true; + } + + foreach ( array_keys( array_filter( $strategies ) ) as $attr ) { + // Prevent adding attribute when already added in #12009. if ( ! preg_match( ":\s$attr(=|>|\s):", $tag ) ) { $tag = preg_replace( ':(?=>):', " $attr", $tag, 1 ); diff --git a/src/wp-content/themes/twentytwenty/functions.php b/src/wp-content/themes/twentytwenty/functions.php index fc2b0dddbfeca..1ca2e4318a53a 100644 --- a/src/wp-content/themes/twentytwenty/functions.php +++ b/src/wp-content/themes/twentytwenty/functions.php @@ -135,7 +135,11 @@ function twentytwenty_theme_support() { * by the theme. */ $loader = new TwentyTwenty_Script_Loader(); - add_filter( 'script_loader_tag', array( $loader, 'filter_script_loader_tag' ), 10, 2 ); + if ( version_compare( $GLOBALS['wp_version'], '6.3', '<' ) ) { + add_filter( 'script_loader_tag', array( $loader, 'filter_script_loader_tag' ), 10, 2 ); + } else { + add_filter( 'print_scripts_array', array( $loader, 'migrate_legacy_strategy_script_data' ), 100 ); + } } add_action( 'after_setup_theme', 'twentytwenty_theme_support' ); @@ -211,8 +215,16 @@ function twentytwenty_register_scripts() { wp_enqueue_script( 'comment-reply' ); } - wp_enqueue_script( 'twentytwenty-js', get_template_directory_uri() . '/assets/js/index.js', array(), $theme_version ); - wp_script_add_data( 'twentytwenty-js', 'async', true ); + wp_enqueue_script( + 'twentytwenty-js', + get_template_directory_uri() . '/assets/js/index.js', + array(), + $theme_version, + array( + 'in_footer' => false, // Because involves header. + 'strategy' => 'defer', + ) + ); } add_action( 'wp_enqueue_scripts', 'twentytwenty_register_scripts' ); diff --git a/src/wp-content/themes/twentytwentyone/functions.php b/src/wp-content/themes/twentytwentyone/functions.php index bdbaf9e336352..f163e394df734 100644 --- a/src/wp-content/themes/twentytwentyone/functions.php +++ b/src/wp-content/themes/twentytwentyone/functions.php @@ -449,7 +449,10 @@ function twenty_twenty_one_scripts() { get_template_directory_uri() . '/assets/js/primary-navigation.js', array( 'twenty-twenty-one-ie11-polyfills' ), wp_get_theme()->get( 'Version' ), - array( 'in_footer' => true ) + array( + 'in_footer' => false, // Because involves header. + 'strategy' => 'defer', + ) ); } From 44e71c8e703bb473924e0d2bd35999d3aa17e734 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 12 Sep 2023 13:00:32 +0000 Subject: [PATCH 068/105] General: Add optional callback argument to serialize_block(s). Allow passing a function callback to serialize_block(s) that is invoked on each node in the tree of parsed blocks as it is traversed for serialization. A function argument was chosen for passing the callback function as it reflects a pattern familiar from other algorithms that apply a given callback function while traversing a data structure -- most notably PHP's own `array_map()`. Introducing a filter was considered as an alternative but ultimately dismissed. For a fairly low-level and general-purpose function such as `serialize_block()`, using a filter to pass the callback seemed risky, as it also requires ''removing'' that filter after usage in order to prevent the callback from being accidentally applied when `serialize_block()` is called in an entirely different context. Introducing a separate function for applying a given operation during tree traversal (i.e. independently of serialization) was also considered but dismissed, as it would unnecessarily duplicate tree traversal. Props dlh, gziolo. Fixes #59327. See #59313. git-svn-id: https://develop.svn.wordpress.org/trunk@56557 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/blocks.php | 24 ++++++++++++++++++------ tests/phpunit/tests/blocks/serialize.php | 24 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 6fc72e358a5ef..590f3706f71f5 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -794,16 +794,22 @@ function get_comment_delimited_block_content( $block_name, $block_attributes, $b * instead preserve the markup as parsed. * * @since 5.3.1 + * @since 6.4.0 The `$callback` parameter was added. * - * @param array $block A representative array of a single parsed block object. See WP_Block_Parser_Block. + * @param array $block A representative array of a single parsed block object. See WP_Block_Parser_Block. + * @param callable|null $callback Optional. Callback to run on each block in the tree before serialization. Default null. * @return string String of rendered HTML. */ -function serialize_block( $block ) { +function serialize_block( $block, $callback = null ) { + if ( is_callable( $callback ) ) { + $block = call_user_func( $callback, $block ); + } + $block_content = ''; $index = 0; foreach ( $block['innerContent'] as $chunk ) { - $block_content .= is_string( $chunk ) ? $chunk : serialize_block( $block['innerBlocks'][ $index++ ] ); + $block_content .= is_string( $chunk ) ? $chunk : serialize_block( $block['innerBlocks'][ $index++ ], $callback ); } if ( ! is_array( $block['attrs'] ) ) { @@ -822,12 +828,18 @@ function serialize_block( $block ) { * parsed blocks. * * @since 5.3.1 + * @since 6.4.0 The `$callback` parameter was added. * - * @param array[] $blocks An array of representative arrays of parsed block objects. See serialize_block(). + * @param array[] $blocks An array of representative arrays of parsed block objects. See serialize_block(). + * @param callable|null $callback Optional. Callback to run on each block in the tree before serialization. Default null. * @return string String of rendered HTML. */ -function serialize_blocks( $blocks ) { - return implode( '', array_map( 'serialize_block', $blocks ) ); +function serialize_blocks( $blocks, $callback = null ) { + $result = ''; + foreach ( $blocks as $block ) { + $result .= serialize_block( $block, $callback ); + }; + return $result; } /** diff --git a/tests/phpunit/tests/blocks/serialize.php b/tests/phpunit/tests/blocks/serialize.php index 4437c8ca852c3..3bfda3ed55a8f 100644 --- a/tests/phpunit/tests/blocks/serialize.php +++ b/tests/phpunit/tests/blocks/serialize.php @@ -54,4 +54,28 @@ public function test_serialized_block_name() { $this->assertSame( 'example', strip_core_block_namespace( 'core/example' ) ); $this->assertSame( 'plugin/example', strip_core_block_namespace( 'plugin/example' ) ); } + + /** + * @ticket 59327 + * + * @covers ::serialize_blocks + */ + public function test_callback_argument() { + $markup = "Example.\n\nExample.\n\n"; + $blocks = parse_blocks( $markup ); + + $actual = serialize_blocks( $blocks, array( __CLASS__, 'add_attribute_to_inner_block' ) ); + + $this->assertSame( + "Example.\n\nExample.\n\n", + $actual + ); + } + + public static function add_attribute_to_inner_block( $block ) { + if ( 'core/inner' === $block['blockName'] ) { + $block['attrs']['myattr'] = 'myvalue'; + } + return $block; + } } From 9c9329c44791336e247fec4d7c2dca31f505180f Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 12 Sep 2023 15:10:19 +0000 Subject: [PATCH 069/105] HTML API: Store current token reference in HTML Processor state. The `$current_token` reference has been stored in the HTML Processor itself, but I suggested to move it into the externalized state so that it can be stored and replaced. In this patch the reference is moved to that state variable and it should become more possible to save and load state, to resume execution after pausing. Props dmsnell. Fixes #59268. git-svn-id: https://develop.svn.wordpress.org/trunk@56558 602fd350-edb4-49c9-b593-d223f7449a82 --- .../class-wp-html-processor-state.php | 9 +++++ .../html-api/class-wp-html-processor.php | 35 ++++++++----------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-processor-state.php b/src/wp-includes/html-api/class-wp-html-processor-state.php index 3fe5192431bd3..9cf10c344107a 100644 --- a/src/wp-includes/html-api/class-wp-html-processor-state.php +++ b/src/wp-includes/html-api/class-wp-html-processor-state.php @@ -85,6 +85,15 @@ class WP_HTML_Processor_State { */ public $active_formatting_elements = null; + /** + * Refers to the currently-matched tag, if any. + * + * @since 6.4.0 + * + * @var WP_HTML_Token|null + */ + public $current_token = null; + /** * Tree construction insertion mode. * diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index b5a20dbd82cdc..64fd23924eada 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -164,15 +164,6 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { */ private $bookmark_counter = 0; - /** - * Refers to the currently-matched tag, if any. - * - * @since 6.4.0 - * - * @var WP_HTML_Token|null - */ - private $current_token = null; - /** * Stores an explanation for why something failed, if it did. * @@ -451,7 +442,7 @@ public function step( $node_to_process = self::PROCESS_NEXT_NODE ) { return false; } - $this->current_token = new WP_HTML_Token( + $this->state->current_token = new WP_HTML_Token( $this->bookmark_tag(), $this->get_tag(), $this->is_tag_closer(), @@ -538,7 +529,7 @@ private function step_in_body() { } $this->reconstruct_active_formatting_elements(); - $this->insert_html_element( $this->current_token ); + $this->insert_html_element( $this->state->current_token ); $this->state->frameset_ok = false; return true; @@ -558,7 +549,7 @@ private function step_in_body() { $this->close_a_p_element(); } - $this->insert_html_element( $this->current_token ); + $this->insert_html_element( $this->state->current_token ); return true; /* @@ -590,7 +581,7 @@ private function step_in_body() { */ case '-P': if ( ! $this->state->stack_of_open_elements->has_p_in_button_scope() ) { - $this->insert_html_element( $this->current_token ); + $this->insert_html_element( $this->state->current_token ); } $this->close_a_p_element(); @@ -612,8 +603,8 @@ private function step_in_body() { } $this->reconstruct_active_formatting_elements(); - $this->insert_html_element( $this->current_token ); - $this->state->active_formatting_elements->push( $this->current_token ); + $this->insert_html_element( $this->state->current_token ); + $this->state->active_formatting_elements->push( $this->state->current_token ); return true; /* @@ -633,8 +624,8 @@ private function step_in_body() { case '+TT': case '+U': $this->reconstruct_active_formatting_elements(); - $this->insert_html_element( $this->current_token ); - $this->state->active_formatting_elements->push( $this->current_token ); + $this->insert_html_element( $this->state->current_token ); + $this->state->active_formatting_elements->push( $this->state->current_token ); return true; /* @@ -662,7 +653,7 @@ private function step_in_body() { */ case '+IMG': $this->reconstruct_active_formatting_elements(); - $this->insert_html_element( $this->current_token ); + $this->insert_html_element( $this->state->current_token ); return true; /* @@ -670,7 +661,7 @@ private function step_in_body() { */ case '+SPAN': $this->reconstruct_active_formatting_elements(); - $this->insert_html_element( $this->current_token ); + $this->insert_html_element( $this->state->current_token ); return true; /* @@ -796,7 +787,9 @@ public function release_bookmark( $bookmark_name ) { */ public function seek( $bookmark_name ) { $actual_bookmark_name = "_{$bookmark_name}"; - $processor_started_at = $this->current_token ? $this->bookmarks[ $this->current_token->bookmark_name ]->start : 0; + $processor_started_at = $this->state->current_token + ? $this->bookmarks[ $this->state->current_token->bookmark_name ]->start + : 0; $bookmark_starts_at = $this->bookmarks[ $actual_bookmark_name ]->start; $direction = $bookmark_starts_at > $processor_started_at ? 'forward' : 'backward'; @@ -804,7 +797,7 @@ public function seek( $bookmark_name ) { case 'forward': // When moving forwards, re-parse the document until reaching the same location as the original bookmark. while ( $this->step() ) { - if ( $bookmark_starts_at === $this->bookmarks[ $this->current_token->bookmark_name ]->start ) { + if ( $bookmark_starts_at === $this->bookmarks[ $this->state->current_token->bookmark_name ]->start ) { return true; } } From fd6c5606b1c572442f0eb15bafee0852cbbb7035 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 12 Sep 2023 15:21:02 +0000 Subject: [PATCH 070/105] Coding Standards: Include one space after `function` keyword for closures. Note: This is enforced by WPCS 3.0.0. Reference: [https://github.com/WordPress/WordPress-Coding-Standards/pull/2328 WPCS: PR #2328 Core: properly check formatting of function declaration statements]. Props jrf. See #59161, #58831. git-svn-id: https://develop.svn.wordpress.org/trunk@56559 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/edit-form-blocks.php | 2 +- .../includes/class-wp-community-events.php | 2 +- .../class-wp-site-health-auto-updates.php | 2 +- src/wp-admin/includes/file.php | 2 +- src/wp-admin/includes/update-core.php | 2 +- src/wp-admin/options-privacy.php | 2 +- src/wp-admin/privacy-policy-guide.php | 2 +- src/wp-admin/site-editor.php | 2 +- src/wp-admin/upload.php | 2 +- .../classes/class-twentytwenty-customize.php | 2 +- .../class-twenty-twenty-one-customize.php | 2 +- .../class-twenty-twenty-one-dark-mode.php | 8 ++--- src/wp-includes/block-supports/layout.php | 2 +- src/wp-includes/blocks.php | 2 +- src/wp-includes/blocks/index.php | 2 +- .../class-wp-customize-widgets.php | 4 +-- src/wp-includes/class-wp-http.php | 2 +- .../class-wp-navigation-fallback.php | 2 +- src/wp-includes/class-wp-theme-json.php | 6 ++-- src/wp-includes/formatting.php | 6 ++-- src/wp-includes/functions.php | 2 +- src/wp-includes/kses.php | 2 +- src/wp-includes/post.php | 2 +- .../endpoints/class-wp-rest-controller.php | 2 +- .../class-wp-rest-plugins-controller.php | 4 +-- .../class-wp-rest-site-health-controller.php | 2 +- .../class-wp-rest-widget-types-controller.php | 2 +- .../class-wp-rest-widgets-controller.php | 2 +- src/wp-includes/script-loader.php | 10 +++--- src/wp-includes/update.php | 2 +- src/wp-includes/user.php | 2 +- .../wp-content/mu-plugins/server-timing.php | 4 +-- tests/phpunit/tests/actions.php | 4 +-- tests/phpunit/tests/admin/includesFile.php | 2 +- tests/phpunit/tests/admin/includesPost.php | 2 +- tests/phpunit/tests/admin/includesSchema.php | 2 +- .../tests/admin/wpAutomaticUpdater.php | 4 +-- .../tests/admin/wpCommentsListTable.php | 2 +- tests/phpunit/tests/admin/wpSiteHealth.php | 2 +- tests/phpunit/tests/ajax/wpAjaxAddTag.php | 2 +- .../tests/ajax/wpAjaxAjaxTagSearch.php | 2 +- tests/phpunit/tests/block-template.php | 2 +- tests/phpunit/tests/blocks/context.php | 8 ++--- tests/phpunit/tests/blocks/editor.php | 2 +- .../tests/blocks/getBlockTemplates.php | 2 +- tests/phpunit/tests/blocks/register.php | 6 ++-- .../tests/blocks/renderCommentTemplate.php | 4 +-- tests/phpunit/tests/blocks/wpBlock.php | 16 ++++----- tests/phpunit/tests/canonical.php | 2 +- .../phpunit/tests/category/walkerCategory.php | 2 +- tests/phpunit/tests/cron.php | 20 +++++------ tests/phpunit/tests/dependencies/scripts.php | 2 +- tests/phpunit/tests/feed/rss2.php | 6 ++-- tests/phpunit/tests/file.php | 10 +++--- .../tests/formatting/wpTrimExcerpt.php | 2 +- tests/phpunit/tests/functions.php | 4 +-- tests/phpunit/tests/functions/wpFilesize.php | 4 +-- .../phpunit/tests/general/feedLinksExtra.php | 4 +-- tests/phpunit/tests/http/http.php | 2 +- tests/phpunit/tests/https-detection.php | 6 ++-- tests/phpunit/tests/https-migration.php | 4 +-- tests/phpunit/tests/image/editorImagick.php | 2 +- tests/phpunit/tests/image/functions.php | 4 +-- .../phpunit/tests/image/intermediateSize.php | 2 +- tests/phpunit/tests/l10n/determineLocale.php | 34 +++++++++---------- tests/phpunit/tests/link/editTermLink.php | 2 +- tests/phpunit/tests/link/getEditTermLink.php | 2 +- tests/phpunit/tests/media.php | 20 +++++------ .../media/wpGenerateAttachmentMetadata.php | 2 +- .../tests/media/wpImageTagAddDecodingAttr.php | 4 +-- tests/phpunit/tests/menu/walker-nav-menu.php | 2 +- .../option/wpSetOptionAutoloadValues.php | 2 +- tests/phpunit/tests/post/getPages.php | 2 +- tests/phpunit/tests/post/revisions.php | 2 +- tests/phpunit/tests/post/thumbnails.php | 2 +- tests/phpunit/tests/post/walkerPage.php | 2 +- .../tests/post/wpGetAttachmentLink.php | 2 +- tests/phpunit/tests/query.php | 4 +-- tests/phpunit/tests/query/conditionals.php | 4 +-- .../rest-application-passwords-controller.php | 2 +- .../rest-block-directory-controller.php | 2 +- .../rest-block-renderer-controller.php | 2 +- .../rest-pattern-directory-controller.php | 4 +-- .../rest-api/rest-plugins-controller.php | 2 +- .../tests/rest-api/rest-post-meta-fields.php | 2 +- .../tests/rest-api/rest-posts-controller.php | 4 +-- tests/phpunit/tests/rest-api/rest-server.php | 10 +++--- .../rest-api/rest-widget-types-controller.php | 6 ++-- .../rest-api/wpRestUrlDetailsController.php | 8 ++--- tests/phpunit/tests/robots.php | 2 +- tests/phpunit/tests/term/getTermLink.php | 2 +- tests/phpunit/tests/theme/customHeader.php | 4 +-- .../tests/theme/wpThemeJsonResolver.php | 4 +-- tests/phpunit/tests/user/queryCache.php | 2 +- tests/phpunit/tests/user/retrievePassword.php | 2 +- tests/phpunit/tests/widgets.php | 2 +- 96 files changed, 188 insertions(+), 188 deletions(-) diff --git a/src/wp-admin/edit-form-blocks.php b/src/wp-admin/edit-form-blocks.php index 66a6bbfc25326..e200b29621924 100644 --- a/src/wp-admin/edit-form-blocks.php +++ b/src/wp-admin/edit-form-blocks.php @@ -31,7 +31,7 @@ // Default to is-fullscreen-mode to avoid jumps in the UI. add_filter( 'admin_body_class', - static function( $classes ) { + static function ( $classes ) { return "$classes is-fullscreen-mode"; } ); diff --git a/src/wp-admin/includes/class-wp-community-events.php b/src/wp-admin/includes/class-wp-community-events.php index 09557c86a4782..008611af21c09 100644 --- a/src/wp-admin/includes/class-wp-community-events.php +++ b/src/wp-admin/includes/class-wp-community-events.php @@ -483,7 +483,7 @@ protected function trim_events( array $events ) { $future_wordcamps = array_filter( $future_events, - static function( $wordcamp ) { + static function ( $wordcamp ) { return 'wordcamp' === $wordcamp['type']; } ); diff --git a/src/wp-admin/includes/class-wp-site-health-auto-updates.php b/src/wp-admin/includes/class-wp-site-health-auto-updates.php index d1655eb1d87d6..f8521ab2b0846 100644 --- a/src/wp-admin/includes/class-wp-site-health-auto-updates.php +++ b/src/wp-admin/includes/class-wp-site-health-auto-updates.php @@ -42,7 +42,7 @@ public function run_tests() { $tests = array_filter( $tests ); $tests = array_map( - static function( $test ) { + static function ( $test ) { $test = (object) $test; if ( empty( $test->severity ) ) { diff --git a/src/wp-admin/includes/file.php b/src/wp-admin/includes/file.php index aa8e25c8ed5fa..6531736bd95b9 100644 --- a/src/wp-admin/includes/file.php +++ b/src/wp-admin/includes/file.php @@ -2726,7 +2726,7 @@ function wp_opcache_invalidate_directory( $dir ) { * with sub-directories represented as nested arrays. * @param string $path Absolute path to the directory. */ - $invalidate_directory = static function( $dirlist, $path ) use ( &$invalidate_directory ) { + $invalidate_directory = static function ( $dirlist, $path ) use ( &$invalidate_directory ) { $path = trailingslashit( $path ); foreach ( $dirlist as $name => $details ) { diff --git a/src/wp-admin/includes/update-core.php b/src/wp-admin/includes/update-core.php index 6085b02c8fdc4..fdb522c889609 100644 --- a/src/wp-admin/includes/update-core.php +++ b/src/wp-admin/includes/update-core.php @@ -1805,7 +1805,7 @@ function _upgrade_422_find_genericons_files_in_folder( $directory ) { $dirs = glob( $directory . '*', GLOB_ONLYDIR ); $dirs = array_filter( $dirs, - static function( $dir ) { + static function ( $dir ) { /* * Skip any node_modules directories. * diff --git a/src/wp-admin/options-privacy.php b/src/wp-admin/options-privacy.php index 5c22d39d5df67..1afb8c0601388 100644 --- a/src/wp-admin/options-privacy.php +++ b/src/wp-admin/options-privacy.php @@ -23,7 +23,7 @@ add_filter( 'admin_body_class', - static function( $body_class ) { + static function ( $body_class ) { $body_class .= ' privacy-settings '; return $body_class; diff --git a/src/wp-admin/privacy-policy-guide.php b/src/wp-admin/privacy-policy-guide.php index 7e92a4dea6a83..b8f303aa7f4e0 100644 --- a/src/wp-admin/privacy-policy-guide.php +++ b/src/wp-admin/privacy-policy-guide.php @@ -22,7 +22,7 @@ add_filter( 'admin_body_class', - static function( $body_class ) { + static function ( $body_class ) { $body_class .= ' privacy-settings '; return $body_class; diff --git a/src/wp-admin/site-editor.php b/src/wp-admin/site-editor.php index b7cdfbe0dff63..2da7222d7c8ff 100644 --- a/src/wp-admin/site-editor.php +++ b/src/wp-admin/site-editor.php @@ -42,7 +42,7 @@ // Default to is-fullscreen-mode to avoid jumps in the UI. add_filter( 'admin_body_class', - static function( $classes ) { + static function ( $classes ) { return "$classes is-fullscreen-mode"; } ); diff --git a/src/wp-admin/upload.php b/src/wp-admin/upload.php index 13b54c5840835..6d8c8462b7c19 100644 --- a/src/wp-admin/upload.php +++ b/src/wp-admin/upload.php @@ -144,7 +144,7 @@ // Remove the error parameter added by deprecation of wp-admin/media.php. add_filter( 'removable_query_args', - function() { + function () { return array( 'error' ); }, 10, diff --git a/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-customize.php b/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-customize.php index dedcb3788243b..8a560a8d49ab4 100644 --- a/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-customize.php +++ b/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-customize.php @@ -187,7 +187,7 @@ public static function register( $wp_customize ) { 'settings' => 'accent_hue', 'description' => __( 'Apply a custom color for links, buttons, featured images.', 'twentytwenty' ), 'mode' => 'hue', - 'active_callback' => static function() use ( $wp_customize ) { + 'active_callback' => static function () use ( $wp_customize ) { return ( 'custom' === $wp_customize->get_setting( 'accent_hue_active' )->value() ); }, ) diff --git a/src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-customize.php b/src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-customize.php index d3af05ec42a79..903334089db4d 100644 --- a/src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-customize.php +++ b/src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-customize.php @@ -92,7 +92,7 @@ public function register( $wp_customize ) { array( 'capability' => 'edit_theme_options', 'default' => 'excerpt', - 'sanitize_callback' => static function( $value ) { + 'sanitize_callback' => static function ( $value ) { return 'excerpt' === $value || 'full' === $value ? $value : 'excerpt'; }, ) diff --git a/src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-dark-mode.php b/src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-dark-mode.php index 611ce3756f195..39b3fb726fc88 100644 --- a/src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-dark-mode.php +++ b/src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-dark-mode.php @@ -153,7 +153,7 @@ public function customizer_controls( $wp_customize ) { array( 'section' => 'colors', 'priority' => 100, - 'active_callback' => static 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 @@ public function customizer_controls( $wp_customize ) { array( 'capability' => 'edit_theme_options', 'default' => false, - 'sanitize_callback' => static function( $value ) { + 'sanitize_callback' => static function ( $value ) { return (bool) $value; }, ) @@ -188,7 +188,7 @@ public function customizer_controls( $wp_customize ) { 'label' => esc_html__( 'Dark Mode support', 'twentytwentyone' ), 'priority' => 110, 'description' => $description, - 'active_callback' => static 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' ) ); }, ) @@ -200,7 +200,7 @@ public function customizer_controls( $wp_customize ) { array( 'selector' => '#dark-mode-toggler', 'container_inclusive' => true, - 'render_callback' => function() { + 'render_callback' => function () { $attrs = ( $this->switch_should_render() ) ? array() : array( 'style' => 'display:none;' ); $this->the_html( $attrs ); }, diff --git a/src/wp-includes/block-supports/layout.php b/src/wp-includes/block-supports/layout.php index 519574238dee9..89713c772d206 100644 --- a/src/wp-includes/block-supports/layout.php +++ b/src/wp-includes/block-supports/layout.php @@ -789,7 +789,7 @@ function wp_restore_group_inner_container( $block_content, $block ) { ); $updated_content = preg_replace_callback( $replace_regex, - static function( $matches ) { + static function ( $matches ) { return $matches[1] . '
' . $matches[2] . '
' . $matches[3]; }, $block_content diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 590f3706f71f5..3c88f7b4c381a 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -532,7 +532,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) { * * @return string Returns the block content. */ - $settings['render_callback'] = static function( $attributes, $content, $block ) use ( $template_path ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + $settings['render_callback'] = static function ( $attributes, $content, $block ) use ( $template_path ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable ob_start(); require $template_path; return ob_get_clean(); diff --git a/src/wp-includes/blocks/index.php b/src/wp-includes/blocks/index.php index a966248c796cc..128a06bea26fd 100644 --- a/src/wp-includes/blocks/index.php +++ b/src/wp-includes/blocks/index.php @@ -87,7 +87,7 @@ static function ( $file ) { } } - $register_style = static function( $name, $filename, $style_handle ) use ( $blocks_url, $suffix, $wp_styles, $files ) { + $register_style = static function ( $name, $filename, $style_handle ) use ( $blocks_url, $suffix, $wp_styles, $files ) { $style_path = "{$name}/{$filename}{$suffix}.css"; $path = wp_normalize_path( BLOCKS_PATH . $style_path ); diff --git a/src/wp-includes/class-wp-customize-widgets.php b/src/wp-includes/class-wp-customize-widgets.php index 41a57dc66bbe1..93006ef91671e 100644 --- a/src/wp-includes/class-wp-customize-widgets.php +++ b/src/wp-includes/class-wp-customize-widgets.php @@ -982,10 +982,10 @@ public function get_setting_args( $id, $overrides = array() ) { $args['transport'] = current_theme_supports( 'customize-selective-refresh-widgets' ) ? 'postMessage' : 'refresh'; } elseif ( preg_match( $this->setting_id_patterns['widget_instance'], $id, $matches ) ) { $id_base = $matches['id_base']; - $args['sanitize_callback'] = function( $value ) use ( $id_base ) { + $args['sanitize_callback'] = function ( $value ) use ( $id_base ) { return $this->sanitize_widget_instance( $value, $id_base ); }; - $args['sanitize_js_callback'] = function( $value ) use ( $id_base ) { + $args['sanitize_js_callback'] = function ( $value ) use ( $id_base ) { return $this->sanitize_widget_js_instance( $value, $id_base ); }; $args['transport'] = $this->is_widget_selective_refreshable( $matches['id_base'] ) ? 'postMessage' : 'refresh'; diff --git a/src/wp-includes/class-wp-http.php b/src/wp-includes/class-wp-http.php index 87a9342a92ee8..056680ba4093b 100644 --- a/src/wp-includes/class-wp-http.php +++ b/src/wp-includes/class-wp-http.php @@ -463,7 +463,7 @@ public static function normalize_cookies( $cookies ) { if ( $value instanceof WP_Http_Cookie ) { $attributes = array_filter( $value->get_attributes(), - static function( $attr ) { + static function ( $attr ) { return null !== $attr; } ); diff --git a/src/wp-includes/class-wp-navigation-fallback.php b/src/wp-includes/class-wp-navigation-fallback.php index fb97c643bbcd4..bd9583d1fa323 100644 --- a/src/wp-includes/class-wp-navigation-fallback.php +++ b/src/wp-includes/class-wp-navigation-fallback.php @@ -169,7 +169,7 @@ private static function get_fallback_classic_menu() { private static function get_most_recently_created_nav_menu( $classic_nav_menus ) { usort( $classic_nav_menus, - static function( $a, $b ) { + static function ( $a, $b ) { return $b->term_id - $a->term_id; } ); diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 227398facd2c5..95cbac23c3322 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -2334,7 +2334,7 @@ public function get_styles_for_block( $block_metadata ) { // Prepend the variation selector to the current selector. $split_selectors = explode( ',', $shortened_selector ); $updated_selectors = array_map( - static function( $split_selector ) use ( $clean_style_variation_selector ) { + static function ( $split_selector ) use ( $clean_style_variation_selector ) { return $clean_style_variation_selector . $split_selector; }, $split_selectors @@ -2372,7 +2372,7 @@ static function( $split_selector ) use ( $clean_style_variation_selector ) { $pseudo_matches = array_values( array_filter( $element_pseudo_allowed, - static function( $pseudo_selector ) use ( $selector ) { + static function ( $pseudo_selector ) use ( $selector ) { return str_contains( $selector, $pseudo_selector ); } ) @@ -3733,7 +3733,7 @@ public static function resolve_variables( $theme_json ) { $theme_vars = static::compute_theme_vars( $settings ); $vars = array_reduce( array_merge( $preset_vars, $theme_vars ), - function( $carry, $item ) { + function ( $carry, $item ) { $name = $item['name']; $carry[ "var({$name})" ] = $item['value']; return $carry; diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index fddd2b1aa1db4..05084329d333e 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -3259,7 +3259,7 @@ function wp_rel_nofollow( $text ) { $text = stripslashes( $text ); $text = preg_replace_callback( '||i', - static function( $matches ) { + static function ( $matches ) { return wp_rel_callback( $matches, 'nofollow' ); }, $text @@ -3293,7 +3293,7 @@ function wp_rel_ugc( $text ) { $text = stripslashes( $text ); $text = preg_replace_callback( '||i', - static function( $matches ) { + static function ( $matches ) { return wp_rel_callback( $matches, 'nofollow ugc' ); }, $text @@ -4756,7 +4756,7 @@ function esc_xml( $text ) { $safe_text = (string) preg_replace_callback( $regex, - static function( $matches ) { + static function ( $matches ) { if ( ! isset( $matches[0] ) ) { return ''; } diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 6963de3a3831d..28975154c382c 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -846,7 +846,7 @@ function wp_extract_urls( $content ) { $post_links = array_unique( array_map( - static function( $link ) { + static function ( $link ) { // Decode to replace valid entities, like &. $link = html_entity_decode( $link ); // Maintain backward compatibility by removing extraneous semi-colons (`;`). diff --git a/src/wp-includes/kses.php b/src/wp-includes/kses.php index 7eeadca569944..f6bd75741d6c4 100644 --- a/src/wp-includes/kses.php +++ b/src/wp-includes/kses.php @@ -1183,7 +1183,7 @@ function wp_kses_attr( $element, $attr, $allowed_html, $allowed_protocols ) { // Check if there are attributes that are required. $required_attrs = array_filter( $allowed_html[ $element_low ], - static function( $required_attr_limits ) { + static function ( $required_attr_limits ) { return isset( $required_attr_limits['required'] ) && true === $required_attr_limits['required']; } ); diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 2a8d6b41f6844..e1af9227a54e7 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -6071,7 +6071,7 @@ function get_pages( $args = array() ) { */ $orderby = wp_parse_list( $parsed_args['sort_column'] ); $orderby = array_map( - static function( $orderby_field ) { + static function ( $orderby_field ) { $orderby_field = trim( $orderby_field ); if ( 'post_modified_gmt' === $orderby_field || 'modified_gmt' === $orderby_field ) { $orderby_field = str_replace( '_gmt', '', $orderby_field ); diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php index 81fc991ba980f..4b960d6c6b157 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php @@ -625,7 +625,7 @@ public function get_fields_for_response( $request ) { // Return the list of all requested fields which appear in the schema. return array_reduce( $requested_fields, - static 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/src/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php index 4cbc5063e906e..8d24b60db26cb 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php @@ -381,7 +381,7 @@ public function create_item( $request ) { $installed_locales = apply_filters( 'plugins_update_check_locales', $installed_locales ); $language_packs = array_map( - static function( $item ) { + static function ( $item ) { return (object) $item; }, $api->language_packs @@ -389,7 +389,7 @@ static function( $item ) { $language_packs = array_filter( $language_packs, - static function( $pack ) use ( $installed_locales ) { + static function ( $pack ) use ( $installed_locales ) { return in_array( $pack->language, $installed_locales, true ); } ); diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php index 18d67dc2dd7a0..41e15337add5f 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php @@ -152,7 +152,7 @@ public function register_routes() { array( 'methods' => 'GET', 'callback' => array( $this, 'get_directory_sizes' ), - 'permission_callback' => function() { + 'permission_callback' => function () { return $this->validate_request_permission( 'directory_sizes' ) && ! is_multisite(); }, ) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php index 9734ae66255c0..b01dd1649ec43 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php @@ -85,7 +85,7 @@ public function register_routes() { 'form_data' => array( 'description' => __( 'Serialized widget form data to encode into instance settings.' ), 'type' => 'string', - 'sanitize_callback' => static function( $form_data ) { + 'sanitize_callback' => static function ( $form_data ) { $array = array(); wp_parse_str( $form_data, $array ); return $array; diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php index 267a75ffaedb9..acbd88c4896d1 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php @@ -861,7 +861,7 @@ public function get_item_schema() { 'type' => 'string', 'context' => array(), 'arg_options' => array( - 'sanitize_callback' => static function( $form_data ) { + 'sanitize_callback' => static function ( $form_data ) { $array = array(); wp_parse_str( $form_data, $array ); return $array; diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index d99cc9b035d8b..b51569f40cf10 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -2453,7 +2453,7 @@ function wp_common_block_scripts_and_styles() { function wp_filter_out_block_nodes( $nodes ) { return array_filter( $nodes, - static function( $node ) { + static function ( $node ) { return ! in_array( 'blocks', $node['path'], true ); }, ARRAY_FILTER_USE_BOTH @@ -2655,7 +2655,7 @@ function enqueue_block_styles_assets() { if ( wp_should_load_separate_core_block_assets() ) { add_filter( 'render_block', - static function( $html, $block ) use ( $block_name, $style_properties ) { + static function ( $html, $block ) use ( $block_name, $style_properties ) { if ( $block['blockName'] === $block_name ) { wp_enqueue_style( $style_properties['style_handle'] ); } @@ -2917,7 +2917,7 @@ function wp_maybe_inline_styles() { // Reorder styles array based on size. usort( $styles, - static function( $a, $b ) { + static function ( $a, $b ) { return ( $a['size'] <= $b['size'] ) ? -1 : 1; } ); @@ -3150,7 +3150,7 @@ function wp_enqueue_block_style( $block_name, $args ) { * is to ensure the content exists. * @return string Block content. */ - $callback = static function( $content ) use ( $args ) { + $callback = static function ( $content ) use ( $args ) { // Register the stylesheet. if ( ! empty( $args['src'] ) ) { wp_register_style( $args['handle'], $args['src'], $args['deps'], $args['ver'], $args['media'] ); @@ -3188,7 +3188,7 @@ function wp_enqueue_block_style( $block_name, $args ) { * @param array $block The full block, including name and attributes. * @return string Block content. */ - $callback_separate = static function( $content, $block ) use ( $block_name, $callback ) { + $callback_separate = static function ( $content, $block ) use ( $block_name, $callback ) { if ( ! empty( $block['blockName'] ) && $block_name === $block['blockName'] ) { return $callback( $content ); } diff --git a/src/wp-includes/update.php b/src/wp-includes/update.php index c5349832ac2a4..e2ac6b8b54dbc 100644 --- a/src/wp-includes/update.php +++ b/src/wp-includes/update.php @@ -553,7 +553,7 @@ function wp_update_plugins( $extra_stats = array() ) { } } - $sanitize_plugin_update_payload = static function( &$item ) { + $sanitize_plugin_update_payload = static function ( &$item ) { $item = (object) $item; unset( $item->translations, $item->compatibility ); diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php index aaba3a7e7e095..fc40f4cd753ab 100644 --- a/src/wp-includes/user.php +++ b/src/wp-includes/user.php @@ -3899,7 +3899,7 @@ function wp_user_personal_data_exporter( $email_address ) { // Remove items that use reserved names. $extra_data = array_filter( $_extra_data, - static function( $item ) use ( $reserved_names ) { + static function ( $item ) use ( $reserved_names ) { return ! in_array( $item['name'], $reserved_names, true ); } ); diff --git a/tests/performance/wp-content/mu-plugins/server-timing.php b/tests/performance/wp-content/mu-plugins/server-timing.php index 9ae95561ec903..4f9a0d04f1ebb 100644 --- a/tests/performance/wp-content/mu-plugins/server-timing.php +++ b/tests/performance/wp-content/mu-plugins/server-timing.php @@ -2,7 +2,7 @@ add_filter( 'template_include', - static function( $template ) { + static function ( $template ) { global $timestart; @@ -15,7 +15,7 @@ static function( $template ) { add_action( 'shutdown', - static function() use ( $server_timing_values, $template_start ) { + static function () use ( $server_timing_values, $template_start ) { global $timestart; diff --git a/tests/phpunit/tests/actions.php b/tests/phpunit/tests/actions.php index ae02973c5ec6a..8b57382b9c545 100644 --- a/tests/phpunit/tests/actions.php +++ b/tests/phpunit/tests/actions.php @@ -387,7 +387,7 @@ public function test_action_keyed_array() { */ public function test_action_closure() { $hook_name = __FUNCTION__; - $closure = static function( $a, $b ) { + $closure = static function ( $a, $b ) { $GLOBALS[ $a ] = $b; }; add_action( $hook_name, $closure, 10, 2 ); @@ -400,7 +400,7 @@ public function test_action_closure() { $this->assertSame( $GLOBALS[ $context[0] ], $context[1] ); $hook_name2 = __FUNCTION__ . '_2'; - $closure2 = static function() { + $closure2 = static function () { $GLOBALS['closure_no_args'] = true; }; add_action( $hook_name2, $closure2 ); diff --git a/tests/phpunit/tests/admin/includesFile.php b/tests/phpunit/tests/admin/includesFile.php index 375f895c84a2e..4a5295b29a0be 100644 --- a/tests/phpunit/tests/admin/includesFile.php +++ b/tests/phpunit/tests/admin/includesFile.php @@ -343,7 +343,7 @@ public function test_download_url_no_warning_for_url_without_path_with_signature add_filter( 'wp_signature_hosts', - static function( $urls ) { + static function ( $urls ) { $urls[] = 'example.com'; return $urls; } diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php index 4ce59dbabe177..102449cc79899 100644 --- a/tests/phpunit/tests/admin/includesPost.php +++ b/tests/phpunit/tests/admin/includesPost.php @@ -795,7 +795,7 @@ public function test_get_sample_permalink_should_preserve_the_original_post_prop add_filter( 'get_sample_permalink', - function( $permalink, $post_id, $title, $name, $post ) use ( $post_original ) { + function ( $permalink, $post_id, $title, $name, $post ) use ( $post_original ) { $this->assertEquals( $post_original, $post, 'Modified post object passed to get_sample_permalink filter.' ); return $permalink; }, diff --git a/tests/phpunit/tests/admin/includesSchema.php b/tests/phpunit/tests/admin/includesSchema.php index f33dff148b9dc..77b3e06a53ed6 100644 --- a/tests/phpunit/tests/admin/includesSchema.php +++ b/tests/phpunit/tests/admin/includesSchema.php @@ -192,7 +192,7 @@ public function test_populate_options_when_locale_uses_deprecated_timezone_strin // Set the "default" value for the timezone to a deprecated timezone. add_filter( 'gettext_with_context', - static function( $translation, $text, $context ) { + static function ( $translation, $text, $context ) { if ( '0' === $text && 'default GMT offset or timezone string' === $context ) { return 'America/Buenos_Aires'; } diff --git a/tests/phpunit/tests/admin/wpAutomaticUpdater.php b/tests/phpunit/tests/admin/wpAutomaticUpdater.php index eb91a97c09e5b..1746d9490c9db 100644 --- a/tests/phpunit/tests/admin/wpAutomaticUpdater.php +++ b/tests/phpunit/tests/admin/wpAutomaticUpdater.php @@ -54,7 +54,7 @@ public function set_up() { public function test_send_plugin_theme_email_should_append_plugin_urls( $urls, $successful, $failed ) { add_filter( 'wp_mail', - function( $args ) use ( $urls ) { + function ( $args ) use ( $urls ) { foreach ( $urls as $url ) { $this->assertStringContainsString( $url, @@ -322,7 +322,7 @@ public function data_send_plugin_theme_email_should_append_plugin_urls() { public function test_send_plugin_theme_email_should_not_append_plugin_urls( $urls, $successful, $failed ) { add_filter( 'wp_mail', - function( $args ) use ( $urls ) { + function ( $args ) use ( $urls ) { foreach ( $urls as $url ) { $this->assertStringNotContainsString( $url, diff --git a/tests/phpunit/tests/admin/wpCommentsListTable.php b/tests/phpunit/tests/admin/wpCommentsListTable.php index dc440a117bdbd..8ba12eed0e24d 100644 --- a/tests/phpunit/tests/admin/wpCommentsListTable.php +++ b/tests/phpunit/tests/admin/wpCommentsListTable.php @@ -96,7 +96,7 @@ public function test_empty_trash_button_should_not_be_shown_if_there_are_no_comm public function test_bulk_action_menu_supports_options_and_optgroups() { add_filter( 'bulk_actions-edit-comments', - static function() { + static function () { return array( 'delete' => 'Delete', 'Change State' => array( diff --git a/tests/phpunit/tests/admin/wpSiteHealth.php b/tests/phpunit/tests/admin/wpSiteHealth.php index 0d7ccb6112cbd..f8b2e2e0c8655 100644 --- a/tests/phpunit/tests/admin/wpSiteHealth.php +++ b/tests/phpunit/tests/admin/wpSiteHealth.php @@ -421,7 +421,7 @@ public function test_object_cache_default_thresholds_non_multisite() { // Set thresholds so high they should never be exceeded. add_filter( 'site_status_persistent_object_cache_thresholds', - static function() { + static function () { return array( 'alloptions_count' => PHP_INT_MAX, 'alloptions_bytes' => PHP_INT_MAX, diff --git a/tests/phpunit/tests/ajax/wpAjaxAddTag.php b/tests/phpunit/tests/ajax/wpAjaxAddTag.php index 6060b1db64256..fbb65ff6aec84 100755 --- a/tests/phpunit/tests/ajax/wpAjaxAddTag.php +++ b/tests/phpunit/tests/ajax/wpAjaxAddTag.php @@ -74,7 +74,7 @@ public function data_add_tag() { 'tag-name' => 'techno', ), 'expected' => 'A new category added.', - 'callback' => static function( array $messages ) { + 'callback' => static function ( array $messages ) { $messages['category'][1] = 'A new category added.'; return $messages; }, diff --git a/tests/phpunit/tests/ajax/wpAjaxAjaxTagSearch.php b/tests/phpunit/tests/ajax/wpAjaxAjaxTagSearch.php index fa41463c62a61..dbcc4cbe0f62b 100644 --- a/tests/phpunit/tests/ajax/wpAjaxAjaxTagSearch.php +++ b/tests/phpunit/tests/ajax/wpAjaxAjaxTagSearch.php @@ -176,7 +176,7 @@ public function test_ajax_term_search_results_filter() { // Add the ajax_term_search_results filter. add_filter( 'ajax_term_search_results', - static function( $results, $tax, $s ) { + static function ( $results, $tax, $s ) { return array( 'ajax_term_search_results was applied' ); }, 10, diff --git a/tests/phpunit/tests/block-template.php b/tests/phpunit/tests/block-template.php index 3344b895bb4e6..64260fb21518a 100644 --- a/tests/phpunit/tests/block-template.php +++ b/tests/phpunit/tests/block-template.php @@ -284,7 +284,7 @@ private function register_in_the_loop_logger_block( array &$in_the_loop_logs ) { register_block_type( 'test/in-the-loop-logger', array( - 'render_callback' => function() use ( &$in_the_loop_logs ) { + 'render_callback' => function () use ( &$in_the_loop_logs ) { $in_the_loop_logs[] = in_the_loop(); return ''; }, diff --git a/tests/phpunit/tests/blocks/context.php b/tests/phpunit/tests/blocks/context.php index 68ead5d398f2f..3edddcf8ef6e5 100644 --- a/tests/phpunit/tests/blocks/context.php +++ b/tests/phpunit/tests/blocks/context.php @@ -109,7 +109,7 @@ public function test_provides_block_context() { 'gutenberg/contextWithAssigned', 'gutenberg/contextWithoutDefault', ), - 'render_callback' => static function( $attributes, $content, $block ) use ( &$provided_context ) { + 'render_callback' => static function ( $attributes, $content, $block ) use ( &$provided_context ) { $provided_context[] = $block->context; return ''; @@ -149,7 +149,7 @@ public function test_provides_default_context() { 'gutenberg/test-context-consumer', array( 'uses_context' => array( 'postId', 'postType' ), - 'render_callback' => static function( $attributes, $content, $block ) use ( &$provided_context ) { + 'render_callback' => static function ( $attributes, $content, $block ) use ( &$provided_context ) { $provided_context[] = $block->context; return ''; @@ -182,7 +182,7 @@ public function test_default_context_is_filterable() { 'gutenberg/test-context-consumer', array( 'uses_context' => array( 'example' ), - 'render_callback' => static function( $attributes, $content, $block ) use ( &$provided_context ) { + 'render_callback' => static function ( $attributes, $content, $block ) use ( &$provided_context ) { $provided_context[] = $block->context; return ''; @@ -190,7 +190,7 @@ public function test_default_context_is_filterable() { ) ); - $filter_block_context = static function( $context ) { + $filter_block_context = static function ( $context ) { $context['example'] = 'ok'; return $context; }; diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index 1d008560e90b5..13dbf59556547 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -307,7 +307,7 @@ public function test_get_default_block_editor_settings_max_upload_file_size() { // Force the return value of wp_max_upload_size() to be 500. add_filter( 'upload_size_limit', - static function() { + static function () { return 500; } ); diff --git a/tests/phpunit/tests/blocks/getBlockTemplates.php b/tests/phpunit/tests/blocks/getBlockTemplates.php index 50554479d0591..91f202a0b0119 100644 --- a/tests/phpunit/tests/blocks/getBlockTemplates.php +++ b/tests/phpunit/tests/blocks/getBlockTemplates.php @@ -101,7 +101,7 @@ public function set_up() { */ private function get_template_ids( $templates ) { return array_map( - static function( $template ) { + static function ( $template ) { return $template->id; }, $templates diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index 8ad1a88f3a2b3..eb61f3c307bea 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -957,7 +957,7 @@ public function test_has_blocks_with_invalid_post() { * @ticket 49615 */ public function test_filter_block_registration() { - $filter_registration = static function( $args, $name ) { + $filter_registration = static function ( $args, $name ) { $args['attributes'] = array( $name => array( 'type' => 'boolean' ) ); return $args; }; @@ -975,7 +975,7 @@ public function test_filter_block_registration() { * @ticket 52138 */ public function test_filter_block_registration_metadata() { - $filter_metadata_registration = static function( $metadata ) { + $filter_metadata_registration = static function ( $metadata ) { $metadata['apiVersion'] = 3; return $metadata; }; @@ -993,7 +993,7 @@ public function test_filter_block_registration_metadata() { * @ticket 52138 */ public function test_filter_block_registration_metadata_settings() { - $filter_metadata_registration = static function( $settings, $metadata ) { + $filter_metadata_registration = static function ( $settings, $metadata ) { $settings['api_version'] = $metadata['apiVersion'] + 1; return $settings; }; diff --git a/tests/phpunit/tests/blocks/renderCommentTemplate.php b/tests/phpunit/tests/blocks/renderCommentTemplate.php index 796bbcef8692f..0e29dc2241eec 100644 --- a/tests/phpunit/tests/blocks/renderCommentTemplate.php +++ b/tests/phpunit/tests/blocks/renderCommentTemplate.php @@ -536,7 +536,7 @@ public function test_rendering_comment_template_sets_comment_id_context() { add_filter( 'render_block', - static function( $block_content, $block ) use ( $parsed_comment_author_name_block ) { + static function ( $block_content, $block ) use ( $parsed_comment_author_name_block ) { /* * Insert a Comment Author Name block (which requires `commentId` * block context to work) after the Comment Content block. @@ -591,7 +591,7 @@ public function test_inner_block_inserted_by_render_block_data_is_retained() { $render_block_callback = new MockAction(); add_filter( 'render_block', array( $render_block_callback, 'filter' ), 10, 3 ); - $render_block_data_callback = static function( $parsed_block ) { + $render_block_data_callback = static function ( $parsed_block ) { // Add a Social Links block to a Comment Template block's inner blocks. if ( 'core/comment-template' === $parsed_block['blockName'] ) { $inserted_block_markup = <<registry->register( 'core/dynamic', array( - 'render_callback' => static function() { + 'render_callback' => static function () { return 'b'; }, ) @@ -296,7 +296,7 @@ public function test_render_passes_block_for_render_callback() { $this->registry->register( 'core/greeting', array( - 'render_callback' => static function( $attributes, $content, $block ) { + 'render_callback' => static function ( $attributes, $content, $block ) { return sprintf( 'Hello from %s', $block->name ); }, ) @@ -366,7 +366,7 @@ public function test_passes_attributes_to_render_callback() { 'default' => '!', ), ), - 'render_callback' => static function( $block_attributes ) { + 'render_callback' => static function ( $block_attributes ) { return sprintf( 'Hello %s%s', $block_attributes['toWhom'], @@ -391,7 +391,7 @@ public function test_passes_content_to_render_callback() { $this->registry->register( 'core/outer', array( - 'render_callback' => static function( $block_attributes, $content ) { + 'render_callback' => static function ( $block_attributes, $content ) { return $content; }, ) @@ -399,7 +399,7 @@ public function test_passes_content_to_render_callback() { $this->registry->register( 'core/inner', array( - 'render_callback' => static function() { + 'render_callback' => static function () { return 'b'; }, ) @@ -601,7 +601,7 @@ public function test_query_loop_block_query_vars_filter() { add_filter( 'query_loop_block_query_vars', - static function( $query, $block, $page ) { + static function ( $query, $block, $page ) { $query['post_type'] = 'book'; return $query; }, @@ -768,7 +768,7 @@ public function test_block_filters_for_inner_blocks() { $this->registry->register( 'core/outer', array( - 'render_callback' => static function( $block_attributes, $content ) { + 'render_callback' => static function ( $block_attributes, $content ) { return $content; }, ) @@ -777,7 +777,7 @@ public function test_block_filters_for_inner_blocks() { $this->registry->register( 'core/inner', array( - 'render_callback' => static function() { + 'render_callback' => static function () { return 'b'; }, ) diff --git a/tests/phpunit/tests/canonical.php b/tests/phpunit/tests/canonical.php index 6d16402112c21..10edea42bf517 100644 --- a/tests/phpunit/tests/canonical.php +++ b/tests/phpunit/tests/canonical.php @@ -247,7 +247,7 @@ public function test_pre_redirect_guess_404_permalink() { // Test short-circuit filter. add_filter( 'pre_redirect_guess_404_permalink', - static function() { + static function () { return 'wp'; } ); diff --git a/tests/phpunit/tests/category/walkerCategory.php b/tests/phpunit/tests/category/walkerCategory.php index 2728b11131168..9e1ff4e094525 100644 --- a/tests/phpunit/tests/category/walkerCategory.php +++ b/tests/phpunit/tests/category/walkerCategory.php @@ -40,7 +40,7 @@ public function test_start_el_with_empty_attributes( $value, $expected ) { add_filter( 'category_list_link_attributes', - static function( $atts ) use ( $value ) { + static function ( $atts ) use ( $value ) { $atts['data-test'] = $value; return $atts; } diff --git a/tests/phpunit/tests/cron.php b/tests/phpunit/tests/cron.php index 6369a244c624e..ec97b366d0713 100644 --- a/tests/phpunit/tests/cron.php +++ b/tests/phpunit/tests/cron.php @@ -910,7 +910,7 @@ public function test_disallowed_event_returns_error_when_wp_error_is_set_to_true * @covers ::wp_reschedule_event */ public function test_schedule_short_circuit_with_error_returns_false_when_wp_error_is_set_to_false() { - $return_error = function( $pre, $event, $wp_error ) { + $return_error = function ( $pre, $event, $wp_error ) { $this->assertFalse( $wp_error ); return new WP_Error( @@ -942,7 +942,7 @@ public function test_schedule_short_circuit_with_error_returns_false_when_wp_err * @covers ::wp_reschedule_event */ public function test_schedule_short_circuit_with_error_returns_error_when_wp_error_is_set_to_true() { - $return_error = function( $pre, $event, $wp_error ) { + $return_error = function ( $pre, $event, $wp_error ) { $this->assertTrue( $wp_error ); return new WP_Error( @@ -1029,7 +1029,7 @@ public function test_schedule_short_circuit_with_false_returns_error_when_wp_err * @covers ::wp_clear_scheduled_hook */ public function test_deprecated_argument_usage_of_wp_clear_scheduled_hook() { - $return_pre = function( $pre, $hook, $args, $wp_error ) { + $return_pre = function ( $pre, $hook, $args, $wp_error ) { $this->assertSame( array( 1, 2, 3 ), $args ); $this->assertFalse( $wp_error ); @@ -1072,7 +1072,7 @@ public function test_clear_scheduled_hook_returns_default_pre_filter_error_when_ * @covers ::wp_clear_scheduled_hook */ public function test_clear_scheduled_hook_returns_custom_pre_filter_error_when_wp_error_is_set_to_true() { - $return_error = function( $pre, $timestamp, $hook, $args, $wp_error ) { + $return_error = function ( $pre, $timestamp, $hook, $args, $wp_error ) { $this->assertTrue( $wp_error ); return new WP_Error( 'error_code', 'error message' ); @@ -1107,7 +1107,7 @@ public function test_clear_scheduled_hook_returns_custom_pre_filter_error_when_w * @covers ::wp_unschedule_hook */ public function test_unschedule_short_circuit_with_error_returns_false_when_wp_error_is_set_to_false() { - $return_error = function( $pre, $hook, $wp_error ) { + $return_error = function ( $pre, $hook, $wp_error ) { $this->assertFalse( $wp_error ); return new WP_Error( @@ -1132,7 +1132,7 @@ public function test_unschedule_short_circuit_with_error_returns_false_when_wp_e * @covers ::wp_unschedule_hook */ public function test_unschedule_short_circuit_with_error_returns_error_when_wp_error_is_set_to_true() { - $return_error = function( $pre, $hook, $wp_error ) { + $return_error = function ( $pre, $hook, $wp_error ) { $this->assertTrue( $wp_error ); return new WP_Error( @@ -1194,7 +1194,7 @@ public function test_cron_array_error_is_returned_when_scheduling_single_event() // Force update_option() to fail by setting the new value to match the existing: add_filter( 'pre_update_option_cron', - static function() { + static function () { return get_option( 'cron' ); } ); @@ -1216,7 +1216,7 @@ public function test_cron_array_error_is_returned_when_scheduling_event() { // Force update_option() to fail by setting the new value to match the existing: add_filter( 'pre_update_option_cron', - static function() { + static function () { return get_option( 'cron' ); } ); @@ -1241,7 +1241,7 @@ public function test_cron_array_error_is_returned_when_unscheduling_hook() { // Force update_option() to fail by setting the new value to match the existing: add_filter( 'pre_update_option_cron', - static function() { + static function () { return get_option( 'cron' ); } ); @@ -1267,7 +1267,7 @@ public function test_cron_array_error_is_returned_when_unscheduling_event() { // Force update_option() to fail by setting the new value to match the existing: add_filter( 'pre_update_option_cron', - static function() { + static function () { return get_option( 'cron' ); } ); diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index ca88433713113..37e751b294651 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -2917,7 +2917,7 @@ public function test_wp_external_wp_i18n_print_order() { wp_set_script_translations( 'common' ); $print_scripts = get_echo( - static function() { + static function () { wp_print_scripts(); _print_scripts(); } diff --git a/tests/phpunit/tests/feed/rss2.php b/tests/phpunit/tests/feed/rss2.php index 6fd0ba8c15eda..9a45230d3958c 100644 --- a/tests/phpunit/tests/feed/rss2.php +++ b/tests/phpunit/tests/feed/rss2.php @@ -533,7 +533,7 @@ public function test_feed_last_modified_should_be_a_post_date_when_withcomments_ // The Last-Modified header should have the post's date when "withcomments" is not passed. add_filter( 'wp_headers', - function( $headers ) use ( $last_week ) { + function ( $headers ) use ( $last_week ) { $this->assertSame( strtotime( $headers['Last-Modified'] ), strtotime( $last_week ), @@ -572,7 +572,7 @@ public function test_feed_last_modified_should_be_the_date_of_a_comment_that_is_ // The Last-Modified header should have the comment's date when "withcomments=1" is passed. add_filter( 'wp_headers', - function( $headers ) use ( $yesterday ) { + function ( $headers ) use ( $yesterday ) { $this->assertSame( strtotime( $headers['Last-Modified'] ), strtotime( $yesterday ), @@ -615,7 +615,7 @@ public function test_feed_last_modified_should_be_the_date_of_a_post_that_is_the // The Last-Modified header should have the date from today's post when it is the latest update. add_filter( 'wp_headers', - function( $headers ) use ( $today ) { + function ( $headers ) use ( $today ) { $this->assertSame( strtotime( $headers['Last-Modified'] ), strtotime( $today ), diff --git a/tests/phpunit/tests/file.php b/tests/phpunit/tests/file.php index 5102faab51f16..c99f1baffdd55 100644 --- a/tests/phpunit/tests/file.php +++ b/tests/phpunit/tests/file.php @@ -251,7 +251,7 @@ public function test_wp_tempnam_should_limit_filename_length_to_252_characters_w // Create a conflict by removing the randomness of the generated password. add_filter( 'random_password', - static function() { + static function () { return '123456'; }, 10, @@ -285,7 +285,7 @@ public function test_wp_tempnam_should_limit_filename_length_to_252_characters_w // Force random passwords to 12 characters. add_filter( 'random_password', - static function() { + static function () { return '1a2b3c4d5e6f'; }, 10, @@ -321,7 +321,7 @@ public function test_wp_tempnam_should_limit_filename_length_to_252_characters_w // Make the filter send the filename over the limit. add_filter( 'wp_unique_filename', - static function( $filename ) use ( &$filenames_over_limit ) { + static function ( $filename ) use ( &$filenames_over_limit ) { if ( strlen( $filename ) === 252 ) { $filename .= '1'; ++$filenames_over_limit; @@ -357,7 +357,7 @@ public function test_wp_tempnam_should_limit_filename_length_to_252_characters_w // Force random passwords to 12 characters. add_filter( 'random_password', - static function() { + static function () { return '1a2b3c4d5e6f'; }, 10, @@ -375,7 +375,7 @@ static function() { // Make the filter send the filename over the limit. add_filter( 'wp_unique_filename', - static function( $filename ) use ( &$filenames_over_limit ) { + static function ( $filename ) use ( &$filenames_over_limit ) { if ( strlen( $filename ) === 252 ) { $filename .= '1'; ++$filenames_over_limit; diff --git a/tests/phpunit/tests/formatting/wpTrimExcerpt.php b/tests/phpunit/tests/formatting/wpTrimExcerpt.php index 1cb4389ee9a35..ba5e99f7d8074 100644 --- a/tests/phpunit/tests/formatting/wpTrimExcerpt.php +++ b/tests/phpunit/tests/formatting/wpTrimExcerpt.php @@ -108,7 +108,7 @@ public function test_wp_trim_excerpt_unhooks_wp_filter_content_tags() { $has_filter = true; add_filter( 'the_content', - static function( $content ) use ( &$has_filter ) { + static function ( $content ) use ( &$has_filter ) { $has_filter = has_filter( 'the_content', 'wp_filter_content_tags' ); return $content; } diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 0a5703d94ba8e..5c8a1aa25fa26 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -1726,7 +1726,7 @@ public function test_wp_check_filetype_and_ext_with_filtered_svg() { add_filter( 'upload_mimes', - static function( $mimes ) { + static function ( $mimes ) { $mimes['svg'] = 'image/svg+xml'; return $mimes; } @@ -1764,7 +1764,7 @@ public function test_wp_check_filetype_and_ext_with_filtered_woff() { add_filter( 'upload_mimes', - static function( $mimes ) use ( $woff_mime_type ) { + static function ( $mimes ) use ( $woff_mime_type ) { $mimes['woff'] = $woff_mime_type; return $mimes; } diff --git a/tests/phpunit/tests/functions/wpFilesize.php b/tests/phpunit/tests/functions/wpFilesize.php index f0e510ddc5943..250f7e79c7724 100644 --- a/tests/phpunit/tests/functions/wpFilesize.php +++ b/tests/phpunit/tests/functions/wpFilesize.php @@ -25,7 +25,7 @@ public function test_wp_filesize_filters() { add_filter( 'wp_filesize', - static function() { + static function () { return 999; } ); @@ -34,7 +34,7 @@ static function() { add_filter( 'pre_wp_filesize', - static function() { + static function () { return 111; } ); diff --git a/tests/phpunit/tests/general/feedLinksExtra.php b/tests/phpunit/tests/general/feedLinksExtra.php index ee7f93640f1fe..3bea946e1aff1 100644 --- a/tests/phpunit/tests/general/feedLinksExtra.php +++ b/tests/phpunit/tests/general/feedLinksExtra.php @@ -491,14 +491,14 @@ public function test_feed_links_extra_should_return_empty_when_comments_and_ping public function test_feed_links_extra_should_respect_feed_type() { add_filter( 'default_feed', - static function() { + static function () { return 'foo'; } ); add_filter( 'feed_content_type', - static function() { + static function () { return 'testing/foo'; } ); diff --git a/tests/phpunit/tests/http/http.php b/tests/phpunit/tests/http/http.php index 876a5ed60b895..1648cca4eaf9f 100644 --- a/tests/phpunit/tests/http/http.php +++ b/tests/phpunit/tests/http/http.php @@ -593,7 +593,7 @@ public function test_multiple_location_headers() { // Filter the response made by WP_Http::handle_redirects(). add_filter( 'pre_http_request', - function( $response, $parsed_args, $url ) use ( &$pre_http_request_filter_has_run ) { + function ( $response, $parsed_args, $url ) use ( &$pre_http_request_filter_has_run ) { $pre_http_request_filter_has_run = true; // Assert the redirect URL is correct. diff --git a/tests/phpunit/tests/https-detection.php b/tests/phpunit/tests/https-detection.php index 820f39fc6e47a..80f16846994a9 100644 --- a/tests/phpunit/tests/https-detection.php +++ b/tests/phpunit/tests/https-detection.php @@ -117,7 +117,7 @@ public function test_pre_wp_update_https_detection_errors() { // Override to enforce no errors being detected. add_filter( 'pre_wp_update_https_detection_errors', - static function() { + static function () { return new WP_Error(); } ); @@ -127,7 +127,7 @@ static function() { // Override to enforce an error being detected. add_filter( 'pre_wp_update_https_detection_errors', - static function() { + static function () { return new WP_Error( 'ssl_verification_failed', 'Bad SSL certificate.' @@ -316,7 +316,7 @@ private function get_sample_html_string( $head_tag = '' ) { * @return callable Filter callback. */ private function filter_set_url_scheme( $scheme ) { - return static function( $url ) use ( $scheme ) { + return static function ( $url ) use ( $scheme ) { return set_url_scheme( $url, $scheme ); }; } diff --git a/tests/phpunit/tests/https-migration.php b/tests/phpunit/tests/https-migration.php index d06e1f0fba053..ae66738603e13 100644 --- a/tests/phpunit/tests/https-migration.php +++ b/tests/phpunit/tests/https-migration.php @@ -161,7 +161,7 @@ public function test_wp_should_replace_insecure_home_url_integration() { private function force_wp_is_using_https( $enabled ) { $scheme = $enabled ? 'https' : 'http'; - $replace_scheme = static function( $url ) use ( $scheme ) { + $replace_scheme = static function ( $url ) use ( $scheme ) { return str_replace( array( 'http://', 'https://' ), $scheme . '://', $url ); }; @@ -172,7 +172,7 @@ private function force_wp_is_using_https( $enabled ) { private function force_option( $option, $value ) { add_filter( "option_$option", - static function() use ( $value ) { + static function () use ( $value ) { return $value; } ); diff --git a/tests/phpunit/tests/image/editorImagick.php b/tests/phpunit/tests/image/editorImagick.php index 1209203904033..30747f69f1b62 100644 --- a/tests/phpunit/tests/image/editorImagick.php +++ b/tests/phpunit/tests/image/editorImagick.php @@ -683,7 +683,7 @@ public function test_remove_pdf_alpha_channel_should_remove_the_alpha_channel_in $check_file = path_join( dirname( $attached_file ), $check['file'] ); $imagick = new Imagick( $check_file ); $output = array_map( - static function( $value ) { + static function ( $value ) { return (int) round( $value ); }, array_intersect_key( $imagick->getImagePixelColor( 100, 100 )->getColor( true /* normalized */ ), $rgb ) diff --git a/tests/phpunit/tests/image/functions.php b/tests/phpunit/tests/image/functions.php index 356b2dceacd8c..f55b164496a84 100644 --- a/tests/phpunit/tests/image/functions.php +++ b/tests/phpunit/tests/image/functions.php @@ -692,7 +692,7 @@ public function test_wp_crop_image_should_fail_with_wp_error_object_if_there_was add_filter( 'wp_image_editors', - static function( $editors ) { + static function ( $editors ) { return array( 'WP_Image_Editor_Mock' ); } ); @@ -718,7 +718,7 @@ static function( $editors ) { public function test_wp_crop_image_should_return_correct_file_extension_if_output_format_was_modified() { add_filter( 'image_editor_output_format', - static function() { + static function () { return array_fill_keys( array( 'image/jpg', 'image/jpeg', 'image/png' ), 'image/webp' ); } ); diff --git a/tests/phpunit/tests/image/intermediateSize.php b/tests/phpunit/tests/image/intermediateSize.php index 830359427a8fd..e297bf8427219 100644 --- a/tests/phpunit/tests/image/intermediateSize.php +++ b/tests/phpunit/tests/image/intermediateSize.php @@ -69,7 +69,7 @@ public function test_make_intermediate_size_successful() { public function test_image_editor_output_format_filter() { add_filter( 'image_editor_output_format', - static function() { + static function () { return array( 'image/jpeg' => 'image/webp' ); } ); diff --git a/tests/phpunit/tests/l10n/determineLocale.php b/tests/phpunit/tests/l10n/determineLocale.php index a2c3febd4a0ab..51ab1c28b95f6 100644 --- a/tests/phpunit/tests/l10n/determineLocale.php +++ b/tests/phpunit/tests/l10n/determineLocale.php @@ -33,7 +33,7 @@ public function test_short_circuit_empty() { public function test_short_circuit_no_string() { add_filter( 'pre_determine_locale', - static function() { + static function () { return 1234; } ); @@ -43,7 +43,7 @@ static function() { public function test_short_circuit_string() { add_filter( 'pre_determine_locale', - static function() { + static function () { return 'myNewLocale'; } ); @@ -53,7 +53,7 @@ static function() { public function test_defaults_to_site_locale() { add_filter( 'locale', - static function() { + static function () { return 'siteLocale'; } ); @@ -64,7 +64,7 @@ static function() { public function test_is_admin_no_user() { add_filter( 'locale', - static function() { + static function () { return 'siteLocale'; } ); @@ -77,7 +77,7 @@ static function() { public function test_is_admin_user_locale() { add_filter( 'locale', - static function() { + static function () { return 'siteLocale'; } ); @@ -91,7 +91,7 @@ static function() { public function test_json_request_user_locale() { add_filter( 'locale', - static function() { + static function () { return 'siteLocale'; } ); @@ -107,7 +107,7 @@ static function() { public function test_json_request_user_locale_no_user() { add_filter( 'locale', - static function() { + static function () { return 'siteLocale'; } ); @@ -121,7 +121,7 @@ static function() { public function test_json_request_missing_get_param() { add_filter( 'locale', - static function() { + static function () { return 'siteLocale'; } ); @@ -136,7 +136,7 @@ static function() { public function test_json_request_incorrect_get_param() { add_filter( 'locale', - static function() { + static function () { return 'siteLocale'; } ); @@ -152,7 +152,7 @@ static function() { public function test_get_param_but_no_json_request() { add_filter( 'locale', - static function() { + static function () { return 'siteLocale'; } ); @@ -167,7 +167,7 @@ static function() { public function test_wp_login_get_param_not_on_login_page() { add_filter( 'locale', - static function() { + static function () { return 'siteLocale'; } ); @@ -182,7 +182,7 @@ static function() { public function test_wp_login_get_param_on_login_page() { add_filter( 'locale', - static function() { + static function () { return 'siteLocale'; } ); @@ -198,7 +198,7 @@ static function() { public function test_wp_login_get_param_on_login_page_empty_string() { add_filter( 'locale', - static function() { + static function () { return 'siteLocale'; } ); @@ -214,7 +214,7 @@ static function() { public function test_wp_login_get_param_on_login_page_incorrect_string() { add_filter( 'locale', - static function() { + static function () { return 'siteLocale'; } ); @@ -230,7 +230,7 @@ static function() { public function test_wp_login_cookie_not_on_login_page() { add_filter( 'locale', - static function() { + static function () { return 'siteLocale'; } ); @@ -245,7 +245,7 @@ static function() { public function test_wp_login_cookie_on_login_page() { add_filter( 'locale', - static function() { + static function () { return 'siteLocale'; } ); @@ -261,7 +261,7 @@ static function() { public function test_wp_login_cookie_on_login_page_empty_string() { add_filter( 'locale', - static function() { + static function () { return 'siteLocale'; } ); diff --git a/tests/phpunit/tests/link/editTermLink.php b/tests/phpunit/tests/link/editTermLink.php index 3128ddfe0eb09..2e0145e5967c2 100644 --- a/tests/phpunit/tests/link/editTermLink.php +++ b/tests/phpunit/tests/link/editTermLink.php @@ -101,7 +101,7 @@ public function test_edit_term_link_filter_should_receive_term_id( $taxonomy, $u add_filter( 'edit_term_link', - function( $location, $term ) { + function ( $location, $term ) { $this->assertIsInt( $term ); }, 10, diff --git a/tests/phpunit/tests/link/getEditTermLink.php b/tests/phpunit/tests/link/getEditTermLink.php index 2df1aa7aac111..d0303f1b1a403 100644 --- a/tests/phpunit/tests/link/getEditTermLink.php +++ b/tests/phpunit/tests/link/getEditTermLink.php @@ -187,7 +187,7 @@ public function test_get_edit_term_link_filter_should_receive_term_id( $taxonomy add_filter( 'get_edit_term_link', - function( $location, $term ) { + function ( $location, $term ) { $this->assertIsInt( $term ); }, 10, diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 545d1c854f3a4..ebd2f767e1d3d 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -2357,7 +2357,7 @@ public function test_wp_filter_content_tags_filter_with_identical_image_tags_cus add_filter( 'wp_content_img_tag', - static function( $filtered_image ) { + static function ( $filtered_image ) { return "$filtered_image"; } ); @@ -2381,7 +2381,7 @@ public function test_wp_filter_content_tags_filter_with_identical_image_tags_dis add_filter( 'wp_content_img_tag', - static function( $filtered_image ) { + static function ( $filtered_image ) { return "$filtered_image"; } ); @@ -4020,7 +4020,7 @@ public function test_wp_filter_content_tags_does_not_lazy_load_first_featured_im add_filter( 'wp_img_tag_add_decoding_attr', '__return_false' ); add_filter( 'wp_get_attachment_image_attributes', - static function( $attr ) { + static function ( $attr ) { unset( $attr['srcset'], $attr['sizes'], $attr['decoding'] ); return $attr; } @@ -4154,7 +4154,7 @@ public function test_wp_filter_content_tags_does_not_apply_loading_optimization_ // Overwrite post content with an image. add_filter( 'the_content', - static function() use ( &$image_within_content ) { + static function () use ( &$image_within_content ) { // Replace content with an image tag, i.e. the 'wp_get_attachment_image' context is used while running 'the_content' filter. $image_within_content = wp_get_attachment_image( self::$large_id, 'large', false ); return $image_within_content; @@ -4221,7 +4221,7 @@ public function test_wp_get_loading_attr_default_should_return_false_for_special $result = null; add_filter( 'the_content', - static function( $content ) use ( &$result, $context ) { + static function ( $content ) use ( &$result, $context ) { $result = wp_get_loading_attr_default( $context ); return $content; } @@ -4523,7 +4523,7 @@ public function test_wp_get_loading_optimization_attributes_should_not_modify_im $result = null; add_filter( 'the_content', - function( $content ) use ( &$result, $context ) { + function ( $content ) use ( &$result, $context ) { $attr = $this->get_width_height_for_high_priority(); $result = wp_get_loading_optimization_attributes( 'img', $attr, $context ); return $content; @@ -4805,7 +4805,7 @@ public function test_wp_get_attachment_image_context_filter_value_is_passed_corr // Add a filter that modifies the context. add_filter( 'wp_get_attachment_image_context', - static function() { + static function () { return 'my_custom_context'; } ); @@ -5208,7 +5208,7 @@ public function test_wp_maybe_add_fetchpriority_high_attr_min_priority_filter() add_filter( 'wp_min_priority_img_pixels', - static function( $res ) { + static function ( $res ) { return 2500; // 50*50=2500 } ); @@ -5281,7 +5281,7 @@ public function test_wp_get_loading_optimization_attributes_image_before_loop_in private function track_last_attachment_image_context( &$last_context ) { add_filter( 'wp_get_attachment_image_context', - static function( $context ) use ( &$last_context ) { + static function ( $context ) use ( &$last_context ) { $last_context = $context; return $context; }, @@ -5336,7 +5336,7 @@ public function image_editor_change_quality_low_jpeg( $quality, $mime_type ) { public function force_omit_loading_attr_threshold( $threshold ) { add_filter( 'wp_omit_loading_attr_threshold', - static function() use ( $threshold ) { + static function () use ( $threshold ) { return $threshold; } ); diff --git a/tests/phpunit/tests/media/wpGenerateAttachmentMetadata.php b/tests/phpunit/tests/media/wpGenerateAttachmentMetadata.php index 82fe7dabd61b2..fee7ebb5776eb 100644 --- a/tests/phpunit/tests/media/wpGenerateAttachmentMetadata.php +++ b/tests/phpunit/tests/media/wpGenerateAttachmentMetadata.php @@ -73,7 +73,7 @@ public function test_wp_generate_attachment_metadata_includes_filesize_in_psd_me // PSD mime type is not allowed by default on multisite. add_filter( 'upload_mimes', - static function( $mimes ) { + static function ( $mimes ) { $mimes['psd'] = 'application/octet-stream'; return $mimes; } diff --git a/tests/phpunit/tests/media/wpImageTagAddDecodingAttr.php b/tests/phpunit/tests/media/wpImageTagAddDecodingAttr.php index 3ffe1bc6b4a19..7011d816da1ab 100644 --- a/tests/phpunit/tests/media/wpImageTagAddDecodingAttr.php +++ b/tests/phpunit/tests/media/wpImageTagAddDecodingAttr.php @@ -25,7 +25,7 @@ public function test_should_add_decoding_attr( $image, $context, $decoding, $exp if ( 'no value' !== $decoding ) { add_filter( 'wp_img_tag_add_decoding_attr', - static function( $value ) use ( $decoding ) { + static function ( $value ) use ( $decoding ) { return $decoding; } ); @@ -86,7 +86,7 @@ public function test_should_not_add_decoding_attr( $image, $context, $decoding, if ( 'no value' !== $decoding ) { add_filter( 'wp_img_tag_add_decoding_attr', - static function( $value ) use ( $decoding ) { + static function ( $value ) use ( $decoding ) { return $decoding; } ); diff --git a/tests/phpunit/tests/menu/walker-nav-menu.php b/tests/phpunit/tests/menu/walker-nav-menu.php index 1fa255ef61305..878bf12cc4c4b 100644 --- a/tests/phpunit/tests/menu/walker-nav-menu.php +++ b/tests/phpunit/tests/menu/walker-nav-menu.php @@ -101,7 +101,7 @@ public function test_start_el_with_empty_attributes( $value, $expected ) { add_filter( 'nav_menu_link_attributes', - static function( $atts ) use ( $value ) { + static function ( $atts ) use ( $value ) { $atts['data-test'] = $value; return $atts; } diff --git a/tests/phpunit/tests/option/wpSetOptionAutoloadValues.php b/tests/phpunit/tests/option/wpSetOptionAutoloadValues.php index a49348db13d02..f474bd1093b3a 100644 --- a/tests/phpunit/tests/option/wpSetOptionAutoloadValues.php +++ b/tests/phpunit/tests/option/wpSetOptionAutoloadValues.php @@ -186,7 +186,7 @@ public function test_wp_set_option_autoload_values_with_sql_query_failure() { // Force UPDATE queries to fail, leading to no autoload values being updated. add_filter( 'query', - static function( $query ) { + static function ( $query ) { if ( str_starts_with( $query, 'UPDATE ' ) ) { return ''; } diff --git a/tests/phpunit/tests/post/getPages.php b/tests/phpunit/tests/post/getPages.php index c0aa28564d7d2..626f2a528c509 100644 --- a/tests/phpunit/tests/post/getPages.php +++ b/tests/phpunit/tests/post/getPages.php @@ -344,7 +344,7 @@ public function test_get_pages_test_filter() { // Filter the query to return the wptests_pt post type. add_filter( 'get_pages_query_args', - static function( $query_args, $parsed_args ) use ( &$query_args_values, &$parsed_args_values ) { + static function ( $query_args, $parsed_args ) use ( &$query_args_values, &$parsed_args_values ) { $query_args['post_type'] = 'wptests_pt'; $query_args_values = $query_args; $parsed_args_values = $parsed_args; diff --git a/tests/phpunit/tests/post/revisions.php b/tests/phpunit/tests/post/revisions.php index 8bdcb399b4a46..a4e45aefcf349 100644 --- a/tests/phpunit/tests/post/revisions.php +++ b/tests/phpunit/tests/post/revisions.php @@ -883,7 +883,7 @@ public function test_wp_save_post_revision_should_respect_revisions_before_delet add_filter( 'wp_revisions_to_keep', - static function() { + static function () { return 1; } ); diff --git a/tests/phpunit/tests/post/thumbnails.php b/tests/phpunit/tests/post/thumbnails.php index 44801059a88ac..b06ec025708cf 100644 --- a/tests/phpunit/tests/post/thumbnails.php +++ b/tests/phpunit/tests/post/thumbnails.php @@ -571,7 +571,7 @@ public function test_get_the_post_thumbnail_should_remove_the_post_thumbnail_con private function track_last_attachment_image_context( &$last_context ) { add_filter( 'wp_get_attachment_image_context', - static function( $context ) use ( &$last_context ) { + static function ( $context ) use ( &$last_context ) { $last_context = $context; return $context; }, diff --git a/tests/phpunit/tests/post/walkerPage.php b/tests/phpunit/tests/post/walkerPage.php index a5a632dcdaa85..d8a2312a54eff 100644 --- a/tests/phpunit/tests/post/walkerPage.php +++ b/tests/phpunit/tests/post/walkerPage.php @@ -33,7 +33,7 @@ public function test_start_el_with_empty_attributes( $value, $expected ) { add_filter( 'page_menu_link_attributes', - static function( $atts ) use ( $value ) { + static function ( $atts ) use ( $value ) { $atts['data-test'] = $value; return $atts; } diff --git a/tests/phpunit/tests/post/wpGetAttachmentLink.php b/tests/phpunit/tests/post/wpGetAttachmentLink.php index 2d658e002e572..141b8a2427af4 100644 --- a/tests/phpunit/tests/post/wpGetAttachmentLink.php +++ b/tests/phpunit/tests/post/wpGetAttachmentLink.php @@ -41,7 +41,7 @@ public function test_should_apply_attributes_filter( $attributes, $expected ) { add_filter( 'wp_get_attachment_link_attributes', - static function( $attr ) use ( $attributes ) { + static function ( $attr ) use ( $attributes ) { return array_merge( $attr, $attributes ); } ); diff --git a/tests/phpunit/tests/query.php b/tests/phpunit/tests/query.php index 52c6ebfc12ec1..37dd51a06392a 100644 --- a/tests/phpunit/tests/query.php +++ b/tests/phpunit/tests/query.php @@ -730,7 +730,7 @@ public function test_get_queried_object_should_work_for_author_name_before_get_p public function test_posts_clauses_filter_should_receive_filtered_clauses() { add_filter( 'posts_join_paged', - static function() { + static function () { return '/* posts_join_paged */'; } ); @@ -755,7 +755,7 @@ static function() { public function test_posts_clauses_request_filter_should_receive_filtered_clauses() { add_filter( 'posts_join_request', - static function() { + static function () { return '/* posts_join_request */'; } ); diff --git a/tests/phpunit/tests/query/conditionals.php b/tests/phpunit/tests/query/conditionals.php index 8eed70288bc14..05278ffd7a4cd 100644 --- a/tests/phpunit/tests/query/conditionals.php +++ b/tests/phpunit/tests/query/conditionals.php @@ -1641,14 +1641,14 @@ public function data_conditional_tags_trigger_doing_it_wrong_and_return_false_if // Get the list of `is_*()` conditional tags. $functions = array_filter( get_class_methods( 'WP_Query' ), - static function( $function_name ) { + static function ( $function_name ) { return str_starts_with( $function_name, 'is_' ); } ); // Wrap each function name in an array. $functions = array_map( - static function( $function_name ) { + static function ( $function_name ) { return array( $function_name ); }, $functions diff --git a/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php b/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php index 0515c31512d3c..96d1b193bbb73 100644 --- a/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php +++ b/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php @@ -961,7 +961,7 @@ public function test_introspect_item_password_invalid() { $this->setup_app_password_authenticated_request(); add_action( 'application_password_did_authenticate', - static function() { + static function () { $GLOBALS['wp_rest_application_password_uuid'] = 'invalid_uuid'; } ); diff --git a/tests/phpunit/tests/rest-api/rest-block-directory-controller.php b/tests/phpunit/tests/rest-api/rest-block-directory-controller.php index c3cac6011e491..f61b317240532 100644 --- a/tests/phpunit/tests/rest-api/rest-block-directory-controller.php +++ b/tests/phpunit/tests/rest-api/rest-block-directory-controller.php @@ -359,7 +359,7 @@ private function get_mock_plugin() { private function mock_remote_request( array $expected ) { add_filter( 'pre_http_request', - static function() use ( $expected ) { + static function () use ( $expected ) { $default = array( 'headers' => array(), 'response' => array( diff --git a/tests/phpunit/tests/rest-api/rest-block-renderer-controller.php b/tests/phpunit/tests/rest-api/rest-block-renderer-controller.php index 3c79da56510d3..3573ecb6e0bea 100644 --- a/tests/phpunit/tests/rest-api/rest-block-renderer-controller.php +++ b/tests/phpunit/tests/rest-api/rest-block-renderer-controller.php @@ -429,7 +429,7 @@ public function test_get_item() { public function test_get_item_with_pre_render_block_filter() { wp_set_current_user( self::$user_id ); - $pre_render_filter = static function( $output, $block ) { + $pre_render_filter = static function ( $output, $block ) { if ( $block['blockName'] === self::$block_name ) { return '

Alternate content.

'; } diff --git a/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php b/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php index d8f15013b99b8..eda42beebe25f 100644 --- a/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php +++ b/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php @@ -310,7 +310,7 @@ public function test_get_items_prepare_filter() { // Test that filter changes uncached values. add_filter( 'rest_prepare_block_pattern', - static function( $response ) { + static function ( $response ) { return 'initial value'; } ); @@ -324,7 +324,7 @@ static function( $response ) { // Test that filter changes cached values (the previous request primed the cache). add_filter( 'rest_prepare_block_pattern', - static function( $response ) { + static function ( $response ) { return 'modified the cache'; }, 11 diff --git a/tests/phpunit/tests/rest-api/rest-plugins-controller.php b/tests/phpunit/tests/rest-api/rest-plugins-controller.php index 1375c81061b8e..1da20c83159d4 100644 --- a/tests/phpunit/tests/rest-api/rest-plugins-controller.php +++ b/tests/phpunit/tests/rest-api/rest-plugins-controller.php @@ -537,7 +537,7 @@ public function test_create_item_unknown_plugin() { wp_set_current_user( self::$super_admin ); add_filter( 'pre_http_request', - static function() { + static function () { /* * Mocks the request to: * https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&request%5Bslug%5D=alex-says-this-block-definitely-doesnt-exist&request%5Bfields%5D%5Bsections%5D=0&request%5Bfields%5D%5Blanguage_packs%5D=1&request%5Blocale%5D=en_US&request%5Bwp_version%5D=5.9 diff --git a/tests/phpunit/tests/rest-api/rest-post-meta-fields.php b/tests/phpunit/tests/rest-api/rest-post-meta-fields.php index 2142e805820a6..11d06b86bef74 100644 --- a/tests/phpunit/tests/rest-api/rest-post-meta-fields.php +++ b/tests/phpunit/tests/rest-api/rest-post-meta-fields.php @@ -2742,7 +2742,7 @@ public function test_boolean_meta_update_to_false_stores_0() { 'single' => true, 'type' => 'boolean', 'show_in_rest' => true, - 'sanitize_callback' => static function( $value ) { + 'sanitize_callback' => static function ( $value ) { return $value ? '1' : '0'; }, ) diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index 92d1262195456..3b584642956eb 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -2278,7 +2278,7 @@ public function test_prepare_item_limit_fields() { */ public function test_prepare_item_filters_content_when_needed() { $filter_count = 0; - $filter_content = static function() use ( &$filter_count ) { + $filter_content = static function () use ( &$filter_count ) { ++$filter_count; return '

Filtered content.

'; }; @@ -2314,7 +2314,7 @@ public function test_prepare_item_filters_content_when_needed() { */ public function test_prepare_item_skips_content_filter_if_not_needed() { $filter_count = 0; - $filter_content = static function() use ( &$filter_count ) { + $filter_content = static function () use ( &$filter_count ) { ++$filter_count; return '

Filtered content.

'; }; diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php index b752b83872af2..a642d37c56f17 100644 --- a/tests/phpunit/tests/rest-api/rest-server.php +++ b/tests/phpunit/tests/rest-api/rest-server.php @@ -937,7 +937,7 @@ public function test_link_embedding_without_links() { * @ticket 56566 */ public function test_link_embedding_returning_wp_error() { - $return_wp_error = static function() { + $return_wp_error = static function () { return new WP_Error( 'some-error', 'This is not valid!' ); }; add_filter( 'rest_pre_dispatch', $return_wp_error ); @@ -1671,7 +1671,7 @@ public function test_get_routes_no_namespace_overriding() { '/test', array( 'methods' => array( 'GET' ), - 'callback' => static function() { + 'callback' => static function () { return new WP_REST_Response( 'data', 204 ); }, 'permission_callback' => '__return_true', @@ -1682,7 +1682,7 @@ public function test_get_routes_no_namespace_overriding() { '/test', array( 'methods' => array( 'GET' ), - 'callback' => static function() { + 'callback' => static function () { return new WP_REST_Response( 'data', 204 ); }, 'permission_callback' => '__return_true', @@ -2080,7 +2080,7 @@ public function test_batch_v1_partial_error() { public function test_batch_v1_max_requests() { add_filter( 'rest_get_max_batch_size', - static function() { + static function () { return 5; } ); @@ -2188,7 +2188,7 @@ public function test_json_encode_error_results_in_500_status_code() { array( array( 'methods' => \WP_REST_Server::READABLE, - 'callback' => static function() { + 'callback' => static function () { return new \WP_REST_Response( INF ); }, 'permission_callback' => '__return_true', diff --git a/tests/phpunit/tests/rest-api/rest-widget-types-controller.php b/tests/phpunit/tests/rest-api/rest-widget-types-controller.php index e9b46d444f371..cac586447e385 100644 --- a/tests/phpunit/tests/rest-api/rest-widget-types-controller.php +++ b/tests/phpunit/tests/rest-api/rest-widget-types-controller.php @@ -161,7 +161,7 @@ public function test_get_items_removes_duplicates() { $data = $response->get_data(); $text_widgets = array_filter( $data, - static function( $widget ) { + static function ( $widget ) { return 'text' === $widget['id']; } ); @@ -189,7 +189,7 @@ public function test_get_widget_legacy() { wp_register_sidebar_widget( $widget_id, 'WP legacy widget', - static function() {} + static function () {} ); wp_set_current_user( self::$admin_id ); $request = new WP_REST_Request( 'GET', '/wp/v2/widget-types/' . $widget_id ); @@ -220,7 +220,7 @@ public function test_get_widgets_decodes_html_entities() { wp_register_sidebar_widget( $widget_id, '‘Legacy ‑ Archive ‑ Widget’', - static function() {}, + static function () {}, array( 'description' => '“A great & interesting archive of your site’s posts!”', ) diff --git a/tests/phpunit/tests/rest-api/wpRestUrlDetailsController.php b/tests/phpunit/tests/rest-api/wpRestUrlDetailsController.php index d8118210526e6..27f526f9d230e 100644 --- a/tests/phpunit/tests/rest-api/wpRestUrlDetailsController.php +++ b/tests/phpunit/tests/rest-api/wpRestUrlDetailsController.php @@ -296,7 +296,7 @@ public function test_can_filter_http_request_args_via_filter() { add_filter( 'rest_url_details_http_request_args', - static function( $args, $url ) { + static function ( $args, $url ) { return array_merge( $args, array( @@ -339,7 +339,7 @@ public function test_will_return_from_cache_if_populated() { // Force cache to return a known value as the remote URL http response body. add_filter( "pre_site_transient_{$transient_name}", - static function() { + static function () { return 'This value from cache.'; } ); @@ -367,7 +367,7 @@ static function() { public function test_allows_filtering_data_retrieved_for_a_given_url() { add_filter( 'rest_prepare_url_details', - static function( $response ) { + static function ( $response ) { $data = $response->get_data(); @@ -417,7 +417,7 @@ public function test_allows_filtering_response() { */ add_filter( 'rest_prepare_url_details', - static function( $response, $url ) { + static function ( $response, $url ) { return new WP_REST_Response( array( 'status' => 418, diff --git a/tests/phpunit/tests/robots.php b/tests/phpunit/tests/robots.php index 87b0e6fb905e0..356224e79b51d 100644 --- a/tests/phpunit/tests/robots.php +++ b/tests/phpunit/tests/robots.php @@ -39,7 +39,7 @@ public function test_wp_robots_renders_when_relevant() { public function test_wp_robots_parses_directives_correctly() { add_filter( 'wp_robots', - static function( array $robots ) { + static function ( array $robots ) { // Directives that should have values must use strings. $robots['directive-with-value'] = 'yes'; $robots['directive-with-numeric-value'] = '1'; diff --git a/tests/phpunit/tests/term/getTermLink.php b/tests/phpunit/tests/term/getTermLink.php index 2a92d8afee78a..94307ba6970a4 100644 --- a/tests/phpunit/tests/term/getTermLink.php +++ b/tests/phpunit/tests/term/getTermLink.php @@ -259,7 +259,7 @@ public function test_term_link_filter_should_receive_term_object( $taxonomy, $us add_filter( 'term_link', - function( $location, $term ) { + function ( $location, $term ) { $this->assertInstanceOf( 'WP_Term', $term ); }, 10, diff --git a/tests/phpunit/tests/theme/customHeader.php b/tests/phpunit/tests/theme/customHeader.php index f78f6fc2af326..b994d7f2dcfe5 100644 --- a/tests/phpunit/tests/theme/customHeader.php +++ b/tests/phpunit/tests/theme/customHeader.php @@ -98,7 +98,7 @@ public function test_get_header_image_from_theme_mod() { public function test_filter_header_image( $header_image, $expected ) { add_filter( 'get_header_image', - static function() use ( $header_image ) { + static function () use ( $header_image ) { return $header_image; } ); @@ -190,7 +190,7 @@ public function test_get_header_image_tag_with_default_performance_attributes() add_filter( 'wp_min_priority_img_pixels', - static function() { + static function () { return 2500; // 50*50=2500 } ); diff --git a/tests/phpunit/tests/theme/wpThemeJsonResolver.php b/tests/phpunit/tests/theme/wpThemeJsonResolver.php index 98f67fea5da4f..cc7cfa2f65238 100644 --- a/tests/phpunit/tests/theme/wpThemeJsonResolver.php +++ b/tests/phpunit/tests/theme/wpThemeJsonResolver.php @@ -600,7 +600,7 @@ public function test_get_user_data_from_wp_global_styles_does_not_use_uncached_q $global_styles_query_count = 0; add_filter( 'query', - static 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++; } @@ -836,7 +836,7 @@ public function test_get_merged_data_returns_origin( $origin, $core_palette, $co $styles = $theme_json->get_styles_block_nodes(); $styles = array_filter( $styles, - static function( $element ) { + static function ( $element ) { return isset( $element['name'] ) && 'my/block-with-styles' === $element['name']; } ); diff --git a/tests/phpunit/tests/user/queryCache.php b/tests/phpunit/tests/user/queryCache.php index d8d26286a716a..7e63907f74290 100644 --- a/tests/phpunit/tests/user/queryCache.php +++ b/tests/phpunit/tests/user/queryCache.php @@ -421,7 +421,7 @@ public function test_query_cache_do_not_cache() { $q1 = new WP_User_Query( $args ); $found1 = $q1->get_results(); - $callback = static function( $user ) { + $callback = static function ( $user ) { return (array) $user; }; diff --git a/tests/phpunit/tests/user/retrievePassword.php b/tests/phpunit/tests/user/retrievePassword.php index 861a2d9e96c01..c0f6f28c30322 100644 --- a/tests/phpunit/tests/user/retrievePassword.php +++ b/tests/phpunit/tests/user/retrievePassword.php @@ -52,7 +52,7 @@ public function test_retrieve_password_reset_notification_email() { public function test_retrieve_password_should_return_wp_error_on_failed_email() { add_filter( 'retrieve_password_notification_email', - static function() { + static function () { return array( 'message' => '' ); } ); diff --git a/tests/phpunit/tests/widgets.php b/tests/phpunit/tests/widgets.php index fd3826ec3dc67..ab4115cff2e26 100644 --- a/tests/phpunit/tests/widgets.php +++ b/tests/phpunit/tests/widgets.php @@ -596,7 +596,7 @@ public function test_widget_display_callback_handles_arrayobject() { add_filter( "pre_option_{$widget->option_name}", - static function() { + static function () { return new ArrayObject( array( 2 => array( 'title' => 'Test Title' ), From 15f5a952a1b804020d0e2677058f38450a874e53 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Tue, 12 Sep 2023 19:18:34 +0000 Subject: [PATCH 071/105] Posts, Post Types: Avoid unnecessarily parsing blocks twice in `wp_trim_excerpt()`. All blocks relevant for the excerpt are already being parsed in `excerpt_remove_blocks()`. Therefore running `do_blocks()` on the post content only to create the excerpt is unnecessary and wasteful from a performance perspective. Props thekt12, spacedmonkey, mukesh27, joemcgill. Fixes #58682. git-svn-id: https://develop.svn.wordpress.org/trunk@56560 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/blocks.php | 4 + src/wp-includes/formatting.php | 17 +++- .../tests/formatting/wpTrimExcerpt.php | 81 +++++++++++++++++++ 3 files changed, 99 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 3c88f7b4c381a..7795a6969b113 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -956,6 +956,10 @@ function filter_block_kses_value( $value, $allowed_html, $allowed_protocols = ar * @return string The parsed and filtered content. */ function excerpt_remove_blocks( $content ) { + if ( ! has_blocks( $content ) ) { + return $content; + } + $allowed_inner_blocks = array( // Classic blocks have their blockName set to null. null, diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 05084329d333e..0e5797fa7e619 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -3980,18 +3980,29 @@ function wp_trim_excerpt( $text = '', $post = null ) { * within the excerpt are stripped out. Modifying the tags here * is wasteful and can lead to bugs in the image counting logic. */ - $filter_removed = remove_filter( 'the_content', 'wp_filter_content_tags' ); + $filter_image_removed = remove_filter( 'the_content', 'wp_filter_content_tags' ); + + /* + * Temporarily unhook do_blocks() since excerpt_remove_blocks( $text ) + * handels block rendering needed for excerpt. + */ + $filter_block_removed = remove_filter( 'the_content', 'do_blocks', 9 ); /** This filter is documented in wp-includes/post-template.php */ $text = apply_filters( 'the_content', $text ); $text = str_replace( ']]>', ']]>', $text ); - /** + // Restore the original filter if removed. + if ( $filter_block_removed ) { + add_filter( 'the_content', 'do_blocks', 9 ); + } + + /* * Only restore the filter callback if it was removed above. The logic * to unhook and restore only applies on the default priority of 10, * which is generally used for the filter callback in WordPress core. */ - if ( $filter_removed ) { + if ( $filter_image_removed ) { add_filter( 'the_content', 'wp_filter_content_tags' ); } diff --git a/tests/phpunit/tests/formatting/wpTrimExcerpt.php b/tests/phpunit/tests/formatting/wpTrimExcerpt.php index ba5e99f7d8074..d77f322058388 100644 --- a/tests/phpunit/tests/formatting/wpTrimExcerpt.php +++ b/tests/phpunit/tests/formatting/wpTrimExcerpt.php @@ -148,4 +148,85 @@ public function test_wp_trim_excerpt_does_not_restore_wp_filter_content_tags_if_ // Assert that the filter callback was not restored after running 'the_content'. $this->assertFalse( has_filter( 'the_content', 'wp_filter_content_tags' ) ); } + + /** + * Tests that `wp_trim_excerpt()` does process valid blocks. + * + * @ticket 58682 + * + * @covers ::wp_trim_excerpt + */ + public function test_wp_trim_excerpt_check_if_block_renders() { + $post = self::factory()->post->create( + array( + 'post_content' => '

A test paragraph

', + ) + ); + + $output_text = wp_trim_excerpt( '', $post ); + + $this->assertSame( 'A test paragraph', $output_text, 'wp_trim_excerpt() did not process paragraph block.' ); + } + + /** + * Tests that `wp_trim_excerpt()` unhooks `do_blocks()` from 'the_content' filter. + * + * @ticket 58682 + * + * @covers ::wp_trim_excerpt + */ + public function test_wp_trim_excerpt_unhooks_do_blocks() { + $post = self::factory()->post->create(); + + /* + * Record that during 'the_content' filter run by wp_trim_excerpt() the + * do_blocks() callback is not used. + */ + $has_filter = true; + add_filter( + 'the_content', + static function( $content ) use ( &$has_filter ) { + $has_filter = has_filter( 'the_content', 'do_blocks' ); + return $content; + } + ); + + wp_trim_excerpt( '', $post ); + + $this->assertFalse( $has_filter, 'do_blocks() was not unhooked in wp_trim_excerpt()' ); + } + + /** + * Tests that `wp_trim_excerpt()` doesn't permanently unhook `do_blocks()` from 'the_content' filter. + * + * @ticket 58682 + * + * @covers ::wp_trim_excerpt + */ + public function test_wp_trim_excerpt_should_not_permanently_unhook_do_blocks() { + $post = self::factory()->post->create(); + + wp_trim_excerpt( '', $post ); + + $this->assertSame( 9, has_filter( 'the_content', 'do_blocks' ), 'do_blocks() was not restored in wp_trim_excerpt()' ); + } + + /** + * Tests that `wp_trim_excerpt()` doesn't restore `do_blocks()` if it was previously unhooked. + * + * @ticket 58682 + * + * @covers ::wp_trim_excerpt + */ + public function test_wp_trim_excerpt_does_not_restore_do_blocks_if_previously_unhooked() { + $post = self::factory()->post->create(); + + // Remove do_blocks() from 'the_content' filter generally. + remove_filter( 'the_content', 'do_blocks', 9 ); + + wp_trim_excerpt( '', $post ); + + // Assert that the filter callback was not restored after running 'the_content'. + $this->assertFalse( has_filter( 'the_content', 'do_blocks' ) ); + } } From 36f8240cc3b7bcb66d6e5f3a680b3f2dfff38034 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 13 Sep 2023 08:06:26 +0000 Subject: [PATCH 072/105] Docs: Fix typo in a comment in `wp_trim_excerpt()`. Includes removing redundant `@covers` tags. There is already an existing annotation for the whole test class, following the [https://docs.phpunit.de/en/9.6/annotations.html#covers PHPUnit recommendation]: > This annotation can be added to the docblock of the test class or the individual test methods. The recommended way is to add the annotation to the docblock of the test class, not to the docblock of the test methods. Follow-up to [56560]. See #58682. git-svn-id: https://develop.svn.wordpress.org/trunk@56561 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/formatting.php | 2 +- tests/phpunit/tests/formatting/wpTrimExcerpt.php | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 0e5797fa7e619..73d95df2af65c 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -3984,7 +3984,7 @@ function wp_trim_excerpt( $text = '', $post = null ) { /* * Temporarily unhook do_blocks() since excerpt_remove_blocks( $text ) - * handels block rendering needed for excerpt. + * handles block rendering needed for excerpt. */ $filter_block_removed = remove_filter( 'the_content', 'do_blocks', 9 ); diff --git a/tests/phpunit/tests/formatting/wpTrimExcerpt.php b/tests/phpunit/tests/formatting/wpTrimExcerpt.php index d77f322058388..d588c01174030 100644 --- a/tests/phpunit/tests/formatting/wpTrimExcerpt.php +++ b/tests/phpunit/tests/formatting/wpTrimExcerpt.php @@ -153,8 +153,6 @@ public function test_wp_trim_excerpt_does_not_restore_wp_filter_content_tags_if_ * Tests that `wp_trim_excerpt()` does process valid blocks. * * @ticket 58682 - * - * @covers ::wp_trim_excerpt */ public function test_wp_trim_excerpt_check_if_block_renders() { $post = self::factory()->post->create( @@ -172,8 +170,6 @@ public function test_wp_trim_excerpt_check_if_block_renders() { * Tests that `wp_trim_excerpt()` unhooks `do_blocks()` from 'the_content' filter. * * @ticket 58682 - * - * @covers ::wp_trim_excerpt */ public function test_wp_trim_excerpt_unhooks_do_blocks() { $post = self::factory()->post->create(); @@ -200,8 +196,6 @@ static function( $content ) use ( &$has_filter ) { * Tests that `wp_trim_excerpt()` doesn't permanently unhook `do_blocks()` from 'the_content' filter. * * @ticket 58682 - * - * @covers ::wp_trim_excerpt */ public function test_wp_trim_excerpt_should_not_permanently_unhook_do_blocks() { $post = self::factory()->post->create(); @@ -215,8 +209,6 @@ public function test_wp_trim_excerpt_should_not_permanently_unhook_do_blocks() { * Tests that `wp_trim_excerpt()` doesn't restore `do_blocks()` if it was previously unhooked. * * @ticket 58682 - * - * @covers ::wp_trim_excerpt */ public function test_wp_trim_excerpt_does_not_restore_do_blocks_if_previously_unhooked() { $post = self::factory()->post->create(); From 8e4ff2a01da9d315cb4fc57dc02d8ba750ad8288 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 13 Sep 2023 12:03:14 +0000 Subject: [PATCH 073/105] Themes: Add test for `theme` atttibute in file-based block template. While we already have unit test coverage for `_inject_theme_attribute_in_block_template_content`, those tests only verify that ''that'' function does what is supposed to do; there's however no guarantee that `_build_block_template_result_from_file` uses that function (or whatever other technique) to actually inject the theme attribute. This patch adds test coverage to verify that the theme attribute is correctly injected by `_build_block_template_result_from_file`. Props costdev, gziolo, mukesh27, spacedmonkey. Fixes #59325. See #59313. git-svn-id: https://develop.svn.wordpress.org/trunk@56562 602fd350-edb4-49c9-b593-d223f7449a82 --- .../template-with-nested-template-part.html | 3 + ...te-part-with-existing-theme-attribute.html | 1 + .../template-with-template-part.html | 1 + tests/phpunit/tests/block-template-utils.php | 58 +++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 tests/phpunit/data/templates/template-with-nested-template-part.html create mode 100644 tests/phpunit/data/templates/template-with-template-part-with-existing-theme-attribute.html create mode 100644 tests/phpunit/data/templates/template-with-template-part.html diff --git a/tests/phpunit/data/templates/template-with-nested-template-part.html b/tests/phpunit/data/templates/template-with-nested-template-part.html new file mode 100644 index 0000000000000..7df8341fe5e4b --- /dev/null +++ b/tests/phpunit/data/templates/template-with-nested-template-part.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/tests/phpunit/data/templates/template-with-template-part-with-existing-theme-attribute.html b/tests/phpunit/data/templates/template-with-template-part-with-existing-theme-attribute.html new file mode 100644 index 0000000000000..d5f92e7d11102 --- /dev/null +++ b/tests/phpunit/data/templates/template-with-template-part-with-existing-theme-attribute.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/phpunit/data/templates/template-with-template-part.html b/tests/phpunit/data/templates/template-with-template-part.html new file mode 100644 index 0000000000000..ccec47b64817b --- /dev/null +++ b/tests/phpunit/data/templates/template-with-template-part.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/phpunit/tests/block-template-utils.php b/tests/phpunit/tests/block-template-utils.php index b5587def995a0..7c5e8dd5955c0 100644 --- a/tests/phpunit/tests/block-template-utils.php +++ b/tests/phpunit/tests/block-template-utils.php @@ -161,6 +161,64 @@ public function test_build_block_template_result_from_file() { $this->assertEmpty( $template_part->modified ); } + /** + * @ticket 59325 + * + * @covers ::_build_block_template_result_from_file + * + * @dataProvider data_build_block_template_result_from_file_injects_theme_attribute + * + * @param string $filename The template's filename. + * @param string $expected The expected block markup. + */ + public function test_build_block_template_result_from_file_injects_theme_attribute( $filename, $expected ) { + $template = _build_block_template_result_from_file( + array( + 'slug' => 'single', + 'path' => DIR_TESTDATA . "/templates/$filename", + ), + 'wp_template' + ); + $this->assertSame( $expected, $template->content ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_build_block_template_result_from_file_injects_theme_attribute() { + $theme = 'block-theme'; + return array( + 'a template with a template part block' => array( + 'filename' => 'template-with-template-part.html', + 'expected' => sprintf( + '', + $theme + ), + ), + 'a template with a template part block nested inside another block' => array( + 'filename' => 'template-with-nested-template-part.html', + 'expected' => sprintf( + ' + +', + $theme + ), + ), + 'a template with a template part block with an existing theme attribute' => array( + 'filename' => 'template-with-template-part-with-existing-theme-attribute.html', + 'expected' => '', + ), + 'a template with no template part block' => array( + 'filename' => 'template.html', + 'expected' => ' +

Just a paragraph

+', + ), + ); + } + public function test_inject_theme_attribute_in_block_template_content() { $theme = get_stylesheet(); $content_without_theme_attribute = ''; From 7dbf409caf97fb7a17b11186102470cfff245e0c Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 13 Sep 2023 12:47:25 +0000 Subject: [PATCH 074/105] HTML API: Skip over contents of RAWTEXT elements such as STYLE. When encountering elements that imply switching into the RAWTEXT parsing state, the Tag Processor should skip processing until exiting the RAWTEXT state. In this patch the Tag Processor does just that, except for the case of the deprecated XMP element which implies further and more complicated rules. There's an implicit assumption that the SCRIPT ENABLED flag in HTML parsing is enabled so that the contents of NOSCRIPT can be skipped. Otherwise, it would be required to parse the contents of that tag. Props dmsnell. Fixes #59292. git-svn-id: https://develop.svn.wordpress.org/trunk@56563 602fd350-edb4-49c9-b593-d223f7449a82 --- .../html-api/class-wp-html-tag-processor.php | 52 +++++++++++++++++-- .../tests/html-api/wpHtmlTagProcessor.php | 37 +++++++++++++ 2 files changed, 86 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-tag-processor.php b/src/wp-includes/html-api/class-wp-html-tag-processor.php index 541b5baf0bfbe..79d96dc8be3f1 100644 --- a/src/wp-includes/html-api/class-wp-html-tag-processor.php +++ b/src/wp-includes/html-api/class-wp-html-tag-processor.php @@ -242,6 +242,8 @@ * unquoted values will appear in the output with double-quotes. * * @since 6.2.0 + * @since 6.2.1 Fix: Support for various invalid comments; attribute updates are case-insensitive. + * @since 6.3.2 Fix: Skip HTML-like content inside rawtext elements such as STYLE. */ class WP_HTML_Tag_Processor { /** @@ -568,7 +570,14 @@ public function next_tag( $query = null ) { * of the tag name as a pre-check avoids a string allocation when it's not needed. */ $t = $this->html[ $this->tag_name_starts_at ]; - if ( ! $this->is_closing_tag && ( 's' === $t || 'S' === $t || 't' === $t || 'T' === $t ) ) { + if ( + ! $this->is_closing_tag && + ( + 'i' === $t || 'I' === $t || + 'n' === $t || 'N' === $t || + 's' === $t || 'S' === $t || + 't' === $t || 'T' === $t + ) ) { $tag_name = $this->get_tag(); if ( 'SCRIPT' === $tag_name && ! $this->skip_script_data() ) { @@ -580,6 +589,25 @@ public function next_tag( $query = null ) { ) { $this->bytes_already_parsed = strlen( $this->html ); return false; + } elseif ( + ( + 'IFRAME' === $tag_name || + 'NOEMBED' === $tag_name || + 'NOFRAMES' === $tag_name || + 'NOSCRIPT' === $tag_name || + 'STYLE' === $tag_name + ) && + ! $this->skip_rawtext( $tag_name ) + ) { + /* + * "XMP" should be here too but its rules are more complicated and require the + * complexity of the HTML Processor (it needs to close out any open P element, + * meaning it can't be skipped here or else the HTML Processor will lose its + * place). For now, it can be ignored as it's a rare HTML tag in practice and + * any normative HTML should be using PRE instead. + */ + $this->bytes_already_parsed = strlen( $this->html ); + return false; } } } while ( $already_found < $this->sought_match_offset ); @@ -710,15 +738,33 @@ public function release_bookmark( $name ) { return true; } + /** + * Skips contents of generic rawtext elements. + * + * @since 6.3.2 + * + * @see https://html.spec.whatwg.org/#generic-raw-text-element-parsing-algorithm + * + * @param string $tag_name The uppercase tag name which will close the RAWTEXT region. + * @return bool Whether an end to the RAWTEXT region was found before the end of the document. + */ + private function skip_rawtext( $tag_name ) { + /* + * These two functions distinguish themselves on whether character references are + * decoded, and since functionality to read the inner markup isn't supported, it's + * not necessary to implement these two functions separately. + */ + return $this->skip_rcdata( $tag_name ); + } /** - * Skips contents of title and textarea tags. + * Skips contents of RCDATA elements, namely title and textarea tags. * * @since 6.2.0 * * @see https://html.spec.whatwg.org/multipage/parsing.html#rcdata-state * - * @param string $tag_name The lowercase tag name which will close the RCDATA region. + * @param string $tag_name The uppercase tag name which will close the RCDATA region. * @return bool Whether an end to the RCDATA region was found before the end of the document. */ private function skip_rcdata( $tag_name ) { diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php index 659ffb848ecb8..31430d07a9e02 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php @@ -1871,6 +1871,43 @@ public function data_next_tag_ignores_contents_of_rcdata_tag() { ); } + /** + * @ticket 59292 + * + * @covers WP_HTML_Tag_Processor::next_tag + * + * @dataProvider data_next_tag_ignores_contents_of_rawtext_tags + * + * @param string $rawtext_element_then_target_node HTML starting with a RAWTEXT-specifying element such as STYLE, + * then an element afterward containing the "target" attribute. + */ + public function test_next_tag_ignores_contents_of_rawtext_tags( $rawtext_element_then_target_node ) { + $processor = new WP_HTML_Tag_Processor( $rawtext_element_then_target_node ); + $processor->next_tag(); + + $processor->next_tag(); + $this->assertNotNull( + $processor->get_attribute( 'target' ), + "Expected to find element with target attribute but found {$processor->get_tag()} instead." + ); + } + + /** + * Data provider. + * + * @return array[]. + */ + public function data_next_tag_ignores_contents_of_rawtext_tags() { + return array( + 'IFRAME' => array( '
' ), + 'NOEMBED' => array( '<p></p>
' ), + 'NOFRAMES' => array( '<p>Check the rules here.</p>
' ), + 'NOSCRIPT' => array( '

' ), + 'STYLE' => array( '

' ), + 'STYLE hiding DIV' => array( '
' ), + ); + } + /** * Ensures that the invalid comment closing syntax "--!>" properly closes a comment. * From 11e91d50d5bfd6c3a9cb2ed847f9356d361330c3 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 13 Sep 2023 13:00:59 +0000 Subject: [PATCH 075/105] HTML API: Update documentation and rename internal variable on HTML Processor This patch updates documentation and an internal variable name within the HTML Processor class so that they are more helpful and complete to a reader. There should be no functional or visual changes in this patch. Props dmsnell, mukesh27. Fixes #59267. git-svn-id: https://develop.svn.wordpress.org/trunk@56565 602fd350-edb4-49c9-b593-d223f7449a82 --- .../html-api/class-wp-html-processor.php | 104 +++++++++++++----- 1 file changed, 76 insertions(+), 28 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php index 64fd23924eada..52735f29e6318 100644 --- a/src/wp-includes/html-api/class-wp-html-processor.php +++ b/src/wp-includes/html-api/class-wp-html-processor.php @@ -27,6 +27,7 @@ * - Unwrapping a tag by removing its parent. * - Inserting and removing nodes. * - Reading and changing inner content. + * - Navigating up or around HTML structure. * * ## Usage * @@ -66,7 +67,7 @@ * `array( 'IMG' )` matches all IMG elements and `array( 'P', 'IMG' )` * matches all IMG elements directly inside a P element. To ensure that no * partial matches erroneously match it's possible to specify in a query - * the full breadcrumb match. + * the full breadcrumb match all the way down from the root HTML element. * * Example: * @@ -76,7 +77,7 @@ * * $html = '
A lovely day outside
'; * // ---- Matches here. - * $processor->next_tag( array( 'breadcrumbs' => array( 'FIGURE', 'IMG', 'FIGCAPTION', 'EM' ) ) ); + * $processor->next_tag( array( 'breadcrumbs' => array( 'FIGURE', 'FIGCAPTION', 'EM' ) ) ); * * $html = '
'; * // ----- Matches here, because IMG must be a direct child of the implicit BODY. @@ -100,7 +101,8 @@ * * - Links: A. * - The formatting elements: B, BIG, CODE, EM, FONT, I, SMALL, STRIKE, STRONG, TT, U. - * - Containers: DIV, FIGCAPTION, FIGURE. + * - Containers: DIV, FIGCAPTION, FIGURE, SPAN. + * - Form elements: BUTTON. * - Paragraph: P. * - Void elements: IMG. * @@ -116,7 +118,9 @@ * - Markup involving only those tags listed above. * - Fully-balanced and non-overlapping tags. * - HTML with unexpected tag closers. + * - Some unbalanced or overlapping tags. * - P tags after unclosed P tags. + * - BUTTON tags after unclosed BUTTON tags. * - A tags after unclosed A tags that don't involve any active formatting elements. * * @since 6.4.0 @@ -126,7 +130,10 @@ */ class WP_HTML_Processor extends WP_HTML_Tag_Processor { /** - * HTML processing requires more bookmarks than basic tag processing. + * The maximum number of bookmarks allowed to exist at any given time. + * + * HTML processing requires more bookmarks than basic tag processing, + * so this class constant from the Tag Processor is overwritten. * * @since 6.4.0 * @@ -137,6 +144,8 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { /** * Static query for instructing the Tag Processor to visit every token. * + * @access private + * * @since 6.4.0 * * @var array @@ -158,8 +167,15 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { /** * Used to create unique bookmark names. * + * This class sets a bookmark for every tag in the HTML document that it encounters. + * The bookmark name is auto-generated and increments, starting with `1`. These are + * internal bookmarks and are automatically released when the referring WP_HTML_Token + * goes out of scope and is garbage-collected. + * * @since 6.4.0 * + * @see WP_HTML_Processor::$release_internal_bookmark_on_destruct + * * @var int */ private $bookmark_counter = 0; @@ -186,7 +202,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { * * @var closure */ - private $release_internal_bookmark = null; + private $release_internal_bookmark_on_destruct = null; /* * Public Interface Functions @@ -258,10 +274,14 @@ public static function createFragment( $html, $context = '', $encoding = ' /** * Constructor. * + * Do not use this method. Use the static creator methods instead. + * * @access private * * @since 6.4.0 * + * @see WP_HTML_Processor::createFragment() + * * @param string $html HTML to process. * @param string|null $use_the_static_create_methods_instead This constructor should not be called manually. */ @@ -287,7 +307,7 @@ public function __construct( $html, $use_the_static_create_methods_instead = nul * a private method into WP_HTML_Token classes without * exposing it to any public API. */ - $this->release_internal_bookmark = function ( $name ) { + $this->release_internal_bookmark_on_destruct = function ( $name ) { parent::release_bookmark( $name ); }; } @@ -298,13 +318,15 @@ public function __construct( $html, $use_the_static_create_methods_instead = nul * Various situations lead to parsing failure but this class will * return `false` in all those cases. To determine why something * failed it's possible to request the last error. This can be - * helpful to know if it's possible to fix something or to give up. + * helpful to know to distinguish whether a given tag couldn't + * be found or if content in the document caused the processor + * to give up and abort processing. * * Example * - * $p = WP_HTML_Processor::createFragment( '