wppaste
WordPress

twentyseventeen_get_svg( array $args = array() ): string

Source
wp-content/themes/twentyseventeen/inc/icon-functions.php:36
Returns SVG markup.

Compatibility

WordPress
core
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.

Parameters

$argsarrayoptional
Parameters needed to display an SVG.Default: array()
  • $iconstring

    Required SVG icon filename.
  • $titlestring

    Optional SVG title.
  • $descstring

    Optional SVG description.

Return value

string
SVG markup.

Performance profile

How much work a call to twentyseventeen_get_svg() 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
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

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

Instructions
8–91

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 101.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
5

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

What it touches

  • hookthird-party callbacksapply_filters()one call below twentyseventeen_get_svg()

Further down the call graph this can also reach option, 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 · 13 distinct outcomes

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

WhenInstructionsCalls it makes
always8–11__()
!empty($args) && !$args47wp_parse_args(), esc_attr(), esc_html(), esc_html()
!empty($args)55wp_parse_args(), esc_attr(), esc_html(), esc_html(), esc_attr()
!empty($args)56–61wp_parse_args(), twentyseventeen_unique_id(), esc_attr(), esc_html(), esc_html()
!empty($args)59wp_parse_args(), esc_attr(), esc_html(), esc_html(), esc_html()
!empty($args)64–69wp_parse_args(), twentyseventeen_unique_id(), esc_attr(), esc_html(), esc_html(), esc_attr()
!empty($args)67wp_parse_args(), esc_attr(), esc_html(), esc_html(), esc_html(), esc_attr()
!empty($args)68–73wp_parse_args(), twentyseventeen_unique_id(), esc_attr(), esc_html(), esc_html(), esc_html()
!empty($args)69wp_parse_args(), esc_attr(), esc_html(), esc_html(), esc_html(), esc_html()
!empty($args)76–81wp_parse_args(), twentyseventeen_unique_id(), esc_attr(), esc_html(), esc_html(), esc_html(), esc_attr()
!empty($args)77wp_parse_args(), esc_attr(), esc_html(), esc_html(), esc_html(), esc_html(), esc_attr()
!empty($args)78–83wp_parse_args(), twentyseventeen_unique_id(), esc_attr(), esc_html(), esc_html(), esc_html(), esc_html()
1 further outcome, up to 91 instructions
!empty($args) && $args86–91wp_parse_args(), twentyseventeen_unique_id(), esc_attr(), esc_html(), esc_html(), esc_html(), esc_html(), esc_attr()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 101 instructions, 8–91 executed per call, 7 branches. The work does not change between versions.

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.

Uses · 5

Used by · 5

Source code

function twentyseventeen_get_svg( $args = array() ) {	// Make sure $args are an array.	if ( empty( $args ) ) {		return __( 'Please define default parameters in the form of an array.', 'twentyseventeen' );	} 	// Define an icon.	if ( false === array_key_exists( 'icon', $args ) ) {		return __( 'Please define an SVG icon filename.', 'twentyseventeen' );	} 	// Set defaults.	$defaults = array(		'icon'     => '',		'title'    => '',		'desc'     => '',		'fallback' => false,	); 	// Parse args.	$args = wp_parse_args( $args, $defaults ); 	// Set aria hidden.	$aria_hidden = ' aria-hidden="true"'; 	// Set ARIA.	$aria_labelledby = ''; 	/*	 * Twenty Seventeen doesn't use the SVG title or description attributes; non-decorative icons are described with .screen-reader-text.	 *	 * However, child themes can use the title and description to add information to non-decorative SVG icons to improve accessibility.	 *	 * Example 1 with title: <?php echo twentyseventeen_get_svg( array( 'icon' => 'arrow-right', 'title' => __( 'This is the title', 'textdomain' ) ) ); ?>	 *	 * Example 2 with title and description: <?php echo twentyseventeen_get_svg( array( 'icon' => 'arrow-right', 'title' => __( 'This is the title', 'textdomain' ), 'desc' => __( 'This is the description', 'textdomain' ) ) ); ?>	 *	 * See https://www.paciellogroup.com/blog/2013/12/using-aria-enhance-svg-accessibility/.	 */	if ( $args['title'] ) {		$aria_hidden     = '';		$unique_id       = twentyseventeen_unique_id();		$aria_labelledby = ' aria-labelledby="title-' . $unique_id . '"'; 		if ( $args['desc'] ) {			$aria_labelledby = ' aria-labelledby="title-' . $unique_id . ' desc-' . $unique_id . '"';		}	} 	// Begin SVG markup.	$svg = '<svg class="icon icon-' . esc_attr( $args['icon'] ) . '"' . $aria_hidden . $aria_labelledby . ' role="img">'; 	// Display the title.	if ( $args['title'] ) {		$svg .= '<title id="title-' . $unique_id . '">' . esc_html( $args['title'] ) . '</title>'; 		// Display the desc only if the title is already set.		if ( $args['desc'] ) {			$svg .= '<desc id="desc-' . $unique_id . '">' . esc_html( $args['desc'] ) . '</desc>';		}	} 	/*	 * Display the icon.	 *	 * The whitespace around `<use>` is intentional - it is a work around to a keyboard navigation bug in Safari 10.	 *	 * See https://core.trac.wordpress.org/ticket/38387.	 */	$svg .= ' <use href="#icon-' . esc_html( $args['icon'] ) . '" xlink:href="#icon-' . esc_html( $args['icon'] ) . '"></use> '; 	// Add some markup to use as a fallback for browsers that do not support SVGs.	if ( $args['fallback'] ) {		$svg .= '<span class="svg-fallback icon-' . esc_attr( $args['icon'] ) . '"></span>';	} 	$svg .= '</svg>'; 	return $svg;}

Changelog

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 7.1.0 tag, from src/wp-content/themes/twentyseventeen/inc/icon-functions.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.