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
With this change, the result of a site or network lookup by ID will be cached even if the ID does not exist. When a new site or network is created, the cache for the respective new ID is cleared.
Props mnelson4, nielsdeblaauw.
Fixes#42251.
Built from https://develop.svn.wordpress.org/trunk@45910
git-svn-id: http://core.svn.wordpress.org/trunk@45721 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This tag has been used in the past, but should no longer be used. Just using the `static` keyword in code is enough for PhpDocumentor on PHP5+ to recognize static variables and methods, and PhpDocumentor will mark them as static.
Props birgire.
See #42803.
Built from https://develop.svn.wordpress.org/trunk@42746
git-svn-id: http://core.svn.wordpress.org/trunk@42576 1a063a9b-81f0-0310-95a4-ce76da25c4cd
While `get_site_by()` makes sense as a more explicit and less complex replacement for `get_blog_details()`, it is not ready yet in terms of caching, where it currently falls short of the older function under specific circumstances.
See #40180, #40228.
Built from https://develop.svn.wordpress.org/trunk@41883
git-svn-id: http://core.svn.wordpress.org/trunk@41717 1a063a9b-81f0-0310-95a4-ce76da25c4cd
`get_site_by()` is now the preferred way to retrieve a site object by lookup for identifying data. By using a coherent structure and `get_sites()` internally, it has several advantages over the direct database queries and complex code in `get_blog_details()`. Therefore `get_blog_details()` is now a wrapper for `get_site_by()`, providing backward compatibility fixes where necessary.
Unit tests have been adjusted to account for the `blog-details` and `blog-lookup` cache groups, which are no longer needed.
Props spacedmonkey, jeremyfelt, flixos90.
Fixes#40228.
Built from https://develop.svn.wordpress.org/trunk@41719
git-svn-id: http://core.svn.wordpress.org/trunk@41553 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Prior to about 2013, many class methods lacked even access modifiers which made the `@access` notations that much more useful. Now that we've gotten to a point where the codebase is more mature from a maintenance perspective and we can finally remove these notations. Notable exceptions to this change include standalone functions notated as private as well as some classes still considered to represent "private" APIs.
See #41452.
Built from https://develop.svn.wordpress.org/trunk@41162
git-svn-id: http://core.svn.wordpress.org/trunk@41002 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The behaviour was previously possible with the `blog_details` filter and `get_blog_details()` function. The former is deprecated since [38936].
This change adjusts the magic methods of `WP_Site` to also check if `$key` exists in `WP_Site::get_details()`.
Fixes#40458.
Built from https://develop.svn.wordpress.org/trunk@40478
git-svn-id: http://core.svn.wordpress.org/trunk@40354 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In previous iterations of `WP_Site`, there was concern that not all properties would be available when storing a site's details in cache. When introduced in [37918], an `ms_loaded` check was added to address this concern. Any properties that are still `false` after `ms_loaded` really are `false` and can be cached as such.
Props flixos90.
Fixes#40247.
Built from https://develop.svn.wordpress.org/trunk@40344
git-svn-id: http://core.svn.wordpress.org/trunk@40251 1a063a9b-81f0-0310-95a4-ce76da25c4cd
`get_site()` has replaced `get_blog_details()` throughout core and is the recommended way to retrieve a current or single site object.
The `blog_details` filter is applied when full details are requested from `get_blog_details()`.
To ensure backwards compatibility in the switch to `get_site()`, this `blog_details` filter is now applied in `WP_Site::get_details()` and marked as deprecated with a note to rely instead on the `site_details` filter introduced in 4.6.
Props flixos90.
See #37102.
Fixes#38491.
Built from https://develop.svn.wordpress.org/trunk@38936
git-svn-id: http://core.svn.wordpress.org/trunk@38879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Partial revert of [37657]. Moving existing properties in `WP_Site` from public to private broke backwards compatibility in a pretty severe way. We made an initial attempt to work around this, but due to the variety of possible issues, moving forward does not seem wise.
Fixes#36717.
Built from https://develop.svn.wordpress.org/trunk@37923
git-svn-id: http://core.svn.wordpress.org/trunk@37864 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In the past, `get_blog_details()` has been used to retrieve the `home`, `siteurl`, `blogname`, and `post_count` options for a site. By lazy loading properties in a `WP_Site` object, we can avoid having to use `get_blog_details()` and instead provide the properties as needed.
This introduces the global `site-details` cache group in which standard objects representing the site are stored. This will one day be a replacement for the `blog-details` cache group that is currently used in `get_blog_details()`.
This relies on the `ms_loaded` action introduced in [37916] as properties are not available via `get_option()` until multisite has been fully loaded.
Props flixos90.
Fixes#36935.
Built from https://develop.svn.wordpress.org/trunk@37918
git-svn-id: http://core.svn.wordpress.org/trunk@37859 1a063a9b-81f0-0310-95a4-ce76da25c4cd
* Add magic `__get()`, `__set()`, and `__isset()` methods to `WP_Site` and `WP_Network.
* Provide `(int) $network->site_id` for `(string) $network->blog_id`
* Provide `(int) $site->id` for `(string) $site->blog_id`
* Provide `(int) $site->network_id` for `(string) $site->site_id`
Props flixos90, jeremyfelt.
Fixes#36717.
Built from https://develop.svn.wordpress.org/trunk@37657
git-svn-id: http://core.svn.wordpress.org/trunk@37623 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Given a site ID or site object, `get_site()` retrieves site data in the same vein as `get_post()` or `get_comment()`. This will allow for clean retrieval of sites from a primed cache when `WP_Site_Query` is implemented.
Adds a `WP_Site::to_array()` method to support multiple return types within `get_site()`.
Props spacedmonkey.
See #35791.
Built from https://develop.svn.wordpress.org/trunk@37468
git-svn-id: http://core.svn.wordpress.org/trunk@37436 1a063a9b-81f0-0310-95a4-ce76da25c4cd
* A `WP_Site` object initially matches a row from `wp_blogs`.
* A site can be retrieved by its ID through `WP_Site::get_instance()`.
* Adds `sites` to the global cache group and captures instance lookups.
* The multisite bootstrap now ensures `$current_blog` is an instance of `WP_Site`.
Props johnjamesjacoby, jeremyfelt.
See #32450.
Built from https://develop.svn.wordpress.org/trunk@36393
git-svn-id: http://core.svn.wordpress.org/trunk@36360 1a063a9b-81f0-0310-95a4-ce76da25c4cd