Skip to content

Conversation

@anton-vlasenko
Copy link
Owner

Trac ticket:


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

SergeyBiryukov and others added 30 commits August 17, 2021 21:55
…Theme Editor screens.

As per the PHP manual:
> If the `component` parameter is omitted, an associative array is returned.
> If the `component` parameter is specified, `parse_url()` returns a string (or an int, in the case of `PHP_URL_PORT`) instead of an array. If the requested component doesn't exist within the given URL, `null` will be returned.

Reference: [https://www.php.net/manual/en/function.parse-url.php#refsect1-function.parse-url-returnvalues PHP Manual: parse_url(): Return Values]

While it is probably unlikely that someone would have a direct link to the plugin/theme editor on their home page or even on someone else's homepage, it is entirely possible for the referrer URL to not have a "path" component.

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

Changing the logic around and adding validation for the return type value of `parse_url()` prevents that.

Follow-up to [51606], [51622], [51626].

Props jrf, hellofromTonya, SergeyBiryukov.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51629 602fd350-edb4-49c9-b593-d223f7449a82
…kie_constants()`.

As per the PHP manual:
> If the `component` parameter is omitted, an associative array is returned.
> If the `component` parameter is specified, `parse_url()` returns a string (or an int, in the case of `PHP_URL_PORT`) instead of an array. If the requested component doesn't exist within the given URL, `null` will be returned.

Reference: [https://www.php.net/manual/en/function.parse-url.php#refsect1-function.parse-url-returnvalues PHP Manual: parse_url(): Return Values]

It is entirely possible for the `siteurl` option to not have a "path" component.

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

Changing the logic around and adding validation for the return type value of `parse_url()` prevents that.

As this function is declaring global constants, adding tests for this change is not really an option without potentially affecting other tests.

Follow-up to [51606], [51622], [51626], [51629].

Props jrf, hellofromTonya, SergeyBiryukov.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51630 602fd350-edb4-49c9-b593-d223f7449a82
Reduces the right margin of the media library modal on small and medium width screens to remove excess white-space. On very narrow screens this was preventing the media icons from displaying.

Props andraganescu, desrosj, joedolson, moch11, mukesh27, sabernhardt, SergeyBiryukov, zieladam.
Fixes #53679.


git-svn-id: https://develop.svn.wordpress.org/trunk@51631 602fd350-edb4-49c9-b593-d223f7449a82
Increase the number of media items displayed per page from 40 to 80 to improve the experience for users navigating the library on sites with a large quantity of media in the library.

Props AlGala, antpb, hellofromTonya, joedolson, SergeyBiryukov, wb1234.
Fixes #53827.



git-svn-id: https://develop.svn.wordpress.org/trunk@51632 602fd350-edb4-49c9-b593-d223f7449a82
Since PHP 8.1, the `auto_detect_line_endings` setting is deprecated:

> The `auto_detect_line_endings` ini setting modifies the behavior of `file()` and `fgets()` to support an isolated `\r` (as opposed to `\n` or `\r\n`) as a newline character. These newlines were used by “Classic” Mac OS, a system which has been discontinued in 2001, nearly two decades ago. Interoperability with such systems is no longer relevant.

Reference: [https://wiki.php.net/rfc/deprecations_php_8_1#auto_detect_line_endings_ini_setting PHP RFC: Deprecations for PHP 8.1: auto_detect_line_endings ini setting]

> The `auto_detect_line_endings` ini setting has been deprecated. If necessary, handle `\r` line breaks manually instead.

Reference: [https://github.com/php/php-src/blob/1cf4fb739f7a4fa8404a4c0958f13d04eae519d4/UPGRADING#L456-L457 PHP 8.1 Upgrade Notes].

This commit fixes the warning when running tests for the `PO` class:
{{{
Deprecated: auto_detect_line_endings is deprecated in /var/www/src/wp-includes/pomo/po.php on line 16
}}}

Follow-up to [10584], [51628].

See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51633 602fd350-edb4-49c9-b593-d223f7449a82
The latest release includes preliminary PHP 8.1 support, as well as some small bug fixes.

Release notes: https://github.com/PHPMailer/PHPMailer/releases/tag/v6.5.1

For a full list of changes in this update, see the PHPMailer GitHub:
PHPMailer/PHPMailer@v6.5.0...v6.5.1

Follow-up to [50628], [50799], [51169].

Props jrf.
Fixes #53953.

git-svn-id: https://develop.svn.wordpress.org/trunk@51634 602fd350-edb4-49c9-b593-d223f7449a82
These are necessary for a passing PHP Compatibility scan.

Follow-up to [48045], [51634].

See #53953.

git-svn-id: https://develop.svn.wordpress.org/trunk@51635 602fd350-edb4-49c9-b593-d223f7449a82
…line_endings`.

Since PHP 8.1, the `auto_detect_line_endings` setting is deprecated:

> The `auto_detect_line_endings` ini setting modifies the behavior of `file()` and `fgets()` to support an isolated `\r` (as opposed to `\n` or `\r\n`) as a newline character. These newlines were used by “Classic” Mac OS, a system which has been discontinued in 2001, nearly two decades ago. Interoperability with such systems is no longer relevant.

Reference: [https://wiki.php.net/rfc/deprecations_php_8_1#auto_detect_line_endings_ini_setting PHP RFC: Deprecations for PHP 8.1: auto_detect_line_endings ini setting]

> The `auto_detect_line_endings` ini setting has been deprecated. If necessary, handle `\r` line breaks manually instead.

Reference: [https://github.com/php/php-src/blob/1cf4fb739f7a4fa8404a4c0958f13d04eae519d4/UPGRADING#L456-L457 PHP 8.1 Upgrade Notes].

This commit fixes the warning when running tests for the `PO` class:
{{{
Deprecated: auto_detect_line_endings is deprecated in /var/www/src/wp-includes/pomo/po.php on line 16
}}}

While deprecated, the actual `auto_detect_line_endings` functionality has not been removed from PHP (yet) and will still work until PHP 9.0.

For now, we're silencing the deprecation notice as there may still be translation files around which haven't been updated in a long time and which still use the old MacOS standalone `\r` as a line ending.

This should be revisited when PHP 9.0 is in alpha/beta.

Follow-up to [51633].

Props jrf.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51636 602fd350-edb4-49c9-b593-d223f7449a82
Hide the browser's native radio button on the custom background position selector in the Customizer and the legacy background screen. This fixes an issue causing both to display.

Props mukesh27, ravipatel, sabernhardt, walbo.
Fixes #53803.


git-svn-id: https://develop.svn.wordpress.org/trunk@51637 602fd350-edb4-49c9-b593-d223f7449a82
…_Table::prepare_items()`.

The following warnings could, in very select circumstances, be shown:
{{{
// PHP 8.0 and higher:
Warning: foreach() argument must be of type array|object, bool given

// PHP 5.6 – 7.4
Warning: Invalid argument supplied for foreach()
}}}

In `WP_Media_List_Table::prepare_items()`, the cron info array is retrieved via a call to `_get_cron_array()`, but as the documentation (correctly) states, the return type of that function is `array|false`, where `false` is returned for a virgin site, with no cron jobs scheduled yet.

However, no type check is done on the return value, and the method just blindly continues by using it in a `foreach`.

Fixed by adding validation for the returned value from `_get_cron_array()` and only running the `foreach` when the returned value is an array.

Reference: [https://developer.wordpress.org/reference/functions/_get_cron_array/ WordPress Developer Resources: _get_cron_array()]

Follow-up to [48417].

Props jrf, hellofromTonya, mukesh27.
Fixes #53949.

git-svn-id: https://develop.svn.wordpress.org/trunk@51638 602fd350-edb4-49c9-b593-d223f7449a82
…tions.

https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492], [51493], [51623].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51639 602fd350-edb4-49c9-b593-d223f7449a82
…_class()`.

This ensures that the class is loaded once before the first test of the test case class is run, and `require_once()` is not unnecessarily called for each test method individually.

Follow-up to [40607], [51628].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51641 602fd350-edb4-49c9-b593-d223f7449a82
When transition is `all`, it also applies to the icon size, which can cause a bug in Safari where icons get stuck in the wrong size when resizing the browser window. The only expected animation is on the color property, so the transition can be limited to just `color`.

Props johnjamesjacoby, sabernhardt, SergeyBiryukov, audrasjb.
Fixes #43423.



git-svn-id: https://develop.svn.wordpress.org/trunk@51644 602fd350-edb4-49c9-b593-d223f7449a82
Sometimes the submit button wraps to a new line, either because the button label translation is long, or there are long page names. When it wraps, there should be space between the select dropdown and the button.

Props audrasjb, mukesh27, guillaumeturpin.
Fixes #53782.



git-svn-id: https://develop.svn.wordpress.org/trunk@51645 602fd350-edb4-49c9-b593-d223f7449a82
…ntions.

https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492], [51493], [51623], [51639].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51646 602fd350-edb4-49c9-b593-d223f7449a82
This gives more context to GitHub Action related Slack messages without the need to click the workflow URL, or unfurl the links (which shows lots of unnecessary information, such as the repository description and image).

Props earnjam.
See #52644.

git-svn-id: https://develop.svn.wordpress.org/trunk@51647 602fd350-edb4-49c9-b593-d223f7449a82
…it tests for it.

Props antonvlasenko.
Fixes #51636.

git-svn-id: https://develop.svn.wordpress.org/trunk@51648 602fd350-edb4-49c9-b593-d223f7449a82
…ditor`.

Props zieladam.
Fixes #53762.

git-svn-id: https://develop.svn.wordpress.org/trunk@51649 602fd350-edb4-49c9-b593-d223f7449a82
…ming conventions.

https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492], [51493], [51623], [51639], [51646].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51650 602fd350-edb4-49c9-b593-d223f7449a82
…ions.

https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492], [51493], [51623], [51639], [51646], [51650].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51651 602fd350-edb4-49c9-b593-d223f7449a82
…` in `WP_Sitemaps_Provider::get_sitemap_url()`.

The `WP_Sitemaps_Provider::get_sitemap_url()` method calls the PHP native `http_build_query()` function, the second parameter of which is the ''optional'' `$numeric_prefix` parameter which expects a `string`.

A parameter being optional, however, does not automatically make it nullable.

As of PHP 8.1, passing `null` to a non-nullable PHP native function will generate a deprecation notice.

In this case, this function call yielded a `http_build_query(): Passing null to parameter #2 ($numeric_prefix) of type string is deprecated` notice.

Changing the `null` to an empty string fixes this without a backward compatibility break.

This change is already covered by tests as 14 of the existing tests failed on these function calls when running the tests on PHP 8.1.

References:
* [https://www.php.net/manual/en/function.http-build-query.php PHP Manual: http_build_query()]
* [https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg PHP RFC: Deprecate passing null to non-nullable arguments of internal functions]

Follow-up to [48470].

Props jrf.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51652 602fd350-edb4-49c9-b593-d223f7449a82
…ll alternate file names when an image may be converted after uploading. This includes possible collinions with pre-existing images whose sub-sizes/thumbnails are regenerated.

Props ianmjones, azaozz.
Fixes #53668.

git-svn-id: https://develop.svn.wordpress.org/trunk@51653 602fd350-edb4-49c9-b593-d223f7449a82
This matches the `WP_Upgrader::download_package()` documentation more closely.

Follow-up to [11005], [30758], [33685].

See #53399.

git-svn-id: https://develop.svn.wordpress.org/trunk@51654 602fd350-edb4-49c9-b593-d223f7449a82
…of `WP_Upgrader::run()`.

This matches the `WP_Upgrader::download_package()` documentation more closely.

Follow-up to [44954], [45262].

See #53399.

git-svn-id: https://develop.svn.wordpress.org/trunk@51655 602fd350-edb4-49c9-b593-d223f7449a82
When a closure does not use `$this`, it can be made `static` for improved performance.

Static closures are supported in PHP since PHP 5.4. ​

Props jrf, hellofromTonya, swissspidy, SergeyBiryukov.
See #53359.

git-svn-id: https://develop.svn.wordpress.org/trunk@51657 602fd350-edb4-49c9-b593-d223f7449a82
…rs` in PHPCS ruleset.

Follow-up to [45611].

Props jrf, hellofromTonya.
See #53359.

git-svn-id: https://develop.svn.wordpress.org/trunk@51658 602fd350-edb4-49c9-b593-d223f7449a82
…HPCS ruleset.

The WPCS sniff already takes the test classes in the `tests/phpunit/includes` directory into account.

Only the test cases outside of that directory, i.e. in the `tests/phpunit/tests` directory need to be listed here.

Includes alphabetizing the list.

Follow-up to [42346], [45607].

Props jrf, hellofromTonya, SergeyBiryukov.
See #53359.

git-svn-id: https://develop.svn.wordpress.org/trunk@51659 602fd350-edb4-49c9-b593-d223f7449a82
…ions()`.

Follow-up to [43627], [43628].

Props jrf, hellofromTonya.
See #53359.

git-svn-id: https://develop.svn.wordpress.org/trunk@51660 602fd350-edb4-49c9-b593-d223f7449a82
…Health_Auto_Updates::test_vcs_abspath()`.

Follow-up to [44986].

Props jrf, hellofromTonya.
See #53359.

git-svn-id: https://develop.svn.wordpress.org/trunk@51661 602fd350-edb4-49c9-b593-d223f7449a82
…wp_privacy_send_personal_data_export_email()`.

Follow-up to [51129], [51410].

Props jrf, hellofromTonya.
See #53359.

git-svn-id: https://develop.svn.wordpress.org/trunk@51662 602fd350-edb4-49c9-b593-d223f7449a82
TimothyBJacobs and others added 7 commits October 31, 2021 05:17
Props spacedmonkey, peterwilsoncc.
Fixes #54055.


git-svn-id: https://develop.svn.wordpress.org/trunk@51959 602fd350-edb4-49c9-b593-d223f7449a82
Previously, a 200 status code would be sent despite the 500 status code present in the response body.

Props hermpheus, lalitjalandhar.
Fixes #53056.


git-svn-id: https://develop.svn.wordpress.org/trunk@51960 602fd350-edb4-49c9-b593-d223f7449a82
…_schema()` for the `supports` and `visibility` properties.

The `taxonomies` and `rest_base` properties were also added after the method was initially introduced, but that happened during the same release cycle, so they don't need a separate `@since` note.

Follow-up to [38832], [39097], [39191], [39647], [51959].

See #53399.

git-svn-id: https://develop.svn.wordpress.org/trunk@51961 602fd350-edb4-49c9-b593-d223f7449a82
While a custom post type can define a custom route by using the `rest_base` argument, a namespace of `wp/v2` was assumed. This commit introduces support for a `rest_namespace` argument. 

A new `rest_get_route_for_post_type_items` function has been introduced and the `rest_get_route_for_post` function updated to facilitate getting the correct route for custom post types.

While the WordPress Core Block Editor bootstrap code has been updated to use these API functions, for maximum compatibility sticking with the default `wp/v2` namespace is recommended until the API functions see wider use.

Props spacedmonkey, swissspidy.
Fixes #53656.


git-svn-id: https://develop.svn.wordpress.org/trunk@51962 602fd350-edb4-49c9-b593-d223f7449a82
This change adds two now attribute-related config options to KSES:
- An array of allowed values can be defined for attributes. If the attribute value doesn't fall into the list, the attribute will be removed from the tag.
- Attributes can be marked as required. If a required attribute is not present, KSES will remove all attributes from the tag. As KSES doesn't match opening and closing tags, it's not possible to safely remove the tag itself, the safest fallback is to strip all attributes from the tag, instead.

Included with this change is an implementation of these options, allowing the `<object>` tag to be stored in posts, but only when it has a `type` attribute set to `application/pdf`.

Props pento, swissspidy, peterwilsoncc, dd32, jorbin.
Fixes #54261.



git-svn-id: https://develop.svn.wordpress.org/trunk@51963 602fd350-edb4-49c9-b593-d223f7449a82
While a taxonomy can define a custom route by using the rest_base argument, a namespace of wp/v2 was assumed. This commit introduces support for a rest_namespace argument.

A new rest_get_route_for_taxonomy_items function has been introduced and the rest_get_route_for_term function updated to facilitate getting the correct route for taxonomies.

For maximum compatibility sticking with the default wp/v2 namespace is recommended until the API functions see wider use.

Props spacedmonkey.
Fixes #54267.
See [51962].


git-svn-id: https://develop.svn.wordpress.org/trunk@51964 602fd350-edb4-49c9-b593-d223f7449a82
…ter_post_type()` and `register_taxonomy()`.

Use 3-digit, x.x.x-style semantic versioning for `@since` tags of the `$rest_namespace` property in `WP_Post_Type` and `WP_Taxonomy`.

Add a `@since` note to `WP_REST_Taxonomies_Controller::get_item_schema()` for the `visibility` and `rest_namespace` properties.

The `rest_base` property was also added after the method was initially introduced, but that happened during the same release cycle, so it doesn't need a separate `@since` note.

Follow-up to [38832], [39191], [42729], [51959], [51961], [51962], [51964].

See #53399.

git-svn-id: https://develop.svn.wordpress.org/trunk@51965 602fd350-edb4-49c9-b593-d223f7449a82
@anton-vlasenko anton-vlasenko merged commit 93a7d9e into anton-vlasenko:master Nov 1, 2021
anton-vlasenko pushed a commit that referenced this pull request Nov 1, 2021
…rse_request()`.

As per the PHP manual:
> If the `component` parameter is omitted, an associative array is returned.
> If the `component` parameter is specified, `parse_url()` returns a string (or an int, in the case of `PHP_URL_PORT`) instead of an array. If the requested component doesn't exist within the given URL, `null` will be returned.

Reference: [https://www.php.net/manual/en/function.parse-url.php#refsect1-function.parse-url-returnvalues PHP Manual: parse_url(): Return Values]

In this case, `parse_url()` is called with the `PHP_URL_PATH` as `$component`. This will return `null` in the majority of cases, as – exсept for subdirectory-based sites – `home_url()` returns a URL without the trailing slash, like `http://example.org`.

The return value of `parse_url()` was subsequently passed to `trim()`, leading to a `trim(): Passing null to parameter #1 ($string) of type string is deprecated` notice on PHP 8.1.

Fixed by adjusting the logic flow to:
* Only pass the return value of `parse_url()` to follow-on functions if it makes sense, i.e. if it isn't `null`, nor an empty string.
* Preventing calls to `preg_replace()` and `trim()` further down in the function logic flow, when `preg_replace()`/`trim()` would have nothing to do anyhow.

Follow-up to [25617].

Props jrf, hellofromTonya, SergeyBiryukov.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51622 602fd350-edb4-49c9-b593-d223f7449a82
anton-vlasenko pushed a commit that referenced this pull request Nov 1, 2021
This fixes `parse_str(): Passing null to parameter #1 ($string) of type string is deprecated` notices on PHP 8.1, without change in behaviour.

Impact: 311 of the pre-existing tests are affected by this issue.

The PHP native `parse_str()` function expects a string, however, based on the failing tests, it is clear there are functions in WordPress which passes a non-string – including `null` – value to the `wp_parse_str()` function, which would subsequently pass it onto the PHP native function without further input validation.

Most notable offender is the `wp_parse_args()` function which special cases arrays and objects, but passes everything else off to `wp_parse_str()`.

Several ways to fix this issue have been explored, including checking the received value with `is_string()` or `is_scalar()` before passing it off to the PHP native `parse_str()` function.

In the end it was decided against these in favor of a string cast as:
* `is_string()` would significantly change the behavior for anything non-string.
* `is_scalar()` up to a point as well, as it does not take objects with a `__toString()` method into account.

Executing a string cast on the received value before passing it on maintains the pre-existing behavior while still preventing the deprecation notice coming from PHP 8.1.

Reference: [https://www.php.net/manual/en/function.parse-str.php PHP Manual: parse_str()]

Follow-up to [5709].

Props jrf, hellofromTonya, lucatume, SergeyBiryukov.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51624 602fd350-edb4-49c9-b593-d223f7449a82
anton-vlasenko pushed a commit that referenced this pull request Nov 1, 2021
…ad_url()`.

As per the PHP manual:
> If the `component` parameter is omitted, an associative array is returned.
> If the `component` parameter is specified, `parse_url()` returns a string (or an int, in the case of `PHP_URL_PORT`) instead of an array. If the requested component doesn't exist within the given URL, `null` will be returned.

Reference: [https://www.php.net/manual/en/function.parse-url.php#refsect1-function.parse-url-returnvalues PHP Manual: parse_url(): Return Values]

This commit adds three unit tests for `download_url()`:

* The first test is "girl-scouting" to make sure that the code up to the point where the error is expected is tested.
* The second test exposed a PHP 8.1 `basename(): Passing null to parameter #1 ($path) of type string is deprecated` error due to the call to `parse_url()` returning `null` when the component requested does not exist in the passed URL.
* The output of the call to `parse_url()` stored in the `$url_path` variable is used in more places in the function logic. The third test exposes a second PHP 8.1 deprecation notice, this time for `substr(): Passing null to parameter #1 ($string) of type string is deprecated`.

This commit also removes duplicate `parse_url()` calls. Neither `$url` nor `$url_filename` are changed between when they are first received/defined and when they are re-used, so there is no need to repeat the function calls.

Follow-up to [51606], [51622].

Props jrf, hellofromTonya, SergeyBiryukov.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51626 602fd350-edb4-49c9-b593-d223f7449a82
anton-vlasenko pushed a commit that referenced this pull request Nov 23, 2021
… to `strpos()` in `wp_fix_server_vars()`.

If `SCRIPT_NAME'` does not exist (which can happen in cron jobs), the following happens:

* PHP 8.1+:
    * `Warning: Undefined array key "SCRIPT_NAME"`
    * `Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated` 
* PHP 8.0: `Warning: Undefined array key "SCRIPT_NAME"`
* PHP 5.6-7.4: No warning or notice

This commit checks if the key exists before passing it to `strpos()`. This resolves the warning, notice, and future error.

Follow-up to [3034], [3069], [12732].

Props audrasjb, costdev, hellofromTonya, karpstrucking, mcjambi, sergeybiryukov.
Fixes #54142.

git-svn-id: https://develop.svn.wordpress.org/trunk@52144 602fd350-edb4-49c9-b593-d223f7449a82
anton-vlasenko pushed a commit that referenced this pull request Nov 30, 2021
…n `int` or `float`.

For certain images, `wp_exif_frac2dec()` unexpectedly returned a string instead of `int` or `float`. This can occur when an image is missing meta and calls the function with `'0/0'`. For those images, a fatal error was thrown on PHP 8.0+:

{{{
TypeError: round(): Argument #1 ($num) must be of type int|float, string given
}}}

Upon deeper review, inconsistent and unexpected results were returned from different types of input values passed to the function.

Changes are:

* Maintains backwards-compatibility for valid input values.
* Fixes handling of invalid input values by bailing out to return the documented type of `int|float` by returning `0`.
* Improves the fractional conditional check.
* Improves the calculated fraction handling to ensure (a) the numerator and denominator are both numeric and (b) the denominator is not equal to zero.
* Safeguards the behavior via tests for all possible ways code could flow through the function.
* Safeguards the backwards-compatibility of the `wp_read_image_metadata()` by adding some defensive coding around the calls to the `wp_exif_frac2dec()` function.

These changes fix the fatal error and make the function more secure, stable, and predictable while maintaining backwards-compatibility for valid input values.

Follow-up to [6313], [9119], [22319], [28367], [45611], [47287].

Props adamsilverstein, jrf, peterwilsoncc, praem90, stevegs, tobiasbg.
Fixes #54385.

git-svn-id: https://develop.svn.wordpress.org/trunk@52269 602fd350-edb4-49c9-b593-d223f7449a82
anton-vlasenko pushed a commit that referenced this pull request Mar 8, 2022
…mail()`.

As per the PHP manual:
> If the `component` parameter is omitted, an associative array is returned.
> If the `component` parameter is specified, `parse_url()` returns a string (or an int, in the case of `PHP_URL_PORT`) instead of an array. If the requested component doesn't exist within the given URL, `null` will be returned.

Reference: [https://www.php.net/manual/en/function.parse-url.php#refsect1-function.parse-url-returnvalues PHP Manual: parse_url(): Return Values]

In PHP 8.1, if the home URL does not have a "host" component, it would lead to a `substr(): Passing null to parameter #1 ($string) of type string is deprecated` notice.

Changing the logic around and adding validation for the return type value of `wp_parse_url()` prevents that.

Follow-up to [48601], [51606], [51622], [51626], [51629], [51630].

Props dennisatyoast, jrf.
See #54730.

git-svn-id: https://develop.svn.wordpress.org/trunk@52799 602fd350-edb4-49c9-b593-d223f7449a82
anton-vlasenko pushed a commit that referenced this pull request May 26, 2022
anton-vlasenko pushed a commit that referenced this pull request Sep 21, 2022
…ize_Manager::get_return_url()`.

This particular code block only makes sense to run when `$this->return_url` is not null. Previously, it caused a "passing null to non-nullable" deprecation notice on PHP 8.1.

By moving the code into the `if ( $this->return_url )` condition block, the code will only be run when `$this->return_url` contains a non-falsey/non-null value.

No additional tests added as this issue was found via the existing tests for the function containing the bug.

This solves the following two PHP 8.1 test errors:
{{{
1) Tests_WP_Customize_Manager::test_return_url
parse_url(): Passing null to parameter #1 ($url) of type string is deprecated

/var/www/src/wp-includes/class-wp-customize-manager.php:4696
/var/www/tests/phpunit/tests/customize/manager.php:2975
/var/www/vendor/bin/phpunit:123

2) Tests_WP_Customize_Manager::test_customize_pane_settings
parse_url(): Passing null to parameter #1 ($url) of type string is deprecated

/var/www/src/wp-includes/class-wp-customize-manager.php:4696
/var/www/src/wp-includes/class-wp-customize-manager.php:4898
/var/www/tests/phpunit/tests/customize/manager.php:3085
/var/www/vendor/bin/phpunit:123
}}}

Follow-up to [46754].

Props jrf, costdev.
See #55656.

git-svn-id: https://develop.svn.wordpress.org/trunk@54135 602fd350-edb4-49c9-b593-d223f7449a82
anton-vlasenko added a commit that referenced this pull request Sep 27, 2022
1. Deprecated: preg_replace(): Passing null to parameter WordPress#3 ($subject) of type array|string is deprecated in /src/wp-includes/formatting.php on line 5407
2. Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /src/wp-includes/pluggable.php on line 603
anton-vlasenko pushed a commit that referenced this pull request Sep 28, 2022
…pc_server::mw_newPost()`.

The `wp_xmlrpc_server::mw_newPost()` method creates a new post via `wp_insert_post()`, but the default/fallback values used in the function were not in line with the default/fallback values used in the `wp_insert_post()` function.

The `wp_insert_post()` function does a `wp_parse_args()` (array merge) of the received arguments with the defaults. If any of the received arguments are `null`, this would overwrite the default value, as seen in [https://3v4l.org/bfVlv array_merge() example], and lead to "passing null to non-nullable" deprecation notices on PHP 8.1 for certain arguments.

This commit:
* Ensures that all arguments are defined before they are `compact()`'ed together to the arguments array.
* Verifies that the default/fallback value of the arguments as set within the `wp_xmlrpc_server::mw_newPost()` method are the same as the default/fallback values used in the `wp_insert_post()` function.
* Verifies that arguments which do not have a default/fallback value defined in the `wp_insert_post()` function are handled correctly.
 * This was not the case for `$post_name`, which would previously already get an empty string default value in the `wp_xmlrpc_server::mw_newPost()` function, but then in the `wp_insert_post()` function, this would prevent the slug generation from being activated. Fixed now by setting the default in the `wp_xmlrpc_server::mw_newPost()` function to `null`.
 * The `page_template` argument was handled, but not documented in the `wp_insert_post()` function. The argument is now documented in the `wp_insert_post()` function DocBlock. Note: There are more than likely several other potential arguments missing from that list, but verifying the whole list is outside the scope of this particular commit.

Includes minor simplifications, such as:
* Setting a default ahead of an `if`, instead of in an `else` clause (as long as no function call is needed to set the default).
* Removing the unnecessary logic duplication in the `$post_status` switch.
* Using a combined concatenation + assignment operator for adding `$post_more`.

Fixes various errors along the lines of:
{{{
1) Tests_XMLRPC_mw_editPost::test_draft_not_prematurely_published
strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated

/var/www/src/wp-includes/formatting.php:2497
/var/www/src/wp-includes/class-wp-hook.php:308
/var/www/src/wp-includes/plugin.php:205
/var/www/src/wp-includes/post.php:2835
/var/www/src/wp-includes/post.php:2720
/var/www/src/wp-includes/post.php:4066
/var/www/src/wp-includes/class-wp-xmlrpc-server.php:5616
/var/www/tests/phpunit/tests/xmlrpc/mw/editPost.php:315

...

23) Tests_XMLRPC_mw_editPost::test_draft_not_prematurely_published
json_decode(): Passing null to parameter #1 ($json) of type string is deprecated

/var/www/src/wp-includes/kses.php:2074
/var/www/src/wp-includes/class-wp-hook.php:307
/var/www/src/wp-includes/plugin.php:205
/var/www/src/wp-includes/post.php:2835
/var/www/src/wp-includes/post.php:2720
/var/www/src/wp-includes/post.php:4066
/var/www/src/wp-includes/class-wp-xmlrpc-server.php:5615
/var/www/tests/phpunit/tests/xmlrpc/mw/editPost.php:315
/var/www/vendor/bin/phpunit:123
}}}

Follow-up to [1563], [4793], [7900], [16824], [19848], [40677], [51968].

Props jrf.
See #55656.

git-svn-id: https://develop.svn.wordpress.org/trunk@54320 602fd350-edb4-49c9-b593-d223f7449a82
anton-vlasenko pushed a commit that referenced this pull request Sep 28, 2022
…pc_server::_insert_post()`.

The `wp_xmlrpc_server::_insert_post()` method creates a new post via `wp_insert_post()` or updates an existing one via `wp_update_post()`, which subsequently calls `wp_insert_post()`. However, the default/fallback values used in the function were not in line with the default/fallback values used in the `wp_insert_post()` function.

The `wp_insert_post()` function does a `wp_parse_args()` (array merge) of the received arguments with the defaults. If any of the received arguments are `null`, this would overwrite the default value, as seen in [https://3v4l.org/bfVlv array_merge() example], and lead to "passing null to non-nullable" deprecation notices on PHP 8.1 for certain arguments.

Unfortunately, the conditional logic within the `wp_xmlrpc_server::_insert_post()` function itself often uses an `isset()` to trigger certain code blocks, so syncing the defaults with those used in the `wp_insert_post()` function was not an option.

This commit:
* Updates the default/fallback values in the `$defaults` array only for those values where this would not lead to a change in the behavior of the function.
* Adds a safeguard function, filtering out all remaining `null` values from the `$post_data` array before it is passed on to the `wp_insert_post()` or `wp_update_post()` functions. Removing those values is safe as this means that these array keys will now:
 * either be set to the default/fallback value as defined in `wp_insert_post()`.
 * or not be set and for those values which don't have a default/fallback value in `wp_insert_post()`, the function does an `! empty()` or `isset()` check anyway and those array keys not being defined means that the result of those checks will remain the same.

Includes
* Removing a couple of conditions which are now redundant.
* Removing an `expectDeprecation()` in the `Tests_Date_XMLRPC` test class, which is now no longer needed.

Fixes various errors along the lines of:
{{{
36) Tests_XMLRPC_wp_newPost::test_no_content
json_decode(): Passing null to parameter #1 ($json) of type string is deprecated

/var/www/src/wp-includes/kses.php:2074
/var/www/src/wp-includes/class-wp-hook.php:307
/var/www/src/wp-includes/plugin.php:205
/var/www/src/wp-includes/post.php:2835
/var/www/src/wp-includes/post.php:2720
/var/www/src/wp-includes/post.php:4066
/var/www/src/wp-includes/class-wp-xmlrpc-server.php:1683
/var/www/src/wp-includes/class-wp-xmlrpc-server.php:1347
/var/www/tests/phpunit/tests/xmlrpc/wp/newPost.php:25
/var/www/vendor/bin/phpunit:123
}}}

Follow-up to [1563], [4793], [7900], [16824], [19848], [19873], [20632], [40677], [51968], [54320].

Props jrf.
See #55656.

git-svn-id: https://develop.svn.wordpress.org/trunk@54321 602fd350-edb4-49c9-b593-d223f7449a82
anton-vlasenko pushed a commit that referenced this pull request Sep 28, 2022
…ions path.

The `$path` parameter of `load_script_textdomain()` had a default value of `null`, but would be passed onto the `untrailingslashit()` function without any input validation, even though the latter explicitly only expects/supports a string input.

This commit changes the default value for `$path` to an empty string, and adds an `is_string()` check before passing the value to `untrailingslashit()` to fix the issue at the point where the invalid input is incorrectly (not) validated.

Note: Changing the `untrailingslashit()` function is outside the scope of this commit.

Includes:
* Adding a dedicated unit test for this issue.
* Correcting the default value for `$path` from `null` to an empty string in a few related methods and functions:
 * `WP_Dependency::set_translations()`
 * `WP_Scripts::set_translations()`
 * `wp_set_script_translations()`
 * `load_script_textdomain()`

This fix also allows to remove a couple of calls to `expectDeprecation()` in unrelated tests.

Fixes an error when running the test suite:
{{{
4) Tests_Dependencies_Scripts::test_wp_external_wp_i18n_print_order
rtrim(): Passing null to parameter #1 ($string) of type string is deprecated

/var/www/src/wp-includes/formatting.php:2782
/var/www/src/wp-includes/l10n.php:1068
/var/www/src/wp-includes/class.wp-scripts.php:605
/var/www/src/wp-includes/class.wp-scripts.php:320
/var/www/src/wp-includes/class.wp-dependencies.php:136
/var/www/src/wp-includes/functions.wp-scripts.php:109
/var/www/tests/phpunit/tests/dependencies/scripts.php:1505
/var/www/tests/phpunit/includes/utils.php:436
/var/www/tests/phpunit/tests/dependencies/scripts.php:1507
/var/www/vendor/bin/phpunit:123
}}}

Follow-up to [44169], [44607], [51968].

Props jrf, ocean90, Chouby, swissspidy, lovor, iviweb, meysamnorouzi, DarkoG, oneearth27, SergeyBiryukov.
Fixes #55967. See #55656.

git-svn-id: https://develop.svn.wordpress.org/trunk@54349 602fd350-edb4-49c9-b593-d223f7449a82
anton-vlasenko added a commit that referenced this pull request Sep 29, 2022
1) Tests_Blocks_Editor::test_get_block_editor_settings_theme_json_settings
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
2) Tests_Blocks_Editor::test_get_block_editor_settings_deprecated_filter_post_editor
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
12) Tests_Theme_wpGetGlobalStylesheet::test_block_theme_using_defaults
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
13) Tests_Theme_wpGetGlobalStylesheet::test_variables_in_classic_theme_with_no_presets_using_defaults
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
14) Tests_Theme_wpGetGlobalStylesheet::test_variables_in_classic_theme_with_presets_using_defaults
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
15) Tests_Theme_wpThemeJson::test_get_stylesheet_support_for_shorthand_and_longhand_values
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
16) Tests_Theme_wpThemeJson::test_get_stylesheet_skips_disabled_protected_properties
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
17) Tests_Theme_wpThemeJson::test_get_stylesheet_renders_enabled_protected_properties
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
18) Tests_Theme_wpThemeJson::test_get_stylesheet
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
19) Tests_Theme_wpThemeJson::test_get_stylesheet_preset_rules_come_after_block_rules
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
20) Tests_Theme_wpThemeJson::test_get_stylesheet_preset_values_are_marked_as_important
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
21) Tests_Theme_wpThemeJson::test_get_stylesheet_handles_whitelisted_element_pseudo_selectors
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
22) Tests_Theme_wpThemeJson::test_get_stylesheet_handles_only_pseudo_selector_rules_for_given_property
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
23) Tests_Theme_wpThemeJson::test_get_stylesheet_ignores_pseudo_selectors_on_non_whitelisted_elements
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
24) Tests_Theme_wpThemeJson::test_get_stylesheet_ignores_non_whitelisted_pseudo_selectors
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
25) Tests_Theme_wpThemeJson::test_get_stylesheet_handles_priority_of_elements_vs_block_elements_pseudo_selectors
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
26) Tests_Theme_wpThemeJson::test_get_stylesheet_handles_whitelisted_block_level_element_pseudo_selectors
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
27) Tests_Theme_wpThemeJson::test_remove_insecure_properties_removes_unsafe_styles
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
28) Tests_Theme_wpThemeJson::test_remove_insecure_properties_removes_unsafe_styles_sub_properties
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
29) Tests_Theme_wpThemeJson::test_remove_insecure_properties_applies_safe_styles
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
30) Tests_Theme_wpThemeJson::test_remove_invalid_element_pseudo_selectors
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
31) Tests_Theme_wpThemeJson::test_get_property_value_valid
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
32) Tests_Theme_wpThemeJson::test_get_property_value_loop
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
33) Tests_Theme_wpThemeJson::test_get_property_value_recursion
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
34) Tests_Theme_wpThemeJson::test_get_property_value_self
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
35) Tests_Theme_wpThemeJson::test_get_stylesheet_generates_layout_styles with data set "layout definitions" (array(array('default', 'flow', 'is-layout-flow', array(array(' > .alignleft', array('left', '0', '2em')), array(' > .alignright', array('right', '2em', '0')), array(' > .aligncenter', array('auto !important', 'auto !important'))), array(array(' > *', array('0', '0')), array(' > * + *', array(null, '0')))), array('flex', 'flex', 'is-layout-flex', 'flex', array(array('', array('wrap', 'center'))), array(array('', array(null))))))
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
36) Tests_Theme_wpThemeJson::test_get_stylesheet_generates_layout_styles_with_spacing_presets with data set "layout definitions" (array(array('default', 'flow', 'is-layout-flow', array(array(' > .alignleft', array('left', '0', '2em')), array(' > .alignright', array('right', '2em', '0')), array(' > .aligncenter', array('auto !important', 'auto !important'))), array(array(' > *', array('0', '0')), array(' > * + *', array(null, '0')))), array('flex', 'flex', 'is-layout-flex', 'flex', array(array('', array('wrap', 'center'))), array(array('', array(null))))))
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
37) Tests_Theme_wpThemeJson::test_get_stylesheet_generates_fallback_gap_layout_styles with data set "layout definitions" (array(array('default', 'flow', 'is-layout-flow', array(array(' > .alignleft', array('left', '0', '2em')), array(' > .alignright', array('right', '2em', '0')), array(' > .aligncenter', array('auto !important', 'auto !important'))), array(array(' > *', array('0', '0')), array(' > * + *', array(null, '0')))), array('flex', 'flex', 'is-layout-flex', 'flex', array(array('', array('wrap', 'center'))), array(array('', array(null))))))
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
38) Tests_Theme_wpThemeJson::test_get_stylesheet_generates_valid_block_gap_values_and_skips_null_or_false_values with data set "layout definitions" (array(array('default', 'flow', 'is-layout-flow', array(array(' > .alignleft', array('left', '0', '2em')), array(' > .alignright', array('right', '2em', '0')), array(' > .aligncenter', array('auto !important', 'auto !important'))), array(array(' > *', array('0', '0')), array(' > * + *', array(null, '0')))), array('flex', 'flex', 'is-layout-flex', 'flex', array(array('', array('wrap', 'center'))), array(array('', array(null))))))
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
39) Tests_Theme_wpThemeJson::test_get_styles_for_block_with_padding_aware_alignments
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
40) Tests_Theme_wpThemeJson::test_get_styles_for_block_without_padding_aware_alignments
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
41) Tests_Theme_wpThemeJson::test_get_styles_for_block_with_content_width
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
42) Tests_Webfonts_wpThemeJsonWebfontsHandler::test_font_face_generated_from_themejson
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
43) Tests_Webfonts_wpThemeJsonWebfontsHandler::test_font_face_not_generated with data set "no "fontFace" in theme.json" ('block-theme')
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
44) Tests_Webfonts_wpThemeJsonWebfontsHandler::test_font_face_not_generated with data set "empty "fontFace" in theme.json" ('empty-fontface-theme')
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
anton-vlasenko added a commit that referenced this pull request Sep 29, 2022
1) Tests_Blocks_Editor::test_get_block_editor_settings_theme_json_settings
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
2) Tests_Blocks_Editor::test_get_block_editor_settings_deprecated_filter_post_editor
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
12) Tests_Theme_wpGetGlobalStylesheet::test_block_theme_using_defaults
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
13) Tests_Theme_wpGetGlobalStylesheet::test_variables_in_classic_theme_with_no_presets_using_defaults
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
14) Tests_Theme_wpGetGlobalStylesheet::test_variables_in_classic_theme_with_presets_using_defaults
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
15) Tests_Theme_wpThemeJson::test_get_stylesheet_support_for_shorthand_and_longhand_values
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
16) Tests_Theme_wpThemeJson::test_get_stylesheet_skips_disabled_protected_properties
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
17) Tests_Theme_wpThemeJson::test_get_stylesheet_renders_enabled_protected_properties
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
18) Tests_Theme_wpThemeJson::test_get_stylesheet
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
19) Tests_Theme_wpThemeJson::test_get_stylesheet_preset_rules_come_after_block_rules
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
20) Tests_Theme_wpThemeJson::test_get_stylesheet_preset_values_are_marked_as_important
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
21) Tests_Theme_wpThemeJson::test_get_stylesheet_handles_whitelisted_element_pseudo_selectors
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
22) Tests_Theme_wpThemeJson::test_get_stylesheet_handles_only_pseudo_selector_rules_for_given_property
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
23) Tests_Theme_wpThemeJson::test_get_stylesheet_ignores_pseudo_selectors_on_non_whitelisted_elements
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
24) Tests_Theme_wpThemeJson::test_get_stylesheet_ignores_non_whitelisted_pseudo_selectors
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
25) Tests_Theme_wpThemeJson::test_get_stylesheet_handles_priority_of_elements_vs_block_elements_pseudo_selectors
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
26) Tests_Theme_wpThemeJson::test_get_stylesheet_handles_whitelisted_block_level_element_pseudo_selectors
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
27) Tests_Theme_wpThemeJson::test_remove_insecure_properties_removes_unsafe_styles
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
28) Tests_Theme_wpThemeJson::test_remove_insecure_properties_removes_unsafe_styles_sub_properties
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
29) Tests_Theme_wpThemeJson::test_remove_insecure_properties_applies_safe_styles
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
30) Tests_Theme_wpThemeJson::test_remove_invalid_element_pseudo_selectors
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
31) Tests_Theme_wpThemeJson::test_get_property_value_valid
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
32) Tests_Theme_wpThemeJson::test_get_property_value_loop
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
33) Tests_Theme_wpThemeJson::test_get_property_value_recursion
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
34) Tests_Theme_wpThemeJson::test_get_property_value_self
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
35) Tests_Theme_wpThemeJson::test_get_stylesheet_generates_layout_styles with data set "layout definitions" (array(array('default', 'flow', 'is-layout-flow', array(array(' > .alignleft', array('left', '0', '2em')), array(' > .alignright', array('right', '2em', '0')), array(' > .aligncenter', array('auto !important', 'auto !important'))), array(array(' > *', array('0', '0')), array(' > * + *', array(null, '0')))), array('flex', 'flex', 'is-layout-flex', 'flex', array(array('', array('wrap', 'center'))), array(array('', array(null))))))
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
36) Tests_Theme_wpThemeJson::test_get_stylesheet_generates_layout_styles_with_spacing_presets with data set "layout definitions" (array(array('default', 'flow', 'is-layout-flow', array(array(' > .alignleft', array('left', '0', '2em')), array(' > .alignright', array('right', '2em', '0')), array(' > .aligncenter', array('auto !important', 'auto !important'))), array(array(' > *', array('0', '0')), array(' > * + *', array(null, '0')))), array('flex', 'flex', 'is-layout-flex', 'flex', array(array('', array('wrap', 'center'))), array(array('', array(null))))))
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
37) Tests_Theme_wpThemeJson::test_get_stylesheet_generates_fallback_gap_layout_styles with data set "layout definitions" (array(array('default', 'flow', 'is-layout-flow', array(array(' > .alignleft', array('left', '0', '2em')), array(' > .alignright', array('right', '2em', '0')), array(' > .aligncenter', array('auto !important', 'auto !important'))), array(array(' > *', array('0', '0')), array(' > * + *', array(null, '0')))), array('flex', 'flex', 'is-layout-flex', 'flex', array(array('', array('wrap', 'center'))), array(array('', array(null))))))
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
38) Tests_Theme_wpThemeJson::test_get_stylesheet_generates_valid_block_gap_values_and_skips_null_or_false_values with data set "layout definitions" (array(array('default', 'flow', 'is-layout-flow', array(array(' > .alignleft', array('left', '0', '2em')), array(' > .alignright', array('right', '2em', '0')), array(' > .aligncenter', array('auto !important', 'auto !important'))), array(array(' > *', array('0', '0')), array(' > * + *', array(null, '0')))), array('flex', 'flex', 'is-layout-flex', 'flex', array(array('', array('wrap', 'center'))), array(array('', array(null))))))
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
39) Tests_Theme_wpThemeJson::test_get_styles_for_block_with_padding_aware_alignments
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
40) Tests_Theme_wpThemeJson::test_get_styles_for_block_without_padding_aware_alignments
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
41) Tests_Theme_wpThemeJson::test_get_styles_for_block_with_content_width
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
42) Tests_Webfonts_wpThemeJsonWebfontsHandler::test_font_face_generated_from_themejson
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
43) Tests_Webfonts_wpThemeJsonWebfontsHandler::test_font_face_not_generated with data set "no "fontFace" in theme.json" ('block-theme')
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
44) Tests_Webfonts_wpThemeJsonWebfontsHandler::test_font_face_not_generated with data set "empty "fontFace" in theme.json" ('empty-fontface-theme')
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated
hellofromtonya pushed a commit that referenced this pull request Oct 4, 2022
…_JSON::get_property_value()`.

This commit aims to fix errors caused by incorrect usage of the `strncmp()` function inside the `WP_Theme_JSON::get_property_value()` method on PHP 8.1 and above.

Some history of the affected code:
* [50973] introduced the `WP_Theme_JSON::get_property_value()` method.
* [54162] removed the `$default` parameter from the `_wp_array_get()` call in the method.

With the latter change, the default value that is returned if the path does not exist within the array, or if `$array` or `$path` are not arrays, became `null` instead of an empty string. Since `null` would then be unintentionally passed to the `strncmp()` function further in the code, this caused ~35 errors in the test suite along the lines of:
{{{
1) Tests_Blocks_Editor::test_get_block_editor_settings_theme_json_settings
strncmp(): Passing null to parameter #1 ($string1) of type string is deprecated

/var/www/src/wp-includes/class-wp-theme-json.php:1754
/var/www/src/wp-includes/class-wp-theme-json.php:1641
/var/www/src/wp-includes/class-wp-theme-json.php:2066
/var/www/src/wp-includes/class-wp-theme-json.php:1002
/var/www/src/wp-includes/class-wp-theme-json.php:898
/var/www/src/wp-includes/global-styles-and-settings.php:140
/var/www/src/wp-includes/block-editor.php:421
/var/www/tests/phpunit/tests/blocks/editor.php:388
/var/www/vendor/bin/phpunit:123
}}}

This commit includes:
* Restoring the `$default` value for `_wp_array_get()` call.
* Adding an early return if the value is an empty string or `null`.
* Adding a dedicated unit test to ensure that the method returns a string for invalid paths or `null` values.

Follow-up to [50973], [54162].

Props antonvlasenko, jrf, imadarshakshat, SergeyBiryukov.
Fixes #56620.

git-svn-id: https://develop.svn.wordpress.org/trunk@54362 602fd350-edb4-49c9-b593-d223f7449a82
hellofromtonya pushed a commit that referenced this pull request Oct 4, 2022
…L10n`.

These three tests for `wp_dashboard_recent_drafts()` would run into a PHP 8.1 "passing null to non-nullable" deprecation for the call to `ltrim()` when the result of `get_edit_post_link()` is passed to `esc_url()`.

Setting a deprecation expectation would not solve this as the returned value would still not match the expected value(s).

The recent drafts list is only displayed on the Dashboard screen for users with the `edit_posts` capability. By setting the current user to Editor, the prerequisites for `wp_dashboard_recent_drafts()` are met, which means the deprecation notice is avoided and the assertions will succeed.

This commit addresses a few errors in the test suite along the lines of:
{{{
1) Tests_L10n::test_length_of_draft_should_be_counted_by_words
ltrim(): Passing null to parameter #1 ($string) of type string is deprecated

/var/www/src/wp-includes/formatting.php:4376
/var/www/src/wp-admin/includes/dashboard.php:657
/var/www/tests/phpunit/tests/l10n.php:449
/var/www/vendor/bin/phpunit:123
}}}

Follow-up to [45505], [52253], [52259].

Props jrf, desrosj, SergeyBiryukov.
See #56681, #55652, #55656.

git-svn-id: https://develop.svn.wordpress.org/trunk@54365 602fd350-edb4-49c9-b593-d223f7449a82
anton-vlasenko pushed a commit that referenced this pull request Feb 24, 2023
The `$credentials['user_login']` and `$credentials['user_password']` parameters are passed by reference to the `wp_authenticate` action, and are at that point [https://www.php.net/manual/en/language.references.pass.php#124383 created as null] if they don't exist in the array.

This commit sets those values to an empty string, resolving two PHP 8.1 deprecation notices:
 * One from `preg_replace()` in `wp_strip_all_tags()` via `sanitize_user()` in `wp_authenticate()`:
{{{
Deprecated: preg_replace(): Passing null to parameter WordPress#3 ($subject) of type array|string is deprecated
}}}
 * One from `trim()` in `wp_authenticate()` itself:
{{{
Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated
}}}

Includes documenting the `$credentials` parameter using hash notation.

Follow-up to [6643], [37697].

Props lenasterg, TobiasBg, ocean90, afragen, lkraav, SergeyBiryukov.
Fixes #56850.

git-svn-id: https://develop.svn.wordpress.org/trunk@55301 602fd350-edb4-49c9-b593-d223f7449a82
anton-vlasenko pushed a commit that referenced this pull request Feb 24, 2023
…air screen.

The table is no longer created by core as of WordPress 3.0, and support for global terms was removed in WordPress 6.1, so `$wpdb->sitecategories` is unset by default.

This commit resolves a "passing null to non-nullable" deprecation notice on PHP 8.1:
{{{
Deprecated: addcslashes(): Passing null to parameter #1 ($string) of type string is deprecated in wp-includes/class-wpdb.php on line 1804
}}}

The `tables_to_repair` filter is available for plugins to readd the table or include any additional tables to repair.

Follow-up to [14854], [14880], [54240].

Props ipajen, chiragrathod103, SergeyBiryukov.
Fixes #57762.

git-svn-id: https://develop.svn.wordpress.org/trunk@55421 602fd350-edb4-49c9-b593-d223f7449a82
anton-vlasenko pushed a commit that referenced this pull request Sep 29, 2023
…om next_posts().

The `esc_url()` function expects to a string for `$url` parameter. There is no input validation within that function. The function contains a `ltrim()` which also expects a string. Passing `null` to this parameter results in `Deprecated: ltrim(): Passing null to parameter #1 ($string) of type string is deprecated` notice on PHP 8.1+.

Tracing the stack back, a `null` is being passed to it within `next_posts()` when `get_next_posts_page_link()` returns `null` (it can return a string or `null`).

On PHP 7.0 to PHP 8.x, an empty string is returned from `esc_url()` when `null` is passed to it. The change in this changeset avoids the deprecation notice by not invoking `esc_url()` when `get_next_posts_page_link()` returns `null` and instead sets the `$output` to an empty string, thus maintain the same behavior as before (minus the deprecation notice).

Adds a test to validate an empty string is returned and the absence of the deprecation (when running on PHP 8.1+).

Follow-up to [11383], [9632].

Props codersantosh, nihar007, hellofromTonya, mukesh27, oglekler, rajinsharwar.
Fixes #59154.

git-svn-id: https://develop.svn.wordpress.org/trunk@56740 602fd350-edb4-49c9-b593-d223f7449a82
anton-vlasenko pushed a commit that referenced this pull request Sep 29, 2023
…om next_posts().

The `esc_url()` function expects to a string for `$url` parameter. There is no input validation within that function. The function contains a `ltrim()` which also expects a string. Passing `null` to this parameter results in `Deprecated: ltrim(): Passing null to parameter #1 ($string) of type string is deprecated` notice on PHP 8.1+.

Tracing the stack back, a `null` is being passed to it within `next_posts()` when `get_next_posts_page_link()` returns `null` (it can return a string or `null`).

On PHP 7.0 to PHP 8.x, an empty string is returned from `esc_url()` when `null` is passed to it. The change in this changeset avoids the deprecation notice by not invoking `esc_url()` when `get_next_posts_page_link()` returns `null` and instead sets the `$output` to an empty string, thus maintain the same behavior as before (minus the deprecation notice).

Adds a test to validate an empty string is returned and the absence of the deprecation (when running on PHP 8.1+).

Follow-up to [11383], [9632].

Props codersantosh, nihar007, hellofromTonya, mukesh27, oglekler, rajinsharwar.
Fixes #59154.

git-svn-id: https://develop.svn.wordpress.org/trunk@56740 602fd350-edb4-49c9-b593-d223f7449a82
anton-vlasenko pushed a commit that referenced this pull request Aug 6, 2024
…Info screen.

This resolves a fatal error if `strict_types` PHP setting is enabled:
{{{
Argument #1 ($num) must be of type float, string given
}}}

Since the goal of the Site Health Info screen is to display raw values where possible, the `number_format()` call here does not seem to provide any benefit.

Props krishneup, sabernhardt, audrasjb, SergeyBiryukov.
Fixes #60364.

git-svn-id: https://develop.svn.wordpress.org/trunk@58847 602fd350-edb4-49c9-b593-d223f7449a82
anton-vlasenko pushed a commit that referenced this pull request Oct 29, 2024
…ord()`.

This resolves a "passing null to non-nullable" deprecation notice on PHP 8.1+:
{{{
Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated
}}}

Follow-up to [50129], [54477].

Props afragen, peterwilsoncc, SergeyBiryukov.
Fixes #62298.

git-svn-id: https://develop.svn.wordpress.org/trunk@59312 602fd350-edb4-49c9-b593-d223f7449a82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.