W3cubDocs

/WordPress

WP_REST_Templates_Controller::get_wp_templates_original_source_field( WP_Block_Template $template_object ): string

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 ( '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

Version Description
6.5.0 Introduced.