wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes



_get_block_template_file › WordPress Function

Depuis5.9.0
Dépréciéen/a
_get_block_template_file ( $template_type, $slug )
Accès:
  • private
Paramètres: (2)
  • (string) $template_type Template type. Either 'wp_template' or 'wp_template_part'.
    Requis: Oui
  • (string) $slug Template slug.
    Requis: Oui
Retourne:
  • (array|null) { Array with template metadata if $template_type is one of 'wp_template' or 'wp_template_part', null otherwise. @type string $slug Template slug. @type string $path Template file path. @type string $theme Theme slug. @type string $type Template type. @type string $area Template area. Only for 'wp_template_part'. @type string $title Optional. Template title. @type string[] $postTypes Optional. List of post types that the template supports. Only for 'wp_template'. }
Défini(e) dans:
Codex:

Retrieves the template file from the theme for a given slug.



Source

function _get_block_template_file( $template_type, $slug ) {
	if ( 'wp_template' !== $template_type && 'wp_template_part' !== $template_type ) {
		return null;
	}

	$themes = array(
		get_stylesheet() => get_stylesheet_directory(),
		get_template()   => get_template_directory(),
	);
	foreach ( $themes as $theme_slug => $theme_dir ) {
		$template_base_paths = get_block_theme_folders( $theme_slug );
		$file_path           = $theme_dir . '/' . $template_base_paths[ $template_type ] . '/' . $slug . '.html';
		if ( file_exists( $file_path ) ) {
			$new_template_item = array(
				'slug'  => $slug,
				'path'  => $file_path,
				'theme' => $theme_slug,
				'type'  => $template_type,
			);

			if ( 'wp_template_part' === $template_type ) {
				return _add_block_template_part_area_info( $new_template_item );
			}

			if ( 'wp_template' === $template_type ) {
				return _add_block_template_info( $new_template_item );
			}

			return $new_template_item;
		}
	}

	return null;
}