wppaste
WordPress

_get_plugin_data_markup_translate( string $plugin_file, array $plugin_data, bool $markup = true, bool $translate = true ): array

Since
2.7.0
Source
wp-admin/includes/plugin.php:140
Sanitizes plugin data, optionally adds markup, optionally translates.

Compatibility

WordPress
since 2.7.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.

Parameters

$plugin_filestring
Path to the main plugin file.
$plugin_dataarray
An array of plugin data. See get_plugin_data().
$markupbooloptional
If the returned data should have HTML markup applied.
Default true.Default: true
$translatebooloptional
If the returned data should be translated. Default true.Default: true

Return value

array
Plugin data. Values will be empty if not supplied by the plugin.
See get_plugin_data() for the list of possible values.

Performance profile

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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
65–131

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
4

4 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 _get_plugin_data_markup_translate()

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

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

WhenInstructionsCalls it makes
always65plugin_basename(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url()
$plugin_data && is_textdomain_loaded()72–75plugin_basename(), is_textdomain_loaded(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url()
!$plugin_data73–77plugin_basename(), basename(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url()
!$plugin_data78–98plugin_basename(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url(), wptexturize()
$plugin_data && !is_textdomain_loaded()81–86plugin_basename(), is_textdomain_loaded(), load_plugin_textdomain(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url()
is_textdomain_loaded()85–108plugin_basename(), is_textdomain_loaded(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url(), wptexturize()
!$plugin_data86–110plugin_basename(), basename(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url(), wptexturize()
$plugin_data90–110plugin_basename(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url(), wptexturize(), __(), sprintf()
!is_textdomain_loaded()94–119plugin_basename(), is_textdomain_loaded(), load_plugin_textdomain(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url(), wptexturize()
$plugin_data && is_textdomain_loaded()97–120plugin_basename(), is_textdomain_loaded(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url(), wptexturize(), __(), sprintf()
always98–122plugin_basename(), basename(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url(), wptexturize(), __(), sprintf()
$plugin_data && !is_textdomain_loaded()106–131plugin_basename(), is_textdomain_loaded(), load_plugin_textdomain(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url(), wptexturize(), __(), sprintf()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev15565–13115
8.515565–13115
8.415565–131154 fewer instructions than PHP 8.3
8.315965–13315
8.215965–13315
8.115965–13315
7.415965–13315

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 · 8

Used by · 4

Source code

function _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup = true, $translate = true ) { 	// Sanitize the plugin filename to a WP_PLUGIN_DIR relative path.	$plugin_file = plugin_basename( $plugin_file ); 	// Translate fields.	if ( $translate ) {		$textdomain = $plugin_data['TextDomain'];		if ( $textdomain ) {			if ( ! is_textdomain_loaded( $textdomain ) ) {				if ( $plugin_data['DomainPath'] ) {					load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) . $plugin_data['DomainPath'] );				} else {					load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) );				}			}		} elseif ( 'hello.php' === basename( $plugin_file ) ) {			$textdomain = 'default';		}		if ( $textdomain ) {			foreach ( array( 'Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version' ) as $field ) {				if ( ! empty( $plugin_data[ $field ] ) ) {					// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain					$plugin_data[ $field ] = translate( $plugin_data[ $field ], $textdomain );				}			}		}	} 	// Sanitize fields.	$allowed_tags_in_links = array(		'abbr'    => array( 'title' => true ),		'acronym' => array( 'title' => true ),		'code'    => true,		'em'      => true,		'strong'  => true,	); 	$allowed_tags      = $allowed_tags_in_links;	$allowed_tags['a'] = array(		'href'  => true,		'title' => true,	); 	/*	 * Name is marked up inside <a> tags. Don't allow these.	 * Author is too, but some plugins have used <a> here (omitting Author URI).	 */	$plugin_data['Name']   = wp_kses( $plugin_data['Name'], $allowed_tags_in_links );	$plugin_data['Author'] = wp_kses( $plugin_data['Author'], $allowed_tags ); 	$plugin_data['Description'] = wp_kses( $plugin_data['Description'], $allowed_tags );	$plugin_data['Version']     = wp_kses( $plugin_data['Version'], $allowed_tags ); 	$plugin_data['PluginURI'] = esc_url( $plugin_data['PluginURI'] );	$plugin_data['AuthorURI'] = esc_url( $plugin_data['AuthorURI'] ); 	$plugin_data['Title']      = $plugin_data['Name'];	$plugin_data['AuthorName'] = $plugin_data['Author']; 	// Apply markup.	if ( $markup ) {		if ( $plugin_data['PluginURI'] && $plugin_data['Name'] ) {			$plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '">' . $plugin_data['Name'] . '</a>';		} 		if ( $plugin_data['AuthorURI'] && $plugin_data['Author'] ) {			$plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>';		} 		$plugin_data['Description'] = wptexturize( $plugin_data['Description'] ); 		if ( $plugin_data['Author'] ) {			$plugin_data['Description'] .= sprintf(				/* translators: %s: Plugin author. */				' <cite>' . __( 'By %s.' ) . '</cite>',				$plugin_data['Author']			);		}	}

Changelog

Introduced in 2.7.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-admin/includes/plugin.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.