Edit File by line
/home/zeestwma/redstone.../wp-inclu...
File: block-template-utils.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Utilities used to fetch and create templates and template parts.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @since 5.8.0
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
// Define constants for supported wp_template_part_area taxonomy.
[8] Fix | Delete
if ( ! defined( 'WP_TEMPLATE_PART_AREA_HEADER' ) ) {
[9] Fix | Delete
define( 'WP_TEMPLATE_PART_AREA_HEADER', 'header' );
[10] Fix | Delete
}
[11] Fix | Delete
if ( ! defined( 'WP_TEMPLATE_PART_AREA_FOOTER' ) ) {
[12] Fix | Delete
define( 'WP_TEMPLATE_PART_AREA_FOOTER', 'footer' );
[13] Fix | Delete
}
[14] Fix | Delete
if ( ! defined( 'WP_TEMPLATE_PART_AREA_SIDEBAR' ) ) {
[15] Fix | Delete
define( 'WP_TEMPLATE_PART_AREA_SIDEBAR', 'sidebar' );
[16] Fix | Delete
}
[17] Fix | Delete
if ( ! defined( 'WP_TEMPLATE_PART_AREA_UNCATEGORIZED' ) ) {
[18] Fix | Delete
define( 'WP_TEMPLATE_PART_AREA_UNCATEGORIZED', 'uncategorized' );
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* For backward compatibility reasons,
[23] Fix | Delete
* block themes might be using block-templates or block-template-parts,
[24] Fix | Delete
* this function ensures we fallback to these folders properly.
[25] Fix | Delete
*
[26] Fix | Delete
* @since 5.9.0
[27] Fix | Delete
*
[28] Fix | Delete
* @param string $theme_stylesheet The stylesheet. Default is to leverage the main theme root.
[29] Fix | Delete
*
[30] Fix | Delete
* @return string[] {
[31] Fix | Delete
* Folder names used by block themes.
[32] Fix | Delete
*
[33] Fix | Delete
* @type string $wp_template Theme-relative directory name for block templates.
[34] Fix | Delete
* @type string $wp_template_part Theme-relative directory name for block template parts.
[35] Fix | Delete
* }
[36] Fix | Delete
*/
[37] Fix | Delete
function get_block_theme_folders( $theme_stylesheet = null ) {
[38] Fix | Delete
$theme = wp_get_theme( (string) $theme_stylesheet );
[39] Fix | Delete
if ( ! $theme->exists() ) {
[40] Fix | Delete
// Return the default folders if the theme doesn't exist.
[41] Fix | Delete
return array(
[42] Fix | Delete
'wp_template' => 'templates',
[43] Fix | Delete
'wp_template_part' => 'parts',
[44] Fix | Delete
);
[45] Fix | Delete
}
[46] Fix | Delete
return $theme->get_block_template_folders();
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* Returns a filtered list of allowed area values for template parts.
[51] Fix | Delete
*
[52] Fix | Delete
* @since 5.9.0
[53] Fix | Delete
*
[54] Fix | Delete
* @return array[] {
[55] Fix | Delete
* The allowed template part area values.
[56] Fix | Delete
*
[57] Fix | Delete
* @type array ...$0 {
[58] Fix | Delete
* Data for the allowed template part area.
[59] Fix | Delete
*
[60] Fix | Delete
* @type string $area Template part area name.
[61] Fix | Delete
* @type string $label Template part area label.
[62] Fix | Delete
* @type string $description Template part area description.
[63] Fix | Delete
* @type string $icon Template part area icon.
[64] Fix | Delete
* @type string $area_tag Template part area tag.
[65] Fix | Delete
* }
[66] Fix | Delete
* }
[67] Fix | Delete
*/
[68] Fix | Delete
function get_allowed_block_template_part_areas() {
[69] Fix | Delete
$default_area_definitions = array(
[70] Fix | Delete
array(
[71] Fix | Delete
'area' => WP_TEMPLATE_PART_AREA_UNCATEGORIZED,
[72] Fix | Delete
'label' => _x( 'General', 'template part area' ),
[73] Fix | Delete
'description' => __(
[74] Fix | Delete
'General templates often perform a specific role like displaying post content, and are not tied to any particular area.'
[75] Fix | Delete
),
[76] Fix | Delete
'icon' => 'layout',
[77] Fix | Delete
'area_tag' => 'div',
[78] Fix | Delete
),
[79] Fix | Delete
array(
[80] Fix | Delete
'area' => WP_TEMPLATE_PART_AREA_HEADER,
[81] Fix | Delete
'label' => _x( 'Header', 'template part area' ),
[82] Fix | Delete
'description' => __(
[83] Fix | Delete
'The Header template defines a page area that typically contains a title, logo, and main navigation.'
[84] Fix | Delete
),
[85] Fix | Delete
'icon' => 'header',
[86] Fix | Delete
'area_tag' => 'header',
[87] Fix | Delete
),
[88] Fix | Delete
array(
[89] Fix | Delete
'area' => WP_TEMPLATE_PART_AREA_FOOTER,
[90] Fix | Delete
'label' => _x( 'Footer', 'template part area' ),
[91] Fix | Delete
'description' => __(
[92] Fix | Delete
'The Footer template defines a page area that typically contains site credits, social links, or any other combination of blocks.'
[93] Fix | Delete
),
[94] Fix | Delete
'icon' => 'footer',
[95] Fix | Delete
'area_tag' => 'footer',
[96] Fix | Delete
),
[97] Fix | Delete
);
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Filters the list of allowed template part area values.
[101] Fix | Delete
*
[102] Fix | Delete
* @since 5.9.0
[103] Fix | Delete
*
[104] Fix | Delete
* @param array[] $default_area_definitions {
[105] Fix | Delete
* The allowed template part area values.
[106] Fix | Delete
*
[107] Fix | Delete
* @type array ...$0 {
[108] Fix | Delete
* Data for the template part area.
[109] Fix | Delete
*
[110] Fix | Delete
* @type string $area Template part area name.
[111] Fix | Delete
* @type string $label Template part area label.
[112] Fix | Delete
* @type string $description Template part area description.
[113] Fix | Delete
* @type string $icon Template part area icon.
[114] Fix | Delete
* @type string $area_tag Template part area tag.
[115] Fix | Delete
* }
[116] Fix | Delete
* }
[117] Fix | Delete
*/
[118] Fix | Delete
return apply_filters( 'default_wp_template_part_areas', $default_area_definitions );
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* Returns a filtered list of default template types, containing their
[124] Fix | Delete
* localized titles and descriptions.
[125] Fix | Delete
*
[126] Fix | Delete
* @since 5.9.0
[127] Fix | Delete
*
[128] Fix | Delete
* @return array[] {
[129] Fix | Delete
* The default template types.
[130] Fix | Delete
*
[131] Fix | Delete
* @type array ...$0 {
[132] Fix | Delete
* Data for the template type.
[133] Fix | Delete
*
[134] Fix | Delete
* @type string $title Template type title.
[135] Fix | Delete
* @type string $description Template type description.
[136] Fix | Delete
* }
[137] Fix | Delete
* }
[138] Fix | Delete
*/
[139] Fix | Delete
function get_default_block_template_types() {
[140] Fix | Delete
$default_template_types = array(
[141] Fix | Delete
'index' => array(
[142] Fix | Delete
'title' => _x( 'Index', 'Template name' ),
[143] Fix | Delete
'description' => __( 'Used as a fallback template for all pages when a more specific template is not defined.' ),
[144] Fix | Delete
),
[145] Fix | Delete
'home' => array(
[146] Fix | Delete
'title' => _x( 'Blog Home', 'Template name' ),
[147] Fix | Delete
'description' => __( 'Displays the latest posts as either the site homepage or as the "Posts page" as defined under reading settings. If it exists, the Front Page template overrides this template when posts are shown on the homepage.' ),
[148] Fix | Delete
),
[149] Fix | Delete
'front-page' => array(
[150] Fix | Delete
'title' => _x( 'Front Page', 'Template name' ),
[151] Fix | Delete
'description' => __( 'Displays your site\'s homepage, whether it is set to display latest posts or a static page. The Front Page template takes precedence over all templates.' ),
[152] Fix | Delete
),
[153] Fix | Delete
'singular' => array(
[154] Fix | Delete
'title' => _x( 'Single Entries', 'Template name' ),
[155] Fix | Delete
'description' => __( 'Displays any single entry, such as a post or a page. This template will serve as a fallback when a more specific template (e.g. Single Post, Page, or Attachment) cannot be found.' ),
[156] Fix | Delete
),
[157] Fix | Delete
'single' => array(
[158] Fix | Delete
'title' => _x( 'Single Posts', 'Template name' ),
[159] Fix | Delete
'description' => __( 'Displays a single post on your website unless a custom template has been applied to that post or a dedicated template exists.' ),
[160] Fix | Delete
),
[161] Fix | Delete
'page' => array(
[162] Fix | Delete
'title' => _x( 'Pages', 'Template name' ),
[163] Fix | Delete
'description' => __( 'Displays a static page unless a custom template has been applied to that page or a dedicated template exists.' ),
[164] Fix | Delete
),
[165] Fix | Delete
'archive' => array(
[166] Fix | Delete
'title' => _x( 'All Archives', 'Template name' ),
[167] Fix | Delete
'description' => __( 'Displays any archive, including posts by a single author, category, tag, taxonomy, custom post type, and date. This template will serve as a fallback when more specific templates (e.g. Category or Tag) cannot be found.' ),
[168] Fix | Delete
),
[169] Fix | Delete
'author' => array(
[170] Fix | Delete
'title' => _x( 'Author Archives', 'Template name' ),
[171] Fix | Delete
'description' => __( 'Displays a single author\'s post archive. This template will serve as a fallback when a more specific template (e.g. Author: Admin) cannot be found.' ),
[172] Fix | Delete
),
[173] Fix | Delete
'category' => array(
[174] Fix | Delete
'title' => _x( 'Category Archives', 'Template name' ),
[175] Fix | Delete
'description' => __( 'Displays a post category archive. This template will serve as a fallback when a more specific template (e.g. Category: Recipes) cannot be found.' ),
[176] Fix | Delete
),
[177] Fix | Delete
'taxonomy' => array(
[178] Fix | Delete
'title' => _x( 'Taxonomy', 'Template name' ),
[179] Fix | Delete
'description' => __( 'Displays a custom taxonomy archive. Like categories and tags, taxonomies have terms which you use to classify things. For example: a taxonomy named "Art" can have multiple terms, such as "Modern" and "18th Century." This template will serve as a fallback when a more specific template (e.g. Taxonomy: Art) cannot be found.' ),
[180] Fix | Delete
),
[181] Fix | Delete
'date' => array(
[182] Fix | Delete
'title' => _x( 'Date Archives', 'Template name' ),
[183] Fix | Delete
'description' => __( 'Displays a post archive when a specific date is visited (e.g., example.com/2023/).' ),
[184] Fix | Delete
),
[185] Fix | Delete
'tag' => array(
[186] Fix | Delete
'title' => _x( 'Tag Archives', 'Template name' ),
[187] Fix | Delete
'description' => __( 'Displays a post tag archive. This template will serve as a fallback when a more specific template (e.g. Tag: Pizza) cannot be found.' ),
[188] Fix | Delete
),
[189] Fix | Delete
'attachment' => array(
[190] Fix | Delete
'title' => __( 'Attachment Pages' ),
[191] Fix | Delete
'description' => __( 'Displays when a visitor views the dedicated page that exists for any media attachment.' ),
[192] Fix | Delete
),
[193] Fix | Delete
'search' => array(
[194] Fix | Delete
'title' => _x( 'Search Results', 'Template name' ),
[195] Fix | Delete
'description' => __( 'Displays when a visitor performs a search on your website.' ),
[196] Fix | Delete
),
[197] Fix | Delete
'privacy-policy' => array(
[198] Fix | Delete
'title' => __( 'Privacy Policy' ),
[199] Fix | Delete
'description' => __( 'Displays your site\'s Privacy Policy page.' ),
[200] Fix | Delete
),
[201] Fix | Delete
'404' => array(
[202] Fix | Delete
'title' => _x( 'Page: 404', 'Template name' ),
[203] Fix | Delete
'description' => __( 'Displays when a visitor views a non-existent page, such as a dead link or a mistyped URL.' ),
[204] Fix | Delete
),
[205] Fix | Delete
);
[206] Fix | Delete
[207] Fix | Delete
// Add a title and description to post format templates.
[208] Fix | Delete
$post_formats = get_post_format_strings();
[209] Fix | Delete
foreach ( $post_formats as $post_format_slug => $post_format_name ) {
[210] Fix | Delete
$default_template_types[ 'taxonomy-post_format-post-format-' . $post_format_slug ] = array(
[211] Fix | Delete
'title' => sprintf(
[212] Fix | Delete
/* translators: %s: Post format name. */
[213] Fix | Delete
_x( 'Post Format: %s', 'Template name' ),
[214] Fix | Delete
$post_format_name
[215] Fix | Delete
),
[216] Fix | Delete
'description' => sprintf(
[217] Fix | Delete
/* translators: %s: Post format name. */
[218] Fix | Delete
__( 'Displays the %s post format archive.' ),
[219] Fix | Delete
$post_format_name
[220] Fix | Delete
),
[221] Fix | Delete
);
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
/**
[225] Fix | Delete
* Filters the list of default template types.
[226] Fix | Delete
*
[227] Fix | Delete
* @since 5.9.0
[228] Fix | Delete
*
[229] Fix | Delete
* @param array[] $default_template_types {
[230] Fix | Delete
* The default template types.
[231] Fix | Delete
*
[232] Fix | Delete
* @type array ...$0 {
[233] Fix | Delete
* Data for the template type.
[234] Fix | Delete
*
[235] Fix | Delete
* @type string $title Template type title.
[236] Fix | Delete
* @type string $description Template type description.
[237] Fix | Delete
* }
[238] Fix | Delete
* }
[239] Fix | Delete
*/
[240] Fix | Delete
return apply_filters( 'default_template_types', $default_template_types );
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
/**
[244] Fix | Delete
* Checks whether the input 'area' is a supported value.
[245] Fix | Delete
* Returns the input if supported, otherwise returns the 'uncategorized' value.
[246] Fix | Delete
*
[247] Fix | Delete
* @since 5.9.0
[248] Fix | Delete
* @access private
[249] Fix | Delete
*
[250] Fix | Delete
* @param string $type Template part area name.
[251] Fix | Delete
* @return string Input if supported, else the uncategorized value.
[252] Fix | Delete
*/
[253] Fix | Delete
function _filter_block_template_part_area( $type ) {
[254] Fix | Delete
$allowed_areas = array_map(
[255] Fix | Delete
static function ( $item ) {
[256] Fix | Delete
return $item['area'];
[257] Fix | Delete
},
[258] Fix | Delete
get_allowed_block_template_part_areas()
[259] Fix | Delete
);
[260] Fix | Delete
if ( in_array( $type, $allowed_areas, true ) ) {
[261] Fix | Delete
return $type;
[262] Fix | Delete
}
[263] Fix | Delete
[264] Fix | Delete
$warning_message = sprintf(
[265] Fix | Delete
/* translators: %1$s: Template area type, %2$s: the uncategorized template area value. */
[266] Fix | Delete
__( '"%1$s" is not a supported wp_template_part area value and has been added as "%2$s".' ),
[267] Fix | Delete
$type,
[268] Fix | Delete
WP_TEMPLATE_PART_AREA_UNCATEGORIZED
[269] Fix | Delete
);
[270] Fix | Delete
wp_trigger_error( __FUNCTION__, $warning_message );
[271] Fix | Delete
return WP_TEMPLATE_PART_AREA_UNCATEGORIZED;
[272] Fix | Delete
}
[273] Fix | Delete
[274] Fix | Delete
/**
[275] Fix | Delete
* Finds all nested template part file paths in a theme's directory.
[276] Fix | Delete
*
[277] Fix | Delete
* @since 5.9.0
[278] Fix | Delete
* @access private
[279] Fix | Delete
*
[280] Fix | Delete
* @param string $base_directory The theme's file path.
[281] Fix | Delete
* @return string[] A list of paths to all template part files.
[282] Fix | Delete
*/
[283] Fix | Delete
function _get_block_templates_paths( $base_directory ) {
[284] Fix | Delete
static $template_path_list = array();
[285] Fix | Delete
if ( isset( $template_path_list[ $base_directory ] ) ) {
[286] Fix | Delete
return $template_path_list[ $base_directory ];
[287] Fix | Delete
}
[288] Fix | Delete
$path_list = array();
[289] Fix | Delete
if ( is_dir( $base_directory ) ) {
[290] Fix | Delete
$nested_files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $base_directory ) );
[291] Fix | Delete
$nested_html_files = new RegexIterator( $nested_files, '/^.+\.html$/i', RecursiveRegexIterator::GET_MATCH );
[292] Fix | Delete
foreach ( $nested_html_files as $path => $file ) {
[293] Fix | Delete
$path_list[] = $path;
[294] Fix | Delete
}
[295] Fix | Delete
}
[296] Fix | Delete
$template_path_list[ $base_directory ] = $path_list;
[297] Fix | Delete
return $path_list;
[298] Fix | Delete
}
[299] Fix | Delete
[300] Fix | Delete
/**
[301] Fix | Delete
* Retrieves the template file from the theme for a given slug.
[302] Fix | Delete
*
[303] Fix | Delete
* @since 5.9.0
[304] Fix | Delete
* @access private
[305] Fix | Delete
*
[306] Fix | Delete
* @param string $template_type Template type. Either 'wp_template' or 'wp_template_part'.
[307] Fix | Delete
* @param string $slug Template slug.
[308] Fix | Delete
* @return array|null {
[309] Fix | Delete
* Array with template metadata if $template_type is one of 'wp_template' or 'wp_template_part',
[310] Fix | Delete
* null otherwise.
[311] Fix | Delete
*
[312] Fix | Delete
* @type string $slug Template slug.
[313] Fix | Delete
* @type string $path Template file path.
[314] Fix | Delete
* @type string $theme Theme slug.
[315] Fix | Delete
* @type string $type Template type.
[316] Fix | Delete
* @type string $area Template area. Only for 'wp_template_part'.
[317] Fix | Delete
* @type string $title Optional. Template title.
[318] Fix | Delete
* @type string[] $postTypes Optional. List of post types that the template supports. Only for 'wp_template'.
[319] Fix | Delete
* }
[320] Fix | Delete
*/
[321] Fix | Delete
function _get_block_template_file( $template_type, $slug ) {
[322] Fix | Delete
if ( 'wp_template' !== $template_type && 'wp_template_part' !== $template_type ) {
[323] Fix | Delete
return null;
[324] Fix | Delete
}
[325] Fix | Delete
[326] Fix | Delete
$themes = array(
[327] Fix | Delete
get_stylesheet() => get_stylesheet_directory(),
[328] Fix | Delete
get_template() => get_template_directory(),
[329] Fix | Delete
);
[330] Fix | Delete
foreach ( $themes as $theme_slug => $theme_dir ) {
[331] Fix | Delete
$template_base_paths = get_block_theme_folders( $theme_slug );
[332] Fix | Delete
$file_path = $theme_dir . '/' . $template_base_paths[ $template_type ] . '/' . $slug . '.html';
[333] Fix | Delete
if ( file_exists( $file_path ) ) {
[334] Fix | Delete
$new_template_item = array(
[335] Fix | Delete
'slug' => $slug,
[336] Fix | Delete
'path' => $file_path,
[337] Fix | Delete
'theme' => $theme_slug,
[338] Fix | Delete
'type' => $template_type,
[339] Fix | Delete
);
[340] Fix | Delete
[341] Fix | Delete
if ( 'wp_template_part' === $template_type ) {
[342] Fix | Delete
return _add_block_template_part_area_info( $new_template_item );
[343] Fix | Delete
}
[344] Fix | Delete
[345] Fix | Delete
// If it's not a `wp_template_part`, it must be a `wp_template`.
[346] Fix | Delete
return _add_block_template_info( $new_template_item );
[347] Fix | Delete
}
[348] Fix | Delete
}
[349] Fix | Delete
[350] Fix | Delete
return null;
[351] Fix | Delete
}
[352] Fix | Delete
[353] Fix | Delete
/**
[354] Fix | Delete
* Retrieves the template files from the theme.
[355] Fix | Delete
*
[356] Fix | Delete
* @since 5.9.0
[357] Fix | Delete
* @since 6.3.0 Added the `$query` parameter.
[358] Fix | Delete
* @access private
[359] Fix | Delete
*
[360] Fix | Delete
* @param string $template_type Template type. Either 'wp_template' or 'wp_template_part'.
[361] Fix | Delete
* @param array $query {
[362] Fix | Delete
* Arguments to retrieve templates. Optional, empty by default.
[363] Fix | Delete
*
[364] Fix | Delete
* @type string[] $slug__in List of slugs to include.
[365] Fix | Delete
* @type string[] $slug__not_in List of slugs to skip.
[366] Fix | Delete
* @type string $area A 'wp_template_part_area' taxonomy value to filter by (for 'wp_template_part' template type only).
[367] Fix | Delete
* @type string $post_type Post type to get the templates for.
[368] Fix | Delete
* }
[369] Fix | Delete
*
[370] Fix | Delete
* @return array|null Template files on success, null if `$template_type` is not matched.
[371] Fix | Delete
*/
[372] Fix | Delete
function _get_block_templates_files( $template_type, $query = array() ) {
[373] Fix | Delete
if ( 'wp_template' !== $template_type && 'wp_template_part' !== $template_type ) {
[374] Fix | Delete
return null;
[375] Fix | Delete
}
[376] Fix | Delete
[377] Fix | Delete
$default_template_types = array();
[378] Fix | Delete
if ( 'wp_template' === $template_type ) {
[379] Fix | Delete
$default_template_types = get_default_block_template_types();
[380] Fix | Delete
}
[381] Fix | Delete
[382] Fix | Delete
// Prepare metadata from $query.
[383] Fix | Delete
$slugs_to_include = isset( $query['slug__in'] ) ? $query['slug__in'] : array();
[384] Fix | Delete
$slugs_to_skip = isset( $query['slug__not_in'] ) ? $query['slug__not_in'] : array();
[385] Fix | Delete
$area = isset( $query['area'] ) ? $query['area'] : null;
[386] Fix | Delete
$post_type = isset( $query['post_type'] ) ? $query['post_type'] : '';
[387] Fix | Delete
[388] Fix | Delete
$stylesheet = get_stylesheet();
[389] Fix | Delete
$template = get_template();
[390] Fix | Delete
$themes = array(
[391] Fix | Delete
$stylesheet => get_stylesheet_directory(),
[392] Fix | Delete
);
[393] Fix | Delete
// Add the parent theme if it's not the same as the current theme.
[394] Fix | Delete
if ( $stylesheet !== $template ) {
[395] Fix | Delete
$themes[ $template ] = get_template_directory();
[396] Fix | Delete
}
[397] Fix | Delete
$template_files = array();
[398] Fix | Delete
foreach ( $themes as $theme_slug => $theme_dir ) {
[399] Fix | Delete
$template_base_paths = get_block_theme_folders( $theme_slug );
[400] Fix | Delete
$theme_template_files = _get_block_templates_paths( $theme_dir . '/' . $template_base_paths[ $template_type ] );
[401] Fix | Delete
foreach ( $theme_template_files as $template_file ) {
[402] Fix | Delete
$template_base_path = $template_base_paths[ $template_type ];
[403] Fix | Delete
$template_slug = substr(
[404] Fix | Delete
$template_file,
[405] Fix | Delete
// Starting position of slug.
[406] Fix | Delete
strpos( $template_file, $template_base_path . DIRECTORY_SEPARATOR ) + 1 + strlen( $template_base_path ),
[407] Fix | Delete
// Subtract ending '.html'.
[408] Fix | Delete
-5
[409] Fix | Delete
);
[410] Fix | Delete
[411] Fix | Delete
// Skip this item if its slug doesn't match any of the slugs to include.
[412] Fix | Delete
if ( ! empty( $slugs_to_include ) && ! in_array( $template_slug, $slugs_to_include, true ) ) {
[413] Fix | Delete
continue;
[414] Fix | Delete
}
[415] Fix | Delete
[416] Fix | Delete
// Skip this item if its slug matches any of the slugs to skip.
[417] Fix | Delete
if ( ! empty( $slugs_to_skip ) && in_array( $template_slug, $slugs_to_skip, true ) ) {
[418] Fix | Delete
continue;
[419] Fix | Delete
}
[420] Fix | Delete
[421] Fix | Delete
/*
[422] Fix | Delete
* The child theme items (stylesheet) are processed before the parent theme's (template).
[423] Fix | Delete
* If a child theme defines a template, prevent the parent template from being added to the list as well.
[424] Fix | Delete
*/
[425] Fix | Delete
if ( isset( $template_files[ $template_slug ] ) ) {
[426] Fix | Delete
continue;
[427] Fix | Delete
}
[428] Fix | Delete
[429] Fix | Delete
$new_template_item = array(
[430] Fix | Delete
'slug' => $template_slug,
[431] Fix | Delete
'path' => $template_file,
[432] Fix | Delete
'theme' => $theme_slug,
[433] Fix | Delete
'type' => $template_type,
[434] Fix | Delete
);
[435] Fix | Delete
[436] Fix | Delete
if ( 'wp_template_part' === $template_type ) {
[437] Fix | Delete
$candidate = _add_block_template_part_area_info( $new_template_item );
[438] Fix | Delete
if ( ! isset( $area ) || $area === $candidate['area'] ) {
[439] Fix | Delete
$template_files[ $template_slug ] = $candidate;
[440] Fix | Delete
}
[441] Fix | Delete
}
[442] Fix | Delete
[443] Fix | Delete
if ( 'wp_template' === $template_type ) {
[444] Fix | Delete
$candidate = _add_block_template_info( $new_template_item );
[445] Fix | Delete
$is_custom = ! isset( $default_template_types[ $candidate['slug'] ] );
[446] Fix | Delete
[447] Fix | Delete
if (
[448] Fix | Delete
! $post_type ||
[449] Fix | Delete
( $post_type && isset( $candidate['postTypes'] ) && in_array( $post_type, $candidate['postTypes'], true ) )
[450] Fix | Delete
) {
[451] Fix | Delete
$template_files[ $template_slug ] = $candidate;
[452] Fix | Delete
}
[453] Fix | Delete
[454] Fix | Delete
// The custom templates with no associated post types are available for all post types.
[455] Fix | Delete
if ( $post_type && ! isset( $candidate['postTypes'] ) && $is_custom ) {
[456] Fix | Delete
$template_files[ $template_slug ] = $candidate;
[457] Fix | Delete
}
[458] Fix | Delete
}
[459] Fix | Delete
}
[460] Fix | Delete
}
[461] Fix | Delete
[462] Fix | Delete
return array_values( $template_files );
[463] Fix | Delete
}
[464] Fix | Delete
[465] Fix | Delete
/**
[466] Fix | Delete
* Attempts to add custom template information to the template item.
[467] Fix | Delete
*
[468] Fix | Delete
* @since 5.9.0
[469] Fix | Delete
* @access private
[470] Fix | Delete
*
[471] Fix | Delete
* @param array $template_item Template to add information to (requires 'slug' field).
[472] Fix | Delete
* @return array Template item.
[473] Fix | Delete
*/
[474] Fix | Delete
function _add_block_template_info( $template_item ) {
[475] Fix | Delete
if ( ! wp_theme_has_theme_json() ) {
[476] Fix | Delete
return $template_item;
[477] Fix | Delete
}
[478] Fix | Delete
[479] Fix | Delete
$theme_data = wp_get_theme_data_custom_templates();
[480] Fix | Delete
if ( isset( $theme_data[ $template_item['slug'] ] ) ) {
[481] Fix | Delete
$template_item['title'] = $theme_data[ $template_item['slug'] ]['title'];
[482] Fix | Delete
$template_item['postTypes'] = $theme_data[ $template_item['slug'] ]['postTypes'];
[483] Fix | Delete
}
[484] Fix | Delete
[485] Fix | Delete
return $template_item;
[486] Fix | Delete
}
[487] Fix | Delete
[488] Fix | Delete
/**
[489] Fix | Delete
* Attempts to add the template part's area information to the input template.
[490] Fix | Delete
*
[491] Fix | Delete
* @since 5.9.0
[492] Fix | Delete
* @access private
[493] Fix | Delete
*
[494] Fix | Delete
* @param array $template_info Template to add information to (requires 'type' and 'slug' fields).
[495] Fix | Delete
* @return array Template info.
[496] Fix | Delete
*/
[497] Fix | Delete
function _add_block_template_part_area_info( $template_info ) {
[498] Fix | Delete
if ( wp_theme_has_theme_json() ) {
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function