Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #162, Conflicts with Wordpress 5.5 Sitemaps #163

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions msm-sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Plugin Name: Metro Sitemap
Description: Comprehensive sitemaps for your WordPress site. Joint collaboration between Metro.co.uk, MAKE, Alley Interactive, and WordPress.com VIP.
Author: Artur Synowiec, Paul Kevan, and others
Version: 1.4.1
Stable tag: 1.4.1
Version: 1.5.0
Stable tag: 1.5.0
License: GPLv2
*/

Expand Down Expand Up @@ -38,7 +38,7 @@ public static function setup() {
add_action( 'init', array( __CLASS__, 'create_post_type' ) );
add_filter( 'posts_pre_query', array( __CLASS__, 'disable_main_query_for_sitemap_xml' ), 10, 2 );
add_filter( 'template_include', array( __CLASS__, 'load_sitemap_template' ) );

// Disable WordPress 5.5-era sitemaps.
add_filter( 'wp_sitemaps_enabled', '__return_false' );

Expand Down Expand Up @@ -82,14 +82,14 @@ public static function sitemap_init() {
*/
public static function sitemap_rewrite_init() {
// Allow 'sitemap=true' parameter
add_rewrite_tag( '%sitemap%', 'true' );
add_rewrite_tag( '%sitemap_msm%', 'true' );

// Define rewrite rules for the index based on the setup
if ( self::$index_by_year ) {
add_rewrite_tag( '%sitemap-year%', '[0-9]{4}' );
add_rewrite_rule( '^sitemap-([0-9]{4}).xml$','index.php?sitemap=true&sitemap-year=$matches[1]','top' );
add_rewrite_tag( '%sitemap_msm-year%', '[0-9]{4}' );
add_rewrite_rule( '^sitemap-([0-9]{4}).xml$','index.php?sitemap_msm=true&sitemap_msm-year=$matches[1]','top' );
} else {
add_rewrite_rule( '^sitemap.xml$','index.php?sitemap=true','top' );
add_rewrite_rule( '^sitemap.xml$','index.php?sitemap_msm=true','top' );
}
}

Expand Down Expand Up @@ -635,7 +635,7 @@ public static function update_sitemap_from_modified_posts() {
* Trigger rendering of the actual sitemap
*/
public static function load_sitemap_template( $template ) {
if ( get_query_var( 'sitemap' ) === 'true' ) {
if ( get_query_var( 'sitemap_msm' ) === 'true' ) {
$template = dirname( __FILE__ ) . '/templates/full-sitemaps.php';
}
return $template;
Expand All @@ -648,7 +648,7 @@ public static function load_sitemap_template( $template ) {
* @param WP_Query $query The WP_Query instance.
*/
public static function disable_main_query_for_sitemap_xml( $posts, $query ) {
if ( $query->is_main_query() && isset($query->query_vars['sitemap']) && 'true' === $query->query_vars['sitemap'] ) {
if ( $query->is_main_query() && isset($query->query_vars['sitemap_msm']) && 'true' === $query->query_vars['sitemap_msm'] ) {
$posts = array();
}
return $posts;
Expand Down
2 changes: 1 addition & 1 deletion templates/full-sitemaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
);
}

$req_year = get_query_var( 'sitemap-year' );
$req_year = get_query_var( 'sitemap_msm-year' );
if ( empty( $req_year ) ) {
$req_year = ( isset( $_GET['yyyy'] ) ) ? intval( $_GET['yyyy'] ) : false;
}
Expand Down