-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathclass-ecwid-integration-google-sitemap-generator.php
More file actions
45 lines (35 loc) · 1.58 KB
/
class-ecwid-integration-google-sitemap-generator.php
File metadata and controls
45 lines (35 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
class Ecwid_Integration_Google_Sitemap_Generator {
public $plugin_version;
public function __construct() {
// Older versions of Google XML Sitemaps plugin generate it in admin, newer in site area, so the hook should be assigned in both of them
add_action( 'sm_buildmap', array( $this, 'build_sitemap' ) );
add_filter( 'ecwid_sitemap_builder_set_unlimited', '__return_true' );
$plugin_data = get_file_data( WP_PLUGIN_DIR . '/google-sitemap-generator/sitemap.php', array( 'version' => 'Version' ), 'plugin' );
$this->plugin_version = $plugin_data['version'];
}
public function build_sitemap() {
return ecwid_build_sitemap( array( $this, 'sitemap_callback' ) );
}
//phpcs:disable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
public function sitemap_callback( $url, $priority, $frequency ) {
if ( ! class_exists( 'GoogleSitemapGenerator' ) || ! class_exists( 'GoogleSitemapGeneratorPage' ) ) {
return false;
}
if ( version_compare( $this->plugin_version, '4.1.2', '>=' ) ) {
$generator_object = GoogleSitemapGenerator::get_instance();
} else {
$generator_object = GoogleSitemapGenerator::GetInstance();
}
if ( $generator_object !== null ) {
$page = new GoogleSitemapGeneratorPage( $url, $priority, $frequency );
if ( version_compare( $this->plugin_version, '4.1.2', '>=' ) ) {
$generator_object->add_element( $page );
} else {
$generator_object->AddElement( $page );
}
}
}
//phpcs:enable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
}
new Ecwid_Integration_Google_Sitemap_Generator();