Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../public_h.../wp-inclu...
File: block-template-utils.php
$blocks = parse_blocks( $template->content );
[1000] Fix | Delete
$template->content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );
[1001] Fix | Delete
}
[1002] Fix | Delete
[1003] Fix | Delete
return $template;
[1004] Fix | Delete
}
[1005] Fix | Delete
[1006] Fix | Delete
/**
[1007] Fix | Delete
* Retrieves a list of unified template objects based on a query.
[1008] Fix | Delete
*
[1009] Fix | Delete
* @since 5.8.0
[1010] Fix | Delete
*
[1011] Fix | Delete
* @param array $query {
[1012] Fix | Delete
* Optional. Arguments to retrieve templates.
[1013] Fix | Delete
*
[1014] Fix | Delete
* @type string[] $slug__in List of slugs to include.
[1015] Fix | Delete
* @type int $wp_id Post ID of customized template.
[1016] Fix | Delete
* @type string $area A 'wp_template_part_area' taxonomy value to filter by (for 'wp_template_part' template type only).
[1017] Fix | Delete
* @type string $post_type Post type to get the templates for.
[1018] Fix | Delete
* }
[1019] Fix | Delete
* @param string $template_type Template type. Either 'wp_template' or 'wp_template_part'.
[1020] Fix | Delete
* @return WP_Block_Template[] Array of block templates.
[1021] Fix | Delete
*/
[1022] Fix | Delete
function get_block_templates( $query = array(), $template_type = 'wp_template' ) {
[1023] Fix | Delete
/**
[1024] Fix | Delete
* Filters the block templates array before the query takes place.
[1025] Fix | Delete
*
[1026] Fix | Delete
* Return a non-null value to bypass the WordPress queries.
[1027] Fix | Delete
*
[1028] Fix | Delete
* @since 5.9.0
[1029] Fix | Delete
*
[1030] Fix | Delete
* @param WP_Block_Template[]|null $block_templates Return an array of block templates to short-circuit the default query,
[1031] Fix | Delete
* or null to allow WP to run its normal queries.
[1032] Fix | Delete
* @param array $query {
[1033] Fix | Delete
* Arguments to retrieve templates. All arguments are optional.
[1034] Fix | Delete
*
[1035] Fix | Delete
* @type string[] $slug__in List of slugs to include.
[1036] Fix | Delete
* @type int $wp_id Post ID of customized template.
[1037] Fix | Delete
* @type string $area A 'wp_template_part_area' taxonomy value to filter by (for 'wp_template_part' template type only).
[1038] Fix | Delete
* @type string $post_type Post type to get the templates for.
[1039] Fix | Delete
* }
[1040] Fix | Delete
* @param string $template_type Template type. Either 'wp_template' or 'wp_template_part'.
[1041] Fix | Delete
*/
[1042] Fix | Delete
$templates = apply_filters( 'pre_get_block_templates', null, $query, $template_type );
[1043] Fix | Delete
if ( ! is_null( $templates ) ) {
[1044] Fix | Delete
return $templates;
[1045] Fix | Delete
}
[1046] Fix | Delete
[1047] Fix | Delete
$post_type = isset( $query['post_type'] ) ? $query['post_type'] : '';
[1048] Fix | Delete
$wp_query_args = array(
[1049] Fix | Delete
'post_status' => array( 'auto-draft', 'draft', 'publish' ),
[1050] Fix | Delete
'post_type' => $template_type,
[1051] Fix | Delete
'posts_per_page' => -1,
[1052] Fix | Delete
'no_found_rows' => true,
[1053] Fix | Delete
'lazy_load_term_meta' => false,
[1054] Fix | Delete
'tax_query' => array(
[1055] Fix | Delete
array(
[1056] Fix | Delete
'taxonomy' => 'wp_theme',
[1057] Fix | Delete
'field' => 'name',
[1058] Fix | Delete
'terms' => get_stylesheet(),
[1059] Fix | Delete
),
[1060] Fix | Delete
),
[1061] Fix | Delete
);
[1062] Fix | Delete
[1063] Fix | Delete
if ( 'wp_template_part' === $template_type && isset( $query['area'] ) ) {
[1064] Fix | Delete
$wp_query_args['tax_query'][] = array(
[1065] Fix | Delete
'taxonomy' => 'wp_template_part_area',
[1066] Fix | Delete
'field' => 'name',
[1067] Fix | Delete
'terms' => $query['area'],
[1068] Fix | Delete
);
[1069] Fix | Delete
$wp_query_args['tax_query']['relation'] = 'AND';
[1070] Fix | Delete
}
[1071] Fix | Delete
[1072] Fix | Delete
if ( ! empty( $query['slug__in'] ) ) {
[1073] Fix | Delete
$wp_query_args['post_name__in'] = $query['slug__in'];
[1074] Fix | Delete
$wp_query_args['posts_per_page'] = count( array_unique( $query['slug__in'] ) );
[1075] Fix | Delete
}
[1076] Fix | Delete
[1077] Fix | Delete
// This is only needed for the regular templates/template parts post type listing and editor.
[1078] Fix | Delete
if ( isset( $query['wp_id'] ) ) {
[1079] Fix | Delete
$wp_query_args['p'] = $query['wp_id'];
[1080] Fix | Delete
} else {
[1081] Fix | Delete
$wp_query_args['post_status'] = 'publish';
[1082] Fix | Delete
}
[1083] Fix | Delete
[1084] Fix | Delete
$template_query = new WP_Query( $wp_query_args );
[1085] Fix | Delete
$query_result = array();
[1086] Fix | Delete
foreach ( $template_query->posts as $post ) {
[1087] Fix | Delete
$template = _build_block_template_result_from_post( $post );
[1088] Fix | Delete
[1089] Fix | Delete
if ( is_wp_error( $template ) ) {
[1090] Fix | Delete
continue;
[1091] Fix | Delete
}
[1092] Fix | Delete
[1093] Fix | Delete
if ( $post_type && ! $template->is_custom ) {
[1094] Fix | Delete
continue;
[1095] Fix | Delete
}
[1096] Fix | Delete
[1097] Fix | Delete
if (
[1098] Fix | Delete
$post_type &&
[1099] Fix | Delete
isset( $template->post_types ) &&
[1100] Fix | Delete
! in_array( $post_type, $template->post_types, true )
[1101] Fix | Delete
) {
[1102] Fix | Delete
continue;
[1103] Fix | Delete
}
[1104] Fix | Delete
[1105] Fix | Delete
$query_result[] = $template;
[1106] Fix | Delete
}
[1107] Fix | Delete
[1108] Fix | Delete
if ( ! isset( $query['wp_id'] ) ) {
[1109] Fix | Delete
/*
[1110] Fix | Delete
* If the query has found some use templates, those have priority
[1111] Fix | Delete
* over the theme-provided ones, so we skip querying and building them.
[1112] Fix | Delete
*/
[1113] Fix | Delete
$query['slug__not_in'] = wp_list_pluck( $query_result, 'slug' );
[1114] Fix | Delete
$template_files = _get_block_templates_files( $template_type, $query );
[1115] Fix | Delete
foreach ( $template_files as $template_file ) {
[1116] Fix | Delete
$query_result[] = _build_block_template_result_from_file( $template_file, $template_type );
[1117] Fix | Delete
}
[1118] Fix | Delete
}
[1119] Fix | Delete
[1120] Fix | Delete
/**
[1121] Fix | Delete
* Filters the array of queried block templates array after they've been fetched.
[1122] Fix | Delete
*
[1123] Fix | Delete
* @since 5.9.0
[1124] Fix | Delete
*
[1125] Fix | Delete
* @param WP_Block_Template[] $query_result Array of found block templates.
[1126] Fix | Delete
* @param array $query {
[1127] Fix | Delete
* Arguments to retrieve templates. All arguments are optional.
[1128] Fix | Delete
*
[1129] Fix | Delete
* @type string[] $slug__in List of slugs to include.
[1130] Fix | Delete
* @type int $wp_id Post ID of customized template.
[1131] Fix | Delete
* @type string $area A 'wp_template_part_area' taxonomy value to filter by (for 'wp_template_part' template type only).
[1132] Fix | Delete
* @type string $post_type Post type to get the templates for.
[1133] Fix | Delete
* }
[1134] Fix | Delete
* @param string $template_type wp_template or wp_template_part.
[1135] Fix | Delete
*/
[1136] Fix | Delete
return apply_filters( 'get_block_templates', $query_result, $query, $template_type );
[1137] Fix | Delete
}
[1138] Fix | Delete
[1139] Fix | Delete
/**
[1140] Fix | Delete
* Retrieves a single unified template object using its id.
[1141] Fix | Delete
*
[1142] Fix | Delete
* @since 5.8.0
[1143] Fix | Delete
*
[1144] Fix | Delete
* @param string $id Template unique identifier (example: 'theme_slug//template_slug').
[1145] Fix | Delete
* @param string $template_type Optional. Template type. Either 'wp_template' or 'wp_template_part'.
[1146] Fix | Delete
* Default 'wp_template'.
[1147] Fix | Delete
* @return WP_Block_Template|null Template.
[1148] Fix | Delete
*/
[1149] Fix | Delete
function get_block_template( $id, $template_type = 'wp_template' ) {
[1150] Fix | Delete
/**
[1151] Fix | Delete
* Filters the block template object before the query takes place.
[1152] Fix | Delete
*
[1153] Fix | Delete
* Return a non-null value to bypass the WordPress queries.
[1154] Fix | Delete
*
[1155] Fix | Delete
* @since 5.9.0
[1156] Fix | Delete
*
[1157] Fix | Delete
* @param WP_Block_Template|null $block_template Return block template object to short-circuit the default query,
[1158] Fix | Delete
* or null to allow WP to run its normal queries.
[1159] Fix | Delete
* @param string $id Template unique identifier (example: 'theme_slug//template_slug').
[1160] Fix | Delete
* @param string $template_type Template type. Either 'wp_template' or 'wp_template_part'.
[1161] Fix | Delete
*/
[1162] Fix | Delete
$block_template = apply_filters( 'pre_get_block_template', null, $id, $template_type );
[1163] Fix | Delete
if ( ! is_null( $block_template ) ) {
[1164] Fix | Delete
return $block_template;
[1165] Fix | Delete
}
[1166] Fix | Delete
[1167] Fix | Delete
$parts = explode( '//', $id, 2 );
[1168] Fix | Delete
if ( count( $parts ) < 2 ) {
[1169] Fix | Delete
return null;
[1170] Fix | Delete
}
[1171] Fix | Delete
list( $theme, $slug ) = $parts;
[1172] Fix | Delete
$wp_query_args = array(
[1173] Fix | Delete
'post_name__in' => array( $slug ),
[1174] Fix | Delete
'post_type' => $template_type,
[1175] Fix | Delete
'post_status' => array( 'auto-draft', 'draft', 'publish', 'trash' ),
[1176] Fix | Delete
'posts_per_page' => 1,
[1177] Fix | Delete
'no_found_rows' => true,
[1178] Fix | Delete
'tax_query' => array(
[1179] Fix | Delete
array(
[1180] Fix | Delete
'taxonomy' => 'wp_theme',
[1181] Fix | Delete
'field' => 'name',
[1182] Fix | Delete
'terms' => $theme,
[1183] Fix | Delete
),
[1184] Fix | Delete
),
[1185] Fix | Delete
);
[1186] Fix | Delete
$template_query = new WP_Query( $wp_query_args );
[1187] Fix | Delete
$posts = $template_query->posts;
[1188] Fix | Delete
[1189] Fix | Delete
if ( count( $posts ) > 0 ) {
[1190] Fix | Delete
$template = _build_block_template_result_from_post( $posts[0] );
[1191] Fix | Delete
[1192] Fix | Delete
if ( ! is_wp_error( $template ) ) {
[1193] Fix | Delete
return $template;
[1194] Fix | Delete
}
[1195] Fix | Delete
}
[1196] Fix | Delete
[1197] Fix | Delete
$block_template = get_block_file_template( $id, $template_type );
[1198] Fix | Delete
[1199] Fix | Delete
/**
[1200] Fix | Delete
* Filters the queried block template object after it's been fetched.
[1201] Fix | Delete
*
[1202] Fix | Delete
* @since 5.9.0
[1203] Fix | Delete
*
[1204] Fix | Delete
* @param WP_Block_Template|null $block_template The found block template, or null if there isn't one.
[1205] Fix | Delete
* @param string $id Template unique identifier (example: 'theme_slug//template_slug').
[1206] Fix | Delete
* @param string $template_type Template type. Either 'wp_template' or 'wp_template_part'.
[1207] Fix | Delete
*/
[1208] Fix | Delete
return apply_filters( 'get_block_template', $block_template, $id, $template_type );
[1209] Fix | Delete
}
[1210] Fix | Delete
[1211] Fix | Delete
/**
[1212] Fix | Delete
* Retrieves a unified template object based on a theme file.
[1213] Fix | Delete
*
[1214] Fix | Delete
* This is a fallback of get_block_template(), used when no templates are found in the database.
[1215] Fix | Delete
*
[1216] Fix | Delete
* @since 5.9.0
[1217] Fix | Delete
*
[1218] Fix | Delete
* @param string $id Template unique identifier (example: 'theme_slug//template_slug').
[1219] Fix | Delete
* @param string $template_type Optional. Template type. Either 'wp_template' or 'wp_template_part'.
[1220] Fix | Delete
* Default 'wp_template'.
[1221] Fix | Delete
* @return WP_Block_Template|null The found block template, or null if there isn't one.
[1222] Fix | Delete
*/
[1223] Fix | Delete
function get_block_file_template( $id, $template_type = 'wp_template' ) {
[1224] Fix | Delete
/**
[1225] Fix | Delete
* Filters the block template object before the theme file discovery takes place.
[1226] Fix | Delete
*
[1227] Fix | Delete
* Return a non-null value to bypass the WordPress theme file discovery.
[1228] Fix | Delete
*
[1229] Fix | Delete
* @since 5.9.0
[1230] Fix | Delete
*
[1231] Fix | Delete
* @param WP_Block_Template|null $block_template Return block template object to short-circuit the default query,
[1232] Fix | Delete
* or null to allow WP to run its normal queries.
[1233] Fix | Delete
* @param string $id Template unique identifier (example: 'theme_slug//template_slug').
[1234] Fix | Delete
* @param string $template_type Template type. Either 'wp_template' or 'wp_template_part'.
[1235] Fix | Delete
*/
[1236] Fix | Delete
$block_template = apply_filters( 'pre_get_block_file_template', null, $id, $template_type );
[1237] Fix | Delete
if ( ! is_null( $block_template ) ) {
[1238] Fix | Delete
return $block_template;
[1239] Fix | Delete
}
[1240] Fix | Delete
[1241] Fix | Delete
$parts = explode( '//', $id, 2 );
[1242] Fix | Delete
if ( count( $parts ) < 2 ) {
[1243] Fix | Delete
/** This filter is documented in wp-includes/block-template-utils.php */
[1244] Fix | Delete
return apply_filters( 'get_block_file_template', null, $id, $template_type );
[1245] Fix | Delete
}
[1246] Fix | Delete
list( $theme, $slug ) = $parts;
[1247] Fix | Delete
[1248] Fix | Delete
if ( get_stylesheet() !== $theme ) {
[1249] Fix | Delete
/** This filter is documented in wp-includes/block-template-utils.php */
[1250] Fix | Delete
return apply_filters( 'get_block_file_template', null, $id, $template_type );
[1251] Fix | Delete
}
[1252] Fix | Delete
[1253] Fix | Delete
$template_file = _get_block_template_file( $template_type, $slug );
[1254] Fix | Delete
if ( null === $template_file ) {
[1255] Fix | Delete
/** This filter is documented in wp-includes/block-template-utils.php */
[1256] Fix | Delete
return apply_filters( 'get_block_file_template', null, $id, $template_type );
[1257] Fix | Delete
}
[1258] Fix | Delete
[1259] Fix | Delete
$block_template = _build_block_template_result_from_file( $template_file, $template_type );
[1260] Fix | Delete
[1261] Fix | Delete
/**
[1262] Fix | Delete
* Filters the block template object after it has been (potentially) fetched from the theme file.
[1263] Fix | Delete
*
[1264] Fix | Delete
* @since 5.9.0
[1265] Fix | Delete
*
[1266] Fix | Delete
* @param WP_Block_Template|null $block_template The found block template, or null if there is none.
[1267] Fix | Delete
* @param string $id Template unique identifier (example: 'theme_slug//template_slug').
[1268] Fix | Delete
* @param string $template_type Template type. Either 'wp_template' or 'wp_template_part'.
[1269] Fix | Delete
*/
[1270] Fix | Delete
return apply_filters( 'get_block_file_template', $block_template, $id, $template_type );
[1271] Fix | Delete
}
[1272] Fix | Delete
[1273] Fix | Delete
/**
[1274] Fix | Delete
* Prints a block template part.
[1275] Fix | Delete
*
[1276] Fix | Delete
* @since 5.9.0
[1277] Fix | Delete
*
[1278] Fix | Delete
* @param string $part The block template part to print, for example 'header' or 'footer'.
[1279] Fix | Delete
*/
[1280] Fix | Delete
function block_template_part( $part ) {
[1281] Fix | Delete
$template_part = get_block_template( get_stylesheet() . '//' . $part, 'wp_template_part' );
[1282] Fix | Delete
if ( ! $template_part || empty( $template_part->content ) ) {
[1283] Fix | Delete
return;
[1284] Fix | Delete
}
[1285] Fix | Delete
echo do_blocks( $template_part->content );
[1286] Fix | Delete
}
[1287] Fix | Delete
[1288] Fix | Delete
/**
[1289] Fix | Delete
* Prints the header block template part.
[1290] Fix | Delete
*
[1291] Fix | Delete
* @since 5.9.0
[1292] Fix | Delete
*/
[1293] Fix | Delete
function block_header_area() {
[1294] Fix | Delete
block_template_part( 'header' );
[1295] Fix | Delete
}
[1296] Fix | Delete
[1297] Fix | Delete
/**
[1298] Fix | Delete
* Prints the footer block template part.
[1299] Fix | Delete
*
[1300] Fix | Delete
* @since 5.9.0
[1301] Fix | Delete
*/
[1302] Fix | Delete
function block_footer_area() {
[1303] Fix | Delete
block_template_part( 'footer' );
[1304] Fix | Delete
}
[1305] Fix | Delete
[1306] Fix | Delete
/**
[1307] Fix | Delete
* Determines whether a theme directory should be ignored during export.
[1308] Fix | Delete
*
[1309] Fix | Delete
* @since 6.0.0
[1310] Fix | Delete
*
[1311] Fix | Delete
* @param string $path The path of the file in the theme.
[1312] Fix | Delete
* @return bool Whether this file is in an ignored directory.
[1313] Fix | Delete
*/
[1314] Fix | Delete
function wp_is_theme_directory_ignored( $path ) {
[1315] Fix | Delete
$directories_to_ignore = array( '.DS_Store', '.svn', '.git', '.hg', '.bzr', 'node_modules', 'vendor' );
[1316] Fix | Delete
[1317] Fix | Delete
foreach ( $directories_to_ignore as $directory ) {
[1318] Fix | Delete
if ( str_starts_with( $path, $directory ) ) {
[1319] Fix | Delete
return true;
[1320] Fix | Delete
}
[1321] Fix | Delete
}
[1322] Fix | Delete
[1323] Fix | Delete
return false;
[1324] Fix | Delete
}
[1325] Fix | Delete
[1326] Fix | Delete
/**
[1327] Fix | Delete
* Creates an export of the current templates and
[1328] Fix | Delete
* template parts from the site editor at the
[1329] Fix | Delete
* specified path in a ZIP file.
[1330] Fix | Delete
*
[1331] Fix | Delete
* @since 5.9.0
[1332] Fix | Delete
* @since 6.0.0 Adds the whole theme to the export archive.
[1333] Fix | Delete
*
[1334] Fix | Delete
* @global string $wp_version The WordPress version string.
[1335] Fix | Delete
*
[1336] Fix | Delete
* @return WP_Error|string Path of the ZIP file or error on failure.
[1337] Fix | Delete
*/
[1338] Fix | Delete
function wp_generate_block_templates_export_file() {
[1339] Fix | Delete
global $wp_version;
[1340] Fix | Delete
[1341] Fix | Delete
if ( ! class_exists( 'ZipArchive' ) ) {
[1342] Fix | Delete
return new WP_Error( 'missing_zip_package', __( 'Zip Export not supported.' ) );
[1343] Fix | Delete
}
[1344] Fix | Delete
[1345] Fix | Delete
$obscura = wp_generate_password( 12, false, false );
[1346] Fix | Delete
$theme_name = basename( get_stylesheet() );
[1347] Fix | Delete
$filename = get_temp_dir() . $theme_name . $obscura . '.zip';
[1348] Fix | Delete
[1349] Fix | Delete
$zip = new ZipArchive();
[1350] Fix | Delete
if ( true !== $zip->open( $filename, ZipArchive::CREATE | ZipArchive::OVERWRITE ) ) {
[1351] Fix | Delete
return new WP_Error( 'unable_to_create_zip', __( 'Unable to open export file (archive) for writing.' ) );
[1352] Fix | Delete
}
[1353] Fix | Delete
[1354] Fix | Delete
$zip->addEmptyDir( 'templates' );
[1355] Fix | Delete
$zip->addEmptyDir( 'parts' );
[1356] Fix | Delete
[1357] Fix | Delete
// Get path of the theme.
[1358] Fix | Delete
$theme_path = wp_normalize_path( get_stylesheet_directory() );
[1359] Fix | Delete
[1360] Fix | Delete
// Create recursive directory iterator.
[1361] Fix | Delete
$theme_files = new RecursiveIteratorIterator(
[1362] Fix | Delete
new RecursiveDirectoryIterator( $theme_path ),
[1363] Fix | Delete
RecursiveIteratorIterator::LEAVES_ONLY
[1364] Fix | Delete
);
[1365] Fix | Delete
[1366] Fix | Delete
// Make a copy of the current theme.
[1367] Fix | Delete
foreach ( $theme_files as $file ) {
[1368] Fix | Delete
// Skip directories as they are added automatically.
[1369] Fix | Delete
if ( ! $file->isDir() ) {
[1370] Fix | Delete
// Get real and relative path for current file.
[1371] Fix | Delete
$file_path = wp_normalize_path( $file );
[1372] Fix | Delete
$relative_path = substr( $file_path, strlen( $theme_path ) + 1 );
[1373] Fix | Delete
[1374] Fix | Delete
if ( ! wp_is_theme_directory_ignored( $relative_path ) ) {
[1375] Fix | Delete
$zip->addFile( $file_path, $relative_path );
[1376] Fix | Delete
}
[1377] Fix | Delete
}
[1378] Fix | Delete
}
[1379] Fix | Delete
[1380] Fix | Delete
// Load templates into the zip file.
[1381] Fix | Delete
$templates = get_block_templates();
[1382] Fix | Delete
foreach ( $templates as $template ) {
[1383] Fix | Delete
$template->content = traverse_and_serialize_blocks(
[1384] Fix | Delete
parse_blocks( $template->content ),
[1385] Fix | Delete
'_remove_theme_attribute_from_template_part_block'
[1386] Fix | Delete
);
[1387] Fix | Delete
[1388] Fix | Delete
$zip->addFromString(
[1389] Fix | Delete
'templates/' . $template->slug . '.html',
[1390] Fix | Delete
$template->content
[1391] Fix | Delete
);
[1392] Fix | Delete
}
[1393] Fix | Delete
[1394] Fix | Delete
// Load template parts into the zip file.
[1395] Fix | Delete
$template_parts = get_block_templates( array(), 'wp_template_part' );
[1396] Fix | Delete
foreach ( $template_parts as $template_part ) {
[1397] Fix | Delete
$zip->addFromString(
[1398] Fix | Delete
'parts/' . $template_part->slug . '.html',
[1399] Fix | Delete
$template_part->content
[1400] Fix | Delete
);
[1401] Fix | Delete
}
[1402] Fix | Delete
[1403] Fix | Delete
// Load theme.json into the zip file.
[1404] Fix | Delete
$tree = WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) );
[1405] Fix | Delete
// Merge with user data.
[1406] Fix | Delete
$tree->merge( WP_Theme_JSON_Resolver::get_user_data() );
[1407] Fix | Delete
[1408] Fix | Delete
$theme_json_raw = $tree->get_data();
[1409] Fix | Delete
// If a version is defined, add a schema.
[1410] Fix | Delete
if ( $theme_json_raw['version'] ) {
[1411] Fix | Delete
$theme_json_version = 'wp/' . substr( $wp_version, 0, 3 );
[1412] Fix | Delete
$schema = array( '$schema' => 'https://schemas.wp.org/' . $theme_json_version . '/theme.json' );
[1413] Fix | Delete
$theme_json_raw = array_merge( $schema, $theme_json_raw );
[1414] Fix | Delete
}
[1415] Fix | Delete
[1416] Fix | Delete
// Convert to a string.
[1417] Fix | Delete
$theme_json_encoded = wp_json_encode( $theme_json_raw, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
[1418] Fix | Delete
[1419] Fix | Delete
// Replace 4 spaces with a tab.
[1420] Fix | Delete
$theme_json_tabbed = preg_replace( '~(?:^|\G)\h{4}~m', "\t", $theme_json_encoded );
[1421] Fix | Delete
[1422] Fix | Delete
// Add the theme.json file to the zip.
[1423] Fix | Delete
$zip->addFromString(
[1424] Fix | Delete
'theme.json',
[1425] Fix | Delete
$theme_json_tabbed
[1426] Fix | Delete
);
[1427] Fix | Delete
[1428] Fix | Delete
// Save changes to the zip file.
[1429] Fix | Delete
$zip->close();
[1430] Fix | Delete
[1431] Fix | Delete
return $filename;
[1432] Fix | Delete
}
[1433] Fix | Delete
[1434] Fix | Delete
/**
[1435] Fix | Delete
* Gets the template hierarchy for the given template slug to be created.
[1436] Fix | Delete
*
[1437] Fix | Delete
* Note: Always add `index` as the last fallback template.
[1438] Fix | Delete
*
[1439] Fix | Delete
* @since 6.1.0
[1440] Fix | Delete
*
[1441] Fix | Delete
* @param string $slug The template slug to be created.
[1442] Fix | Delete
* @param bool $is_custom Optional. Indicates if a template is custom or
[1443] Fix | Delete
* part of the template hierarchy. Default false.
[1444] Fix | Delete
* @param string $template_prefix Optional. The template prefix for the created template.
[1445] Fix | Delete
* Used to extract the main template type, e.g.
[1446] Fix | Delete
* in `taxonomy-books` the `taxonomy` is extracted.
[1447] Fix | Delete
* Default empty string.
[1448] Fix | Delete
* @return string[] The template hierarchy.
[1449] Fix | Delete
*/
[1450] Fix | Delete
function get_template_hierarchy( $slug, $is_custom = false, $template_prefix = '' ) {
[1451] Fix | Delete
if ( 'index' === $slug ) {
[1452] Fix | Delete
/** This filter is documented in wp-includes/template.php */
[1453] Fix | Delete
return apply_filters( 'index_template_hierarchy', array( 'index' ) );
[1454] Fix | Delete
}
[1455] Fix | Delete
if ( $is_custom ) {
[1456] Fix | Delete
/** This filter is documented in wp-includes/template.php */
[1457] Fix | Delete
return apply_filters( 'page_template_hierarchy', array( 'page', 'singular', 'index' ) );
[1458] Fix | Delete
}
[1459] Fix | Delete
if ( 'front-page' === $slug ) {
[1460] Fix | Delete
/** This filter is documented in wp-includes/template.php */
[1461] Fix | Delete
return apply_filters( 'frontpage_template_hierarchy', array( 'front-page', 'home', 'index' ) );
[1462] Fix | Delete
}
[1463] Fix | Delete
[1464] Fix | Delete
$matches = array();
[1465] Fix | Delete
[1466] Fix | Delete
$template_hierarchy = array( $slug );
[1467] Fix | Delete
// Most default templates don't have `$template_prefix` assigned.
[1468] Fix | Delete
if ( ! empty( $template_prefix ) ) {
[1469] Fix | Delete
list( $type ) = explode( '-', $template_prefix );
[1470] Fix | Delete
// We need these checks because we always add the `$slug` above.
[1471] Fix | Delete
if ( ! in_array( $template_prefix, array( $slug, $type ), true ) ) {
[1472] Fix | Delete
$template_hierarchy[] = $template_prefix;
[1473] Fix | Delete
}
[1474] Fix | Delete
if ( $slug !== $type ) {
[1475] Fix | Delete
$template_hierarchy[] = $type;
[1476] Fix | Delete
}
[1477] Fix | Delete
} elseif ( preg_match( '/^(author|category|archive|tag|page)-.+$/', $slug, $matches ) ) {
[1478] Fix | Delete
$template_hierarchy[] = $matches[1];
[1479] Fix | Delete
} elseif ( preg_match( '/^(taxonomy|single)-(.+)$/', $slug, $matches ) ) {
[1480] Fix | Delete
$type = $matches[1];
[1481] Fix | Delete
$slug_remaining = $matches[2];
[1482] Fix | Delete
[1483] Fix | Delete
$items = 'single' === $type ? get_post_types() : get_taxonomies();
[1484] Fix | Delete
foreach ( $items as $item ) {
[1485] Fix | Delete
if ( ! str_starts_with( $slug_remaining, $item ) ) {
[1486] Fix | Delete
continue;
[1487] Fix | Delete
}
[1488] Fix | Delete
[1489] Fix | Delete
// If $slug_remaining is equal to $post_type or $taxonomy we have
[1490] Fix | Delete
// the single-$post_type template or the taxonomy-$taxonomy template.
[1491] Fix | Delete
if ( $slug_remaining === $item ) {
[1492] Fix | Delete
$template_hierarchy[] = $type;
[1493] Fix | Delete
break;
[1494] Fix | Delete
}
[1495] Fix | Delete
[1496] Fix | Delete
// If $slug_remaining is single-$post_type-$slug template.
[1497] Fix | Delete
if ( strlen( $slug_remaining ) > strlen( $item ) + 1 ) {
[1498] Fix | Delete
$template_hierarchy[] = "$type-$item";
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function