_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
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
- Scaling
- Scales with input
- Instructions
- 65–131
- Plugin surface
- None
- Called by
- 4
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 155.
Nothing here hands control to plugin code.
4 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 65 | plugin_basename(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url() |
$plugin_data && is_textdomain_loaded() | 72–75 | plugin_basename(), is_textdomain_loaded(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url() |
!$plugin_data | 73–77 | plugin_basename(), basename(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url() |
!$plugin_data | 78–98 | plugin_basename(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url(), wptexturize() |
$plugin_data && !is_textdomain_loaded() | 81–86 | plugin_basename(), is_textdomain_loaded(), load_plugin_textdomain(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url() |
is_textdomain_loaded() | 85–108 | plugin_basename(), is_textdomain_loaded(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url(), wptexturize() |
!$plugin_data | 86–110 | plugin_basename(), basename(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url(), wptexturize() |
$plugin_data | 90–110 | plugin_basename(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url(), wptexturize(), __(), sprintf() |
!is_textdomain_loaded() | 94–119 | plugin_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–120 | plugin_basename(), is_textdomain_loaded(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url(), wptexturize(), __(), sprintf() |
| always | 98–122 | plugin_basename(), basename(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url(), wptexturize(), __(), sprintf() |
$plugin_data && !is_textdomain_loaded() | 106–131 | plugin_basename(), is_textdomain_loaded(), load_plugin_textdomain(), wp_kses(), wp_kses(), wp_kses(), wp_kses(), esc_url(), esc_url(), wptexturize(), __(), sprintf() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 155 | 65–131 | 15 | |
| 8.5 | 155 | 65–131 | 15 | |
| 8.4 | 155 | 65–131 | 15 | 4 fewer instructions than PHP 8.3 |
| 8.3 | 159 | 65–133 | 15 | |
| 8.2 | 159 | 65–133 | 15 | |
| 8.1 | 159 | 65–133 | 15 | |
| 7.4 | 159 | 65–133 | 15 |
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
- plugin_basename()Gets the basename of a plugin.
- is_textdomain_loaded()Determines whether there are translations for the text domain.
- load_plugin_textdomain()Loads a plugin's translated strings.
- translate()Retrieves the translation of $text.
- wp_kses()Filters text content and strips out disallowed HTML.
- esc_url()Checks and cleans a URL.
- wptexturize()Replaces common plain text characters with formatted entities.
- __()Retrieves the translation of $text.
Used by · 4
- WP_Plugins_List_Table::prepare_items()
- WP_REST_Plugins_Controller::prepare_item_for_response()Prepares the plugin for the REST response.
- get_plugin_data()Parses the plugin contents to retrieve plugin's metadata.
- list_plugin_updates()Display the upgrade plugins form.
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.
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.