WP_REST_Templates_Controller::get_wp_templates_original_source_field( WP_Block_Template $template_object ): string

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Returns the source from where the template originally comes from.

Parameters

$template_objectWP_Block_Templaterequired
Template instance.

Return

string Original source of the template one of theme, plugin, site, or user.

Source

private static function get_wp_templates_original_source_field( $template_object ) {
	if ( 'wp_template' === $template_object->type || 'wp_template_part' === $template_object->type ) {
		// Added by theme.
		// Template originally provided by a theme, but customized by a user.
		// Templates originally didn't have the 'origin' field so identify
		// older customized templates by checking for no origin and a 'theme'
		// or 'custom' source.
		if ( $template_object->has_theme_file &&
		( 'theme' === $template_object->origin || (
			empty( $template_object->origin ) && in_array(
				$template_object->source,
				array(
					'theme',
					'custom',
				),
				true
			) )
		)
		) {
			return 'theme';
		}

		// Added by plugin.
		if ( $template_object->has_theme_file && 'plugin' === $template_object->origin ) {
			return 'plugin';
		}

		// Added by site.
		// Template was created from scratch, but has no author. Author support
		// was only added to templates in WordPress 5.9. Fallback to showing the
		// site logo and title.
		if ( empty( $template_object->has_theme_file ) && 'custom' === $template_object->source && empty( $template_object->author ) ) {
			return 'site';
		}
	}

	// Added by user.
	return 'user';
}

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.