wppaste
WordPress

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
Returns a human readable text for the author of the template.

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

Reaches the database via get_user_by().

Scaling
Scales with input

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

Instructions
7–66

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

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

What it touches

  • querycontent queryget_user_by()called directly
  • optionoption read or writeget_option()one call below WP_REST_Templates_Controller::get_wp_templates_author_text_field()
  • cacheobject cachewp_cache_get()one call below WP_REST_Templates_Controller::get_wp_templates_author_text_field()
  • hookthird-party callbacksapply_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.

WhenInstructionsCalls it makes
always7–15::get_wp_templates_original_source_field()
always10–16::get_wp_templates_original_source_field(), get_bloginfo()
always18–21::get_wp_templates_original_source_field(), wp_get_theme(), ->get()
always18–26::get_wp_templates_original_source_field(), get_user_by(), ->get()
always18–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

PHPCompiledExecutedBranchesNotes
8.6-dev1127–6616
8.51127–6616
8.41127–6616
8.31127–6616
8.21127–6616
8.11127–6616Different branch profile from PHP 7.4
7.41127–6716

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

Used by · 1

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.

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