Skip to content

Commit

Permalink
WPML url fix, thanks to hermes3por3
Browse files Browse the repository at this point in the history
  • Loading branch information
RavanH committed Jul 12, 2016
1 parent 6a35eab commit 78eac0f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
27 changes: 17 additions & 10 deletions includes/class-xmlsitemapfeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,17 @@ public function rewrite_rules($wp_rewrite)
$wp_rewrite->rules = $xmlsf_rules + $wp_rewrite->rules;
}

public function wpml_language_switcher() {
// WPML: switch language
// @see https://wpml.org/wpml-hook/wpml_post_language_details/
global $sitepress,$post;
if( isset($sitepress) ) {
$post_language = apply_filters( 'wpml_post_language_details', NULL, $post->ID );
$sitepress->switch_lang($post_language['language_code']);
}

}

/**
* REQUEST FILTER
*/
Expand All @@ -866,14 +877,11 @@ public function filter_request( $request )
// Polylang compat
$request['lang'] = '';
// WPML compat
global $wpml_query_filter,$wpml_url_filters;
if ( isset($wpml_query_filter) && isset($wpml_url_filters) && is_object($wpml_query_filter) && is_object($wpml_url_filters) ) {
global $wpml_query_filter;
if ( isset($wpml_query_filter) && is_object($wpml_query_filter) ) {
remove_filter( 'posts_join', array( $wpml_query_filter, 'posts_join_filter' ) );
remove_filter( 'posts_where', array( $wpml_query_filter, 'posts_where_filter' ) );
remove_filter( 'post_link', array( $wpml_url_filters, 'permalink_filter' ), 1 );
remove_filter( 'post_type_link', array( $wpml_url_filters, 'permalink_filter' ), 1 );
remove_filter( 'page_link', array( $wpml_url_filters, 'permalink_filter_root' ), 1 );
remove_filter( 'page_link', array( $wpml_url_filters, 'permalink_filter' ), 1 );
add_action( 'the_post', array( $this, 'wpml_language_switcher' ) );
}

if ( $request['feed'] == 'sitemap-news' ) {
Expand Down Expand Up @@ -926,13 +934,12 @@ public function filter_request( $request )
$request['taxonomy'] = $taxonomy;

// WPML compat
global $sitepress,$wpml_url_converter;
if ( isset($sitepress) && isset($wpml_url_converter) && is_object($sitepress) && is_object($wpml_url_converter) ) {
global $sitepress;
if ( isset($sitepress) && is_object($sitepress) ) {
remove_filter( 'get_terms_args', array($sitepress, 'get_terms_args_filter') );
remove_filter( 'get_term', array($sitepress,'get_term_adjust_id'), 1 );
remove_filter( 'terms_clauses', array($sitepress,'terms_clauses') );
remove_filter( 'category_link', array($sitepress, 'category_link_adjust_id'), 1 );
remove_filter( 'term_link', array($wpml_url_converter, 'tax_permalink_filter'), 1 );
$sitepress->switch_lang('all');
}

return $request;
Expand Down
9 changes: 6 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravan
Tags: sitemap, xml sitemap, news sitemap, sitemap.xml, robots.txt, Google, Google News, Yahoo, Bing, , Yandex, Baidu, seo, feed, Polylang, WPML, image sitemap
Requires at least: 3.2
Tested up to: 4.5
Stable tag: 4.7.3
Stable tag: 4.7.4

XML and Google News Sitemaps to feed the hungry spiders. Multisite, WP Super Cache, Polylang and WPML compatible.

Expand Down Expand Up @@ -294,11 +294,14 @@ Thanks for sharing your translation :)

== Upgrade Notice ==

= 4.7.3 =
Improved Polylang and WPML compatibility. Various bug fixes.
= 4.7.4 =
WPML compatibility bug fix.

== Changelog ==

= 4.7.4 =
* Another WPML compat issue fixed, special thanks to hermes3por3

= 4.7.3 =
* NEW: xmlsf_excluded filter
* IMPROVEMENT: Polylang and WPML compatibility issues
Expand Down
18 changes: 9 additions & 9 deletions xml-sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin URI: http://status301.net/wordpress-plugins/xml-sitemap-feed/
Description: Feed the hungry spiders in compliance with the XML Sitemap and Google News protocols. Happy with the results? Please leave me a <strong><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ravanhagen%40gmail%2ecom&item_name=XML%20Sitemap%20Feed&item_number=4%2e0&no_shipping=0&tax=0&bn=PP%2dDonationsBF&charset=UTF%2d8&lc=us">tip</a></strong> for continued development and support. Thanks :)
Text Domain: xml-sitemap-feed
Version: 4.7.3
Version: 4.7.4
Author: RavanH
Author URI: http://status301.net/
*/
Expand All @@ -28,22 +28,22 @@
* --------------------
*
* FILTERS
* xmlsf_defaults -> Filters the default array values for different option groups.
* xmlsf_allowed_domain -> Filters the response when checking the url against allowed domains.
* xmlsf_defaults -> Filters the default array values for different option groups.
* xmlsf_allowed_domain -> Filters the response when checking the url against allowed domains.
* Passes variable $url; must return true or false.
* xmlsf_excluded -> Filters the response when checking the post for exclusion flags.
* xmlsf_excluded -> Filters the response when checking the post for exclusion flags.
* Passes variable $post_id; must return true or false.
* the_title_xmlsitemap -> Filters the Google News publication name, title and keywords
* the_title_xmlsitemap -> Filters the Google News publication name, title and keywords
* plus the Image title and caption tags
* xmlsf_custom_urls -> Filters the custom urls array
* xmlsf_custom_sitemaps -> Filters the custom sitemaps array
* xmlsf_custom_urls -> Filters the custom urls array
* xmlsf_custom_sitemaps -> Filters the custom sitemaps array
*
* ACTIONS
* xmlsf_news_tags_after -> Fired inside the Google News Sitemap loop at the end of the news
* xmlsf_news_tags_after -> Fired inside the Google News Sitemap loop at the end of the news
* tags, just before each closing </news:news> is generated. Can be used to
* echo custom tags or trigger another action in the background.
*
* feel free to request, suggest or submit more :)
* Feel free to request, suggest or submit more :)
*/

if ( ! defined( 'WPINC' ) ) die;
Expand Down

0 comments on commit 78eac0f

Please sign in to comment.