get_providers example

/** * Gets an array of sitemap providers. * * @since 5.5.0 * * @return WP_Sitemaps_Provider[] Array of sitemap providers. */
function wp_get_sitemap_providers() {
    $sitemaps = wp_sitemaps_get_server();

    return $sitemaps->registry->get_providers();
}

/** * Registers a new sitemap provider. * * @since 5.5.0 * * @param string $name Unique name for the sitemap provider. * @param WP_Sitemaps_Provider $provider The `Sitemaps_Provider` instance implementing the sitemap. * @return bool Whether the sitemap was added. */
/** * Gets a sitemap list for the index. * * @since 5.5.0 * * @return array[] Array of all sitemaps. */
    public function get_sitemap_list() {
        $sitemaps = array();

        $providers = $this->registry->get_providers();
        /* @var WP_Sitemaps_Provider $provider */
        foreach ( $providers as $name => $provider ) {
            $sitemap_entries = $provider->get_sitemap_entries();

            // Prevent issues with array_push and empty arrays on PHP < 7.3.             if ( ! $sitemap_entries ) {
                continue;
            }

            // Using array_push is more efficient than array_merge in a loop.             array_push( $sitemaps, ...$sitemap_entries );
            
Home | Imprint | This part of the site doesn't use cookies.