44488 Commits

Author SHA1 Message Date
John Blackbourn
5c18b5f642 General: Fix code quality issues which were identified by static analysis.
This fixes minor issues that could cause PHP notices under the right conditions, and fixes some general incorrectness.

Props jrf, hellofromTonya for review

See #52217


git-svn-id: https://develop.svn.wordpress.org/trunk@51850 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-22 20:59:15 +00:00
Sergey Biryukov
cb5e2611a6 Docs: Update description for retrieve_widgets() per the documentation standards.
Follow-up to [51842].

See #53811.

git-svn-id: https://develop.svn.wordpress.org/trunk@51849 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-22 14:09:19 +00:00
Andrew Ozz
d05ecf236f Update and enhance the docs for retrieve_widgets().
Props zieladam, hellofromtonya.
Fixes #53811.

git-svn-id: https://develop.svn.wordpress.org/trunk@51842 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-21 22:12:18 +00:00
John Blackbourn
9269cbd7e8 Formatting: Pass the block instance as a parameter to the render_block filters.
This allows filters to access properties and methods on the block instance.

Fixes #53596


git-svn-id: https://develop.svn.wordpress.org/trunk@51841 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-21 21:31:35 +00:00
John Blackbourn
d7b91f9da6 Docs: Document some more common names for dynamic hooks and standardise the phrasing used.
Fixes #53581


git-svn-id: https://develop.svn.wordpress.org/trunk@51837 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-21 18:19:19 +00:00
Sergey Biryukov
0f0089391b Docs: Add @since notes to register_setting() for the deprecated misc and privacy option groups.
Follow-up to [13745], [13746], [13749], [21838], [51827].

See #53399.

git-svn-id: https://develop.svn.wordpress.org/trunk@51832 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-21 13:20:20 +00:00
Tonya Mork
81ade4da65 Build/Test Tools: Fix null handling and string type casting in WP_UnitTestCase_Base::assertSameIgnoreEOL().
Basically, the whole `assertSameIgnoreEOL()` assertion was fundamentally flawed. The assertion contends that it checks that the expected and actual values are of the same type and value, but the reality was very different.

* The function uses `map_deep()` to potentially handle all sorts of inputs.
* `map_deep()` handles arrays and objects with special casing, but will call the callback on everything else without further distinction.
* The callback used passes the expected/actual value on to the `str_replace()` function to remove potential new line differences.
* And the `str_replace()` function will - with a non-array input for the `$subject` - always return a string.
* The output of these calls to `map_deep()` will therefore have "normalized" _all properties_ in objects, _all values_ in arrays and _all non-object, non-array values_ to strings.
* And a call to `assertSame()` will therefore NEVER do a proper type check as the type of all input has already, unintentionally, been "normalized" to string.

Aside from this clear flaw in the design of the assertion, PHP 8.1 now exposes a further issue as a `null` value for an object property, an array value or a plain value, will now yield a ` str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated` notice.

To fix both these issues, the fix in this PR ensures that the call to `str_replace()` will now only be made if the input is a text string.
All other values passed to the callback are left in their original type.

This ensures that a proper value AND type comparison can be done as well as prevents the PHP 8.1 deprecation notices.

Ref:
* https://developer.wordpress.org/reference/functions/map_deep/
* https://www.php.net/manual/en/function.str-replace.php

This commit:
- Fixes type-casting of non-string values to `string` (the flawed part of this assertion) by invoking `str_replace()` when the value is of string type.
- Fixes the PHP 8.1 `str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated` deprecation notice.
- Micro-optimization: skips `map_deep()` when actual and/or expected are `null` (no need to process).
- Adjusts the method documentation for both this method and the `assertEqualsIgnoreEOL()` alias method to document that the `$expected` and `$actual` parameters can be of any type.

Follow-up to [48937], [51135], [51478].

Props jrf, hellofromTonya.
See #53363, #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51831 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-20 19:58:09 +00:00
Tonya Mork
cece2cca5e REST API: Fix autovivification deprecation notice in WP_Test_REST_Widgets_Controller::set_up().
If the `'widget_testwidget'` option does not exist, `false` was returned from `get_option()`. The `set_up()` logic expects an `array()` and assigns values to keys without checking for an array. The automatic creation of an array (autovivification) triggers a `Deprecated: Automatic conversion of false to array is deprecated in` deprecation notice on PHP 8.1.

This commit:
- Fixes the deprecation notice by making the default value an empty array.
- Moves getting the option within the conditional where it's needed.
- Provides a micro-optimization by only getting the options when the conditions are correct for processing.
- Makes the code consistent within the `set_up()` for both `get_option()` instances.

Follow-up to [51029].

Props jrf, hellofromTonya, BinaryKitten.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51830 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-20 18:48:47 +00:00
Tonya Mork
506aa746b5 Login and Registration: Fix "passing null to non-nullable" deprecation for authorize_application error message.
If there is no URL query in the `$_GET['redirect_to'], `wp_parse_url()` will return `null`. Passing `null` to `parse_str()` results in a PHP 8.1 deprecation notice
{{{
Deprecated: parse_str(): Passing null to parameter #1 ($string) of type string is deprecated
}}}

This commit:
- Fixes the deprecation notice.
- Skips doing the `parse_str()` when there's no URL query.
- Provides a micro-optimization performance boost.

Follow-up to [49109].

Props jrf, hellofromTonya, BinaryKitten.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51829 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-20 18:21:32 +00:00
Tonya Mork
fe9f6a29ac Build/Test Tools: Improve Composer update command in bootstrap error messages.
Refines the test bootstrap error message to include the `-W` in the Composer update command.

Why?

To also update the chain of dependencies for the tests' dependencies. 

`composer update` will update the tests' direct dependencies.
 
`composer update -W` will update the dependencies including *their* dependencies, which is the recommended course of action for WP.

Follow-up to [51598], [51811], [51813].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51828 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-20 16:44:00 +00:00
John James Jacoby
e881178e78 Docs: Remove deprecated option groups from register_setting() and add_option_update_handler().
* `misc` was deprecated in version 3.0.0.
* `privacy` was deprecated in version 3.5.0.

See #53399.



git-svn-id: https://develop.svn.wordpress.org/trunk@51827 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-20 16:18:04 +00:00
Sergey Biryukov
8873b17424 Coding Standards: Rename the $processedHeaders variable to $processed_headers in WP_Http::request().
This fixes a `Variable "$processedHeaders" is not in valid snake_case format` WPCS warning.

Follow-up to [8620], [51823].

See #53359.

git-svn-id: https://develop.svn.wordpress.org/trunk@51826 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-20 12:05:20 +00:00
Sergey Biryukov
a6408603aa Coding Standards: Rename the $arrURL variable to $parsed_url in WP_Http_Streams::request().
This fixes a `Variable "$arrURL" is not in valid snake_case format` WPCS warning.

Follow-up to [8620], [10509], [25044], [25224], [45667], [51823], [51824].

See #53359.

git-svn-id: https://develop.svn.wordpress.org/trunk@51825 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-19 16:59:35 +00:00
Sergey Biryukov
4d669c9ec5 Coding Standards: Rename the $arrURL variable to $parsed_url in WP_Http_Cookie::__construct().
This fixes a `Variable "$arrURL" is not in valid snake_case format` WPCS warning.

Follow-up to [10509], [25044], [45667], [51823].

See #53359.

git-svn-id: https://develop.svn.wordpress.org/trunk@51824 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-19 16:58:43 +00:00
Sergey Biryukov
be12fd20ef Coding Standards: Rename the $arrURL variable to $parsed_url in WP_Http::request().
This fixes a `Variable "$arrURL" is not in valid snake_case format` WPCS warning.

Follow-up to [10509], [45667].

See #53359.

git-svn-id: https://develop.svn.wordpress.org/trunk@51823 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-19 16:57:46 +00:00
Sergey Biryukov
f386f6f5ed Coding Standards: Use strict comparison in wp-inclues/class-wp-http-cookie.php.
Follow-up to [10512].

See #53359.

git-svn-id: https://develop.svn.wordpress.org/trunk@51822 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-18 19:54:30 +00:00
Gary Pendergast
ab9b51e5e3 Embeds: Add Pinterest as a trusted oEmbed provider.
Props ayeshrajans, pento.

Fixes #53448.


git-svn-id: https://develop.svn.wordpress.org/trunk@51821 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-17 03:12:35 +00:00
Sergey Biryukov
ecad6ae28c Twenty Twenty-One: Add missing escaping for the "Secondary menu" label.
Props muhammadfaizanhaidar, teucrium, sabernhardt, mukesh27, SergeyBiryukov.
Fixes #54127.

git-svn-id: https://develop.svn.wordpress.org/trunk@51820 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-16 21:30:36 +00:00
Jorge Costa
57ad9f16df Block editor: Cache global stylesheet by theme key.
Global styles are used in a few different contexts (front, editor, customizer, the theme directory). In the last two contexts, it's important that switching themes immediately refreshes the global stylesheet, to avoid situations in which the styles of the previous theme load with the new one. This was brought up at WordPress/gutenberg#34531 (customizer) and at meta.trac.wordpress.org/ticket/5818 (theme directory).
This commit makes sure the stylesheet is regenerated upon switching themes.

Props oandregal, dd32.
See #53175.

git-svn-id: https://develop.svn.wordpress.org/trunk@51819 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-16 18:03:04 +00:00
Tonya Mork
97790af164 Options, Meta APIs: Fix "passing null to non-nullable" deprecations to (get|add|update|delete)_option().
In all four of the `get_option()`, `add_option()`, `update_option()` and `delete_option()` functions, the `$option` parameter (i.e. the option name) is passed to the PHP native `trim()` function without prior input validation.

In PHP 8.1, this could lead to a `trim(): Passing null to parameter #1 ($string) of type string is deprecated` for each of these functions.

`trim()`:

- expects a text string and is only useful when ''passed'' a text string as no other variable type can contain whitespace.
- will always return a `string`, which means that in practice for any non-string values passed, it would effectively function as a type cast to string.

This commit:
- Adds a check to verify the `$option` name is a scalar before processing it with `trim()`.
- The "type cast" behavior is maintained.
- If the given `$option` name is not a scalar, such as `null`, the fix prevents the PHP 8.1 deprecation notice.
- Tests are added for valid but undesired option names to safeguard against regressions.

This issue is already covered by:
- the existing `Tests_Option_Option::test_bad_option_names()` test group.
- the new `test_valid_but_undesired_option_names()` tests.

Follow-up to [13858], [22633], [23510], [25002], [51817].

Props jrf, hellofromTonya, pbearne.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51818 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-15 22:18:36 +00:00
Tonya Mork
07a7b4262b Build/Test Tools: Reworks Tests_Option_Option::test_bad_option_names() into data provider.
The existing tests were running multiple functions through a `foreach()`. If any test failed, it would bail out and not test against the other scenarios.

This commit:

- Moves the scenarios to a data provider with named data sets, i.e. to ensure all scenarios are run and tested regardless if any fail.
- Splits each function under test into individual test methods.
- Adds a float scenario.
- Adds method visibility modifiers.

Follow-up to [25002].

Props jrf, hellofromTonya, pbearne.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51817 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-15 21:21:58 +00:00
Tonya Mork
c0b328a74d Media: Fix $content parameter default value in img_caption_shortcode().
The shortcode content is expected to be a string, not `null`. `do_shortcode()` expects a string for `$content`.

The `img_caption_shortcode()` also expects a string for the `$content` parameter and is expected to return a string for the HTML content to display the caption. 

Prior to this commit:
The default value for the `$content` parameter was set to `null`. If no `$content` was passed, the function:
- could return `null` when the `$atts['width'] < 1` or there was no caption
- else, it invoked `do_shortcode( $content )` passing `null` which on PHP 8.1+ triggers a deprecation notice:
{{{
strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated
}}}

This commit:

- Fixes the default `$content` value to align to the expected shortcode content of `string`, not `null`.
- Fixes the PHP 8.1 deprecation notice when `null` was being passed to `do_shortcode()`.
- Changes the assertion in a couple of tests to check for the empty string instead of `null.

Follow-up to [8196], [8925], [8239], [26915], [31530], [42704].

Props jrf, hellofromTonya, azaozz, joedolson.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51816 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-15 19:05:20 +00:00
Sergey Biryukov
f5aaafd1fe Upgrade/Install: Create a temporary backup of plugins and themes before updating.
This aims to make the update process more reliable and ensures that if a plugin or theme update fails, the previous version can be safely restored.

* When updating a plugin or theme, the old version is moved to a temporary backup directory:
 * `wp-content/upgrade/temp-backup/plugins/[plugin-slug]` for plugins
 * `wp-content/upgrade/temp-backup/themes/[theme-slug]` for themes.

* If the update fails, then the temporary backup kept in the `upgrade/temp-backup` directory is restored to its original location.
* If the update succeeds, the temporary backup is deleted.

To further help troubleshoot plugin and theme updates, two new checks were added to the Site Health screen:
* A check to make sure that the `temp-backup` directory is writable.
* A check that there is enough disk space available to safely perform updates.

To avoid confusion: The `temp-backup` directory will NOT be used to "roll back" a plugin to a previous version after a completed update. This directory will simply contain a transient backup of the previous version of a plugin or theme being updated, and as soon as the update process finishes, the directory will be empty.

Props aristath, afragen, pbiron, dd32, poena, TimothyBlynJacobs, audrasjb, mikeschroder, a2hosting, hellofromTonya, KZeni, galbaras, richards1052, Boniu91, mai21, francina, SergeyBiryukov.
See #51857.

git-svn-id: https://develop.svn.wordpress.org/trunk@51815 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-15 18:39:09 +00:00
Sergey Biryukov
f329608784 I18N: Add a translator comment to clarify the "Block HTML" string in the Block widget settings form.
The string refers to HTML code of the block, not an option that blocks HTML.

Follow-up to [50995].

Props Amieiro, NekoJonez, knutsp, johnbillion, namith.jawahar, SergeyBiryukov.
Fixes #54110.

git-svn-id: https://develop.svn.wordpress.org/trunk@51814 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-15 11:47:56 +00:00
Tonya Mork
f44a995297 Build/Test Tools: Expect an absolute path in WP_TESTS_PHPUNIT_POLYFILLS_PATH constant.
This commit:
* Removes the use of `realpath()` to prevent issues with WSL and other virtualized filesystems.
* Changes the logic of the Polyfill bootstrap loading to expect an absolute path, rather than a relative path to the root directory of the PHPUnit Polyfills library.
* Adjusts the relevant inline documentation and error messages to expect an absolute path.
* Breaks up error messages into smaller line lengths for readability.

Follow-up to [51598], [51810], [51811], [51812].

Props jrf, schlessera, hellofromTonya, jeherve, lucatume.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51813 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-14 18:52:57 +00:00
Tonya Mork
3062b3d803 Build/Test Tools: Improve messaging when PHPUnit Polyfills do not comply with version requirements.
Previously, two situations were taken in to account:
1. The `WP_TESTS_PHPUNIT_POLYFILLS_PATH` constant is defined => just show a message about the version mismatch.
2. The constant is not defined => show a message to run `composer update`. This message is intended for people trying to run the WP Core tests.

This could lead to an unclear situation for people trying to run plugin/theme integration tests without the new `WP_TESTS_PHPUNIT_POLYFILLS_PATH` constant being defined.

They could be shown the message to run `composer update` while if they would do so for their local install without adding the Polyfills, the message would still display the next time they would attempt to run the tests.

This commit:
1. Provides more information about the PHPUnit Polyfills version detected vs the version expected.
2. Shows a more specific message to guide users which have the `WP_TESTS_PHPUNIT_POLYFILLS_PATH` constant declared.
3. Only shows the message to run `composer update` when the `WP_RUN_CORE_TESTS` constant is declared to prevent confusing people more.

Follow-up to [51598], [51810], [51811].

Props jrf, schlessera, hellofromTonya, jeherve, lucatume.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51812 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-14 18:47:46 +00:00
Tonya Mork
c3a3da800b Build/Test Tools: Improve messaging when PHPUnit Polyfills cannot be found.
Previously, two situations were taken in to account:
1. The `WP_TESTS_PHPUNIT_POLYFILLS_PATH` constant is defined => show message specific to that constant not being set correctly.
    This message would typically be shown for plugin/theme integration tests which are already aware of the changes in WP 5.9.
2. The constant is not defined => show a message to run `composer update`.
    This message is intended for people trying to run the WP Core tests.

This left two situations unaccounted for:
- Someone trying to run the WP Core tests, but not having set the `WP_RUN_CORE_TESTS` constant or not having set it to `1`.
- Someone trying to run plugin/theme integration tests without the new `WP_TESTS_PHPUNIT_POLYFILLS_PATH` constant being defined as they are not (yet) aware of the changes made in WP 5.9.

The changes made in this commit, are intended to improve the error messages displayed in those situations.

Follow-up to [51598], [51810].

Props jrf, schlessera, hellofromTonya, jeherve, lucatume.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51811 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-14 18:40:30 +00:00
Tonya Mork
6f1a983d52 Build/Test Tools: Make WP_TESTS_PHPUNIT_POLYFILLS_PATH more flexible.
The constant `WP_TESTS_PHPUNIT_POLYFILLS_PATH` is intended to contain the path to the root directory of the PHPUnit Polyfills library without trailing slash.

The code already took into account that the value could potentially include a trailing slash.

Now it will also take into account if it is accidentally set to point to the autoload file instead of the path.

Follow-up to [51598].

Props jrf, schlessera, hellofromTonya, jeherve, lucatume.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51810 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-14 18:32:39 +00:00
Sergey Biryukov
f98b284768 Docs: Update description for the $wp_version global.
In addition to holding the version number, the WordPress version string is used to bust caches and to enable development mode for scripts when running from the `/src` directory.

Follow-up to [803], [2585], [6554], [47230].

Props muhammadfaizanhaidar, azaozz.
Fixes #53413.

git-svn-id: https://develop.svn.wordpress.org/trunk@51809 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-14 17:30:48 +00:00
Sergey Biryukov
cabe470ae7 Twenty Seventeen: Make blog header margin more specific on front page.
This avoids a large gap between title and content when the layout is set to one column.

Props laurelfulford, sabernhardt, hirofumi2012, jainnidhi, mukesh27.
Fixes #43628.

git-svn-id: https://develop.svn.wordpress.org/trunk@51808 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-14 10:17:05 +00:00
Sergey Biryukov
a591d5159d Twenty Eleven: Set a fixed height for search form when header image is added.
This ensures that the search form does not collide with the menu on smaller screens.

Props sabernhardt, fedepia, Soean, lukecavanagh, mukesh27.
Fixes #40398.

git-svn-id: https://develop.svn.wordpress.org/trunk@51807 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-13 20:40:29 +00:00
Tonya Mork
08fe0469f9 Code Modernization: Fix "passing null to non-nullable" deprecation notice in WP_Comment_Query::get_comment_ids().
The `WP_Comment_Query::get_comment_ids()` method is supposed to handle `null` as a search query, but was throwing a `strlen(): Passing null to parameter #1 ($string) of type string is deprecated` notice on PHP 8.1.

Discovered via and already covered via the pre-existing `Tests_Comment_Query::test_search_null_should_be_ignored()` test method.

Follow-up to [36345], [48275].

Props jrf, hellofromTonya.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51806 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-13 18:53:57 +00:00
Sergey Biryukov
092ee0fbff Site Health: Move the Imagick entry higher in the list of recommended PHP extensions.
This better matches its position in the [https://make.wordpress.org/hosting/handbook/server-environment/#php-extensions Hosting Team's handbook] recommendations.

Follow-up to [44986], [46268], [51804].

See #52654.

git-svn-id: https://develop.svn.wordpress.org/trunk@51805 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-12 10:08:25 +00:00
Sergey Biryukov
ad96dc2332 Site Health: Add Intl to the list of recommended PHP extensions.
**Why is the PHP Intl extension important?**

WordPress is a global, international software, with support for a multitude of languages and with infinite combinations. Approximately half of the installations are in a language that is not the default (English), and this leads us to think about localization, transliteration, encoding conversions, calendar operations, collation… in short, everything you have with the different languages and formats that are around the planet. And this is what the [https://www.php.net/manual/en/intro.intl.php PHP Intl extension] provides.

**What do we as the WordPress Community gain from this extension?**

This extension provides a lot of functions for better internationalization support, including but not limited to:
* [https://www.php.net/manual/en/collator.compare.php collator_compare()] to compare Unicode text strings
* [https://www.php.net/manual/en/numberformatter.format.php numfmt_format()] to format a number according to the selected locale
* the [https://www.php.net/manual/en/normalizer.normalize.php normalization] of characters
* the [https://www.php.net/manual/en/messageformatter.formatmessage.php formatting] of messages
* getting the [https://www.php.net/manual/en/intlcalendar.getfirstdayofweek.php first day of the week] according to the locale.


In addition to functionality and ease of development, the extension can also help improve security, with classes like `Spoofchecker` that can tell you [https://www.php.net/manual/en/spoofchecker.areconfusable.php if ‘google.com’, ‘goog1e.com’ can confuse the user], or functions related to Internet domains, both to convert an [https://www.php.net/manual/en/function.idn-to-ascii.php IDN domain to text] and [https://www.php.net/manual/en/function.idn-to-utf8.php text to IDN].

**Hosting Team Recommendation**

Taking into account that WordPress continues to grow, the Hosting Team has considered a good recommendation, but not an obligation, for all hosts that work with WordPress to offer this extension, by default, to all users.

Reference: [https://make.wordpress.org/hosting/2021/05/20/why-hosters-should-install-the-php-intl-extension/ Why hosters should install the PHP-intl extension].

Follow-up to [44986], [46268].

Props zodiac1978, JavierCasares, jrf, Clorith, josklever.
Fixes #52654.

git-svn-id: https://develop.svn.wordpress.org/trunk@51804 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-11 18:19:31 +00:00
Tonya Mork
d82accc291 Code Modernization: Fix "passing null to non-nullable" deprecation notices in WP_Http::normalize_cookies().
The `Requests_Cookie` class expects valid - non-`null` - attributes to be passed, either as an array or as a `Requests_Utility_CaseInsensitiveDictionary` object.

However, the `WP_Http_Cookie::get_attributes()` explicitly sets the `expires`, `path` and `domain` index keys in an array with values which _may_ be `null`. This will cause `strtotime(): Passing null to parameter #1 ($datetime) of type string is deprecated`-like errors when the attributes are passed to the `Requests_Cookie` class.

Note: a `null` value for `path` would generate a similar deprecation notice, but for the `preg_match()` function.

Fixed by using `array_filter()` on the attributes to explicitly filter out `null` values before passing the attributes to `Requests_Cookie`.

Note: I'm choosing to explicitly only filter `null` values. Using `array_filter()` without a callback would filter out all "empty" values, but that may also remove values which are explicitly set to `false` or `0`, which may be valid values.

Fixes two errors in the `external-http` group in the WordPress Core test suite:
{{{
1) Tests_HTTP_Functions::test_get_response_cookies_with_wp_http_cookie_object
strtotime(): Passing null to parameter #1 ($datetime) of type string is deprecated

/var/www/src/wp-includes/Requests/Cookie.php:268
/var/www/src/wp-includes/Requests/Cookie.php:237
/var/www/src/wp-includes/Requests/Cookie.php:90
/var/www/src/wp-includes/class-http.php:460
/var/www/src/wp-includes/class-http.php:349
/var/www/src/wp-includes/class-http.php:624
/var/www/src/wp-includes/http.php:162
/var/www/tests/phpunit/tests/http/functions.php:156

2) Tests_HTTP_Functions::test_get_cookie_host_only
strtotime(): Passing null to parameter #1 ($datetime) of type string is deprecated

/var/www/src/wp-includes/Requests/Cookie.php:268
/var/www/src/wp-includes/Requests/Cookie.php:237
/var/www/src/wp-includes/Requests/Cookie.php:90
/var/www/src/wp-includes/class-http.php:460
/var/www/tests/phpunit/tests/http/functions.php:235
}}}

Follow-up to [38164], [45135], [51657].

Props jrf, hellofromTonya.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51801 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-10 17:42:36 +00:00
Tonya Mork
c64c2d77aa Tests: Fix "null to non-nullable" deprecation notice in Tests_Admin_IncludesPlugin::test_get_plugin_files_folder().
The `Tests_Admin_IncludesPlugin::_create_plugin()` expects the first parameter to be a text string to be written to a plugin file using `fwrite()`.

Passing null causes a `fwrite(): Passing null to parameter #2 ($data) of type string is deprecated` notice.

Ref: https://www.php.net/manual/en/function.fwrite

Follow-up to [31002]. [41806].

Props jrf, hellofromTonya.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51800 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-10 17:26:42 +00:00
Tonya Mork
14f92886f1 Code Modernization: Fix "passing null to non-nullable" deprecation in wpdb::_real_escape().
The PHP native `mysqli_real_escape_string()` function expects to be passed a string as the second parameter and this is not a nullable parameter.

Passing `null` to it will result in a `mysqli_real_escape_string(): Passing null to parameter #2 ($string) of type string is deprecated` notice on PHP 8.1.

Previously, an input type check was put in place to prevent fatal errors on PHP 8.0 when an array, object or resource was passed. Changeset [48980].

A `null` value was explicitly excluded from that check, even though a `null` value being passed would only ever result in an empty string anyway.

This commit changes the previous input type check to also bow out early for `null` values and to automatically return an empty string for those.

Refs:
- https://www.php.net/manual/en/mysqli.real-escape-string.php
- https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg

Follow-up to [48980].

Props jrf, hellofromTonya.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51799 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-10 16:35:39 +00:00
Tonya Mork
43de6d5cb5 Tests: Add tests for wpdb::_real_escape().
Adds a new dedicated test file.

Adds a test to check that various input types passed to `wpdb::_real_escape()` are handled correctly.

Note: This new test does not test the actual escaping or other logic in the function. Rather, it just and only tests and documents how the function handles various input types.

Props jrf, hellofromTonya.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51798 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-10 16:29:24 +00:00
Tonya Mork
dade4c62b5 Code Modernization: Fix null to non-nullable deprecations in WP_Meta_Query::get_sql_for_clause().
In the `WP_Meta_Query::get_sql_for_clause()`, the `'value'` index from a meta query array is passed to the PHP native `trim()` function without prior validation.

In PHP 8.1, this could lead to a `trim(): Passing null to parameter #1 ($string) of type string is deprecated` notice.

`trim()` expects a text string and is only useful when ''passed'' a text string as no other variable type can contain whitespace.

Fixed now by verifying that the ''value'' is a string before processing it with `trim()`.

This issue is already covered by the existing `Tests_Meta_Query::test_null_value_sql()` and the `Tests_Meta_Query::test_convert_null_value_to_empty_string()` tests.

Follow-up to [17699], [29887], [29940].

Props jrf, hellofromTonya.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51797 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-10 15:59:17 +00:00
Tonya Mork
9abf35cfa7 Code Modernization: Fix null to non-nullable deprecation in term_exists().
The `term_exists()` function expects a string or an integer for the `$term` parameter. It validates for integer, but not for string or `null`.

One of the pre-existing test cases, passed `null` to the function, leading to a `trim(): Passing null to parameter #1 ($string) of type string is deprecated` notice on PHP 8.1.

Fixed now by doing a cursory check on the variable at the start of the function and bowing out early in case the `$term` is `null`.

The issue was discovered via and is already covered by the `Tests_TermExists::test_term_exists_unknown()` test method.

Follow-up to [15220]. [38716].

Props jrf, hellofromTonya.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51796 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-10 15:02:07 +00:00
Sergey Biryukov
ce168ea06b Accessibility: Administration: Improve aria-label on network admin Themes screen.
This ensures that the beginning of the label matches the visible link text.

Add a similar label for the plugin URI link on the Plugins screen when the plugin is outside of the directory.

Follow-up to [28673], [28706], [35924].

Props sabernhardt, zeo, audrasjb.
Fixes #24442.

git-svn-id: https://develop.svn.wordpress.org/trunk@51795 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-10 14:47:24 +00:00
Andrew Ozz
088f3043a4 External Libraries: Update jQuery UI to 1.13.0-rc2.
The final release is expected at the beginning of October. Updating to rc2 now gives everybody plenty of time to test and report any issues either with UI 1.13.0 or with the WordPress implementation.

Props Clorith, mgol, azaozz.
See #52163.

git-svn-id: https://develop.svn.wordpress.org/trunk@51794 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-10 00:01:24 +00:00
Tonya Mork
acad2b4149 Code Modernization: Fix null to non-nullable deprecation in wp_privacy_anonymize_ip().
The `wp_privacy_anonymize_ip()` function expects a string for the `$ip_addr` parameter, but did not do any input validation.

One of the pre-existing test cases, passed `null` to the function, leading to a `substr_count(): Passing null to parameter #1 ($haystack) of type string is deprecated` notice on PHP 8.1.

Fixed now by doing a cursory check on the variable at the start of the function and bowing out early for a number of cases (`null`, `false`, `0`, `''`) which would all result in the same `0.0.0.0` output anyway.

Follow-up [42971].

Props jrf, hellofromTonya.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51793 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-09 22:55:36 +00:00
Tonya Mork
c556e0dbab Tests: Add more invalid IP test cases and @covers to Tests_Functions_Anonymization.
Adds a few more invalid IP test cases.

Adds extra `@covers` tag for the two functions which are testing the `wp_privacy_anonymize_ip()` function.

(At class level, the `wp_privacy_anonymize_data()` is set as covered).

Follow-up to [42971].

Props jrf, hellofromTonya.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51792 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-09 22:43:49 +00:00
Tonya Mork
1d0e4441c1 Widgets: Revert [51705].
While the new name is much better, it doesn't fully tell what will happen when invoked nor does it fully solve the root problems. 

Why? The function is doing too much. And naming is hard.

Props azaozz, desrosj, andraganescu, zieladam, hellofromTonya.
See #53811.

git-svn-id: https://develop.svn.wordpress.org/trunk@51791 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-09 21:39:39 +00:00
Tonya Mork
50d7248e1e Code Modernization: Fix parameter name mismatches for parent/child classes in WP_Image_Editor::save().
Renames the first parameter in `WP_Image_Editor_GD::save()` to match the parent's method signature.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.

Adds @since to clearly specify why the change happened.

Adds parameter descriptions to parent and both child classes. 

Follow-up to [22094], [22619], [30681].

Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.

git-svn-id: https://develop.svn.wordpress.org/trunk@51790 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-09 20:38:20 +00:00
Tonya Mork
cc1632c046 Code Modernization: Fix parameter name mismatches for parent/child classes in WP_Widget::update().
In each child class, renames the parameter to match the parent's method signature.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.

Adds @since to clearly specify why the change happened.

Replaces the original with the variable name with within each method.
Why? The new name is more specific and descriptive, which improves readability.

Follow-up to [10782], [25090], [26556], [40640].

Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.

git-svn-id: https://develop.svn.wordpress.org/trunk@51789 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-09 20:12:58 +00:00
Tonya Mork
ec3b4135da Code Modernization: Fix parameter name mismatches for parent/child classes in WP_Sitemaps_Provider::get_max_num_pages().
In each child class, renames the parameter to match the parent's method signature.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.

Adds @since to clearly specify why the change happened.

Reassigns the generic parameter to the original parameter.
Why? Restoring the original name keeps the context intact within the method and makes the code more readable. An inline comment explains why this reassignment is made.

Note: Reassignment is done after the guard clause.
Why? To avoid unnecessary processing and memory should the method bail out.

Follow-up to [48072].

Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.

git-svn-id: https://develop.svn.wordpress.org/trunk@51788 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-09 19:41:53 +00:00
Tonya Mork
36bca16d31 Code Modernization: Fix parameter name mismatches for parent/child classes in WP_Sitemaps_Provider::get_url_list().
In each child and grandchild class, renames the second parameter to match the parent's method signature.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.

Adds @since to clearly specify why the change happened.

Reassigns the generic parameter to the original parameter.
Why? Restoring the original name keeps the context intact within the method and makes the code more readable. An inline comment explains why this reassignment is made.

Follow-up to [48072].

Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.

git-svn-id: https://develop.svn.wordpress.org/trunk@51787 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-09 19:20:56 +00:00
Tonya Mork
36d6e7d3b0 Code Modernization: Fix parameter name mismatches for parent/child classes in WP_REST_Controller::prepare_item_for_response().
In each child and grandchild class, renames the first parameter to match the parent's method signature.

Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.

Changes for readability:

- `@since` clearly specifies the original parameter name and its new name as well as why the change happened.

- In methods longer than a single line, the generic parameter is reassigned to the original parameter restoring it for context for use within the method. An inline comment is added to explain why this reassignment is made.

Follow-up to [38832], [39011], [39015], [39021], [39024], [39025], [39031], [39036], [43519], [43735], [43739], [43768], [46821], [48173], [48242], [49088], [50995], [51003], [51021].

Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.

git-svn-id: https://develop.svn.wordpress.org/trunk@51786 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-09 18:35:34 +00:00