Skip to content

Commit f4350cd

Browse files
committed
Sitemaps: Remove XSL stylesheets.
Browser support for client-side XSLT is being deprecated and removed. For sites including an XSL stylesheet, the display of the XML sitemaps may fail. This removes the stylesheets in favour of allowing browsers to render them as they will. This change deprecates: * `WP_Sitemaps_Renderer::$stylesheet` * `WP_Sitemaps_Renderer::$stylesheet_index` * `WP_Sitemaps_Renderer::get_sitemap_stylesheet_url()` * `WP_Sitemaps_Renderer::get_sitemap_index_stylesheet_url()` * `WP_Sitemaps_Stylesheet` in its entirety * the `sitemap-stylesheet` rewrite tag * the `sitemap-stylesheet` query variable * the `*.xls` rewrite rules * the `wp_sitemaps_stylesheet_url` filter * the `wp_sitemaps_stylesheet_index_url` filter * the `wp_sitemaps_stylesheet_index_content` filter * the `wp_sitemaps_stylesheet_content` filter * the `wp_sitemaps_stylesheet_css` filter The outcome of the deprecated filters is ignored, the filters are now only fired in order to provide deprecation notices to developers. Developed in #12448 Props masteradhoc, pbiron, westonruter, peterwilsoncc. Fixes #65593. git-svn-id: https://develop.svn.wordpress.org/trunk@64073 602fd350-edb4-49c9-b593-d223f7449a82
1 parent d1b25df commit f4350cd

13 files changed

Lines changed: 235 additions & 534 deletions

File tree

‎src/wp-includes/canonical.php‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,7 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) {
707707
}
708708

709709
// Remove trailing slash for robots.txt or sitemap requests.
710-
if ( is_robots()
711-
|| ! empty( get_query_var( 'sitemap' ) ) || ! empty( get_query_var( 'sitemap-stylesheet' ) )
712-
) {
710+
if ( is_robots() || ! empty( get_query_var( 'sitemap' ) ) ) {
713711
$redirect['path'] = untrailingslashit( $redirect['path'] );
714712
}
715713

‎src/wp-includes/class-wp.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ public function handle_404() {
748748

749749
// Never 404 here for the admin, robots, favicon, or sitemaps.
750750
// Sitemap routes send their own status in WP_Sitemaps::render_sitemaps().
751-
if ( is_admin() || is_robots() || is_favicon() || is_sitemap() || get_query_var( 'sitemap-stylesheet' ) ) {
751+
if ( is_admin() || is_robots() || is_favicon() || is_sitemap() ) {
752752
$set_404 = false;
753753

754754
// If posts were found, check for paged content.

‎src/wp-includes/sitemaps/class-wp-sitemaps-renderer.php‎

Lines changed: 78 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class WP_Sitemaps_Renderer {
2020
* XSL stylesheet for styling a sitemap for web browsers.
2121
*
2222
* @since 5.5.0
23+
* @deprecated 7.2.0 Stylesheets are no longer supported.
2324
*
2425
* @var string
2526
*/
@@ -29,6 +30,7 @@ class WP_Sitemaps_Renderer {
2930
* XSL stylesheet for styling a sitemap for web browsers.
3031
*
3132
* @since 5.5.0
33+
* @deprecated 7.2.0 Stylesheets are no longer supported.
3234
*
3335
* @var string
3436
*/
@@ -38,81 +40,64 @@ class WP_Sitemaps_Renderer {
3840
* WP_Sitemaps_Renderer constructor.
3941
*
4042
* @since 5.5.0
43+
* @since 7.2.0 No longer sets up the stylesheets, which are no longer supported.
4144
*/
42-
public function __construct() {
43-
$stylesheet_url = $this->get_sitemap_stylesheet_url();
44-
45-
if ( $stylesheet_url ) {
46-
$this->stylesheet = '<?xml-stylesheet type="text/xsl" href="' . esc_url( $stylesheet_url ) . '" ?>';
47-
}
48-
49-
$stylesheet_index_url = $this->get_sitemap_index_stylesheet_url();
50-
51-
if ( $stylesheet_index_url ) {
52-
$this->stylesheet_index = '<?xml-stylesheet type="text/xsl" href="' . esc_url( $stylesheet_index_url ) . '" ?>';
53-
}
54-
}
45+
public function __construct() {}
5546

5647
/**
5748
* Gets the URL for the sitemap stylesheet.
5849
*
5950
* @since 5.5.0
51+
* @deprecated 7.2.0 Stylesheets are no longer supported.
6052
*
61-
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
62-
*
63-
* @return string The sitemap stylesheet URL.
53+
* @return string Empty string.
6454
*/
6555
public function get_sitemap_stylesheet_url() {
66-
global $wp_rewrite;
67-
68-
$sitemap_url = home_url( '/wp-sitemap.xsl' );
69-
70-
if ( ! $wp_rewrite->using_permalinks() ) {
71-
$sitemap_url = home_url( '/?sitemap-stylesheet=sitemap' );
72-
}
56+
_deprecated_function( __METHOD__, '7.2.0' );
7357

7458
/**
7559
* Filters the URL for the sitemap stylesheet.
7660
*
7761
* If a falsey value is returned, no stylesheet will be used and
78-
* the "raw" XML of the sitemap will be displayed.
62+
* Following the deprecation of XSLT by browser manufacturers the
63+
* outcome of this filter is ignored.
7964
*
8065
* @since 5.5.0
66+
* @deprecated 7.2.0 Stylesheets are no longer supported.
8167
*
8268
* @param string $sitemap_url Full URL for the sitemaps XSL file.
8369
*/
84-
return apply_filters( 'wp_sitemaps_stylesheet_url', $sitemap_url );
70+
apply_filters_deprecated( 'wp_sitemaps_stylesheet_url', array( '' ), '7.2.0' );
71+
72+
return '';
8573
}
8674

8775
/**
8876
* Gets the URL for the sitemap index stylesheet.
8977
*
9078
* @since 5.5.0
79+
* @deprecated 7.2.0 Stylesheets are no longer supported.
9180
*
92-
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
93-
*
94-
* @return string The sitemap index stylesheet URL.
81+
* @return string Empty string.
9582
*/
9683
public function get_sitemap_index_stylesheet_url() {
97-
global $wp_rewrite;
98-
99-
$sitemap_url = home_url( '/wp-sitemap-index.xsl' );
100-
101-
if ( ! $wp_rewrite->using_permalinks() ) {
102-
$sitemap_url = home_url( '/?sitemap-stylesheet=index' );
103-
}
84+
_deprecated_function( __METHOD__, '7.2.0' );
10485

10586
/**
10687
* Filters the URL for the sitemap index stylesheet.
10788
*
10889
* If a falsey value is returned, no stylesheet will be used and
109-
* the "raw" XML of the sitemap index will be displayed.
90+
* Following the deprecation of XSLT by browser manufacturers the
91+
* outcome of this filter is ignored.
11092
*
11193
* @since 5.5.0
94+
* @deprecated 7.2.0 Stylesheets are no longer supported.
11295
*
11396
* @param string $sitemap_url Full URL for the sitemaps index XSL file.
11497
*/
115-
return apply_filters( 'wp_sitemaps_stylesheet_index_url', $sitemap_url );
98+
apply_filters_deprecated( 'wp_sitemaps_stylesheet_index_url', array( '' ), '7.2.0' );
99+
100+
return '';
116101
}
117102

118103
/**
@@ -144,11 +129,12 @@ public function render_index( $sitemaps ) {
144129
* @return string|false A well-formed XML string for a sitemap index. False on error.
145130
*/
146131
public function get_sitemap_index_xml( $sitemaps ) {
132+
$this->apply_deprecated_stylesheet_filters( 'index' );
133+
147134
$sitemap_index = new SimpleXMLElement(
148135
sprintf(
149-
'%1$s%2$s%3$s',
136+
'%1$s%2$s',
150137
'<?xml version="1.0" encoding="UTF-8" ?>',
151-
$this->stylesheet_index,
152138
'<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" />'
153139
)
154140
);
@@ -208,11 +194,12 @@ public function render_sitemap( $url_list ) {
208194
* @return string|false A well-formed XML string for a sitemap index. False on error.
209195
*/
210196
public function get_sitemap_xml( $url_list ) {
197+
$this->apply_deprecated_stylesheet_filters( 'sitemap' );
198+
211199
$urlset = new SimpleXMLElement(
212200
sprintf(
213-
'%1$s%2$s%3$s',
201+
'%1$s%2$s',
214202
'<?xml version="1.0" encoding="UTF-8" ?>',
215-
$this->stylesheet,
216203
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" />'
217204
)
218205
);
@@ -243,6 +230,56 @@ public function get_sitemap_xml( $url_list ) {
243230
return $urlset->asXML();
244231
}
245232

233+
/**
234+
* Applies the removed stylesheet filters so that their callbacks trigger deprecation notices.
235+
*
236+
* The stylesheet filters no longer have any effect. Applying them where a sitemap is
237+
* generated ensures a callback still added to one is reported rather than silently ignored.
238+
* No notice is triggered for a filter that has no callbacks.
239+
*
240+
* @since 7.2.0
241+
*
242+
* @param 'sitemap'|'index' $type Sitemap type.
243+
*/
244+
private function apply_deprecated_stylesheet_filters( string $type ): void {
245+
if ( 'index' === $type ) {
246+
/** This filter is documented in wp-includes/sitemaps/class-wp-sitemaps-renderer.php */
247+
apply_filters_deprecated( 'wp_sitemaps_stylesheet_index_url', array( '' ), '7.2.0' );
248+
249+
/**
250+
* Filters the content of the sitemap index stylesheet.
251+
*
252+
* Following the deprecation of XSLT by browser manufacturers the
253+
* outcome of this filter is ignored.
254+
*
255+
* @since 5.5.0
256+
* @deprecated 7.2.0 Stylesheets are no longer supported.
257+
*
258+
* @param string $xsl_content Full content for the XML stylesheet.
259+
*/
260+
apply_filters_deprecated( 'wp_sitemaps_stylesheet_index_content', array( '' ), '7.2.0' );
261+
} else {
262+
/** This filter is documented in wp-includes/sitemaps/class-wp-sitemaps-renderer.php */
263+
apply_filters_deprecated( 'wp_sitemaps_stylesheet_url', array( '' ), '7.2.0' );
264+
265+
/**
266+
* Filters the content of the sitemap stylesheet.
267+
*
268+
* Following the deprecation of XSLT by browser manufacturers the
269+
* outcome of this filter is ignored.
270+
*
271+
* @since 5.5.0
272+
* @deprecated 7.2.0 Stylesheets are no longer supported.
273+
*
274+
* @param string $xsl_content Full content for the XML stylesheet.
275+
*/
276+
apply_filters_deprecated( 'wp_sitemaps_stylesheet_content', array( '' ), '7.2.0' );
277+
}
278+
279+
/** This filter is documented in wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php */
280+
apply_filters_deprecated( 'wp_sitemaps_stylesheet_css', array( '' ), '7.2.0' );
281+
}
282+
246283
/**
247284
* Checks for the availability of the SimpleXML extension and errors if missing.
248285
*

0 commit comments

Comments
 (0)