wppaste
WordPress

WP_Sitemaps_Stylesheet::get_sitemap_stylesheet()

Since
5.5.0
Source
wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php:45
Returns the escaped XSL for all sitemaps, except index.

Compatibility

WordPress
since 5.5.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Performance profile

How much work a call to WP_Sitemaps_Stylesheet::get_sitemap_stylesheet() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Moderate

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
105

Executed per call on PHP 8.5. The body compiles to 105.

Plugin surface
1 hook

Third-party callbacks on 'wp_sitemaps_stylesheet_content' run inside this call, and their cost is not bounded by anything here.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • optionoption read or writeget_option()one call below WP_Sitemaps_Stylesheet::get_sitemap_stylesheet()

Further down the call graph this can also reach cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 1 distinct outcome

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Sitemaps_Stylesheet::get_sitemap_stylesheet() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always105->get_stylesheet_css(), __(), esc_xml(), __(), esc_xml(), __(), esc_url(), __(), esc_xml(), __(), esc_xml(), sprintf(), get_language_attributes(), __(), esc_xml(), __(), esc_xml(), __(), esc_xml(), __(), esc_xml(), apply_filters()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev1051050
8.51051050
8.410510501 fewer instruction than PHP 8.3
8.31061060
8.21061060
8.11061060
7.41061060

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while WP_Sitemaps_Stylesheet::get_sitemap_stylesheet() runs, in this order:

  1. apply_filters( wp_sitemaps_stylesheet_content )filterline 151 (+106 into the body)

    Filters the content of the sitemap stylesheet.

Uses · 6

Used by · 1

Source code

	public function get_sitemap_stylesheet() {		$css         = $this->get_stylesheet_css();		$title       = esc_xml( __( 'XML Sitemap' ) );		$description = esc_xml( __( 'This XML Sitemap is generated by WordPress to make your content more visible for search engines.' ) );		$learn_more  = sprintf(			'<a href="%s">%s</a>',			esc_url( __( 'https://www.sitemaps.org/' ) ),			esc_xml( __( 'Learn more about XML sitemaps.' ) )		); 		$text = sprintf(			/* translators: %s: Number of URLs. */			esc_xml( __( 'Number of URLs in this XML Sitemap: %s.' ) ),			'<xsl:value-of select="count( sitemap:urlset/sitemap:url )" />'		); 		$lang       = get_language_attributes( 'html' );		$url        = esc_xml( __( 'URL' ) );		$lastmod    = esc_xml( __( 'Last Modified' ) );		$changefreq = esc_xml( __( 'Change Frequency' ) );		$priority   = esc_xml( __( 'Priority' ) ); 		$xsl_content = <<<XSL<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet		version="1.0"		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"		xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"		exclude-result-prefixes="sitemap"		> 	<xsl:output method="html" encoding="UTF-8" indent="yes" /> 	<!--	  Set variables for whether lastmod, changefreq or priority occur for any url in the sitemap.	  We do this up front because it can be expensive in a large sitemap.	  -->	<xsl:variable name="has-lastmod"    select="count( /sitemap:urlset/sitemap:url/sitemap:lastmod )"    />	<xsl:variable name="has-changefreq" select="count( /sitemap:urlset/sitemap:url/sitemap:changefreq )" />	<xsl:variable name="has-priority"   select="count( /sitemap:urlset/sitemap:url/sitemap:priority )"   /> 	<xsl:template match="/">		<html {$lang}>			<head>				<title>{$title}</title>				<style>					{$css}				</style>			</head>			<body>				<div id="sitemap">					<div id="sitemap__header">						<h1>{$title}</h1>						<p>{$description}</p>						<p>{$learn_more}</p>					</div>					<div id="sitemap__content">						<p class="text">{$text}</p>						<table id="sitemap__table">							<thead>								<tr>									<th class="loc">{$url}</th>									<xsl:if test="\$has-lastmod">										<th class="lastmod">{$lastmod}</th>									</xsl:if>									<xsl:if test="\$has-changefreq">										<th class="changefreq">{$changefreq}</th>									</xsl:if>									<xsl:if test="\$has-priority">										<th class="priority">{$priority}</th>									</xsl:if>								</tr>							</thead>							<tbody>								<xsl:for-each select="sitemap:urlset/sitemap:url">									<tr>										<td class="loc"><a href="{sitemap:loc}"><xsl:value-of select="sitemap:loc" /></a></td>										<xsl:if test="\$has-lastmod">											<td class="lastmod"><xsl:value-of select="sitemap:lastmod" /></td>										</xsl:if>

Changelog

Introduced in 5.5.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.