Includes:
* Capitalizing "ID" in a consistent way.
* Expanding the comment on not using `filter_var()`.
* Adding a `@covers` tag for the function in unit tests.
* Minor tweak to the `_doing_it_wrong()` message.
Follow-up to [53818], [55543].
See #57593.
Built from https://develop.svn.wordpress.org/trunk@55549
git-svn-id: http://core.svn.wordpress.org/trunk@55061 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0.
There are a number of ways to mitigate this:
* If it is an accidental typo for a declared property: fix the typo.
* For known properties: declare them on the class.
* For unknown properties: add the magic `__get()`, `__set()`, et al. methods to the class or let the class extend `stdClass` which has highly optimized versions of these magic methods built in.
* For unknown ''use'' of dynamic properties, the `#[AllowDynamicProperties]` attribute can be added to the class. The attribute will automatically be inherited by child classes.
Trac ticket #56034 is open to investigate and handle the third and fourth type of situations, however it has become clear this will need more time and will not be ready in time for WP 6.1.
To reduce “noise” in the meantime, both in the error logs of WP users moving onto PHP 8.2, in the test run logs of WP itself, in test runs of plugins and themes, as well as to prevent duplicate tickets from being opened for the same issue, this commit adds the `#[AllowDynamicProperties]` attribute to all “parent” classes in WP.
The logic used for this commit is as follows:
* If a class already has the attribute: no action needed.
* If a class does not `extend`: add the attribute.
* If a class does `extend`:
- If it extends `stdClass`: no action needed (as `stdClass` supports dynamic properties).
- If it extends a PHP native class: add the attribute.
- If it extends a class from one of WP's external dependencies: add the attribute.
* In all other cases: no action — the attribute should not be needed as child classes inherit from the parent.
Whether or not a class contains magic methods has not been taken into account, as a review of the currently existing magic methods has shown that those are generally not sturdy enough and often even set dynamic properties (which they should not). See the [https://www.youtube.com/watch?v=vDZWepDQQVE live stream from August 16, 2022] for more details.
This commit only affects classes in the `src` directory of WordPress core.
* Tests should not get this attribute, but should be fixed to not use dynamic properties instead. Patches for this are already being committed under ticket #56033.
* While a number bundled themes (2014, 2019, 2020, 2021) contain classes, they are not a part of this commit and may be updated separately.
Reference: [https://wiki.php.net/rfc/deprecate_dynamic_properties PHP RFC: Deprecate dynamic properties].
Follow-up to [53922].
Props jrf, hellofromTonya, markjaquith, peterwilsoncc, costdev, knutsp, aristath.
See #56513, #56034.
Built from https://develop.svn.wordpress.org/trunk@54133
git-svn-id: http://core.svn.wordpress.org/trunk@53692 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Some plugins may call the `wp_cache_*()` functions with an empty string, `false`, or `null` as cache key, usually as a result of not checking the return value of another function that's used as the key.
Previously, this was silently failing, leading to odd behavior at best and often breakage due to key collisions.
A valid cache key must be either an integer number or a non-empty string.
This commit introduces a quick type check on the given cache keys and adds a `_doing_it_wrong()` message that should help plugin developers to notice these issues quicker.
Includes:
* A check in `update_user_caches()` and `clean_user_cache()` to make sure user email is not empty before being cached or removed from cache, as it is technically possible to create a user with empty email via `wp_insert_user()`.
* Some minor cleanup in unit tests where the email was passed to `wp_insert_user()` incorrectly or was unintentionally reset.
Props tillkruess, malthert, dd32, spacedmonkey, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes#56198.
Built from https://develop.svn.wordpress.org/trunk@53818
git-svn-id: http://core.svn.wordpress.org/trunk@53377 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Includes:
* Placing `WP_Object_Cache::flush_group()` next to `::flush()`.
* Placing `wp_cache_supports_group_flush()` next to `wp_cache_flush_group()`.
* Placing the `wp_cache_flush_group()` unit test next to the `::flush()` method test.
* Removing test name from assertion messages, as it is already mentioned directly above in case of failure.
* Adjusting function descriptions per the documentation standards.
Follow-up to [52706], [53763].
See #55647, #4476.
Built from https://develop.svn.wordpress.org/trunk@53767
git-svn-id: http://core.svn.wordpress.org/trunk@53326 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Add a new plugable function called `wp_cache_flush_group`, that will allow developers to clear whole cache groups with a single call. Developers can detect if their current implementation of an object cache supports flushing by group, by calling `wp_cache_supports_group_flush` which returns true if it is supported. If the developers of the object cache drop-in has not implemented `wp_cache_flush_group` and `wp_cache_supports_group_flush`, these functions are polyfilled and `wp_cache_supports_group_flush` defaults to false.
Props Spacedmonkey, filosofo, ryan, sc0ttkclark, SergeyBiryukov, scribu, Ste_95, dd32, dhilditch, dougal, lucasbustamante, dg12345, tillkruess, peterwilsoncc, flixos90, pbearne.
Fixes#4476.
Built from https://develop.svn.wordpress.org/trunk@53763
git-svn-id: http://core.svn.wordpress.org/trunk@53322 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The original order was alphabetical, which became less obvious as newer functions got added, resulting in a somewhat random order.
This commits aims to organize the functions and related `WP_Object_Cache` methods in a more predictable order:
* `wp_cache_init()`
* `wp_cache_add()`
* `wp_cache_add_multiple()`
* `wp_cache_replace()`
* `wp_cache_set()`
* `wp_cache_set_multiple()`
* `wp_cache_get()`
* `wp_cache_get_multiple()`
* `wp_cache_delete()`
* `wp_cache_delete_multiple()`
* `wp_cache_incr()`
* `wp_cache_decr()`
* `wp_cache_flush()`
* `wp_cache_close()`
* `wp_cache_add_global_groups()`
* `wp_cache_add_non_persistent_groups()`
* `wp_cache_switch_to_blog()`
* `wp_cache_reset()`
Follow-up to [3011], [6543], [7986], [13066], [18580], [21403], [47938], [52700], [52703-52705].
See #54728, #54574.
Built from https://develop.svn.wordpress.org/trunk@52706
git-svn-id: http://core.svn.wordpress.org/trunk@52295 1a063a9b-81f0-0310-95a4-ce76da25c4cd
While this was previously added and reverted more than once as part of various documentation cleanup efforts, `wp_cache_switch_to_blog()` appears to be the correct alternative for `wp_cache_reset()`, per the latter's DocBlock.
This commit also corrects the `@deprecated` tag for `WP_Object_Cache::reset()` to link to the `::switch_to_blog()` method of the class, instead of the function of the same name.
Follow-up to [13066], [21403], [22111], [33678], [34225], [34226], [40929].
See #54729.
Built from https://develop.svn.wordpress.org/trunk@52705
git-svn-id: http://core.svn.wordpress.org/trunk@52294 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Add new caching functions named `wp_cache_add_multiple`, `wp_cache_set_multiple` and `wp_cache_delete_multiple`. All of these functions allow for an array of data to be passed, so that multiple cache objects can be created / edited / deleted in a single function call. This follows on from [47938] where the `wp_cache_get_multiple` function was introduced and allowed for multiple cache objects to be received in one call.
Props: spacedmonkey, tillkruess, adamsilverstein, flixos90, mitogh, pbearne.
Fixes: #54574.
Built from https://develop.svn.wordpress.org/trunk@52700
git-svn-id: http://core.svn.wordpress.org/trunk@52289 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Many caching backend have support for multiple gets in a single request. This brings that support to core, with a compatability fallback that will loop over requests if needed.
Fixes: #20875.
Props: nacin, tollmanz, wonderboymusic, ryan, jeremyfelt, spacedmonkey, boonebgorges, dd32, rmccue, ocean90, jipmoors, johnjamesjacoby, tillkruess, donmhico, davidbaumwald, SergeyBiryukov, whyisjake.
Built from https://develop.svn.wordpress.org/trunk@47938
git-svn-id: http://core.svn.wordpress.org/trunk@47711 1a063a9b-81f0-0310-95a4-ce76da25c4cd