WP_REST_Templates_Controller::get_wp_templates_original_source_field()private staticWP 6.5.0

Returns the source from where the template originally comes from.

Метод класса: WP_REST_Templates_Controller{}

Хуков нет.

Возвращает

Строку. Original source of the template one of theme, plugin, site, or user.

Использование

$result = WP_REST_Templates_Controller::get_wp_templates_original_source_field( $template_object );
$template_object(WP_Block_Template) (обязательный)
Template instance.

Список изменений

С версии 6.5.0 Введена.

Код WP_REST_Templates_Controller::get_wp_templates_original_source_field() WP 6.7.1

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';
}