[wp-trac] [WordPress Trac] #51318: WP_Sitemaps_Provider protected $name property
WordPress Trac
noreply at wordpress.org
Wed Sep 16 01:05:45 UTC 2020
#51318: WP_Sitemaps_Provider protected $name property
-------------------------+-----------------------------
Reporter: Tkama | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Sitemaps | Version: 5.5.1
Severity: major | Keywords:
Focuses: |
-------------------------+-----------------------------
See:
https://developer.wordpress.org/reference/classes/wp_sitemaps_provider/
Why We need $name property to be protected? It is just name. This is
inconvenient and can cause bugs. For example I create my Sitemaps Provider
like this:
{{{#!php
<?php
add_filter( 'init', 'wpkama_register_sitemap_providers' )
function wpkama_register_sitemap_providers(){
require_once __DIR__ .'/class-
Similar_Posts_Sitemaps_Provider.php';
$provider = new Similar_Posts_Sitemaps_Provider();
wp_register_sitemap_provider( 'similarposts', $provider );
}
}}}
And I can't get the value of $name property like this:
{{{#!php
<?php
$provider = new Similar_Posts_Sitemaps_Provider();
wp_register_sitemap_provider( $provider->name, $provider );
}}}
But if first argument of `wp_register_sitemap_provider()` function and the
`$name` prop are different the Sitemap Provider won't run at all!
So all I can to do is copy $name prop value and past it as parameter. And
if I will change the name I need to remember to copy because they must be
the same (and code itself doesn't tell me this dependency).
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51318>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list