`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).
WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices.
Follow-up to [52039], [52040], [52326], [55703], [55710], [55987].
Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes#58206.
Built from https://develop.svn.wordpress.org/trunk@55988
git-svn-id: http://core.svn.wordpress.org/trunk@55500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Per [https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#writing-include-require-statements WordPress PHP coding standards], it is ''strongly recommended'' to use `require[_once]` for unconditional includes. When using `include[_once]`, PHP will throw a warning when the file is not found but will continue execution, which will almost certainly lead to other errors/warnings/notices being thrown if your application depends on the file loaded, potentially leading to security leaks. For that reason, `require[_once]` is generally the better choice as it will throw a `Fatal Error` if the file cannot be found.
Follow-up to [1674], [1812], [1964], [6779], [8540], [10521], [11005], [11911], [16065], [16149], [25421], [25466], [25823], [37714], [42981], [45448], [47198], [54276], [55633].
Props kausaralm, SergeyBiryukov.
See #57839.
Built from https://develop.svn.wordpress.org/trunk@55641
git-svn-id: http://core.svn.wordpress.org/trunk@55153 1a063a9b-81f0-0310-95a4-ce76da25c4cd
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit:
* Renames the `$null` parameter to `$result` in `Tests_Cron::filter_pre_schedule_event_filter()`.
* Amends the `$pre` parameter of the `pre_schedule_event` filter for consistency.
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938], [54943], [54944], [54945], [54946], [54947], [54948], [54950], [54951], [54952], [54956], [54959], [54960], [54961], [54962], [54964], [54965], [54969], [54970], [54971], [54972], [54996], [55000], [55011], [55013], [55014], [55015], [55016], [55017], [55020], [55021], [55023], [55027], [55028], [55034], [55036], [55037].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@55038
git-svn-id: http://core.svn.wordpress.org/trunk@54571 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Remove the check for future events prior iterating the array of crons in `wp_get_ready_cron_jobs()`. If there are no ready events, the `foreach` loop will break on the first iteration so the optimization is not required.
As WordPress Core adds a number of events by default, accounting for an empty array is not required in most instances.
Props lev0, jrf, SergeyBiryukov.
Fixes#56092.
Built from https://develop.svn.wordpress.org/trunk@54110
git-svn-id: http://core.svn.wordpress.org/trunk@53669 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Change the return type of `_get_cron_array()` to an empty array if the `cron` option is either missing or of an
unexpected type.
This change ensures the return value for no registered events is consistently an empty array. Previously the return
value could be either an empty array or `false`.
Props thakkarhardik, jrf, costdev.
Fixes#53940.
Built from https://develop.svn.wordpress.org/trunk@53791
git-svn-id: http://core.svn.wordpress.org/trunk@53350 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In `wp_schedule_single_event()`, the cron info array is retrieved via a call to `_get_cron_array()` and straight away cast to an array. But as the documentation for that function (correctly) states, the return type of that function is `array|false`, where `false` is returned for a site where no cron jobs have been scheduled (yet).
In the case that `_get_cron_array()` would return `false`, this would now unintentionally create an array with a single entry with key `0` and as the value `false`.
This is a bug. Fixed now by adding validation to the output of `_get_cron_array()` and initializing `$crons` to an empty array if `false` was returned.
Tests added first to prove the bug (a) was introduced in #44818 [44917] and (b) is now fixed.
Follow-up to [44917].
Props jrf, peterwilsoncc.
Fixes#53950.
Built from https://develop.svn.wordpress.org/trunk@51916
git-svn-id: http://core.svn.wordpress.org/trunk@51509 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The private `_set_cron_array()` function expects a cron array as the first parameter, but will often be passed the - potentially updated - output of a call to `_get_cron_array()`.
When the `_get_cron_array()` function returns `false`, a "Deprecated: Automatic conversion of false to array is deprecated" warning will be thrown on PHP 8.1.
The input validation resolves the deprecation warning by setting the cron value to an empty array when not given an `array` data type.
Adds a full set of `_set_cron_array()` tests.
Follow-up to [4189], [50152].
Props jrf, hellofromTonya, peterwilsoncc.
See #53635.
Built from https://develop.svn.wordpress.org/trunk@51695
git-svn-id: http://core.svn.wordpress.org/trunk@51301 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This fixes a "Deprecated: Automatic conversion of false to array is deprecated" warning on PHP 8.1.
In `wp_schedule_event()`, 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 `wp_schedule_event()` function just blindly continues by assigning a value to a subkey of the `$crons` "array".
Fixed by adding validation for the returned value from `_get_cron_array()` and initializing an empty array if `false` was returned.
Reference: [https://developer.wordpress.org/reference/functions/_get_cron_array/ WordPress Developer Resources: _get_cron_array()]
Props jrf, hellofromTonya, lucatume, pbearne, iluy, pedromendonca, SergeyBiryukov.
See #53635.
Built from https://develop.svn.wordpress.org/trunk@51619
git-svn-id: http://core.svn.wordpress.org/trunk@51225 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This allows the functions to return a `WP_Error` object containing more information in case of a problem, instead of just boolean false.
The various `pre_` filters in these functions are also updated so they can return or be passed a `WP_Error` object.
Fixes#49961
Built from https://develop.svn.wordpress.org/trunk@50143
git-svn-id: http://core.svn.wordpress.org/trunk@49822 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Runs cron jobs later on sites using alternative cron, ie the `ALTERNATE_WP_CRON` constant is true, to more closely match when standard cron jobs are run. Jobs now run on the `wp_loaded` hook at priority `20`. Prior to this change they would run on the `init` hook. This ensures custom post types and taxonomies are registered prior to the jobs running.
This change also prevents alternative wp-cron from running on archived or suspended multisite blogs as these are shut down prior to the `wp_loaded` hook from running.
Moves the existing functionality of `wp_cron()` in to a new private function `_wp_cron()`.
Props flixos90, jeremyfelt, johnbillion, jrf, kurtpayne, nacin, peterwilsoncc, prettyboymp, r-a-y, ryan, stevenkword, swissspidy.
Fixes#20537, #24160.
Built from https://develop.svn.wordpress.org/trunk@50135
git-svn-id: http://core.svn.wordpress.org/trunk@49814 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This is a final pass to fix PHP compatibiilty issues in the codebase with code changes or adding `phpcs:ignore` comments.
With this change, all PHP compatibility warnings and errors without specific tickets have been addressed (see #49810 and #41750).
Props desrosj, johnbillion, jrf.
See #49922.
Built from https://develop.svn.wordpress.org/trunk@47902
git-svn-id: http://core.svn.wordpress.org/trunk@47676 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This avoids the performance overhead of the function call every time `dirname( __FILE__ )` was used instead of `__DIR__`.
This commit also includes:
* Removing unnecessary parentheses from `include`/`require` statements. These are language constructs, not function calls.
* Replacing `include` statements for several files with `require_once`, for consistency:
* `wp-admin/admin-header.php`
* `wp-admin/admin-footer.php`
* `wp-includes/version.php`
Props ayeshrajans, desrosj, valentinbora, jrf, joostdevalk, netweb.
Fixes#48082.
Built from https://develop.svn.wordpress.org/trunk@47198
git-svn-id: http://core.svn.wordpress.org/trunk@46998 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Noteable changes:
- The `magic_quotes_runtime` and `magic_quotes_sybase` settings were removed in PHP 5.4, so no longer need to be set.
- Some functions that use external libraries can generate errors that can't be tested for, so are globally allowed to silence errors.
- Quite a few functions would cause errors if `safe_mode` was set. This setting was removed in PHP 5.4.
- Only a handful of `header()` calls needed corresponding `headers_sent()` checks for unit tests to pass, but more may need to be added as the nightlies builds are tested.
See #46732.
Built from https://develop.svn.wordpress.org/trunk@45611
git-svn-id: http://core.svn.wordpress.org/trunk@45422 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Improves the logic in `wp_schedule_single_event()` to ensure an identical event is not scheduled within ten minutes.
This moves the logic for checking for identical events to be self contained rather than relying on `wp_next_scheduled()` as this fails to account for events with a past timestamp when wp-cron fails to trigger or for multiple identical events being scheduled already.
Props bodohugobarwich.
Fixes#44818.
Built from https://develop.svn.wordpress.org/trunk@44917
git-svn-id: http://core.svn.wordpress.org/trunk@44748 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Moves the logic for determining when an event will next run from `wp_next_scheduled()` to `wp_get_scheduled_event()`.
This improves the performance of `wp_get_scheduled_event()` by avoiding duplicate function calls and object cache hits.
Props peterwilsoncc.
Fixes#45976.
Built from https://develop.svn.wordpress.org/trunk@44693
git-svn-id: http://core.svn.wordpress.org/trunk@44524 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Add the function `wp_get_ready_cron_jobs()` to return a modified version of the cron array limited to jobs ready to be run, ie with a timestamp of `time()` or earlier.
The new function includes the filter `pre_get_ready_cron_jobs` to allow for custom cron storage systems. This rounds out the functionality added in #32656.
Props Pento for code review.
Fixes#45797.
Built from https://develop.svn.wordpress.org/trunk@44483
git-svn-id: http://core.svn.wordpress.org/trunk@44314 1a063a9b-81f0-0310-95a4-ce76da25c4cd