[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/sitemaps/ -> class-wp-sitemaps-registry.php (source)

   1  <?php
   2  /**
   3   * Sitemaps: WP_Sitemaps_Registry class
   4   *
   5   * Handles registering sitemap providers.
   6   *
   7   * @package WordPress
   8   * @subpackage Sitemaps
   9   * @since 5.5.0
  10   */
  11  
  12  /**
  13   * Class WP_Sitemaps_Registry.
  14   *
  15   * @since 5.5.0
  16   */
  17  class WP_Sitemaps_Registry {
  18      /**
  19       * Registered sitemap providers.
  20       *
  21       * @since 5.5.0
  22       *
  23       * @var WP_Sitemaps_Provider[] Array of registered sitemap providers.
  24       */
  25      private $providers = array();
  26  
  27      /**
  28       * Adds a new sitemap provider.
  29       *
  30       * @since 5.5.0
  31       *
  32       * @param string               $name     Name of the sitemap provider.
  33       * @param WP_Sitemaps_Provider $provider Instance of a WP_Sitemaps_Provider.
  34       * @return bool Whether the provider was added successfully.
  35       */
  36  	public function add_provider( $name, WP_Sitemaps_Provider $provider ) {
  37          if ( isset( $this->providers[ $name ] ) ) {
  38              return false;
  39          }
  40  
  41          /**
  42           * Filters the sitemap provider before it is added.
  43           *
  44           * @since 5.5.0
  45           *
  46           * @param WP_Sitemaps_Provider $provider Instance of a WP_Sitemaps_Provider.
  47           * @param string               $name     Name of the sitemap provider.
  48           */
  49          $provider = apply_filters( 'wp_sitemaps_add_provider', $provider, $name );
  50          if ( ! $provider instanceof WP_Sitemaps_Provider ) {
  51              return false;
  52          }
  53  
  54          $this->providers[ $name ] = $provider;
  55  
  56          return true;
  57      }
  58  
  59      /**
  60       * Returns a single registered sitemap provider.
  61       *
  62       * @since 5.5.0
  63       *
  64       * @param string $name Sitemap provider name.
  65       * @return WP_Sitemaps_Provider|null Sitemap provider if it exists, null otherwise.
  66       */
  67  	public function get_provider( $name ) {
  68          if ( ! isset( $this->providers[ $name ] ) ) {
  69              return null;
  70          }
  71  
  72          return $this->providers[ $name ];
  73      }
  74  
  75      /**
  76       * Returns all registered sitemap providers.
  77       *
  78       * @since 5.5.0
  79       *
  80       * @return WP_Sitemaps_Provider[] Array of sitemap providers.
  81       */
  82  	public function get_providers() {
  83          return $this->providers;
  84      }
  85  }


Generated: Sat Nov 23 01:00:02 2024 Cross-referenced by PHPXref 0.7.1