Platinum SEO Pack - Version 2.1.1

Version Description

  • 2020-05-22 - Platinum SEO Plugin becomes the first SEO plugin to integrate with the upcoming SiteMap functionality in WordPress Core. The Core siteMap is still in development and Platinum SEO has integrated with the currently available version of the Core Module. If you do like to generate a sitemap with Platinum SEO, do enable it and enable the Object Types for which you want to generate a sitemap in SiteMap settings in Platinum SEO.
Download this release

Release Info

Developer Rajesh Babu
Plugin Icon 128x128 Platinum SEO Pack
Version 2.1.1
Comparing to
See all releases

Code changes from version 2.1.0 to 2.1.1

Changelog.txt CHANGED
@@ -1,3 +1,6 @@
1
= 2.1.0 =
2
* 2020-05-16 - Platinum SEO Plugin will now have its own SEO meta table _platinumseometa. All the SEO meta data used by the plugin will now be in this table. Importers for Yoast, Yoast Indexables and RankMath WordPress SEO Plugins have now been included to make it easy for users using those plugins to migrate to Platinum SEO WordPress Plugin.
3
1
+ = 2.1.1 =
2
+ * 2020-05-22 - Platinum SEO Plugin becomes the first SEO plugin to integrate with the upcoming SiteMap functionality in WordPress Core. The Core siteMap is still in development and Platinum SEO has integrated with the currently available version of the Core Module. If you do like to generate a sitemap with Platinum SEO, do enable it and enable the Object Types for which you want to generate a sitemap in SiteMap settings in Platinum SEO.
3
+
4
= 2.1.0 =
5
* 2020-05-16 - Platinum SEO Plugin will now have its own SEO meta table _platinumseometa. All the SEO meta data used by the plugin will now be in this table. Importers for Yoast, Yoast Indexables and RankMath WordPress SEO Plugins have now been included to make it easy for users using those plugins to migrate to Platinum SEO WordPress Plugin.
6
platinum-seo-pack.php CHANGED
@@ -4,7 +4,7 @@
4
Plugin Name: Platinum SEO Pack
5
Plugin URI: https://techblissonline.com/platinum-wordpress-seo-plugin/
6
Description: Complete SEO and Social optimization solution for your Wordpress blog/site. It is Simple, Uncomplicated and User friendly with several useful features.
7
- Version: 2.1.0
8
Author: Techblissonline.com (Rajesh)
9
Author URI: https://techblissonline.com/
10
Text Domain: platinum-seo-pack
@@ -61,7 +61,9 @@ include_once( PSP_PLUGIN_HOME . PSPINC . '/settings/psp_pre_settings.php' );
61
include_once( PSP_PLUGIN_HOME . PSPINC . '/settings/psp_social_settings.php' );
62
include_once( PSP_PLUGIN_HOME . PSPINC . '/settings/psp_tools_settings.php' );
63
include_once( PSP_PLUGIN_HOME . PSPINC . '/settings/psp_redirect_404.php' );
64
include_once( PSP_PLUGIN_HOME . PSPINC . '/importers/psp_import.php' );
65
66
global $psp;
67
$psp = PspMain::get_instance();
4
Plugin Name: Platinum SEO Pack
5
Plugin URI: https://techblissonline.com/platinum-wordpress-seo-plugin/
6
Description: Complete SEO and Social optimization solution for your Wordpress blog/site. It is Simple, Uncomplicated and User friendly with several useful features.
7
+ Version: 2.1.1
8
Author: Techblissonline.com (Rajesh)
9
Author URI: https://techblissonline.com/
10
Text Domain: platinum-seo-pack
61
include_once( PSP_PLUGIN_HOME . PSPINC . '/settings/psp_social_settings.php' );
62
include_once( PSP_PLUGIN_HOME . PSPINC . '/settings/psp_tools_settings.php' );
63
include_once( PSP_PLUGIN_HOME . PSPINC . '/settings/psp_redirect_404.php' );
64
+ include_once( PSP_PLUGIN_HOME . PSPINC . '/sitemap/psp_sitemap_settings.php' );
65
include_once( PSP_PLUGIN_HOME . PSPINC . '/importers/psp_import.php' );
66
+ include_once( PSP_PLUGIN_HOME . PSPINC . '/sitemap/psp_sitemap.php' );
67
68
global $psp;
69
$psp = PspMain::get_instance();
psp-include/settings/psp_settings.php CHANGED
@@ -21,6 +21,7 @@ class PspSettings {
21
public $psp_redirect_instance;
22
public $psp_social_instance;
23
public $psp_import_instance;
24
25
private $psp_helper;
26
private $sitename;
@@ -35,6 +36,7 @@ class PspSettings {
35
private $psp_social_settings_group = 'psp_social';
36
private $psp_other_settings_group = 'psp_others';
37
private $psp_breadcrumb_settings_group = 'psp_breadcrumb';
38
39
protected $psp_plugin_options_key = 'platinum-seo-social-pack-by-techblissonline';
40
private $psp_settings_tabs = array();
@@ -87,7 +89,9 @@ class PspSettings {
87
$this->psp_redirect_instance = $psp_redirect_instance;
88
$this->sitename = $psp_helper_instance->get_sitename();
89
90
- $this->psp_import_instance = PspImporter::get_instance();
91
92
$psp_do_rewrite_rules = false;
93
@@ -154,6 +158,7 @@ class PspSettings {
154
//$this->psp_settings_tabs[$this->psp_home_settings_group] = 'Home';
155
$this->psp_settings_tabs[$this->psp_archives_settings_group] = 'Archives';
156
$this->psp_settings_tabs[$this->psp_permalink_settings_group] = 'Permalinks';
157
//if (!$psp_premium_status) $this->psp_settings_tabs[$this->psp_social_settings_group] = 'Social';
158
$this->psp_settings_tabs[$this->psp_other_settings_group] = 'Others';
159
$this->psp_settings_tabs[$this->psp_breadcrumb_settings_group] = 'Breadcrumbs';
@@ -267,6 +272,8 @@ class PspSettings {
267
$this->register_posttype_settings($cust_post_type);
268
}
269
270
//if ($tab == $this->psp_archives_settings_group) {
271
$this->register_archive_settings('date_archive');
272
$this->register_archive_settings('author_archive');
@@ -2890,6 +2897,24 @@ class PspSettings {
2890
}
2891
$psp_seo_meta['schema_string'] = $json_schema_string;
2892
2893
//$psp_seo_meta = array_map( 'esc_attr', $psp_seo_meta );
2894
$this->psp_taxonomy_meta_original = $psp_seo_meta;
2895
$psp_social_meta = get_term_meta( $category_id, "psp_category_social_metas_$category_id");
@@ -3020,9 +3045,11 @@ class PspSettings {
3020
3021
//update google sitemap generator
3022
if (!empty($psp_category_seo_data['nositemap'])) {
3023
$this->psp_update_gsg("sm_b_exclude_cats", $t_id, true );
3024
$psp_exclude = true;
3025
} else {
3026
$this->psp_update_gsg("sm_b_exclude_cats", $t_id, false );
3027
$psp_exclude = false;
3028
}
@@ -3118,6 +3145,22 @@ class PspSettings {
3118
$json_schema_string = 'Invalid JSON Schema';
3119
}
3120
$psp_seo_meta['schema_string'] = $json_schema_string;
3121
3122
//$psp_seo_meta = array_map( 'esc_attr', $psp_seo_meta );
3123
$this->psp_taxonomy_meta_original = $psp_seo_meta;
@@ -3248,9 +3291,11 @@ class PspSettings {
3248
}
3249
//update google sitemap generator
3250
if (!empty($psp_taxonomy_seo_data['nositemap'])) {
3251
$this->psp_update_gsg("sm_b_exclude_cats", $t_id, true );
3252
$psp_exclude = true;
3253
} else {
3254
$this->psp_update_gsg("sm_b_exclude_cats", $t_id, false );
3255
$psp_exclude = false;
3256
}
@@ -3341,7 +3386,22 @@ class PspSettings {
3341
$psp_settings_name = "psp_".$post->post_type."_settings";
3342
$psp_p_settings = get_option($psp_settings_name);
3343
3344
- $psp_settings = get_option('psp_sitewide_settings');
3345
$psp_posttype_metabox_advanced_hidden = isset($psp_settings['hide_metabox_advanced']) ? $psp_settings['hide_metabox_advanced'] : '';
3346
3347
$psp_pre_settings = get_option('psp_pre_setting');
@@ -3475,7 +3535,7 @@ class PspSettings {
3475
$psp_post_meta['noindex'] = isset($wp_post_meta_data_arr['_techblissonline_psp_noindex'][0]) ? (!empty($wp_post_meta_data_arr['_techblissonline_psp_noindex'][0]) ? esc_attr($wp_post_meta_data_arr['_techblissonline_psp_noindex'][0]) : '') : esc_attr($psp_posttype_noindex);
3476
$psp_post_meta['nofollow'] = isset($wp_post_meta_data_arr['_techblissonline_psp_nofollow'][0]) ? (!empty($wp_post_meta_data_arr['_techblissonline_psp_nofollow'][0]) ? esc_attr($wp_post_meta_data_arr['_techblissonline_psp_nofollow'][0]) : '') : esc_attr($psp_posttype_nofollow);
3477
3478
- $psp_post_meta['nositemap'] = !empty($wp_post_meta_data_arr['_techblissonline_psp_nositemap'][0]) ? esc_attr($wp_post_meta_data_arr['_techblissonline_psp_nositemap'][0]) : '';
3479
$psp_post_meta['canonical_url'] = !empty($wp_post_meta_data_arr['_techblissonline_psp_canonical_url'][0]) ? esc_url_raw($wp_post_meta_data_arr['_techblissonline_psp_canonical_url'][0]) : '';
3480
//$psp_post_meta['schema_string'] = isset($wp_post_meta_data_arr['_techblissonline_psp_schema_string'][0]) ? esc_attr($wp_post_meta_data_arr['_techblissonline_psp_schema_string'][0]) : '';
3481
//$psp_post_meta['schema_string'] = !empty($wp_post_meta_data_arr['_techblissonline_psp_schema_string'][0]) ? html_entity_decode(stripcslashes(esc_attr($wp_post_meta_data_arr['_techblissonline_psp_schema_string'][0]))) : '';
@@ -4350,9 +4410,11 @@ class PspSettings {
4350
4351
//update google sitemap generator
4352
if (!empty($psp_post_seo_data['nositemap'])) {
4353
$this->psp_update_gsg("sm_b_exclude", $post_id, true );
4354
$psp_exclude = true;
4355
} else {
4356
$this->psp_update_gsg("sm_b_exclude", $post_id, false );
4357
$psp_exclude = false;
4358
}
@@ -4363,6 +4425,55 @@ class PspSettings {
4363
do_action( 'techblissonline_psp_update_sitemap', $psp_id, $psp_exclude );
4364
}
4365
4366
//update GoogleSitemapGenerator
4367
private function psp_update_gsg( $gsckey, $post_id, $exclude = false ) {
4368
$className = 'GoogleSitemapGenerator';
@@ -4907,7 +5018,10 @@ class PspSettings {
4907
}
4908
if ($tab_key == $this->psp_permalink_settings_group) {
4909
$psp_icon = '<span class="dashicons dashicons-admin-links"></span> ';
4910
- }
4911
if ($tab_key == $this->psp_breadcrumb_settings_group) {
4912
$psp_icon = '<span class="dashicons dashicons-networking"></span> ';
4913
}
21
public $psp_redirect_instance;
22
public $psp_social_instance;
23
public $psp_import_instance;
24
+ public $psp_sitemap_instance;
25
26
private $psp_helper;
27
private $sitename;
36
private $psp_social_settings_group = 'psp_social';
37
private $psp_other_settings_group = 'psp_others';
38
private $psp_breadcrumb_settings_group = 'psp_breadcrumb';
39
+ private $psp_sm_settings_group = 'psp_sitemap';
40
41
protected $psp_plugin_options_key = 'platinum-seo-social-pack-by-techblissonline';
42
private $psp_settings_tabs = array();
89
$this->psp_redirect_instance = $psp_redirect_instance;
90
$this->sitename = $psp_helper_instance->get_sitename();
91
92
+ $this->psp_import_instance = PspImporter::get_instance();
93
+
94
+ $this->psp_sitemap_instance = PspSmSettings::get_instance();
95
96
$psp_do_rewrite_rules = false;
97
158
//$this->psp_settings_tabs[$this->psp_home_settings_group] = 'Home';
159
$this->psp_settings_tabs[$this->psp_archives_settings_group] = 'Archives';
160
$this->psp_settings_tabs[$this->psp_permalink_settings_group] = 'Permalinks';
161
+ $this->psp_settings_tabs[$this->psp_sm_settings_group] = 'Sitemap';
162
//if (!$psp_premium_status) $this->psp_settings_tabs[$this->psp_social_settings_group] = 'Social';
163
$this->psp_settings_tabs[$this->psp_other_settings_group] = 'Others';
164
$this->psp_settings_tabs[$this->psp_breadcrumb_settings_group] = 'Breadcrumbs';
272
$this->register_posttype_settings($cust_post_type);
273
}
274
275
+ $this->psp_sitemap_instance->register_sm_settings();
276
+
277
//if ($tab == $this->psp_archives_settings_group) {
278
$this->register_archive_settings('date_archive');
279
$this->register_archive_settings('author_archive');
2897
}
2898
$psp_seo_meta['schema_string'] = $json_schema_string;
2899
2900
+ $psp_sm_settings = get_option('psp_sitemap');
2901
+ $excluded_term_ids = array();
2902
+ $term_excluded_from_sitemap = '';
2903
+
2904
+ if( $psp_sm_settings['excluded_term_ids'] ) {
2905
+ $excluded_term_ids = explode(",", $psp_sm_settings['excluded_term_ids']);
2906
+ }
2907
+ if( !empty( $excluded_term_ids ) ) {
2908
+ $excluded_term_ids = array_map( 'intval', $excluded_term_ids );
2909
+
2910
+ if( in_array($category_id, $excluded_term_ids)) {
2911
+ $term_excluded_from_sitemap = 'on';
2912
+ }
2913
+
2914
+ }
2915
+ //$psp_seo_meta['nositemap'] = $term_excluded_from_sitemap;
2916
+ $psp_seo_meta['nositemap'] = !empty($psp_seo_meta['nositemap']) ? esc_attr($psp_seo_meta['nositemap']) : $term_excluded_from_sitemap;
2917
+
2918
//$psp_seo_meta = array_map( 'esc_attr', $psp_seo_meta );
2919
$this->psp_taxonomy_meta_original = $psp_seo_meta;
2920
$psp_social_meta = get_term_meta( $category_id, "psp_category_social_metas_$category_id");
3045
3046
//update google sitemap generator
3047
if (!empty($psp_category_seo_data['nositemap'])) {
3048
+ $this->psp_update_wps("excluded_term_ids", $t_id, true );
3049
$this->psp_update_gsg("sm_b_exclude_cats", $t_id, true );
3050
$psp_exclude = true;
3051
} else {
3052
+ $this->psp_update_wps("excluded_term_ids", $t_id, false );
3053
$this->psp_update_gsg("sm_b_exclude_cats", $t_id, false );
3054
$psp_exclude = false;
3055
}
3145
$json_schema_string = 'Invalid JSON Schema';
3146
}
3147
$psp_seo_meta['schema_string'] = $json_schema_string;
3148
+
3149
+ $psp_sm_settings = get_option('psp_sitemap');
3150
+ $excluded_term_ids = array();
3151
+ $term_excluded_from_sitemap = '';
3152
+
3153
+ if( $psp_sm_settings['excluded_term_ids'] ) {
3154
+ $excluded_term_ids = explode(",", $psp_sm_settings['excluded_term_ids']);
3155
+ }
3156
+ if( !empty( $excluded_term_ids ) ) {
3157
+ $excluded_term_ids = array_map( 'intval', $excluded_term_ids );
3158
+ if( in_array($t_id, $excluded_term_ids)) {
3159
+ $term_excluded_from_sitemap = 'on';
3160
+ }
3161
+ }
3162
+ //$psp_seo_meta['nositemap'] = $term_excluded_from_sitemap;
3163
+ $psp_seo_meta['nositemap'] = !empty($psp_seo_meta['nositemap']) ? esc_attr($psp_seo_meta['nositemap']) : $term_excluded_from_sitemap;
3164
3165
//$psp_seo_meta = array_map( 'esc_attr', $psp_seo_meta );
3166
$this->psp_taxonomy_meta_original = $psp_seo_meta;
3291
}
3292
//update google sitemap generator
3293
if (!empty($psp_taxonomy_seo_data['nositemap'])) {
3294
+ $this->psp_update_wps("excluded_term_ids", $t_id, true );
3295
$this->psp_update_gsg("sm_b_exclude_cats", $t_id, true );
3296
$psp_exclude = true;
3297
} else {
3298
+ $this->psp_update_wps("excluded_term_ids", $t_id, false );
3299
$this->psp_update_gsg("sm_b_exclude_cats", $t_id, false );
3300
$psp_exclude = false;
3301
}
3386
$psp_settings_name = "psp_".$post->post_type."_settings";
3387
$psp_p_settings = get_option($psp_settings_name);
3388
3389
+ $psp_settings = get_option('psp_sitewide_settings');
3390
+
3391
+ $psp_sm_settings = get_option('psp_sitemap');
3392
+ $excluded_post_ids = array();
3393
+ $post_excluded_from_sitemap = '';
3394
+
3395
+ if( !empty( $psp_sm_settings['excluded_post_ids'] ) ) {
3396
+ $excluded_post_ids = explode(",", $psp_sm_settings['excluded_post_ids']);
3397
+ }
3398
+ if( !empty( $excluded_post_ids ) ) {
3399
+ $excluded_post_ids = array_map( 'intval', $excluded_post_ids );
3400
+ if( in_array($post->ID, $excluded_post_ids)) {
3401
+ $post_excluded_from_sitemap = 'on';
3402
+ }
3403
+ }
3404
+
3405
$psp_posttype_metabox_advanced_hidden = isset($psp_settings['hide_metabox_advanced']) ? $psp_settings['hide_metabox_advanced'] : '';
3406
3407
$psp_pre_settings = get_option('psp_pre_setting');
3535
$psp_post_meta['noindex'] = isset($wp_post_meta_data_arr['_techblissonline_psp_noindex'][0]) ? (!empty($wp_post_meta_data_arr['_techblissonline_psp_noindex'][0]) ? esc_attr($wp_post_meta_data_arr['_techblissonline_psp_noindex'][0]) : '') : esc_attr($psp_posttype_noindex);
3536
$psp_post_meta['nofollow'] = isset($wp_post_meta_data_arr['_techblissonline_psp_nofollow'][0]) ? (!empty($wp_post_meta_data_arr['_techblissonline_psp_nofollow'][0]) ? esc_attr($wp_post_meta_data_arr['_techblissonline_psp_nofollow'][0]) : '') : esc_attr($psp_posttype_nofollow);
3537
3538
+ $psp_post_meta['nositemap'] = !empty($wp_post_meta_data_arr['_techblissonline_psp_nositemap'][0]) ? esc_attr($wp_post_meta_data_arr['_techblissonline_psp_nositemap'][0]) : $post_excluded_from_sitemap;
3539
$psp_post_meta['canonical_url'] = !empty($wp_post_meta_data_arr['_techblissonline_psp_canonical_url'][0]) ? esc_url_raw($wp_post_meta_data_arr['_techblissonline_psp_canonical_url'][0]) : '';
3540
//$psp_post_meta['schema_string'] = isset($wp_post_meta_data_arr['_techblissonline_psp_schema_string'][0]) ? esc_attr($wp_post_meta_data_arr['_techblissonline_psp_schema_string'][0]) : '';
3541
//$psp_post_meta['schema_string'] = !empty($wp_post_meta_data_arr['_techblissonline_psp_schema_string'][0]) ? html_entity_decode(stripcslashes(esc_attr($wp_post_meta_data_arr['_techblissonline_psp_schema_string'][0]))) : '';
4410
4411
//update google sitemap generator
4412
if (!empty($psp_post_seo_data['nositemap'])) {
4413
+ $this->psp_update_wps("excluded_post_ids", $post_id, true );
4414
$this->psp_update_gsg("sm_b_exclude", $post_id, true );
4415
$psp_exclude = true;
4416
} else {
4417
+ $this->psp_update_wps("excluded_post_ids", $post_id, false );
4418
$this->psp_update_gsg("sm_b_exclude", $post_id, false );
4419
$psp_exclude = false;
4420
}
4425
do_action( 'techblissonline_psp_update_sitemap', $psp_id, $psp_exclude );
4426
}
4427
4428
+ //update Platinum SEO Settings for wordPress sitemap
4429
+ private function psp_update_wps( $gsckey, $post_id, $exclude = false ) {
4430
+
4431
+ if (empty($post_id) || empty($gsckey) ) {
4432
+ return;
4433
+ }
4434
+
4435
+ $psp_sm_settings = get_option('psp_sitemap');
4436
+ //$this->psp_sitemap_settings = $psp_sm_settings;
4437
+
4438
+ $excluded_ids = array();
4439
+
4440
+ if( !empty( $psp_sm_settings[$gsckey] ) ) {
4441
+ error_log(print_r($psp_sm_settings[$gsckey], true));
4442
+ $excluded_ids = explode(",", $psp_sm_settings[$gsckey]);
4443
+ }
4444
+
4445
+ if( !empty( $excluded_ids ) ) {
4446
+ //$excluded_ids = array_map( 'intval', $excluded_ids );
4447
+ }
4448
+
4449
+ if($exclude) {
4450
+ if(empty($excluded_ids) || !in_array($post_id, $excluded_ids)) {
4451
+ //$excluded = array_push($excluded_ids, $post_id);
4452
+ $excluded_ids[] = $post_id;
4453
+ $psp_sm_settings[$gsckey] = implode(",", $excluded_ids);
4454
+ update_option("psp_sitemap", $psp_sm_settings);
4455
+ }
4456
+ } else {
4457
+
4458
+ if(!empty($excluded_ids) && in_array($post_id, $excluded_ids)) {
4459
+
4460
+
4461
+ if (($id = array_search($post_id, $excluded_ids)) !== false) {
4462
+ error_log(print_r($excluded_ids[$id], true));
4463
+ unset($excluded_ids[$id]);
4464
+ }
4465
+ if(!empty($excluded_ids)) {
4466
+ $psp_sm_settings[$gsckey] = implode(",", $excluded_ids);
4467
+ } else {
4468
+ //unset($psp_sm_settings[$gsckey]);
4469
+ $psp_sm_settings[$gsckey] = '';
4470
+ }
4471
+ update_option("psp_sitemap", $psp_sm_settings);
4472
+ }
4473
+ }
4474
+
4475
+ }
4476
+
4477
//update GoogleSitemapGenerator
4478
private function psp_update_gsg( $gsckey, $post_id, $exclude = false ) {
4479
$className = 'GoogleSitemapGenerator';
5018
}
5019
if ($tab_key == $this->psp_permalink_settings_group) {
5020
$psp_icon = '<span class="dashicons dashicons-admin-links"></span> ';
5021
+ }
5022
+ if ($tab_key == $this->psp_sm_settings_group) {
5023
+ $psp_icon = '<span class="dashicons dashicons-admin-site-alt3"></span> ';
5024
+ }
5025
if ($tab_key == $this->psp_breadcrumb_settings_group) {
5026
$psp_icon = '<span class="dashicons dashicons-networking"></span> ';
5027
}
psp-include/sitemap/inc/class-core-sitemaps-index.php ADDED
@@ -0,0 +1,81 @@
1
+ <?php
2
+ /**
3
+ * Sitemaps: Core_Sitemaps_Index class.
4
+ *
5
+ * Generates the sitemap index.
6
+ *
7
+ * @package WordPress
8
+ * @subpackage Sitemaps
9
+ * @since 5.5.0
10
+ */
11
+
12
+ /**
13
+ * Class Core_Sitemaps_Index.
14
+ * Builds the sitemap index page that lists the links to all of the sitemaps.
15
+ *
16
+ * @since 5.5.0
17
+ */
18
+ class Core_Sitemaps_Index {
19
+
20
+ /**
21
+ * The main registry of supported sitemaps.
22
+ *
23
+ * @since 5.5.0
24
+ * @var Core_Sitemaps_Registry
25
+ */
26
+ protected $registry;
27
+
28
+ /**
29
+ * Core_Sitemaps_Index constructor.
30
+ *
31
+ * @since 5.5.0
32
+ *
33
+ * @param Core_Sitemaps_Registry $registry Sitemap provider registry.
34
+ */
35
+ public function __construct( $registry ) {
36
+ $this->registry = $registry;
37
+ }
38
+
39
+ /**
40
+ * Gets a sitemap list for the index.
41
+ *
42
+ * @since 5.5.0
43
+ *
44
+ * @return array List of all sitemaps.
45
+ */
46
+ public function get_sitemap_list() {
47
+ $sitemaps = array();
48
+
49
+ $providers = $this->registry->get_sitemaps();
50
+ /* @var Core_Sitemaps_Provider $provider */
51
+ foreach ( $providers as $provider ) {
52
+ // Using array_push is more efficient than array_merge in a loop.
53
+ $sitemap = $provider->get_sitemap_entries();
54
+ //array_push( $sitemaps, ...$provider->get_sitemap_entries() );
55
+ if($sitemap) array_push( $sitemaps, ...$sitemap );
56
+ }
57
+
58
+ return $sitemaps;
59
+ }
60
+
61
+ /**
62
+ * Builds the URL for the sitemap index.
63
+ *
64
+ * @since 5.5.0
65
+ *
66
+ * @return string the sitemap index url.
67
+ */
68
+ public function get_index_url() {
69
+ /* @var WP_Rewrite $wp_rewrite */
70
+ global $wp_rewrite;
71
+
72
+ $url = home_url( '/wp-sitemap.xml' );
73
+ //$url = home_url( '/sitemap.xml' );
74
+
75
+ if ( ! $wp_rewrite->using_permalinks() ) {
76
+ $url = add_query_arg( 'sitemap', 'index', home_url( '/' ) );
77
+ }
78
+
79
+ return $url;
80
+ }
81
+ }
psp-include/sitemap/inc/class-core-sitemaps-provider.php ADDED
@@ -0,0 +1,219 @@
1
+ <?php
2
+ /**
3
+ * Sitemaps: Core_Sitemaps_Provider class
4
+ *
5
+ * This class is a base class for other sitemap providers to extend and contains shared functionality.
6
+ *
7
+ * @package WordPress
8
+ * @subpackage Sitemaps
9
+ * @since 5.5.0
10
+ */
11
+
12
+ /**
13
+ * Class Core_Sitemaps_Provider.
14
+ *
15
+ * @since 5.5.0
16
+ */
17
+ abstract class Core_Sitemaps_Provider {
18
+
19
+ /**
20
+ * Provider name.
21
+ *
22
+ * This will also be used as the public-facing name in URLs.
23
+ *
24
+ * @since 5.5.0
25
+ *
26
+ * @var string
27
+ */
28
+ protected $name = '';
29
+
30
+ /**
31
+ * Object type name (e.g. 'post', 'term', 'user').
32
+ *
33
+ * @since 5.5.0
34
+ *
35
+ * @var string
36
+ */
37
+ protected $object_type = '';
38
+
39
+ /**
40
+ * Object subtype name.
41
+ *
42
+ * For example, this should be a post type name for object type 'post' or
43
+ * a taxonomy name for object type 'term').
44
+ *
45
+ * @since 5.5.0
46
+ *
47
+ * @var string
48
+ */
49
+ protected $object_subtype = '';
50
+
51
+ /**
52
+ * Gets a URL list for a sitemap.
53
+ *
54
+ * @since 5.5.0
55
+ *
56
+ * @param int $page_num Page of results.
57
+ * @param string $object_subtype Optional. Object subtype name. Default empty.
58
+ * @return array List of URLs for a sitemap.
59
+ */
60
+ abstract public function get_url_list( $page_num, $object_subtype = '' );
61
+
62
+ /**
63
+ * Returns the name of the object type or object subtype being queried.
64
+ *
65
+ * @since 5.5.0
66
+ *
67
+ * @return string Object subtype if set, otherwise object type.
68
+ */
69
+ public function get_queried_type() {
70
+ if ( empty( $this->object_subtype ) ) {
71
+ return $this->object_type;
72
+ }
73
+
74
+ return $this->object_subtype;
75
+ }
76
+
77
+ /**
78
+ * Gets the max number of pages available for the object type.
79
+ *
80
+ * @since 5.5.0
81
+ *
82
+ * @param string $object_subtype Optional. Object subtype. Default empty.
83
+ * @return int Total number of pages.
84
+ */
85
+ abstract public function max_num_pages( $object_subtype = '' );
86
+
87
+ /**
88
+ * Sets the object subtype.
89
+ *
90
+ * @since 5.5.0
91
+ *
92
+ * @param string $object_subtype The name of the object subtype.
93
+ * @return bool Returns true on success.
94
+ */
95
+ public function set_object_subtype( $object_subtype ) {
96
+ $this->object_subtype = $object_subtype;
97
+
98
+ return true;
99
+ }
100
+
101
+ /**
102
+ * Gets data about each sitemap type.
103
+ *
104
+ * @since 5.5.0
105
+ *
106
+ * @return array List of sitemap types including object subtype name and number of pages.
107
+ */
108
+ public function get_sitemap_type_data() {
109
+ $sitemap_data = array();
110
+
111
+ $object_subtypes = $this->get_object_subtypes();
112
+
113
+ foreach ( $object_subtypes as $object_subtype_name => $data ) {
114
+ $sitemap_data[] = array(
115
+ 'name' => $object_subtype_name,
116
+ 'pages' => $this->max_num_pages( $object_subtype_name ),
117
+ );
118
+ }
119
+
120
+ return $sitemap_data;
121
+ }
122
+
123
+ /**
124
+ * Lists sitemap pages exposed by this provider.
125
+ *
126
+ * The returned data is used to populate the sitemap entries of the index.
127
+ *
128
+ * @since 5.5.0
129
+ *
130
+ * @return array List of sitemaps.
131
+ */
132
+ public function get_sitemap_entries() {
133
+ $sitemaps = array();
134
+
135
+ $sitemap_types = $this->get_sitemap_type_data();
136
+
137
+ foreach ( $sitemap_types as $type ) {
138
+ for ( $page = 1; $page <= $type['pages']; $page ++ ) {
139
+ $loc = $this->get_sitemap_url( $type['name'], $page );
140
+ $sitemaps[] = array(
141
+ 'loc' => $loc,
142
+ );
143
+ }
144
+ }
145
+
146
+ return $sitemaps;
147
+ }
148
+
149
+ /**
150
+ * Gets the URL of a sitemap entry.
151
+ *
152
+ * @since 5.5.0
153
+ *
154
+ * @param string $name The name of the sitemap.
155
+ * @param int $page The page of the sitemap.
156
+ * @return string The composed URL for a sitemap entry.
157
+ */
158
+ public function get_sitemap_url( $name, $page ) {
159
+ /* @var WP_Rewrite $wp_rewrite */
160
+ global $wp_rewrite;
161
+
162
+ if ( ! $wp_rewrite->using_permalinks() ) {
163
+ return add_query_arg(
164
+ // Accounts for cases where name is not included, ex: sitemaps-users-1.xml.
165
+ array_filter(
166
+ array(
167
+ 'sitemap' => $this->name,
168
+ 'sitemap-sub-type' => $name,
169
+ 'paged' => $page,
170
+ )
171
+ ),
172
+ home_url( '/' )
173
+ );
174
+ }
175
+
176
+ $basename = sprintf(
177
+ '/wp-sitemap-%1$s.xml',
178
+ implode(
179
+ '-',
180
+ // Accounts for cases where name is not included, ex: sitemaps-users-1.xml.
181
+ array_filter(
182
+ array(
183
+ $this->name,
184
+ $name,
185
+ (string) $page,
186
+ )
187
+ )
188
+ )
189
+ );
190
+
191
+ return home_url( $basename );
192
+ }
193
+
194
+ /**
195
+ * Returns the list of supported object sub-types exposed by the provider.
196
+ *
197
+ * @since 5.5.0
198
+ *
199
+ * @return array List of object subtypes objects keyed by their name.
200
+ */
201
+ public function get_object_subtypes() {
202
+ if ( ! empty( $this->object_subtype ) ) {
203
+ return array(
204
+ $this->object_subtype => (object) array( 'name' => $this->object_subtype ),
205
+ );
206
+ }
207
+
208
+ /**
209
+ * To prevent complexity in code calling this function, such as `get_sitemap_type_data()`
210
+ * in this class, a non-empty array is returned, so that sitemaps for providers without
211
+ * object subtypes are still registered correctly.
212
+ *
213
+ * @link https://github.com/GoogleChromeLabs/wp-sitemaps/pull/72#discussion_r347496750
214
+ */
215
+ return array(
216
+ '' => (object) array( 'name' => '' ),
217
+ );
218
+ }
219
+ }
psp-include/sitemap/inc/class-core-sitemaps-registry.php ADDED
@@ -0,0 +1,82 @@
1
+ <?php
2
+ /**
3
+ * Sitemaps: Core_Sitemaps_Registry class
4
+ *
5
+ * Handles registering sitemaps.
6
+ *
7
+ * @package WordPress
8
+ * @subpackage Sitemaps
9
+ * @since 5.5.0
10
+ */
11
+
12
+ /**
13
+ * Class Core_Sitemaps_Registry.
14
+ *
15
+ * @since 5.5.0
16
+ */
17
+ class Core_Sitemaps_Registry {
18
+ /**
19
+ * Registered sitemaps.
20
+ *
21
+ * @since 5.5.0
22
+ *
23
+ * @var array Array of registered sitemaps.
24
+ */
25
+ private $sitemaps = array();
26
+
27
+ /**
28
+ * Adds a sitemap with route to the registry.
29
+ *
30
+ * @since 5.5.0
31
+ *
32
+ * @param string $name Name of the sitemap.
33
+ * @param Core_Sitemaps_Provider $provider Instance of a Core_Sitemaps_Provider.
34
+ * @return bool True if the sitemap was added, false if it is already registered.
35
+ */
36
+ public function add_sitemap( $name, $provider ) {
37
+ if ( isset( $this->sitemaps[ $name ] ) ) {
38
+ return false;
39
+ }
40
+
41
+ if ( ! $provider instanceof Core_Sitemaps_Provider ) {
42
+ return false;
43
+ }
44
+
45
+ $this->sitemaps[ $name ] = $provider;
46
+
47
+ return true;
48
+ }
49
+
50
+ /**
51
+ * Returns a single registered sitemaps provider.
52
+ *
53
+ * @since 5.5.0
54
+ *
55
+ * @param string $name Sitemap provider name.
56
+ * @return Core_Sitemaps_Provider|null Sitemaps provider if it exists, null otherwise.
57
+ */
58
+ public function get_sitemap( $name ) {
59
+ if ( ! isset( $this->sitemaps[ $name ] ) ) {
60
+ return null;
61
+ }
62
+
63
+ return $this->sitemaps[ $name ];
64
+ }
65
+
66
+ /**
67
+ * Lists all registered sitemaps.
68
+ *
69
+ * @since 5.5.0
70
+ *
71
+ * @return array List of sitemaps.
72
+ */
73
+ public function get_sitemaps() {
74
+ $total_sitemaps = count( $this->sitemaps );
75
+
76
+ if ( $total_sitemaps > CORE_SITEMAPS_MAX_SITEMAPS ) {
77
+ return array_slice( $this->sitemaps, 0, CORE_SITEMAPS_MAX_SITEMAPS, true );
78
+ }
79
+
80
+ return $this->sitemaps;
81
+ }
82
+ }
psp-include/sitemap/inc/class-core-sitemaps-renderer.php ADDED
@@ -0,0 +1,262 @@
1
+ <?php
2
+ /**
3
+ * Sitemaps: Core_Sitemaps_Renderer class
4
+ *
5
+ * Responsible for rendering Sitemaps data to XML in accordance with sitemap protocol.
6
+ *
7
+ * @package WordPress
8
+ * @subpackage Sitemaps
9
+ * @since 5.5.0
10
+ */
11
+
12
+ /**
13
+ * Class Core_Sitemaps_Renderer
14
+ *
15
+ * @since 5.5.0
16
+ */
17
+ class Core_Sitemaps_Renderer {
18
+ /**
19
+ * XSL stylesheet for styling a sitemap for web browsers.
20
+ *
21
+ * @since 5.5.0
22
+ *
23
+ * @var string
24
+ */
25
+ protected $stylesheet = '';
26
+
27
+ /**
28
+ * XSL stylesheet for styling a sitemap for web browsers.
29
+ *
30
+ * @since 5.5.0
31
+ *
32
+ * @var string
33
+ */
34
+ protected $stylesheet_index = '';
35
+
36
+ /**
37
+ * Core_Sitemaps_Renderer constructor.
38
+ *
39
+ * @since 5.5.0
40
+ */
41
+ public function __construct() {
42
+ $stylesheet_url = $this->get_sitemap_stylesheet_url();
43
+ if ( $stylesheet_url ) {
44
+ $this->stylesheet = '<?xml-stylesheet type="text/xsl" href="' . esc_url( $stylesheet_url ) . '" ?>';
45
+ }
46
+ $stylesheet_index_url = $this->get_sitemap_index_stylesheet_url();
47
+ if ( $stylesheet_index_url ) {
48
+ $this->stylesheet_index = '<?xml-stylesheet type="text/xsl" href="' . esc_url( $stylesheet_index_url ) . '" ?>';
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Gets the URL for the sitemap stylesheet.
54
+ *
55
+ * @since 5.5.0
56
+ *
57
+ * @return string the sitemap stylesheet url.
58
+ */
59
+ public function get_sitemap_stylesheet_url() {
60
+ /* @var WP_Rewrite $wp_rewrite */
61
+ global $wp_rewrite;
62
+
63
+ $sitemap_url = home_url( '/wp-sitemap.xsl' );
64
+
65
+ if ( ! $wp_rewrite->using_permalinks() ) {
66
+ $sitemap_url = add_query_arg( 'sitemap-stylesheet', 'sitemap', home_url( '/' ) );
67
+ }
68
+
69
+ /**
70
+ * Filters the URL for the sitemap stylesheet.
71
+ *
72
+ * If a falsy value is returned, no stylesheet will be used and
73
+ * the "raw" XML of the sitemap will be displayed.
74
+ *
75
+ * @since 5.5.0
76
+ *
77
+ * @param string $sitemap_url Full URL for the sitemaps xsl file.
78
+ */
79
+ return apply_filters( 'core_sitemaps_stylesheet_url', $sitemap_url );
80
+ }
81
+
82
+ /**
83
+ * Gets the URL for the sitemap index stylesheet.
84
+ *
85
+ * @since 5.5.0
86
+ *
87
+ * @return string the sitemap index stylesheet url.
88
+ */
89
+ public function get_sitemap_index_stylesheet_url() {
90
+ /* @var WP_Rewrite $wp_rewrite */
91
+ global $wp_rewrite;
92
+
93
+ $sitemap_url = home_url( '/wp-sitemap-index.xsl' );
94
+
95
+ if ( ! $wp_rewrite->using_permalinks() ) {
96
+ $sitemap_url = add_query_arg( 'sitemap-stylesheet', 'index', home_url( '/' ) );
97
+ }
98
+
99
+ /**
100
+ * Filters the URL for the sitemap index stylesheet.
101
+ *
102
+ * If a falsy value is returned, no stylesheet will be used and
103
+ * the "raw" XML of the sitemap index will be displayed.
104
+ *
105
+ * @since 5.5.0
106
+ *
107
+ * @param string $sitemap_url Full URL for the sitemaps index xsl file.
108
+ */
109
+ return apply_filters( 'core_sitemaps_stylesheet_index_url', $sitemap_url );
110
+ }
111
+
112
+ /**
113
+ * Renders a sitemap index.
114
+ *
115
+ * @since 5.5.0
116
+ *
117
+ * @param array $sitemaps List of sitemap entries.
118
+ */
119
+ public function render_index( $sitemaps ) {
120
+ header( 'Content-type: application/xml; charset=UTF-8' );
121
+
122
+ $this->check_for_simple_xml_availability();
123
+
124
+ $index_xml = $this->get_sitemap_index_xml( $sitemaps );
125
+
126
+ if ( ! empty( $index_xml ) ) {
127
+ // All output is escaped within get_sitemap_index_xml().
128
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
129
+ echo $index_xml;
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Gets XML for a sitemap index.
135
+ *
136
+ * @since 5.5.0
137
+ *
138
+ * @param array $sitemaps List of sitemap entries.
139
+ * @return string|false A well-formed XML string for a sitemap index. False on error.
140
+ */
141
+ public function get_sitemap_index_xml( $sitemaps ) {
142
+ $sitemap_index = new SimpleXMLElement(
143
+ sprintf(
144
+ '%1$s%2$s%3$s',
145
+ '<?xml version="1.0" encoding="UTF-8" ?>',
146
+ $this->stylesheet_index,
147
+ '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" />'
148
+ )
149
+ );
150
+
151
+ foreach ( $sitemaps as $entry ) {
152
+ $sitemap = $sitemap_index->addChild( 'sitemap' );
153
+ $sitemap->addChild( 'loc', esc_url( $entry['loc'] ) );
154
+ }
155
+
156
+ return $sitemap_index->asXML();
157
+ }
158
+
159
+ /**
160
+ * Renders a sitemap.
161
+ *
162
+ * @since 5.5.0
163
+ *
164
+ * @param array $url_list A list of URLs for a sitemap.
165
+ */
166
+ public function render_sitemap( $url_list, $object_subtype ) {
167
+ header( 'Content-type: application/xml; charset=UTF-8' );
168
+
169
+ $this->check_for_simple_xml_availability();
170
+
171
+ $sitemap_xml = apply_filters( "core_sitemaps_get_sitemap_xml", $url_list, $object_subtype );
172
+
173
+ if ( empty( $sitemap_xml ) ) {
174
+
175
+ $sitemap_xml = $this->get_sitemap_xml( $url_list );
176
+
177
+ }
178
+
179
+ if ( ! empty( $sitemap_xml ) ) {
180
+ // All output is escaped within get_sitemap_xml().
181
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
182
+ $dom = new DOMDocument;
183
+ $dom->preserveWhiteSpace = false;
184
+ $dom->formatOutput = true;
185
+ $dom->loadXML($sitemap_xml);
186
+ echo $dom->saveXML();
187
+ //echo $sitemap_xml;
188
+ }
189
+ }
190
+
191
+ /**
192
+ * Gets XML for a sitemap.
193
+ *
194
+ * @since 5.5.0
195
+ *
196
+ * @param array $url_list A list of URLs for a sitemap.
197
+ * @return string|false A well-formed XML string for a sitemap index. False on error.
198
+ */
199
+ public function get_sitemap_xml( $url_list ) {
200
+ $urlset = new SimpleXMLElement(
201
+ sprintf(
202
+ '%1$s%2$s%3$s',
203
+ '<?xml version="1.0" encoding="UTF-8" ?>',
204
+ $this->stylesheet,
205
+ //'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" />'
206
+ '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-image/1.1 http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" />'
207
+ )
208
+ );
209
+
210
+ foreach ( $url_list as $url_item ) {
211
+ $url = $urlset->addChild( 'url' );
212
+
213
+ // Add each attribute as a child node to the URL entry.
214
+ foreach ( $url_item as $attr => $value ) {
215
+ if ( 'url' === $attr ) {
216
+ $url->addChild( $attr, esc_url( $value ) );
217
+ } else if ('image' === $attr) {
218
+ //$image = $url->addChild('image:image');
219
+ //$image = $url->addChild('image:image', null, 'http://www.google.com/schemas/sitemap-image/1.1');
220
+ foreach ($value as $imageattr) {
221
+ $image = $url->addChild('image:image', null, 'http://www.google.com/schemas/sitemap-image/1.1');
222
+ if(array_key_exists("loc", $imageattr)) $image->addChild('image:loc',esc_url( $imageattr['loc'] ), 'http://www.google.com/schemas/sitemap-image/1.1');
223
+ if(array_key_exists("title", $imageattr)) $image->addChild('image:title',esc_attr( $imageattr['title'] ), 'http://www.google.com/schemas/sitemap-image/1.1');
224
+ if(array_key_exists("caption", $imageattr)) $image->addChild('image:caption',esc_attr( $imageattr['caption'] ), 'http://www.google.com/schemas/sitemap-image/1.1');
225
+ }
226
+ } else {
227
+ $url->addChild( $attr, esc_attr( $value ) );
228
+ }
229
+ }
230
+ }
231
+
232
+ return $urlset->asXML();
233
+ }
234
+
235
+ /**
236
+ * Checks for the availability of the SimpleXML extension and errors if missing.
237
+ *
238
+ * @since 5.5.0
239
+ */
240
+ private function check_for_simple_xml_availability() {
241
+ if ( ! class_exists( 'SimpleXMLElement' ) ) {
242
+ add_filter(
243
+ 'wp_die_handler',
244
+ static function () {
245
+ return '_xml_wp_die_handler';
246
+ }
247
+ );
248
+
249
+ wp_die(
250
+ sprintf(
251
+ /* translators: %s: SimpleXML */
252
+ __( 'Could not generate XML sitemap due to missing %s extension', 'core-sitemaps' ),
253
+ 'SimpleXML'
254
+ ),
255
+ __( 'WordPress &rsaquo; Error', 'core-sitemaps' ),
256
+ array(
257
+ 'response' => 501, // "Not implemented".
258
+ )
259
+ );
260
+ }
261
+ }
262
+ }
psp-include/sitemap/inc/class-core-sitemaps-stylesheet.php ADDED
@@ -0,0 +1,252 @@
1
+ <?php
2
+ /**
3
+ * Sitemaps: Core_Sitemaps_Stylesheet class
4
+ *
5
+ * This class provides the XSL stylesheets to style all sitemaps.
6
+ *
7
+ * @package WordPress
8
+ * @subpackage Sitemaps
9
+ * @since 5.5.0
10
+ */
11
+
12
+ /**
13
+ * Stylesheet provider class.
14
+ *
15
+ * @since 5.5.0
16
+ */
17
+ class Core_Sitemaps_Stylesheet {
18
+ /**
19
+ * Renders the xsl stylesheet depending on whether its the sitemap index or not.
20
+ *
21
+ * @param string $type Stylesheet type. Either 'sitemap' or 'index'.
22
+ */
23
+ public function render_stylesheet( $type ) {
24
+ header( 'Content-type: application/xml; charset=UTF-8' );
25
+
26
+ if ( 'sitemap' === $type ) {
27
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- All content escaped below.
28
+ echo $this->get_sitemap_stylesheet();
29
+ }
30
+
31
+ if ( 'index' === $type ) {
32
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- All content escaped below.
33
+ echo $this->get_sitemap_index_stylesheet();
34
+ }
35
+
36
+ exit;
37
+ }
38
+
39
+ /**
40
+ * Returns the escaped xsl for all sitemaps, except index.
41
+ *
42
+ * @since 5.5.0
43
+ */
44
+ public function get_sitemap_stylesheet() {
45
+ $css = $this->get_stylesheet_css();
46
+ $title = esc_html__( 'XML Sitemap', 'core-sitemaps' );
47
+ $description = sprintf(
48
+ /* translators: %s: URL to sitemaps documentation. */
49
+ __( 'This XML Sitemap is generated by WordPress to make your content more visible for search engines. Learn more about XML sitemaps on <a href="%s">sitemaps.org</a>.', 'core-sitemaps' ),
50
+ __( 'https://www.sitemaps.org/', 'core-sitemaps' )
51
+ );
52
+ $text = sprintf(
53
+ /* translators: %s: number of URLs. */
54
+ __( 'Number of URLs in this XML Sitemap: %s.', 'core-sitemaps' ),
55
+ '<xsl:value-of select="count(sitemap:urlset/sitemap:url)"/>'
56
+ );
57
+
58
+ $url = esc_html__( 'URL', 'core-sitemaps' );
59
+
60
+ $xsl_content = <<<XSL
61
+ <?xml version="1.0" encoding="UTF-8"?>
62
+ <xsl:stylesheet version="2.0"
63
+ xmlns:html="http://www.w3.org/TR/REC-html40"
64
+ xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
65
+ xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
66
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
67
+ <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
68
+ <xsl:template match="/">
69
+ <html xmlns="http://www.w3.org/1999/xhtml">
70
+ <head>
71
+ <title>$title</title>
72
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
73
+ <style type="text/css">
74
+ $css
75
+ </style>
76
+ </head>
77
+ <body>
78
+ <div id="sitemap__header">
79
+ <h1>$title</h1>
80
+ <p>$description</p>
81
+ </div>
82
+ <div id="sitemap__content">
83
+ <p class="text">$text</p>
84
+ <table id="sitemap__table">
85
+ <thead>
86
+ <tr>
87
+ <th>$url</th>
88
+ </tr>
89
+ </thead>
90
+ <tbody>
91
+ <xsl:for-each select="sitemap:urlset/sitemap:url">
92
+ <tr>
93
+ <td>
94
+ <xsl:variable name="itemURL">
95
+ <xsl:value-of select="sitemap:loc"/>
96
+ </xsl:variable>
97
+ <a href="{\$itemURL}">
98
+ <xsl:value-of select="sitemap:loc"/>
99
+ </a>
100
+ </td>
101
+ </tr>
102
+ </xsl:for-each>
103
+ </tbody>
104
+ </table>
105
+
106
+ </div>
107
+ </body>
108
+ </html>
109
+ </xsl:template>
110
+ </xsl:stylesheet>\n
111
+ XSL;
112
+
113
+ /**
114
+ * Filters the content of the sitemap stylesheet.
115
+ *
116
+ * @since 5.5.0
117
+ *
118
+ * @param string $xsl Full content for the xml stylesheet.
119
+ */
120
+ return apply_filters( 'core_sitemaps_stylesheet_content', $xsl_content );
121
+ }
122
+
123
+ /**
124
+ * Returns the escaped xsl for the index sitemaps.
125
+ *
126
+ * @since 5.5.0
127
+ */
128
+ public function get_sitemap_index_stylesheet() {
129
+ $css = $this->get_stylesheet_css();
130
+ $title = esc_html__( 'XML Sitemap', 'core-sitemaps' );
131
+ $description = sprintf(
132
+ /* translators: %s: URL to sitemaps documentation. */
133
+ __( 'This XML Sitemap is generated by WordPress to make your content more visible for search engines. Learn more about XML sitemaps on <a href="%s">sitemaps.org</a>.', 'core-sitemaps' ),
134
+ __( 'https://www.sitemaps.org/', 'core-sitemaps' )
135
+ );
136
+ $text = sprintf(
137
+ /* translators: %s: number of URLs. */
138
+ __( 'This XML Sitemap contains %s URLs.', 'core-sitemaps' ),
139
+ '<xsl:value-of select="count(sitemap:sitemapindex/sitemap:sitemap)"/>'
140
+ );
141
+
142
+ $url = esc_html__( 'URL', 'core-sitemaps' );
143
+
144
+ $xsl_content = <<<XSL
145
+ <?xml version="1.0" encoding="UTF-8"?>
146
+ <xsl:stylesheet version="2.0"
147
+ xmlns:html="http://www.w3.org/TR/REC-html40"
148
+ xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
149
+ xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
150
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
151
+ <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
152
+ <xsl:template match="/">
153
+ <html xmlns="http://www.w3.org/1999/xhtml">
154
+ <head>
155
+ <title>$title</title>
156
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
157
+ <style type="text/css">
158
+ $css
159
+ </style>
160
+ </head>
161
+ <body>
162
+ <div id="sitemap__header">
163
+ <h1>$title</h1>
164
+ <p>$description</p>
165
+ </div>
166
+ <div id="sitemap__content">
167
+ <p class="text">$text</p>
168
+ <table id="sitemap__table">
169
+ <thead>
170
+ <tr>
171
+ <th>$url</th>
172
+ </tr>
173
+ </thead>
174
+ <tbody>
175
+ <xsl:for-each select="sitemap:sitemapindex/sitemap:sitemap">
176
+ <tr>
177
+ <td>
178
+ <xsl:variable name="itemURL">
179
+ <xsl:value-of select="sitemap:loc"/>
180
+ </xsl:variable>
181
+ <a href="{\$itemURL}">
182
+ <xsl:value-of select="sitemap:loc"/>
183
+ </a>
184
+ </td>
185
+ </tr>
186
+ </xsl:for-each>
187
+ </tbody>
188
+ </table>
189
+
190
+ </div>
191
+ </body>
192
+ </html>
193
+ </xsl:template>
194
+ </xsl:stylesheet>\n
195
+ XSL;
196
+
197
+ /**
198
+ * Filters the content of the sitemap index stylesheet.
199
+ *
200
+ * @since 5.5.0
201
+ *
202
+ * @param string $xsl Full content for the xml stylesheet.
203
+ */
204
+ return apply_filters( 'core_sitemaps_index_stylesheet_content', $xsl_content );
205
+ }
206
+
207
+ /**
208
+ * Gets the CSS to be included in sitemap XSL stylesheets.
209
+ *
210
+ * @since 5.5.0
211
+ *
212
+ * @return string The CSS.
213
+ */
214
+ public function get_stylesheet_css() {
215
+ $css = '
216
+ body {
217
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
218
+ color: #444;
219
+ }
220
+
221
+ #sitemap__table {
222
+ border: solid 1px #ccc;
223
+ border-collapse: collapse;
224
+ }
225
+
226
+ #sitemap__table tr th {
227
+ text-align: left;
228
+ }
229
+
230
+ #sitemap__table tr td,
231
+ #sitemap__table tr th {
232
+ padding: 10px;
233
+ }
234
+
235
+ #sitemap__table tr:nth-child(odd) td {
236
+ background-color: #eee;
237
+ }
238
+
239
+ a:hover {
240
+ text-decoration: none;
241
+ }';
242
+
243
+ /**
244
+ * Filters the css only for the sitemap stylesheet.
245
+ *
246
+ * @since 5.5.0
247
+ *
248
+ * @param string $css CSS to be applied to default xsl file.
249
+ */
250
+ return apply_filters( 'core_sitemaps_stylesheet_css', $css );
251
+ }
252
+ }
psp-include/sitemap/inc/class-core-sitemaps.php ADDED
@@ -0,0 +1,287 @@
1
+ <?php
2
+ /**
3
+ * Sitemaps: Core_Sitemaps class
4
+ *
5
+ * This is the main class integrating all other classes.
6
+ *
7
+ * @package WordPress
8
+ * @subpackage Sitemaps
9
+ * @since 5.5.0
10
+ */
11
+
12
+ /**
13
+ * Class Core_Sitemaps.
14
+ *
15
+ * @since 5.5.0
16
+ */
17
+ class Core_Sitemaps {
18
+ /**
19
+ * The main index of supported sitemaps.
20
+ *
21
+ * @since 5.5.0
22
+ *
23
+ * @var Core_Sitemaps_Index
24
+ */
25
+ public $index;
26
+
27
+ /**
28
+ * The main registry of supported sitemaps.
29
+ *
30
+ * @since 5.5.0
31
+ *
32
+ * @var Core_Sitemaps_Registry
33
+ */
34
+ public $registry;
35
+
36
+ /**
37
+ * An instance of the renderer class.
38
+ *
39
+ * @since 5.5.0
40
+ *
41
+ * @var Core_Sitemaps_Renderer
42
+ */
43
+ public $renderer;
44
+
45
+ /**
46
+ * Core_Sitemaps constructor.
47
+ *
48
+ * @since 5.5.0
49
+ */
50
+ public function __construct() {
51
+ $this->registry = new Core_Sitemaps_Registry();
52
+ $this->renderer = new Core_Sitemaps_Renderer();
53
+ $this->index = new Core_Sitemaps_Index( $this->registry );
54
+ }
55
+
56
+ /**
57
+ * Initiates all sitemap functionality.
58
+ *
59
+ * @since 5.5.0
60
+ */
61
+ public function init() {
62
+ // These will all fire on the init hook.
63
+ $this->register_sitemaps();
64
+
65
+ // Add additional action callbacks.
66
+ add_action( 'core_sitemaps_init', array( $this, 'register_rewrites' ) );
67
+ add_action( 'template_redirect', array( $this, 'render_sitemaps' ) );
68
+ add_action( 'wp_loaded', array( $this, 'maybe_flush_rewrites' ) );
69
+ add_filter( 'pre_handle_404', array( $this, 'redirect_sitemapxml' ), 10, 2 );
70
+ add_filter( 'robots_txt', array( $this, 'add_robots' ), 0, 2 );
71
+ add_filter( 'redirect_canonical', array( $this, 'redirect_canonical' ) );
72
+ }
73
+
74
+ /**
75
+ * Registers and sets up the functionality for all supported sitemaps.
76
+ *
77
+ * @since 5.5.0
78
+ */
79
+ public function register_sitemaps() {
80
+ /**
81
+ * Filters the list of registered sitemap providers.
82
+ *
83
+ * @since 5.5.0
84
+ *
85
+ * @param array $providers Array of Core_Sitemap_Provider objects keyed by their name.
86
+ */
87
+ $providers = apply_filters(
88
+ 'core_sitemaps_register_providers',
89
+ array(
90
+ 'posts' => new Core_Sitemaps_Posts(),
91
+ 'taxonomies' => new Core_Sitemaps_Taxonomies(),
92
+ 'users' => new Core_Sitemaps_Users(),
93
+ )
94
+ );
95
+
96
+ // Register each supported provider.
97
+ /* @var Core_Sitemaps_Provider $provider */
98
+ foreach ( $providers as $name => $provider ) {
99
+ $this->registry->add_sitemap( $name, $provider );
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Registers sitemap rewrite tags and routing rules.
105
+ *
106
+ * @since 5.5.0
107
+ */
108
+ public function register_rewrites() {
109
+ // Add rewrite tags.
110
+ add_rewrite_tag( '%sitemap%', '([^?]+)' );
111
+ add_rewrite_tag( '%sitemap-sub-type%', '([^?]+)' );
112
+
113
+ // Register index route.
114
+ add_rewrite_rule( '^wp-sitemap\.xml#x27;, 'index.php?sitemap=index', 'top' );
115
+
116
+ // Register rewrites for the XSL stylesheet.
117
+ add_rewrite_tag( '%sitemap-stylesheet%', '([^?]+)' );
118
+ add_rewrite_rule( '^wp-sitemap\.xsl#x27;, 'index.php?sitemap-stylesheet=sitemap', 'top' );
119
+ add_rewrite_rule( '^wp-sitemap-index\.xsl#x27;, 'index.php?sitemap-stylesheet=index', 'top' );
120
+
121
+ // Register routes for providers.
122
+ add_rewrite_rule(
123
+ '^wp-sitemap-([a-z]+?)-([a-z\d_-]+?)-(\d+?)\.xml#x27;,
124
+ 'index.php?sitemap=$matches[1]&sitemap-sub-type=$matches[2]&paged=$matches[3]',
125
+ 'top'
126
+ );
127
+ add_rewrite_rule(
128
+ '^wp-sitemap-([a-z]+?)-(\d+?)\.xml#x27;,
129
+ 'index.php?sitemap=$matches[1]&paged=$matches[2]',
130
+ 'top'
131
+ );
132
+ }
133
+
134
+ /**
135
+ * Un-registers sitemap rewrite tags and routing rules.
136
+ *
137
+ * @since 5.5.0
138
+ */
139
+ public function unregister_rewrites() {
140
+ /* @var WP_Rewrite $wp_rewrite */
141
+ global $wp_rewrite;
142
+
143
+ // Unregister index route.
144
+ unset( $wp_rewrite->extra_rules_top['^wp-sitemap\.xml#x27;] );
145
+
146
+ // Unregister rewrites for the XSL stylesheet.
147
+ unset( $wp_rewrite->extra_rules_top['^wp-sitemap\.xsl#x27;] );
148
+ unset( $wp_rewrite->extra_rules_top['^wp-sitemap-index\.xsl#x27;] );
149
+
150
+ // Unregister routes for providers.
151
+ unset( $wp_rewrite->extra_rules_top['^wp-sitemap-([a-z]+?)-([a-z\d-]+?)-(\d+?)\.xml#x27;] );
152
+ unset( $wp_rewrite->extra_rules_top['^wp-sitemap-([a-z]+?)-(\d+?)\.xml#x27;] );
153
+ }
154
+
155
+ /**
156
+ * Flushes rewrite rules if developers updated them.
157
+ *
158
+ * @since 5.5.0
159
+ */
160
+ public function maybe_flush_rewrites() {
161
+ if ( update_option( 'core_sitemaps_rewrite_version', CORE_SITEMAPS_REWRITE_VERSION ) ) {
162
+ flush_rewrite_rules( false );
163
+ }
164
+ }
165
+
166
+ /**
167
+ * Renders sitemap templates based on rewrite rules.
168
+ *
169
+ * @since 5.5.0
170
+ */
171
+ public function render_sitemaps() {
172
+ global $wp_query;
173
+
174
+ $sitemap = sanitize_text_field( get_query_var( 'sitemap' ) );
175
+ $object_subtype = sanitize_text_field( get_query_var( 'sitemap-sub-type' ) );
176
+ $stylesheet_type = sanitize_text_field( get_query_var( 'sitemap-stylesheet' ) );
177
+ $paged = absint( get_query_var( 'paged' ) );
178
+
179
+ // Bail early if this isn't a sitemap or stylesheet route.
180
+ if ( ! ( $sitemap || $stylesheet_type ) ) {
181
+ return;
182
+ }
183
+
184
+ // Render stylesheet if this is stylesheet route.
185
+ if ( $stylesheet_type ) {
186
+ $stylesheet = new Core_Sitemaps_Stylesheet();
187
+
188
+ $stylesheet->render_stylesheet( $stylesheet_type );
189
+ exit;
190
+ }
191
+
192
+ // Render the index.
193
+ if ( 'index' === $sitemap ) {
194
+ $sitemap_list = $this->index->get_sitemap_list();
195
+
196
+ $this->renderer->render_index( $sitemap_list );
197
+ exit;
198
+ }
199
+
200
+ $provider = $this->registry->get_sitemap( $sitemap );
201
+
202
+ if ( ! $provider ) {
203
+ return;
204
+ }
205
+
206
+ if ( empty( $paged ) ) {
207
+ $paged = 1;
208
+ }
209
+
210
+ $object_subtypes = $provider->get_object_subtypes();
211
+
212
+ // Only set the current object sub-type if it's supported.
213
+ if ( isset( $object_subtypes[ $object_subtype ] ) ) {
214
+ $provider->set_object_subtype( $object_subtype );
215
+ }
216
+
217
+ $url_list = $provider->get_url_list( $paged, $object_subtype );
218
+
219
+ // Force a 404 and bail early if no URLs are present.
220
+ if ( empty( $url_list ) ) {
221
+ $wp_query->set_404();
222
+ return;
223
+ }
224
+
225
+ $this->renderer->render_sitemap( $url_list, $object_subtype );
226
+ exit;
227
+ }
228
+
229
+ /**
230
+ * Redirects a URL to the wp-sitemap.xml
231
+ *
232
+ * @since 5.5.0
233
+ *
234
+ * @param bool $bypass Pass-through of the pre_handle_404 filter value.
235
+ * @param WP_Query $query The WP_Query object.
236
+ *
237
+ * @return bool bypass value.
238
+ */
239
+ public function redirect_sitemapxml( $bypass, $query ) {
240
+ // If a plugin has already utilized the pre_handle_404 function, return without action to avoid conflicts.
241
+ if ( $bypass ) {
242
+ return $bypass;
243
+ }
244
+
245
+ // 'pagename' is for most permalink types, name is for when the %postname% is used as a top-level field.
246
+ if ( 'sitemap-xml' === $query->get( 'pagename' ) ||
247
+ 'sitemap-xml' === $query->get( 'name' ) ) {
248
+ wp_safe_redirect( $this->index->get_index_url() );
249
+ exit();
250
+ }
251
+
252
+ return $bypass;
253
+ }
254
+
255
+ /**
256
+ * Adds the sitemap index to robots.txt.
257
+ *
258
+ * @since 5.5.0
259
+ *
260
+ * @param string $output robots.txt output.
261
+ * @param bool $public Whether the site is public or not.
262
+ * @return string robots.txt output.
263
+ */
264
+ public function add_robots( $output, $public ) {
265
+ if ( $public ) {
266
+ $output .= "\nSitemap: " . esc_url( $this->index->get_index_url() ) . "\n";
267
+ }
268
+
269
+ return $output;
270
+ }
271
+
272
+ /**
273
+ * Prevent trailing slashes.
274
+ *
275
+ * @since 5.5.0
276
+ *
277
+ * @param string $redirect The redirect URL currently determined.
278
+ * @return bool|string $redirect
279
+ */
280
+ public function redirect_canonical( $redirect ) {
281
+ if ( get_query_var( 'sitemap' ) || get_query_var( 'sitemap-stylesheet' ) ) {
282
+ return false;
283
+ }
284
+
285
+ return $redirect;
286
+ }
287
+ }
psp-include/sitemap/inc/functions.php ADDED
@@ -0,0 +1,119 @@
1
+ <?php
2
+ /**
3
+ * Sitemaps: Public functions
4
+ *
5
+ * This file contains a variety of public functions developers can use to interact with
6
+ * the XML Sitemaps API.
7
+ *
8
+ * @package WordPress
9
+ * @subpackage Sitemaps
10
+ * @since 5.5.0
11
+ */
12
+
13
+ /**
14
+ * Retrieves the current Sitemaps server instance.
15
+ *
16
+ * @since 5.5.0
17
+ *
18
+ * @return Core_Sitemaps|null Core_Sitemaps instance, or null of sitemaps are disabled.
19
+ */
20
+ function core_sitemaps_get_server() {
21
+ /**
22
+ * Global Core Sitemaps instance.
23
+ *
24
+ * @since 5.5.0
25
+ *
26
+ * @var Core_Sitemaps $core_sitemaps
27
+ */
28
+ global $core_sitemaps;
29
+
30
+ $is_enabled = (bool) get_option( 'blog_public' );
31
+
32
+ /**
33
+ * Filters whether XML Sitemaps are enabled or not.
34
+ *
35
+ * @since 5.5.0
36
+ *
37
+ * @param bool $is_enabled Whether XML Sitemaps are enabled or not. Defaults to true for public sites.
38
+ */
39
+ $is_enabled = (bool) apply_filters( 'core_sitemaps_is_enabled', $is_enabled );
40
+
41
+ if ( ! $is_enabled ) {
42
+ return null;
43
+ }
44
+
45
+ // If there isn't a global instance, set and bootstrap the sitemaps system.
46
+ if ( empty( $core_sitemaps ) ) {
47
+ $core_sitemaps = new Core_Sitemaps();
48
+ $core_sitemaps->init();
49
+
50
+ /**
51
+ * Fires when initializing the Core_Sitemaps object.
52
+ *
53
+ * Additional sitemaps should be registered on this hook.
54
+ *
55
+ * @since 5.5.0
56
+ *
57
+ * @param core_sitemaps $core_sitemaps Server object.
58
+ */
59
+ do_action( 'core_sitemaps_init', $core_sitemaps );
60
+ }
61
+
62
+ return $core_sitemaps;
63
+ }
64
+
65
+ /**
66
+ * Gets a list of sitemap providers.
67
+ *
68
+ * @since 5.5.0
69
+ *
70
+ * @return array $sitemaps A list of registered sitemap providers.
71
+ */
72
+ function core_sitemaps_get_sitemaps() {
73
+ $core_sitemaps = core_sitemaps_get_server();
74
+
75
+ if ( ! $core_sitemaps ) {
76
+ return array();
77
+ }
78
+
79
+ return $core_sitemaps->registry->get_sitemaps();
80
+ }
81
+
82
+ /**
83
+ * Registers a new sitemap provider.
84
+ *
85
+ * @since 5.5.0
86
+ *
87
+ * @param string $name Unique name for the sitemap provider.
88
+ * @param Core_Sitemaps_Provider $provider The `Core_Sitemaps_Provider` instance implementing the sitemap.
89
+ * @return bool Returns true if the sitemap was added. False on failure.
90
+ */
91
+ function core_sitemaps_register_sitemap( $name, $provider ) {
92
+ $core_sitemaps = core_sitemaps_get_server();
93
+
94
+ if ( ! $core_sitemaps ) {
95
+ return false;
96
+ }
97
+
98
+ return $core_sitemaps->registry->add_sitemap( $name, $provider );
99
+ }
100
+
101
+ /**
102
+ * Gets the maximum number of URLs for a sitemap.
103
+ *
104
+ * @since 5.5.0
105
+ *
106
+ * @param string $object_type Object type for sitemap to be filtered (e.g. 'post', 'term', 'user').
107
+ * @return int The maximum number of URLs.
108
+ */
109
+ function core_sitemaps_get_max_urls( $object_type ) {
110
+ /**
111
+ * Filters the maximum number of URLs displayed on a sitemap.
112
+ *
113
+ * @since 5.5.0
114
+ *
115
+ * @param int $max_urls The maximum number of URLs included in a sitemap. Default 2000.
116
+ * @param string $object_type Object type for sitemap to be filtered (e.g. 'post', 'term', 'user').
117
+ */
118
+ return apply_filters( 'core_sitemaps_max_urls', CORE_SITEMAPS_MAX_URLS, $object_type );
119
+ }
psp-include/sitemap/inc/providers/class-core-sitemaps-posts.php ADDED
@@ -0,0 +1,160 @@
1
+ <?php
2
+ /**
3
+ * Sitemaps: Core_Sitemaps_Posts class
4
+ *
5
+ * Builds the sitemaps for the 'post' object type.
6
+ *
7
+ * @package WordPress
8
+ * @subpackage Sitemaps
9
+ * @since 5.5.0
10
+ */
11
+
12
+ /**
13
+ * Posts XML sitemap provider.
14
+ *
15
+ * @since 5.5.0
16
+ */
17
+ class Core_Sitemaps_Posts extends Core_Sitemaps_Provider {
18
+ /**
19
+ * Core_Sitemaps_Posts constructor.
20
+ *
21
+ * @since 5.5.0
22
+ */
23
+ public function __construct() {
24
+ $this->name = 'posts';
25
+ $this->object_type = 'post';
26
+ }
27
+
28
+ /**
29
+ * Returns the public post types, which excludes nav_items and similar types.
30
+ * Attachments are also excluded. This includes custom post types with public = true.
31
+ *
32
+ * @since 5.5.0
33
+ *
34
+ * @return array Map of registered post type objects keyed by their name.
35
+ */
36
+ public function get_object_subtypes() {
37
+ $post_types = get_post_types( array( 'public' => true ), 'objects' );
38
+ unset( $post_types['attachment'] );
39
+
40
+ /**
41
+ * Filters the list of post object sub types available within the sitemap.
42
+ *
43
+ * @since 5.5.0
44
+ *
45
+ * @param array $post_types Map of registered post type objects keyed by their name.
46
+ */
47
+ return apply_filters( 'core_sitemaps_post_types', $post_types );
48
+ }
49
+
50
+ /**
51
+ * Gets a URL list for a post type sitemap.
52
+ *
53
+ * @since 5.5.0
54
+ *
55
+ * @param int $page_num Page of results.
56
+ * @param string $post_type Optional. Post type name. Default empty.
57
+ * @return array List of URLs for a sitemap.
58
+ */
59
+ public function get_url_list( $page_num, $post_type = '' ) {
60
+ if ( ! $post_type ) {
61
+ $post_type = $this->get_queried_type();
62
+ }
63
+
64
+ // Return an empty array if the type is not supported.
65
+ $supported_types = $this->get_object_subtypes();
66
+
67
+ if ( ! isset( $supported_types[ $post_type ] ) ) {
68
+ return array();
69
+ }
70
+
71
+ $query = new WP_Query(
72
+ array(
73
+ 'fields' => 'ids',
74
+ 'orderby' => 'ID',
75
+ 'order' => 'ASC',
76
+ 'post_type' => $post_type,
77
+ 'posts_per_page' => core_sitemaps_get_max_urls( $this->object_type ),
78
+ 'post_status' => array( 'publish' ),
79
+ 'paged' => $page_num,
80
+ 'no_found_rows' => true,
81
+ 'update_post_term_cache' => false,
82
+ 'update_post_meta_cache' => false,
83
+ )
84
+ );
85
+
86
+ /**
87
+ * Returns an array of posts.
88
+ *
89
+ * @var array<int, \WP_Post> $posts
90
+ */
91
+ $posts = $query->get_posts();
92
+
93
+ $posts = apply_filters( 'core_sitemaps_posts_list', $posts, $post_type, $page_num );
94
+
95
+ $url_list = array();
96
+
97
+ $post_sitemap_attributes = array();
98
+
99
+ /*
100
+ * Add a URL for the homepage in the pages sitemap.
101
+ * Shows only on the first page if the reading settings are set to display latest posts.
102
+ */
103
+ if ( 'page' === $post_type && 1 === $page_num && 'posts' === get_option( 'show_on_front' ) ) {
104
+ // Extract the data needed for home URL to add to the array.
105
+ $url_list[] = array(
106
+ 'loc' => home_url(),
107
+ );
108
+ }
109
+
110
+ foreach ( $posts as $post ) {
111
+ $post_sitemap_attributes = array( 'loc' => get_permalink( $post )) ;
112
+ $url_list[] = apply_filters( 'core_sitemaps_post_attributes', $post_sitemap_attributes, $post );
113
+ /***
114
+ $url_list[] = array(
115
+ 'loc' => get_permalink( $post ),
116
+ );
117
+ ***/
118
+ }
119
+
120
+ /**
121
+ * Filters the list of URLs for a sitemap before rendering.
122
+ *
123
+ * @since 5.5.0
124
+ *
125
+ * @param array $url_list List of URLs for a sitemap.
126
+ * @param string $post_type Name of the post_type.
127
+ * @param int $page_num Page number of the results.
128
+ */
129
+ return apply_filters( 'core_sitemaps_posts_url_list', $url_list, $post_type, $page_num );
130
+ }
131
+
132
+ /**
133
+ * Gets the max number of pages available for the object type.
134
+ *
135
+ * @since 5.5.0
136
+ *
137
+ * @param string $post_type Optional. Post type name. Default empty.
138
+ * @return int Total number of pages.
139
+ */
140
+ public function max_num_pages( $post_type = '' ) {
141
+ if ( empty( $post_type ) ) {
142
+ $post_type = $this->get_queried_type();
143
+ }
144
+
145
+ $query = new WP_Query(
146
+ array(
147
+ 'fields' => 'ids',
148
+ 'orderby' => 'ID',
149
+ 'order' => 'ASC',
150
+ 'post_type' => $post_type,
151
+ 'posts_per_page' => core_sitemaps_get_max_urls( $this->object_type ),
152
+ 'paged' => 1,
153
+ 'update_post_term_cache' => false,
154
+ 'update_post_meta_cache' => false,
155
+ )
156
+ );
157
+
158
+ return isset( $query->max_num_pages ) ? $query->max_num_pages : 1;
159
+ }
160
+ }
psp-include/sitemap/inc/providers/class-core-sitemaps-taxonomies.php ADDED
@@ -0,0 +1,143 @@
1
+ <?php
2
+ /**
3
+ * Sitemaps: Core_Sitemaps_Taxonomies class
4
+ *
5
+ * Builds the sitemaps for the 'taxonomy' object type.
6
+ *
7
+ * @package WordPress
8
+ * @subpackage Sitemaps
9
+ * @since 5.5.0
10
+ */
11
+
12
+ /**
13
+ * Taxonomies XML sitemap provider.
14
+ *
15
+ * @since 5.5.0
16
+ */
17
+ class Core_Sitemaps_Taxonomies extends Core_Sitemaps_Provider {
18
+ /**
19
+ * Core_Sitemaps_Taxonomies constructor.
20
+ *
21
+ * @since 5.5.0
22
+ */
23
+ public function __construct() {
24
+ $this->name = 'taxonomies';
25
+ $this->object_type = 'term';
26
+ }
27
+
28
+ /**
29
+ * Returns all public, registered taxonomies.
30
+ *
31
+ * @since 5.5.0
32
+ *
33
+ * @return array Map of registered taxonomy objects keyed by their name.
34
+ */
35
+ public function get_object_subtypes() {
36
+ $taxonomies = get_taxonomies( array( 'public' => true ), 'objects' );
37
+
38
+ /**
39
+ * Filter the list of taxonomy object subtypes available within the sitemap.
40
+ *
41
+ * @since 5.5.0
42
+ *
43
+ * @param array $taxonomies Map of registered taxonomy objects keyed by their name.
44
+ */
45
+ return apply_filters( 'core_sitemaps_taxonomies', $taxonomies );
46
+ }
47
+
48
+ /**
49
+ * Gets a URL list for a taxonomy sitemap.
50
+ *
51
+ * @since 5.5.0
52
+ *
53
+ * @param int $page_num Page of results.
54
+ * @param string $taxonomy Optional. Taxonomy name. Default empty.
55
+ * @return array List of URLs for a sitemap.
56
+ */
57
+ public function get_url_list( $page_num, $taxonomy = '' ) {
58
+ // Find the query_var for subtype.
59
+ if ( ! $taxonomy ) {
60
+ $taxonomy = $this->get_queried_type();
61
+ }
62
+
63
+ // Bail early if we don't have a taxonomy.
64
+ if ( empty( $taxonomy ) ) {
65
+ return array();
66
+ }
67
+
68
+ $supported_types = $this->get_object_subtypes();
69
+
70
+ // Bail early if the queried taxonomy is not a supported type.
71
+ if ( ! isset( $supported_types[ $taxonomy ] ) ) {
72
+ return array();
73
+ }
74
+
75
+ $url_list = array();
76
+
77
+ // Offset by how many terms should be included in previous pages.
78
+ $offset = ( $page_num - 1 ) * core_sitemaps_get_max_urls( $this->object_type );
79
+
80
+ $args = array(
81
+ 'fields' => 'ids',
82
+ 'taxonomy' => $taxonomy,
83
+ 'orderby' => 'term_order',
84
+ 'number' => core_sitemaps_get_max_urls( $this->object_type ),
85
+ 'offset' => $offset,
86
+ 'hide_empty' => true,
87
+
88
+ /*
89
+ * Limits aren't included in queries when hierarchical is set to true (by default).
90
+ *
91
+ * @link: https://github.com/WordPress/WordPress/blob/5.3/wp-includes/class-wp-term-query.php#L558-L567
92
+ */
93
+ 'hierarchical' => false,
94
+ 'update_term_meta_cache' => false,
95
+ );
96
+
97
+ $taxonomy_terms = new WP_Term_Query( $args );
98
+
99
+ $taxonomy_terms = apply_filters( 'core_sitemaps_terms_list', $taxonomy_terms, $taxonomy, $page_num );
100
+
101
+ if ( ! empty( $taxonomy_terms->terms ) ) {
102
+ foreach ( $taxonomy_terms->terms as $term ) {
103
+
104
+ $term_sitemap_attributes = array( 'loc' => get_term_link( $term )) ;
105
+ $url_list[] = apply_filters( 'core_sitemaps_term_attributes', $term_sitemap_attributes, $term );
106
+ /**
107
+ $url_list[] = array(
108
+ 'loc' => get_term_link( $term ),
109
+ );
110
+ **/
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Filters the list of URLs for a sitemap before rendering.
116
+ *
117
+ * @since 5.5.0
118
+ *
119
+ * @param array $url_list List of URLs for a sitemap.
120
+ * @param string $taxonomy Taxonomy name.
121
+ * @param int $page_num Page of results.
122
+ */
123
+ return apply_filters( 'core_sitemaps_taxonomies_url_list', $url_list, $taxonomy, $page_num );
124
+ }
125
+
126
+ /**
127
+ * Gets the max number of pages available for the object type.
128
+ *
129
+ * @since 5.5.0
130
+ *
131
+ * @param string $taxonomy Taxonomy name.
132
+ * @return int Total number of pages.
133
+ */
134
+ public function max_num_pages( $taxonomy = '' ) {
135
+ if ( empty( $taxonomy ) ) {
136
+ $taxonomy = $this->get_queried_type();
137
+ }
138
+
139
+ $term_count = wp_count_terms( $taxonomy, array( 'hide_empty' => true ) );
140
+
141
+ return (int) ceil( $term_count / core_sitemaps_get_max_urls( $this->object_type ) );
142
+ }
143
+ }
psp-include/sitemap/inc/providers/class-core-sitemaps-users.php ADDED
@@ -0,0 +1,111 @@
1
+ <?php
2
+ /**
3
+ * Sitemaps: Core_Sitemaps_Users class
4
+ *
5
+ * Builds the sitemaps for the 'user' object type.
6
+ *
7
+ * @package WordPress
8
+ * @subpackage Sitemaps
9
+ * @since 5.5.0
10
+ */
11
+
12
+ /**
13
+ * Users XML sitemap provider.
14
+ *
15
+ * @since 5.5.0
16
+ */
17
+ class Core_Sitemaps_Users extends Core_Sitemaps_Provider {
18
+ /**
19
+ * Core_Sitemaps_Users constructor.
20
+ *
21
+ * @since 5.5.0
22
+ */
23
+ public function __construct() {
24
+ $this->name = 'users';
25
+ $this->object_type = 'user';
26
+ }
27
+
28
+ /**
29
+ * Gets a URL list for a user sitemap.
30
+ *
31
+ * @since 5.5.0
32
+ *
33
+ * @param int $page_num Page of results.
34
+ * @param string $object_subtype Optional. Not applicable for Users but
35
+ * required for compatibility with the parent
36
+ * provider class. Default empty.
37
+ * @return array List of URLs for a sitemap.
38
+ */
39
+ public function get_url_list( $page_num, $object_subtype = '' ) {
40