| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Polylang |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* Handles the core sitemaps for subdomains and multiple domains. |
| 8 |
* |
| 9 |
* @since 3.0 |
| 10 |
*/ |
| 11 |
class PLL_Sitemaps_Domain extends PLL_Abstract_Sitemaps { |
| 12 |
/** |
| 13 |
* @var PLL_Links_Abstract_Domain |
| 14 |
*/ |
| 15 |
protected $links_model; |
| 16 |
|
| 17 |
/** |
| 18 |
* Constructor. |
| 19 |
* |
| 20 |
* @since 3.0 |
| 21 |
* |
| 22 |
* @param object $polylang Main Polylang object. |
| 23 |
*/ |
| 24 |
public function __construct( &$polylang ) { |
| 25 |
$this->links_model = &$polylang->links_model; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Setups actions and filters. |
| 30 |
* |
| 31 |
* @since 3.0 |
| 32 |
* |
| 33 |
* @return void |
| 34 |
*/ |
| 35 |
public function init() { |
| 36 |
parent::init(); |
| 37 |
|
| 38 |
add_filter( 'wp_sitemaps_index_entry', array( $this, 'index_entry' ) ); |
| 39 |
add_filter( 'wp_sitemaps_stylesheet_url', array( $this->links_model, 'site_url' ) ); |
| 40 |
add_filter( 'wp_sitemaps_stylesheet_index_url', array( $this->links_model, 'site_url' ) ); |
| 41 |
add_filter( 'home_url', array( $this, 'sitemap_url' ) ); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Filters the sitemap index entries for subdomains and multiple domains. |
| 46 |
* |
| 47 |
* @since 2.8 |
| 48 |
* |
| 49 |
* @param array $sitemap_entry Sitemap entry for the post. |
| 50 |
* @return array |
| 51 |
*/ |
| 52 |
public function index_entry( $sitemap_entry ) { |
| 53 |
$sitemap_entry['loc'] = $this->links_model->site_url( $sitemap_entry['loc'] ); |
| 54 |
return $sitemap_entry; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Makes sure that the sitemap urls are always evaluated on the current domain. |
| 59 |
* |
| 60 |
* @since 2.8.4 |
| 61 |
* |
| 62 |
* @param string $url A sitemap url. |
| 63 |
* @return string |
| 64 |
*/ |
| 65 |
public function sitemap_url( $url ) { |
| 66 |
if ( false !== strpos( $url, '/wp-sitemap' ) ) { |
| 67 |
$url = $this->links_model->site_url( $url ); |
| 68 |
} |
| 69 |
return $url; |
| 70 |
} |
| 71 |
} |
| 72 |
|