Commit Graph

11 Commits

Author SHA1 Message Date
Sergey Biryukov b1f7eb6e1e Code Modernization: Rename parameters that use reserved keywords in `wp-includes/sitemaps/class-wp-sitemaps.php`.
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 `$public` parameter to `$is_public` in `WP_Sitemaps::add_robots()`.

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].

Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@55000


git-svn-id: http://core.svn.wordpress.org/trunk@54533 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-16 10:43:16 +00:00
Sergey Biryukov 8c7a3bf415 Docs: Correct DocBlock formatting for `wp_sitemaps_enabled` filter.
Follow-up to [48072], [48094], [48523].

See #56792.
Built from https://develop.svn.wordpress.org/trunk@54755


git-svn-id: http://core.svn.wordpress.org/trunk@54307 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-11-06 14:48:10 +00:00
Sergey Biryukov c03305852e Code Modernization: Add `AllowDynamicProperties` attribute to all (parent) classes.
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
2022-09-12 15:47:14 +00:00
John Blackbourn 0bf9b04c53 Docs: Various formatting improvements to inline docblocks.
See #49572
Built from https://develop.svn.wordpress.org/trunk@48574


git-svn-id: http://core.svn.wordpress.org/trunk@48336 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-23 00:52:05 +00:00
Pascal Birchler 1f153b0d12 Sitemaps: Replace `wp_sitemaps_register_providers` filter with more suitable `wp_sitemaps_add_provider` filter.
The previous filter failed the goal of allowing developers to filter all providers before they are registered, since it only filtered the built-in ones.

The more specific `wp_sitemaps_add_provider` filter enables exactly that, as it filters every sitemap provider right before it is added to the sitemaps registry.

Props pbiron, pfefferle, Chouby, swissspidy.
Fixes #50660.
Built from https://develop.svn.wordpress.org/trunk@48543


git-svn-id: http://core.svn.wordpress.org/trunk@48305 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-21 16:14:07 +00:00
Sergey Biryukov 12daeec1f7 Sitemaps: Rename 'sitemap' to 'provider' in `WP_Sitemaps_Registry` class.
This class is for registering sitemap providers, not individual sitemaps.

Props swissspidy.
Fixes #50724.
Built from https://develop.svn.wordpress.org/trunk@48536


git-svn-id: http://core.svn.wordpress.org/trunk@48298 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-21 15:29:02 +00:00
whyisjake 7f92797960 Sitemaps: Ensure correct HTTP status when sitemaps are disabled
If sitemaps are disabled, previously there would be a rewrite rule for the sitemap endpoint. This endpoint would display the homepage since there was a rewrite rule. Now, Sitemaps are loaded, and the proper HTTP headers are returned.

Fixes #50643.
Props swissspidy, kraftbj, donmhico.


Built from https://develop.svn.wordpress.org/trunk@48523


git-svn-id: http://core.svn.wordpress.org/trunk@48285 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-21 00:57:05 +00:00
John Blackbourn fe823d698f Docs: Corrections and improvements to inline docs related to XML sitemaps.
See #50117, #49572
Built from https://develop.svn.wordpress.org/trunk@48098


git-svn-id: http://core.svn.wordpress.org/trunk@47867 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-19 22:26:10 +00:00
Sergey Biryukov a15912561e Docs: Document globals in `WP_Sitemaps_*` classes the same way they are documented in the rest of core.
See #49572, #50117.
Built from https://develop.svn.wordpress.org/trunk@48093


git-svn-id: http://core.svn.wordpress.org/trunk@47860 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-19 17:56:09 +00:00
Sergey Biryukov 168a9df672 Coding Standards: Fix WPCS issues in `wp-includes/sitemaps/`.
Some of these were not caught when running `composer lint:errors`, but are fixed when running `phpcbf` directly.

Follow-up to [48072], [48080].

See #49542, #50117.
Built from https://develop.svn.wordpress.org/trunk@48081


git-svn-id: http://core.svn.wordpress.org/trunk@47848 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-18 14:46:09 +00:00
Pascal Birchler 609dd1d14f Sitemaps: Add XML sitemaps functionality to WordPress.
While web crawlers are able to discover pages from links within the site and from other sites, XML sitemaps supplement this approach by allowing crawlers to quickly and comprehensively identify all URLs included in the sitemap and learn other signals about those URLs using the associated metadata.

See https://make.wordpress.org/core/2020/06/10/merge-announcement-extensible-core-sitemaps/ for more details.

This feature exposes the sitemap index via `/wp-sitemap.xml` and exposes a variety of new filters and hooks for developers to modify the behavior. Users can disable sitemaps completely by turning off search engine visibility in WordPress admin.

This change also introduces a new `esc_xml()` function to escape strings for output in XML, as well as XML support to `wp_kses_normalize_entities()`.

Props Adrian McShane, afragen, adamsilverstein, casiepa, flixos90, garrett-eclipse, joemcgill, kburgoine, kraftbj, milana_cap, pacifika, pbiron, pfefferle, Ruxandra Gradina, swissspidy, szepeviktor, tangrufus, tweetythierry.
Fixes #50117.
See #3670. See #19998.

Built from https://develop.svn.wordpress.org/trunk@48072


git-svn-id: http://core.svn.wordpress.org/trunk@47839 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-17 15:24:07 +00:00