WP_REST_Templates_Controller::get_wp_templates_author_text_field( WP_Block_Template $template_object ): string
- Since
- 6.5.0
- Source
wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php:897
Compatibility
- WordPress
- since 6.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.
Parameters
$template_objectWP_Block_Template- Template instance.
Return value
string- Human readable text for the author.
Performance profile
How much work a call to WP_REST_Templates_Controller::get_wp_templates_author_text_field() 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
- Heavy
- Scaling
- Scales with input
- Instructions
- 7–66
- Plugin surface
- None
- Called by
- 1
Reaches the database via get_user_by().
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 112.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_user_by()called directly - optionoption read or write
get_option()one call below WP_REST_Templates_Controller::get_wp_templates_author_text_field() - cacheobject cache
wp_cache_get()one call below WP_REST_Templates_Controller::get_wp_templates_author_text_field() - hookthird-party callbacks
apply_filters()one call below WP_REST_Templates_Controller::get_wp_templates_author_text_field()
Further down the call graph this can also reach 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 · 9 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_REST_Templates_Controller::get_wp_templates_author_text_field() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 7–15 | ::get_wp_templates_original_source_field() |
| always | 10–16 | ::get_wp_templates_original_source_field(), get_bloginfo() |
| always | 18–21 | ::get_wp_templates_original_source_field(), wp_get_theme(), ->get() |
| always | 18–26 | ::get_wp_templates_original_source_field(), get_user_by(), ->get() |
| always | 18–26 | ::get_wp_templates_original_source_field(), get_user_by(), __() |
!isset($template_object) | 29–40 | ::get_wp_templates_original_source_field(), function_exists(), get_plugins(), sanitize_text_field(), plugin_basename() |
isset($template_object) | 34–46 | ::get_wp_templates_original_source_field(), function_exists(), wp_get_active_and_valid_plugins(), get_plugins(), sanitize_text_field(), plugin_basename() |
isset($template_object) && !$plugins && $plugin_slug === false && !empty($plugin_data) | 40–47 | ::get_wp_templates_original_source_field(), function_exists(), wp_get_active_and_valid_plugins(), plugin_basename(), explode(), get_plugin_data() |
isset($template_object) && !$plugins && $plugin_slug === false && empty($plugin_data) | 55–66 | ::get_wp_templates_original_source_field(), function_exists(), wp_get_active_and_valid_plugins(), plugin_basename(), explode(), get_plugin_data(), get_plugins(), sanitize_text_field(), plugin_basename() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 112 | 7–66 | 16 | |
| 8.5 | 112 | 7–66 | 16 | |
| 8.4 | 112 | 7–66 | 16 | |
| 8.3 | 112 | 7–66 | 16 | |
| 8.2 | 112 | 7–66 | 16 | |
| 8.1 | 112 | 7–66 | 16 | Different branch profile from PHP 7.4 |
| 7.4 | 112 | 7–67 | 16 |
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 · 11
- wp_get_theme()Gets a WP_Theme object for a theme.
- wp_get_active_and_valid_plugins()Retrieves an array of active and valid plugin files.
- plugin_basename()Gets the basename of a plugin.
- get_plugin_data()Parses the plugin contents to retrieve plugin's metadata.
- get_plugins()Checks the plugins directory and retrieve all plugin files with plugin data.
- sanitize_text_field()Sanitizes a string from user input or from the database.
- get_bloginfo()Retrieves information about the current site.
- get_user_by()Retrieves user info by a given field.
- __()Retrieves the translation of $text.
- WP_REST_Templates_Controller::get_wp_templates_original_source_field()Returns the source from where the template originally comes from.
- wp_get_theme($template_object->theme)::get()
Used by · 1
- WP_REST_Templates_Controller::prepare_item_for_response()Prepare a single template output for response
Source code
private static function get_wp_templates_author_text_field( $template_object ) { $original_source = self::get_wp_templates_original_source_field( $template_object ); switch ( $original_source ) { case 'theme': $theme_name = wp_get_theme( $template_object->theme )->get( 'Name' ); return empty( $theme_name ) ? $template_object->theme : $theme_name; case 'plugin': if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } if ( isset( $template_object->plugin ) ) { $plugins = wp_get_active_and_valid_plugins(); foreach ( $plugins as $plugin_file ) { $plugin_basename = plugin_basename( $plugin_file ); // Split basename by '/' to get the plugin slug. list( $plugin_slug, ) = explode( '/', $plugin_basename ); if ( $plugin_slug === $template_object->plugin ) { $plugin_data = get_plugin_data( $plugin_file ); if ( ! empty( $plugin_data['Name'] ) ) { return $plugin_data['Name']; } break; } } } /* * Fall back to the theme name if the plugin is not defined. That's needed to keep backwards * compatibility with templates that were registered before the plugin attribute was added. */ $plugins = get_plugins(); $plugin_basename = plugin_basename( sanitize_text_field( $template_object->theme . '.php' ) ); if ( isset( $plugins[ $plugin_basename ] ) && isset( $plugins[ $plugin_basename ]['Name'] ) ) { return $plugins[ $plugin_basename ]['Name']; } return $template_object->plugin ?? $template_object->theme; case 'site': return get_bloginfo( 'name' ); case 'user': $author = get_user_by( 'id', $template_object->author ); if ( ! $author ) { return __( 'Unknown author' ); } return $author->get( 'display_name' ); } // Fail-safe to return a string should the original source ever fall through. return ''; }Changelog
Introduced in 6.5.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 7.1.0 tag, from
src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.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.