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
/home/sportsfe.../httpdocs/clone/wp-inclu...
File: global-styles-and-settings.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* APIs to interact with global settings & styles.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Gets the settings resulting of merging core, theme, and user data.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 5.9.0
[10] Fix | Delete
*
[11] Fix | Delete
* @param array $path Path to the specific setting to retrieve. Optional.
[12] Fix | Delete
* If empty, will return all settings.
[13] Fix | Delete
* @param array $context {
[14] Fix | Delete
* Metadata to know where to retrieve the $path from. Optional.
[15] Fix | Delete
*
[16] Fix | Delete
* @type string $block_name Which block to retrieve the settings from.
[17] Fix | Delete
* If empty, it'll return the settings for the global context.
[18] Fix | Delete
* @type string $origin Which origin to take data from.
[19] Fix | Delete
* Valid values are 'all' (core, theme, and user) or 'base' (core and theme).
[20] Fix | Delete
* If empty or unknown, 'all' is used.
[21] Fix | Delete
* }
[22] Fix | Delete
* @return mixed The settings array or individual setting value to retrieve.
[23] Fix | Delete
*/
[24] Fix | Delete
function wp_get_global_settings( $path = array(), $context = array() ) {
[25] Fix | Delete
if ( ! empty( $context['block_name'] ) ) {
[26] Fix | Delete
$new_path = array( 'blocks', $context['block_name'] );
[27] Fix | Delete
foreach ( $path as $subpath ) {
[28] Fix | Delete
$new_path[] = $subpath;
[29] Fix | Delete
}
[30] Fix | Delete
$path = $new_path;
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
/*
[34] Fix | Delete
* This is the default value when no origin is provided or when it is 'all'.
[35] Fix | Delete
*
[36] Fix | Delete
* The $origin is used as part of the cache key. Changes here need to account
[37] Fix | Delete
* for clearing the cache appropriately.
[38] Fix | Delete
*/
[39] Fix | Delete
$origin = 'custom';
[40] Fix | Delete
if (
[41] Fix | Delete
! wp_theme_has_theme_json() ||
[42] Fix | Delete
( isset( $context['origin'] ) && 'base' === $context['origin'] )
[43] Fix | Delete
) {
[44] Fix | Delete
$origin = 'theme';
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
/*
[48] Fix | Delete
* By using the 'theme_json' group, this data is marked to be non-persistent across requests.
[49] Fix | Delete
* See `wp_cache_add_non_persistent_groups` in src/wp-includes/load.php and other places.
[50] Fix | Delete
*
[51] Fix | Delete
* The rationale for this is to make sure derived data from theme.json
[52] Fix | Delete
* is always fresh from the potential modifications done via hooks
[53] Fix | Delete
* that can use dynamic data (modify the stylesheet depending on some option,
[54] Fix | Delete
* settings depending on user permissions, etc.).
[55] Fix | Delete
* See some of the existing hooks to modify theme.json behavior:
[56] Fix | Delete
* https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/
[57] Fix | Delete
*
[58] Fix | Delete
* A different alternative considered was to invalidate the cache upon certain
[59] Fix | Delete
* events such as options add/update/delete, user meta, etc.
[60] Fix | Delete
* It was judged not enough, hence this approach.
[61] Fix | Delete
* See https://github.com/WordPress/gutenberg/pull/45372
[62] Fix | Delete
*/
[63] Fix | Delete
$cache_group = 'theme_json';
[64] Fix | Delete
$cache_key = 'wp_get_global_settings_' . $origin;
[65] Fix | Delete
[66] Fix | Delete
/*
[67] Fix | Delete
* Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme
[68] Fix | Delete
* developer's workflow.
[69] Fix | Delete
*/
[70] Fix | Delete
$can_use_cached = ! wp_is_development_mode( 'theme' );
[71] Fix | Delete
[72] Fix | Delete
$settings = false;
[73] Fix | Delete
if ( $can_use_cached ) {
[74] Fix | Delete
$settings = wp_cache_get( $cache_key, $cache_group );
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
if ( false === $settings ) {
[78] Fix | Delete
$settings = WP_Theme_JSON_Resolver::get_merged_data( $origin )->get_settings();
[79] Fix | Delete
if ( $can_use_cached ) {
[80] Fix | Delete
wp_cache_set( $cache_key, $settings, $cache_group );
[81] Fix | Delete
}
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
return _wp_array_get( $settings, $path, $settings );
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Gets the styles resulting of merging core, theme, and user data.
[89] Fix | Delete
*
[90] Fix | Delete
* @since 5.9.0
[91] Fix | Delete
* @since 6.3.0 the internal link format "var:preset|color|secondary" is resolved
[92] Fix | Delete
* to "var(--wp--preset--font-size--small)" so consumers don't have to.
[93] Fix | Delete
* @since 6.3.0 `transforms` is now usable in the `context` parameter. In case [`transforms`]['resolve_variables']
[94] Fix | Delete
* is defined, variables are resolved to their value in the styles.
[95] Fix | Delete
*
[96] Fix | Delete
* @param array $path Path to the specific style to retrieve. Optional.
[97] Fix | Delete
* If empty, will return all styles.
[98] Fix | Delete
* @param array $context {
[99] Fix | Delete
* Metadata to know where to retrieve the $path from. Optional.
[100] Fix | Delete
*
[101] Fix | Delete
* @type string $block_name Which block to retrieve the styles from.
[102] Fix | Delete
* If empty, it'll return the styles for the global context.
[103] Fix | Delete
* @type string $origin Which origin to take data from.
[104] Fix | Delete
* Valid values are 'all' (core, theme, and user) or 'base' (core and theme).
[105] Fix | Delete
* If empty or unknown, 'all' is used.
[106] Fix | Delete
* @type array $transforms Which transformation(s) to apply.
[107] Fix | Delete
* Valid value is array( 'resolve-variables' ).
[108] Fix | Delete
* If defined, variables are resolved to their value in the styles.
[109] Fix | Delete
* }
[110] Fix | Delete
* @return mixed The styles array or individual style value to retrieve.
[111] Fix | Delete
*/
[112] Fix | Delete
function wp_get_global_styles( $path = array(), $context = array() ) {
[113] Fix | Delete
if ( ! empty( $context['block_name'] ) ) {
[114] Fix | Delete
$path = array_merge( array( 'blocks', $context['block_name'] ), $path );
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
$origin = 'custom';
[118] Fix | Delete
if ( isset( $context['origin'] ) && 'base' === $context['origin'] ) {
[119] Fix | Delete
$origin = 'theme';
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
$resolve_variables = isset( $context['transforms'] )
[123] Fix | Delete
&& is_array( $context['transforms'] )
[124] Fix | Delete
&& in_array( 'resolve-variables', $context['transforms'], true );
[125] Fix | Delete
[126] Fix | Delete
$merged_data = WP_Theme_JSON_Resolver::get_merged_data( $origin );
[127] Fix | Delete
if ( $resolve_variables ) {
[128] Fix | Delete
$merged_data = WP_Theme_JSON::resolve_variables( $merged_data );
[129] Fix | Delete
}
[130] Fix | Delete
$styles = $merged_data->get_raw_data()['styles'];
[131] Fix | Delete
return _wp_array_get( $styles, $path, $styles );
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
[135] Fix | Delete
/**
[136] Fix | Delete
* Returns the stylesheet resulting of merging core, theme, and user data.
[137] Fix | Delete
*
[138] Fix | Delete
* @since 5.9.0
[139] Fix | Delete
* @since 6.1.0 Added 'base-layout-styles' support.
[140] Fix | Delete
* @since 6.6.0 Resolves relative paths in theme.json styles to theme absolute paths.
[141] Fix | Delete
*
[142] Fix | Delete
* @param array $types Optional. Types of styles to load.
[143] Fix | Delete
* It accepts as values 'variables', 'presets', 'styles', 'base-layout-styles'.
[144] Fix | Delete
* If empty, it'll load the following:
[145] Fix | Delete
* - for themes without theme.json: 'variables', 'presets', 'base-layout-styles'.
[146] Fix | Delete
* - for themes with theme.json: 'variables', 'presets', 'styles'.
[147] Fix | Delete
* @return string Stylesheet.
[148] Fix | Delete
*/
[149] Fix | Delete
function wp_get_global_stylesheet( $types = array() ) {
[150] Fix | Delete
/*
[151] Fix | Delete
* Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme
[152] Fix | Delete
* developer's workflow.
[153] Fix | Delete
*/
[154] Fix | Delete
$can_use_cached = empty( $types ) && ! wp_is_development_mode( 'theme' );
[155] Fix | Delete
[156] Fix | Delete
/*
[157] Fix | Delete
* By using the 'theme_json' group, this data is marked to be non-persistent across requests.
[158] Fix | Delete
* @see `wp_cache_add_non_persistent_groups()`.
[159] Fix | Delete
*
[160] Fix | Delete
* The rationale for this is to make sure derived data from theme.json
[161] Fix | Delete
* is always fresh from the potential modifications done via hooks
[162] Fix | Delete
* that can use dynamic data (modify the stylesheet depending on some option,
[163] Fix | Delete
* settings depending on user permissions, etc.).
[164] Fix | Delete
* See some of the existing hooks to modify theme.json behavior:
[165] Fix | Delete
* @see https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/
[166] Fix | Delete
*
[167] Fix | Delete
* A different alternative considered was to invalidate the cache upon certain
[168] Fix | Delete
* events such as options add/update/delete, user meta, etc.
[169] Fix | Delete
* It was judged not enough, hence this approach.
[170] Fix | Delete
* @see https://github.com/WordPress/gutenberg/pull/45372
[171] Fix | Delete
*/
[172] Fix | Delete
$cache_group = 'theme_json';
[173] Fix | Delete
$cache_key = 'wp_get_global_stylesheet';
[174] Fix | Delete
if ( $can_use_cached ) {
[175] Fix | Delete
$cached = wp_cache_get( $cache_key, $cache_group );
[176] Fix | Delete
if ( $cached ) {
[177] Fix | Delete
return $cached;
[178] Fix | Delete
}
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
$tree = WP_Theme_JSON_Resolver::resolve_theme_file_uris( WP_Theme_JSON_Resolver::get_merged_data() );
[182] Fix | Delete
$supports_theme_json = wp_theme_has_theme_json();
[183] Fix | Delete
[184] Fix | Delete
if ( empty( $types ) && ! $supports_theme_json ) {
[185] Fix | Delete
$types = array( 'variables', 'presets', 'base-layout-styles' );
[186] Fix | Delete
} elseif ( empty( $types ) ) {
[187] Fix | Delete
$types = array( 'variables', 'styles', 'presets' );
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
/*
[191] Fix | Delete
* If variables are part of the stylesheet, then add them.
[192] Fix | Delete
* This is so themes without a theme.json still work as before 5.9:
[193] Fix | Delete
* they can override the default presets.
[194] Fix | Delete
* See https://core.trac.wordpress.org/ticket/54782
[195] Fix | Delete
*/
[196] Fix | Delete
$styles_variables = '';
[197] Fix | Delete
if ( in_array( 'variables', $types, true ) ) {
[198] Fix | Delete
/*
[199] Fix | Delete
* Only use the default, theme, and custom origins. Why?
[200] Fix | Delete
* Because styles for `blocks` origin are added at a later phase
[201] Fix | Delete
* (i.e. in the render cycle). Here, only the ones in use are rendered.
[202] Fix | Delete
* @see wp_add_global_styles_for_blocks
[203] Fix | Delete
*/
[204] Fix | Delete
$origins = array( 'default', 'theme', 'custom' );
[205] Fix | Delete
$styles_variables = $tree->get_stylesheet( array( 'variables' ), $origins );
[206] Fix | Delete
$types = array_diff( $types, array( 'variables' ) );
[207] Fix | Delete
}
[208] Fix | Delete
[209] Fix | Delete
/*
[210] Fix | Delete
* For the remaining types (presets, styles), we do consider origins:
[211] Fix | Delete
*
[212] Fix | Delete
* - themes without theme.json: only the classes for the presets defined by core
[213] Fix | Delete
* - themes with theme.json: the presets and styles classes, both from core and the theme
[214] Fix | Delete
*/
[215] Fix | Delete
$styles_rest = '';
[216] Fix | Delete
if ( ! empty( $types ) ) {
[217] Fix | Delete
/*
[218] Fix | Delete
* Only use the default, theme, and custom origins. Why?
[219] Fix | Delete
* Because styles for `blocks` origin are added at a later phase
[220] Fix | Delete
* (i.e. in the render cycle). Here, only the ones in use are rendered.
[221] Fix | Delete
* @see wp_add_global_styles_for_blocks
[222] Fix | Delete
*/
[223] Fix | Delete
$origins = array( 'default', 'theme', 'custom' );
[224] Fix | Delete
/*
[225] Fix | Delete
* If the theme doesn't have theme.json but supports both appearance tools and color palette,
[226] Fix | Delete
* the 'theme' origin should be included so color palette presets are also output.
[227] Fix | Delete
*/
[228] Fix | Delete
if ( ! $supports_theme_json && ( current_theme_supports( 'appearance-tools' ) || current_theme_supports( 'border' ) ) && current_theme_supports( 'editor-color-palette' ) ) {
[229] Fix | Delete
$origins = array( 'default', 'theme' );
[230] Fix | Delete
} elseif ( ! $supports_theme_json ) {
[231] Fix | Delete
$origins = array( 'default' );
[232] Fix | Delete
}
[233] Fix | Delete
$styles_rest = $tree->get_stylesheet( $types, $origins );
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
$stylesheet = $styles_variables . $styles_rest;
[237] Fix | Delete
if ( $can_use_cached ) {
[238] Fix | Delete
wp_cache_set( $cache_key, $stylesheet, $cache_group );
[239] Fix | Delete
}
[240] Fix | Delete
[241] Fix | Delete
return $stylesheet;
[242] Fix | Delete
}
[243] Fix | Delete
[244] Fix | Delete
/**
[245] Fix | Delete
* Gets the global styles custom CSS from theme.json.
[246] Fix | Delete
*
[247] Fix | Delete
* @since 6.2.0
[248] Fix | Delete
*
[249] Fix | Delete
* @return string The global styles custom CSS.
[250] Fix | Delete
*/
[251] Fix | Delete
function wp_get_global_styles_custom_css() {
[252] Fix | Delete
if ( ! wp_theme_has_theme_json() ) {
[253] Fix | Delete
return '';
[254] Fix | Delete
}
[255] Fix | Delete
/*
[256] Fix | Delete
* Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme
[257] Fix | Delete
* developer's workflow.
[258] Fix | Delete
*/
[259] Fix | Delete
$can_use_cached = ! wp_is_development_mode( 'theme' );
[260] Fix | Delete
[261] Fix | Delete
/*
[262] Fix | Delete
* By using the 'theme_json' group, this data is marked to be non-persistent across requests.
[263] Fix | Delete
* @see `wp_cache_add_non_persistent_groups()`.
[264] Fix | Delete
*
[265] Fix | Delete
* The rationale for this is to make sure derived data from theme.json
[266] Fix | Delete
* is always fresh from the potential modifications done via hooks
[267] Fix | Delete
* that can use dynamic data (modify the stylesheet depending on some option,
[268] Fix | Delete
* settings depending on user permissions, etc.).
[269] Fix | Delete
* See some of the existing hooks to modify theme.json behavior:
[270] Fix | Delete
* @see https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/
[271] Fix | Delete
*
[272] Fix | Delete
* A different alternative considered was to invalidate the cache upon certain
[273] Fix | Delete
* events such as options add/update/delete, user meta, etc.
[274] Fix | Delete
* It was judged not enough, hence this approach.
[275] Fix | Delete
* @see https://github.com/WordPress/gutenberg/pull/45372
[276] Fix | Delete
*/
[277] Fix | Delete
$cache_key = 'wp_get_global_styles_custom_css';
[278] Fix | Delete
$cache_group = 'theme_json';
[279] Fix | Delete
if ( $can_use_cached ) {
[280] Fix | Delete
$cached = wp_cache_get( $cache_key, $cache_group );
[281] Fix | Delete
if ( $cached ) {
[282] Fix | Delete
return $cached;
[283] Fix | Delete
}
[284] Fix | Delete
}
[285] Fix | Delete
[286] Fix | Delete
$tree = WP_Theme_JSON_Resolver::get_merged_data();
[287] Fix | Delete
$stylesheet = $tree->get_custom_css();
[288] Fix | Delete
[289] Fix | Delete
if ( $can_use_cached ) {
[290] Fix | Delete
wp_cache_set( $cache_key, $stylesheet, $cache_group );
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
return $stylesheet;
[294] Fix | Delete
}
[295] Fix | Delete
[296] Fix | Delete
/**
[297] Fix | Delete
* Adds global style rules to the inline style for each block.
[298] Fix | Delete
*
[299] Fix | Delete
* @since 6.1.0
[300] Fix | Delete
*
[301] Fix | Delete
* @global WP_Styles $wp_styles
[302] Fix | Delete
*/
[303] Fix | Delete
function wp_add_global_styles_for_blocks() {
[304] Fix | Delete
global $wp_styles;
[305] Fix | Delete
[306] Fix | Delete
$tree = WP_Theme_JSON_Resolver::get_merged_data();
[307] Fix | Delete
$block_nodes = $tree->get_styles_block_nodes();
[308] Fix | Delete
foreach ( $block_nodes as $metadata ) {
[309] Fix | Delete
$block_css = $tree->get_styles_for_block( $metadata );
[310] Fix | Delete
[311] Fix | Delete
if ( ! wp_should_load_separate_core_block_assets() ) {
[312] Fix | Delete
wp_add_inline_style( 'global-styles', $block_css );
[313] Fix | Delete
continue;
[314] Fix | Delete
}
[315] Fix | Delete
[316] Fix | Delete
$stylesheet_handle = 'global-styles';
[317] Fix | Delete
[318] Fix | Delete
/*
[319] Fix | Delete
* When `wp_should_load_separate_core_block_assets()` is true, block styles are
[320] Fix | Delete
* enqueued for each block on the page in class WP_Block's render function.
[321] Fix | Delete
* This means there will be a handle in the styles queue for each of those blocks.
[322] Fix | Delete
* Block-specific global styles should be attached to the global-styles handle, but
[323] Fix | Delete
* only for blocks on the page, thus we check if the block's handle is in the queue
[324] Fix | Delete
* before adding the inline style.
[325] Fix | Delete
* This conditional loading only applies to core blocks.
[326] Fix | Delete
*/
[327] Fix | Delete
if ( isset( $metadata['name'] ) ) {
[328] Fix | Delete
if ( str_starts_with( $metadata['name'], 'core/' ) ) {
[329] Fix | Delete
$block_name = str_replace( 'core/', '', $metadata['name'] );
[330] Fix | Delete
$block_handle = 'wp-block-' . $block_name;
[331] Fix | Delete
if ( in_array( $block_handle, $wp_styles->queue, true ) ) {
[332] Fix | Delete
wp_add_inline_style( $stylesheet_handle, $block_css );
[333] Fix | Delete
}
[334] Fix | Delete
} else {
[335] Fix | Delete
wp_add_inline_style( $stylesheet_handle, $block_css );
[336] Fix | Delete
}
[337] Fix | Delete
}
[338] Fix | Delete
[339] Fix | Delete
// The likes of block element styles from theme.json do not have $metadata['name'] set.
[340] Fix | Delete
if ( ! isset( $metadata['name'] ) && ! empty( $metadata['path'] ) ) {
[341] Fix | Delete
$block_name = wp_get_block_name_from_theme_json_path( $metadata['path'] );
[342] Fix | Delete
if ( $block_name ) {
[343] Fix | Delete
if ( str_starts_with( $block_name, 'core/' ) ) {
[344] Fix | Delete
$block_name = str_replace( 'core/', '', $block_name );
[345] Fix | Delete
$block_handle = 'wp-block-' . $block_name;
[346] Fix | Delete
if ( in_array( $block_handle, $wp_styles->queue, true ) ) {
[347] Fix | Delete
wp_add_inline_style( $stylesheet_handle, $block_css );
[348] Fix | Delete
}
[349] Fix | Delete
} else {
[350] Fix | Delete
wp_add_inline_style( $stylesheet_handle, $block_css );
[351] Fix | Delete
}
[352] Fix | Delete
}
[353] Fix | Delete
}
[354] Fix | Delete
}
[355] Fix | Delete
}
[356] Fix | Delete
[357] Fix | Delete
/**
[358] Fix | Delete
* Gets the block name from a given theme.json path.
[359] Fix | Delete
*
[360] Fix | Delete
* @since 6.3.0
[361] Fix | Delete
* @access private
[362] Fix | Delete
*
[363] Fix | Delete
* @param array $path An array of keys describing the path to a property in theme.json.
[364] Fix | Delete
* @return string Identified block name, or empty string if none found.
[365] Fix | Delete
*/
[366] Fix | Delete
function wp_get_block_name_from_theme_json_path( $path ) {
[367] Fix | Delete
// Block name is expected to be the third item after 'styles' and 'blocks'.
[368] Fix | Delete
if (
[369] Fix | Delete
count( $path ) >= 3
[370] Fix | Delete
&& 'styles' === $path[0]
[371] Fix | Delete
&& 'blocks' === $path[1]
[372] Fix | Delete
&& str_contains( $path[2], '/' )
[373] Fix | Delete
) {
[374] Fix | Delete
return $path[2];
[375] Fix | Delete
}
[376] Fix | Delete
[377] Fix | Delete
/*
[378] Fix | Delete
* As fallback and for backward compatibility, allow any core block to be
[379] Fix | Delete
* at any position.
[380] Fix | Delete
*/
[381] Fix | Delete
$result = array_values(
[382] Fix | Delete
array_filter(
[383] Fix | Delete
$path,
[384] Fix | Delete
static function ( $item ) {
[385] Fix | Delete
if ( str_contains( $item, 'core/' ) ) {
[386] Fix | Delete
return true;
[387] Fix | Delete
}
[388] Fix | Delete
return false;
[389] Fix | Delete
}
[390] Fix | Delete
)
[391] Fix | Delete
);
[392] Fix | Delete
if ( isset( $result[0] ) ) {
[393] Fix | Delete
return $result[0];
[394] Fix | Delete
}
[395] Fix | Delete
return '';
[396] Fix | Delete
}
[397] Fix | Delete
[398] Fix | Delete
/**
[399] Fix | Delete
* Checks whether a theme or its parent has a theme.json file.
[400] Fix | Delete
*
[401] Fix | Delete
* @since 6.2.0
[402] Fix | Delete
*
[403] Fix | Delete
* @return bool Returns true if theme or its parent has a theme.json file, false otherwise.
[404] Fix | Delete
*/
[405] Fix | Delete
function wp_theme_has_theme_json() {
[406] Fix | Delete
static $theme_has_support = array();
[407] Fix | Delete
[408] Fix | Delete
$stylesheet = get_stylesheet();
[409] Fix | Delete
[410] Fix | Delete
if (
[411] Fix | Delete
isset( $theme_has_support[ $stylesheet ] ) &&
[412] Fix | Delete
/*
[413] Fix | Delete
* Ignore static cache when the development mode is set to 'theme', to avoid interfering with
[414] Fix | Delete
* the theme developer's workflow.
[415] Fix | Delete
*/
[416] Fix | Delete
! wp_is_development_mode( 'theme' )
[417] Fix | Delete
) {
[418] Fix | Delete
return $theme_has_support[ $stylesheet ];
[419] Fix | Delete
}
[420] Fix | Delete
[421] Fix | Delete
$stylesheet_directory = get_stylesheet_directory();
[422] Fix | Delete
$template_directory = get_template_directory();
[423] Fix | Delete
[424] Fix | Delete
// This is the same as get_theme_file_path(), which isn't available in load-styles.php context
[425] Fix | Delete
if ( $stylesheet_directory !== $template_directory && file_exists( $stylesheet_directory . '/theme.json' ) ) {
[426] Fix | Delete
$path = $stylesheet_directory . '/theme.json';
[427] Fix | Delete
} else {
[428] Fix | Delete
$path = $template_directory . '/theme.json';
[429] Fix | Delete
}
[430] Fix | Delete
[431] Fix | Delete
/** This filter is documented in wp-includes/link-template.php */
[432] Fix | Delete
$path = apply_filters( 'theme_file_path', $path, 'theme.json' );
[433] Fix | Delete
[434] Fix | Delete
$theme_has_support[ $stylesheet ] = file_exists( $path );
[435] Fix | Delete
[436] Fix | Delete
return $theme_has_support[ $stylesheet ];
[437] Fix | Delete
}
[438] Fix | Delete
[439] Fix | Delete
/**
[440] Fix | Delete
* Cleans the caches under the theme_json group.
[441] Fix | Delete
*
[442] Fix | Delete
* @since 6.2.0
[443] Fix | Delete
*/
[444] Fix | Delete
function wp_clean_theme_json_cache() {
[445] Fix | Delete
wp_cache_delete( 'wp_get_global_stylesheet', 'theme_json' );
[446] Fix | Delete
wp_cache_delete( 'wp_get_global_styles_svg_filters', 'theme_json' );
[447] Fix | Delete
wp_cache_delete( 'wp_get_global_settings_custom', 'theme_json' );
[448] Fix | Delete
wp_cache_delete( 'wp_get_global_settings_theme', 'theme_json' );
[449] Fix | Delete
wp_cache_delete( 'wp_get_global_styles_custom_css', 'theme_json' );
[450] Fix | Delete
wp_cache_delete( 'wp_get_theme_data_template_parts', 'theme_json' );
[451] Fix | Delete
WP_Theme_JSON_Resolver::clean_cached_data();
[452] Fix | Delete
}
[453] Fix | Delete
[454] Fix | Delete
/**
[455] Fix | Delete
* Returns the current theme's wanted patterns (slugs) to be
[456] Fix | Delete
* registered from Pattern Directory.
[457] Fix | Delete
*
[458] Fix | Delete
* @since 6.3.0
[459] Fix | Delete
*
[460] Fix | Delete
* @return string[]
[461] Fix | Delete
*/
[462] Fix | Delete
function wp_get_theme_directory_pattern_slugs() {
[463] Fix | Delete
return WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) )->get_patterns();
[464] Fix | Delete
}
[465] Fix | Delete
[466] Fix | Delete
/**
[467] Fix | Delete
* Returns the metadata for the custom templates defined by the theme via theme.json.
[468] Fix | Delete
*
[469] Fix | Delete
* @since 6.4.0
[470] Fix | Delete
*
[471] Fix | Delete
* @return array Associative array of `$template_name => $template_data` pairs,
[472] Fix | Delete
* with `$template_data` having "title" and "postTypes" fields.
[473] Fix | Delete
*/
[474] Fix | Delete
function wp_get_theme_data_custom_templates() {
[475] Fix | Delete
return WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) )->get_custom_templates();
[476] Fix | Delete
}
[477] Fix | Delete
[478] Fix | Delete
/**
[479] Fix | Delete
* Returns the metadata for the template parts defined by the theme.
[480] Fix | Delete
*
[481] Fix | Delete
* @since 6.4.0
[482] Fix | Delete
*
[483] Fix | Delete
* @return array Associative array of `$part_name => $part_data` pairs,
[484] Fix | Delete
* with `$part_data` having "title" and "area" fields.
[485] Fix | Delete
*/
[486] Fix | Delete
function wp_get_theme_data_template_parts() {
[487] Fix | Delete
$cache_group = 'theme_json';
[488] Fix | Delete
$cache_key = 'wp_get_theme_data_template_parts';
[489] Fix | Delete
$can_use_cached = ! wp_is_development_mode( 'theme' );
[490] Fix | Delete
[491] Fix | Delete
$metadata = false;
[492] Fix | Delete
if ( $can_use_cached ) {
[493] Fix | Delete
$metadata = wp_cache_get( $cache_key, $cache_group );
[494] Fix | Delete
if ( false !== $metadata ) {
[495] Fix | Delete
return $metadata;
[496] Fix | Delete
}
[497] Fix | Delete
}
[498] Fix | Delete
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function