WP_Debug_Data::get_wp_active_theme()private staticWP 6.7.0

Gets the WordPress active theme section of the debug data.

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

Хуки из метода

Возвращает

Массив.

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

$result = WP_Debug_Data::get_wp_active_theme(): array;

Заметки

  • Global. Массив. $_wp_theme_features

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

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

Код WP_Debug_Data::get_wp_active_theme() WP 6.7.1

private static function get_wp_active_theme(): array {
	global $_wp_theme_features;

	// Populate the section for the currently active theme.
	$theme_features = array();

	if ( ! empty( $_wp_theme_features ) ) {
		foreach ( $_wp_theme_features as $feature => $options ) {
			$theme_features[] = $feature;
		}
	}

	$active_theme  = wp_get_theme();
	$theme_updates = get_theme_updates();
	$transient     = get_site_transient( 'update_themes' );

	$active_theme_version       = $active_theme->version;
	$active_theme_version_debug = $active_theme_version;

	$auto_updates         = array();
	$auto_updates_enabled = wp_is_auto_update_enabled_for_type( 'theme' );
	if ( $auto_updates_enabled ) {
		$auto_updates = (array) get_site_option( 'auto_update_themes', array() );
	}

	if ( array_key_exists( $active_theme->stylesheet, $theme_updates ) ) {
		$theme_update_new_version = $theme_updates[ $active_theme->stylesheet ]->update['new_version'];

		/* translators: %s: Latest theme version number. */
		$active_theme_version       .= ' ' . sprintf( __( '(Latest version: %s)' ), $theme_update_new_version );
		$active_theme_version_debug .= sprintf( ' (latest version: %s)', $theme_update_new_version );
	}

	$active_theme_author_uri = $active_theme->display( 'AuthorURI' );

	if ( $active_theme->parent_theme ) {
		$active_theme_parent_theme = sprintf(
			/* translators: 1: Theme name. 2: Theme slug. */
			__( '%1$s (%2$s)' ),
			$active_theme->parent_theme,
			$active_theme->template
		);
		$active_theme_parent_theme_debug = sprintf(
			'%s (%s)',
			$active_theme->parent_theme,
			$active_theme->template
		);
	} else {
		$active_theme_parent_theme       = __( 'None' );
		$active_theme_parent_theme_debug = 'none';
	}

	$fields = array(
		'name'           => array(
			'label' => __( 'Name' ),
			'value' => sprintf(
				/* translators: 1: Theme name. 2: Theme slug. */
				__( '%1$s (%2$s)' ),
				$active_theme->name,
				$active_theme->stylesheet
			),
		),
		'version'        => array(
			'label' => __( 'Version' ),
			'value' => $active_theme_version,
			'debug' => $active_theme_version_debug,
		),
		'author'         => array(
			'label' => __( 'Author' ),
			'value' => wp_kses( $active_theme->author, array() ),
		),
		'author_website' => array(
			'label' => __( 'Author website' ),
			'value' => ( $active_theme_author_uri ? $active_theme_author_uri : __( 'Undefined' ) ),
			'debug' => ( $active_theme_author_uri ? $active_theme_author_uri : '(undefined)' ),
		),
		'parent_theme'   => array(
			'label' => __( 'Parent theme' ),
			'value' => $active_theme_parent_theme,
			'debug' => $active_theme_parent_theme_debug,
		),
		'theme_features' => array(
			'label' => __( 'Theme features' ),
			'value' => implode( ', ', $theme_features ),
		),
		'theme_path'     => array(
			'label' => __( 'Theme directory location' ),
			'value' => get_stylesheet_directory(),
		),
	);

	if ( $auto_updates_enabled ) {
		if ( isset( $transient->response[ $active_theme->stylesheet ] ) ) {
			$item = $transient->response[ $active_theme->stylesheet ];
		} elseif ( isset( $transient->no_update[ $active_theme->stylesheet ] ) ) {
			$item = $transient->no_update[ $active_theme->stylesheet ];
		} else {
			$item = array(
				'theme'        => $active_theme->stylesheet,
				'new_version'  => $active_theme->version,
				'url'          => '',
				'package'      => '',
				'requires'     => '',
				'requires_php' => '',
			);
		}

		$auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, (object) $item );

		if ( ! is_null( $auto_update_forced ) ) {
			$enabled = $auto_update_forced;
		} else {
			$enabled = in_array( $active_theme->stylesheet, $auto_updates, true );
		}

		if ( $enabled ) {
			$auto_updates_string = __( 'Enabled' );
		} else {
			$auto_updates_string = __( 'Disabled' );
		}

		/** This filter is documented in wp-admin/includes/class-wp-debug-data.php */
		$auto_updates_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $active_theme, $enabled );

		$fields['auto_update'] = array(
			'label' => __( 'Auto-updates' ),
			'value' => $auto_updates_string,
			'debug' => $auto_updates_string,
		);
	}

	return array(
		'label'  => __( 'Active Theme' ),
		'fields' => $fields,
	);
}