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.../public_h.../wp-inclu...
File: class-wp-theme-json-resolver.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WP_Theme_JSON_Resolver class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Theme
[5] Fix | Delete
* @since 5.8.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Class that abstracts the processing of the different data sources
[10] Fix | Delete
* for site-level config and offers an API to work with them.
[11] Fix | Delete
*
[12] Fix | Delete
* This class is for internal core usage and is not supposed to be used by extenders (plugins and/or themes).
[13] Fix | Delete
* This is a low-level API that may need to do breaking changes. Please,
[14] Fix | Delete
* use get_global_settings(), get_global_styles(), and get_global_stylesheet() instead.
[15] Fix | Delete
*
[16] Fix | Delete
* @access private
[17] Fix | Delete
*/
[18] Fix | Delete
#[AllowDynamicProperties]
[19] Fix | Delete
class WP_Theme_JSON_Resolver {
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* Container for keep track of registered blocks.
[23] Fix | Delete
*
[24] Fix | Delete
* @since 6.1.0
[25] Fix | Delete
* @var array
[26] Fix | Delete
*/
[27] Fix | Delete
protected static $blocks_cache = array(
[28] Fix | Delete
'core' => array(),
[29] Fix | Delete
'blocks' => array(),
[30] Fix | Delete
'theme' => array(),
[31] Fix | Delete
'user' => array(),
[32] Fix | Delete
);
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Container for data coming from core.
[36] Fix | Delete
*
[37] Fix | Delete
* @since 5.8.0
[38] Fix | Delete
* @var WP_Theme_JSON
[39] Fix | Delete
*/
[40] Fix | Delete
protected static $core = null;
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Container for data coming from the blocks.
[44] Fix | Delete
*
[45] Fix | Delete
* @since 6.1.0
[46] Fix | Delete
* @var WP_Theme_JSON
[47] Fix | Delete
*/
[48] Fix | Delete
protected static $blocks = null;
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* Container for data coming from the theme.
[52] Fix | Delete
*
[53] Fix | Delete
* @since 5.8.0
[54] Fix | Delete
* @var WP_Theme_JSON
[55] Fix | Delete
*/
[56] Fix | Delete
protected static $theme = null;
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* Container for data coming from the user.
[60] Fix | Delete
*
[61] Fix | Delete
* @since 5.9.0
[62] Fix | Delete
* @var WP_Theme_JSON
[63] Fix | Delete
*/
[64] Fix | Delete
protected static $user = null;
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* Stores the ID of the custom post type
[68] Fix | Delete
* that holds the user data.
[69] Fix | Delete
*
[70] Fix | Delete
* @since 5.9.0
[71] Fix | Delete
* @var int
[72] Fix | Delete
*/
[73] Fix | Delete
protected static $user_custom_post_type_id = null;
[74] Fix | Delete
[75] Fix | Delete
/**
[76] Fix | Delete
* Container to keep loaded i18n schema for `theme.json`.
[77] Fix | Delete
*
[78] Fix | Delete
* @since 5.8.0 As `$theme_json_i18n`.
[79] Fix | Delete
* @since 5.9.0 Renamed from `$theme_json_i18n` to `$i18n_schema`.
[80] Fix | Delete
* @var array
[81] Fix | Delete
*/
[82] Fix | Delete
protected static $i18n_schema = null;
[83] Fix | Delete
[84] Fix | Delete
/**
[85] Fix | Delete
* `theme.json` file cache.
[86] Fix | Delete
*
[87] Fix | Delete
* @since 6.1.0
[88] Fix | Delete
* @var array
[89] Fix | Delete
*/
[90] Fix | Delete
protected static $theme_json_file_cache = array();
[91] Fix | Delete
[92] Fix | Delete
/**
[93] Fix | Delete
* Processes a file that adheres to the theme.json schema
[94] Fix | Delete
* and returns an array with its contents, or a void array if none found.
[95] Fix | Delete
*
[96] Fix | Delete
* @since 5.8.0
[97] Fix | Delete
* @since 6.1.0 Added caching.
[98] Fix | Delete
*
[99] Fix | Delete
* @param string $file_path Path to file. Empty if no file.
[100] Fix | Delete
* @return array Contents that adhere to the theme.json schema.
[101] Fix | Delete
*/
[102] Fix | Delete
protected static function read_json_file( $file_path ) {
[103] Fix | Delete
if ( $file_path ) {
[104] Fix | Delete
if ( array_key_exists( $file_path, static::$theme_json_file_cache ) ) {
[105] Fix | Delete
return static::$theme_json_file_cache[ $file_path ];
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
$decoded_file = wp_json_file_decode( $file_path, array( 'associative' => true ) );
[109] Fix | Delete
if ( is_array( $decoded_file ) ) {
[110] Fix | Delete
static::$theme_json_file_cache[ $file_path ] = $decoded_file;
[111] Fix | Delete
return static::$theme_json_file_cache[ $file_path ];
[112] Fix | Delete
}
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
return array();
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
/**
[119] Fix | Delete
* Returns a data structure used in theme.json translation.
[120] Fix | Delete
*
[121] Fix | Delete
* @since 5.8.0
[122] Fix | Delete
* @deprecated 5.9.0
[123] Fix | Delete
*
[124] Fix | Delete
* @return array An array of theme.json fields that are translatable and the keys that are translatable.
[125] Fix | Delete
*/
[126] Fix | Delete
public static function get_fields_to_translate() {
[127] Fix | Delete
_deprecated_function( __METHOD__, '5.9.0' );
[128] Fix | Delete
return array();
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
/**
[132] Fix | Delete
* Given a theme.json structure modifies it in place to update certain values
[133] Fix | Delete
* by its translated strings according to the language set by the user.
[134] Fix | Delete
*
[135] Fix | Delete
* @since 5.8.0
[136] Fix | Delete
*
[137] Fix | Delete
* @param array $theme_json The theme.json to translate.
[138] Fix | Delete
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
[139] Fix | Delete
* Default 'default'.
[140] Fix | Delete
* @return array Returns the modified $theme_json_structure.
[141] Fix | Delete
*/
[142] Fix | Delete
protected static function translate( $theme_json, $domain = 'default' ) {
[143] Fix | Delete
if ( null === static::$i18n_schema ) {
[144] Fix | Delete
$i18n_schema = wp_json_file_decode( __DIR__ . '/theme-i18n.json' );
[145] Fix | Delete
static::$i18n_schema = null === $i18n_schema ? array() : $i18n_schema;
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
return translate_settings_using_i18n_schema( static::$i18n_schema, $theme_json, $domain );
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
/**
[152] Fix | Delete
* Returns core's origin config.
[153] Fix | Delete
*
[154] Fix | Delete
* @since 5.8.0
[155] Fix | Delete
*
[156] Fix | Delete
* @return WP_Theme_JSON Entity that holds core data.
[157] Fix | Delete
*/
[158] Fix | Delete
public static function get_core_data() {
[159] Fix | Delete
if ( null !== static::$core && static::has_same_registered_blocks( 'core' ) ) {
[160] Fix | Delete
return static::$core;
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
$config = static::read_json_file( __DIR__ . '/theme.json' );
[164] Fix | Delete
$config = static::translate( $config );
[165] Fix | Delete
[166] Fix | Delete
/**
[167] Fix | Delete
* Filters the default data provided by WordPress for global styles & settings.
[168] Fix | Delete
*
[169] Fix | Delete
* @since 6.1.0
[170] Fix | Delete
*
[171] Fix | Delete
* @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data.
[172] Fix | Delete
*/
[173] Fix | Delete
$theme_json = apply_filters( 'wp_theme_json_data_default', new WP_Theme_JSON_Data( $config, 'default' ) );
[174] Fix | Delete
[175] Fix | Delete
/*
[176] Fix | Delete
* Backward compatibility for extenders returning a WP_Theme_JSON_Data
[177] Fix | Delete
* compatible class that is not a WP_Theme_JSON_Data object.
[178] Fix | Delete
*/
[179] Fix | Delete
if ( $theme_json instanceof WP_Theme_JSON_Data ) {
[180] Fix | Delete
static::$core = $theme_json->get_theme_json();
[181] Fix | Delete
} else {
[182] Fix | Delete
$config = $theme_json->get_data();
[183] Fix | Delete
static::$core = new WP_Theme_JSON( $config, 'default' );
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
return static::$core;
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
/**
[190] Fix | Delete
* Checks whether the registered blocks were already processed for this origin.
[191] Fix | Delete
*
[192] Fix | Delete
* @since 6.1.0
[193] Fix | Delete
*
[194] Fix | Delete
* @param string $origin Data source for which to cache the blocks.
[195] Fix | Delete
* Valid values are 'core', 'blocks', 'theme', and 'user'.
[196] Fix | Delete
* @return bool True on success, false otherwise.
[197] Fix | Delete
*/
[198] Fix | Delete
protected static function has_same_registered_blocks( $origin ) {
[199] Fix | Delete
// Bail out if the origin is invalid.
[200] Fix | Delete
if ( ! isset( static::$blocks_cache[ $origin ] ) ) {
[201] Fix | Delete
return false;
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
$registry = WP_Block_Type_Registry::get_instance();
[205] Fix | Delete
$blocks = $registry->get_all_registered();
[206] Fix | Delete
[207] Fix | Delete
// Is there metadata for all currently registered blocks?
[208] Fix | Delete
$block_diff = array_diff_key( $blocks, static::$blocks_cache[ $origin ] );
[209] Fix | Delete
if ( empty( $block_diff ) ) {
[210] Fix | Delete
return true;
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
foreach ( $blocks as $block_name => $block_type ) {
[214] Fix | Delete
static::$blocks_cache[ $origin ][ $block_name ] = true;
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
return false;
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
/**
[221] Fix | Delete
* Returns the theme's data.
[222] Fix | Delete
*
[223] Fix | Delete
* Data from theme.json will be backfilled from existing
[224] Fix | Delete
* theme supports, if any. Note that if the same data
[225] Fix | Delete
* is present in theme.json and in theme supports,
[226] Fix | Delete
* the theme.json takes precedence.
[227] Fix | Delete
*
[228] Fix | Delete
* @since 5.8.0
[229] Fix | Delete
* @since 5.9.0 Theme supports have been inlined and the `$theme_support_data` argument removed.
[230] Fix | Delete
* @since 6.0.0 Added an `$options` parameter to allow the theme data to be returned without theme supports.
[231] Fix | Delete
* @since 6.6.0 Add support for 'default-font-sizes' and 'default-spacing-sizes' theme supports.
[232] Fix | Delete
* Added registration and merging of block style variations from partial theme.json files and the block styles registry.
[233] Fix | Delete
*
[234] Fix | Delete
* @param array $deprecated Deprecated. Not used.
[235] Fix | Delete
* @param array $options {
[236] Fix | Delete
* Options arguments.
[237] Fix | Delete
*
[238] Fix | Delete
* @type bool $with_supports Whether to include theme supports in the data. Default true.
[239] Fix | Delete
* }
[240] Fix | Delete
* @return WP_Theme_JSON Entity that holds theme data.
[241] Fix | Delete
*/
[242] Fix | Delete
public static function get_theme_data( $deprecated = array(), $options = array() ) {
[243] Fix | Delete
if ( ! empty( $deprecated ) ) {
[244] Fix | Delete
_deprecated_argument( __METHOD__, '5.9.0' );
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
$options = wp_parse_args( $options, array( 'with_supports' => true ) );
[248] Fix | Delete
[249] Fix | Delete
if ( null === static::$theme || ! static::has_same_registered_blocks( 'theme' ) ) {
[250] Fix | Delete
$wp_theme = wp_get_theme();
[251] Fix | Delete
$theme_json_file = $wp_theme->get_file_path( 'theme.json' );
[252] Fix | Delete
if ( is_readable( $theme_json_file ) ) {
[253] Fix | Delete
$theme_json_data = static::read_json_file( $theme_json_file );
[254] Fix | Delete
$theme_json_data = static::translate( $theme_json_data, $wp_theme->get( 'TextDomain' ) );
[255] Fix | Delete
} else {
[256] Fix | Delete
$theme_json_data = array( 'version' => WP_Theme_JSON::LATEST_SCHEMA );
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
/*
[260] Fix | Delete
* Register variations defined by theme partials (theme.json files in the styles directory).
[261] Fix | Delete
* This is required so the variations pass sanitization of theme.json data.
[262] Fix | Delete
*/
[263] Fix | Delete
$variations = static::get_style_variations( 'block' );
[264] Fix | Delete
wp_register_block_style_variations_from_theme_json_partials( $variations );
[265] Fix | Delete
[266] Fix | Delete
/*
[267] Fix | Delete
* Source variations from the block registry and block style variation files. Then, merge them into the existing theme.json data.
[268] Fix | Delete
*
[269] Fix | Delete
* In case the same style properties are defined in several sources, this is how we should resolve the values,
[270] Fix | Delete
* from higher to lower priority:
[271] Fix | Delete
*
[272] Fix | Delete
* - styles.blocks.blockType.variations from theme.json
[273] Fix | Delete
* - styles.variations from theme.json
[274] Fix | Delete
* - variations from block style variation files
[275] Fix | Delete
* - variations from block styles registry
[276] Fix | Delete
*
[277] Fix | Delete
* See test_add_registered_block_styles_to_theme_data and test_unwraps_block_style_variations.
[278] Fix | Delete
*
[279] Fix | Delete
*/
[280] Fix | Delete
$theme_json_data = static::inject_variations_from_block_style_variation_files( $theme_json_data, $variations );
[281] Fix | Delete
$theme_json_data = static::inject_variations_from_block_styles_registry( $theme_json_data );
[282] Fix | Delete
[283] Fix | Delete
/**
[284] Fix | Delete
* Filters the data provided by the theme for global styles and settings.
[285] Fix | Delete
*
[286] Fix | Delete
* @since 6.1.0
[287] Fix | Delete
*
[288] Fix | Delete
* @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data.
[289] Fix | Delete
*/
[290] Fix | Delete
$theme_json = apply_filters( 'wp_theme_json_data_theme', new WP_Theme_JSON_Data( $theme_json_data, 'theme' ) );
[291] Fix | Delete
[292] Fix | Delete
/*
[293] Fix | Delete
* Backward compatibility for extenders returning a WP_Theme_JSON_Data
[294] Fix | Delete
* compatible class that is not a WP_Theme_JSON_Data object.
[295] Fix | Delete
*/
[296] Fix | Delete
if ( $theme_json instanceof WP_Theme_JSON_Data ) {
[297] Fix | Delete
static::$theme = $theme_json->get_theme_json();
[298] Fix | Delete
} else {
[299] Fix | Delete
$config = $theme_json->get_data();
[300] Fix | Delete
static::$theme = new WP_Theme_JSON( $config );
[301] Fix | Delete
}
[302] Fix | Delete
[303] Fix | Delete
if ( $wp_theme->parent() ) {
[304] Fix | Delete
// Get parent theme.json.
[305] Fix | Delete
$parent_theme_json_file = $wp_theme->parent()->get_file_path( 'theme.json' );
[306] Fix | Delete
if ( $theme_json_file !== $parent_theme_json_file && is_readable( $parent_theme_json_file ) ) {
[307] Fix | Delete
$parent_theme_json_data = static::read_json_file( $parent_theme_json_file );
[308] Fix | Delete
$parent_theme_json_data = static::translate( $parent_theme_json_data, $wp_theme->parent()->get( 'TextDomain' ) );
[309] Fix | Delete
$parent_theme = new WP_Theme_JSON( $parent_theme_json_data );
[310] Fix | Delete
[311] Fix | Delete
/*
[312] Fix | Delete
* Merge the child theme.json into the parent theme.json.
[313] Fix | Delete
* The child theme takes precedence over the parent.
[314] Fix | Delete
*/
[315] Fix | Delete
$parent_theme->merge( static::$theme );
[316] Fix | Delete
static::$theme = $parent_theme;
[317] Fix | Delete
}
[318] Fix | Delete
}
[319] Fix | Delete
}
[320] Fix | Delete
[321] Fix | Delete
if ( ! $options['with_supports'] ) {
[322] Fix | Delete
return static::$theme;
[323] Fix | Delete
}
[324] Fix | Delete
[325] Fix | Delete
/*
[326] Fix | Delete
* We want the presets and settings declared in theme.json
[327] Fix | Delete
* to override the ones declared via theme supports.
[328] Fix | Delete
* So we take theme supports, transform it to theme.json shape
[329] Fix | Delete
* and merge the static::$theme upon that.
[330] Fix | Delete
*/
[331] Fix | Delete
$theme_support_data = WP_Theme_JSON::get_from_editor_settings( get_classic_theme_supports_block_editor_settings() );
[332] Fix | Delete
if ( ! wp_theme_has_theme_json() ) {
[333] Fix | Delete
/*
[334] Fix | Delete
* Unlike block themes, classic themes without a theme.json disable
[335] Fix | Delete
* default presets when custom preset theme support is added. This
[336] Fix | Delete
* behavior can be overridden by using the corresponding default
[337] Fix | Delete
* preset theme support.
[338] Fix | Delete
*/
[339] Fix | Delete
$theme_support_data['settings']['color']['defaultPalette'] =
[340] Fix | Delete
! isset( $theme_support_data['settings']['color']['palette'] ) ||
[341] Fix | Delete
current_theme_supports( 'default-color-palette' );
[342] Fix | Delete
$theme_support_data['settings']['color']['defaultGradients'] =
[343] Fix | Delete
! isset( $theme_support_data['settings']['color']['gradients'] ) ||
[344] Fix | Delete
current_theme_supports( 'default-gradient-presets' );
[345] Fix | Delete
$theme_support_data['settings']['typography']['defaultFontSizes'] =
[346] Fix | Delete
! isset( $theme_support_data['settings']['typography']['fontSizes'] ) ||
[347] Fix | Delete
current_theme_supports( 'default-font-sizes' );
[348] Fix | Delete
$theme_support_data['settings']['spacing']['defaultSpacingSizes'] =
[349] Fix | Delete
! isset( $theme_support_data['settings']['spacing']['spacingSizes'] ) ||
[350] Fix | Delete
current_theme_supports( 'default-spacing-sizes' );
[351] Fix | Delete
[352] Fix | Delete
/*
[353] Fix | Delete
* Shadow presets are explicitly disabled for classic themes until a
[354] Fix | Delete
* decision is made for whether the default presets should match the
[355] Fix | Delete
* other presets or if they should be disabled by default in classic
[356] Fix | Delete
* themes. See https://github.com/WordPress/gutenberg/issues/59989.
[357] Fix | Delete
*/
[358] Fix | Delete
$theme_support_data['settings']['shadow']['defaultPresets'] = false;
[359] Fix | Delete
[360] Fix | Delete
// Allow themes to enable link color setting via theme_support.
[361] Fix | Delete
if ( current_theme_supports( 'link-color' ) ) {
[362] Fix | Delete
$theme_support_data['settings']['color']['link'] = true;
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
// Allow themes to enable all border settings via theme_support.
[366] Fix | Delete
if ( current_theme_supports( 'border' ) ) {
[367] Fix | Delete
$theme_support_data['settings']['border']['color'] = true;
[368] Fix | Delete
$theme_support_data['settings']['border']['radius'] = true;
[369] Fix | Delete
$theme_support_data['settings']['border']['style'] = true;
[370] Fix | Delete
$theme_support_data['settings']['border']['width'] = true;
[371] Fix | Delete
}
[372] Fix | Delete
[373] Fix | Delete
// Allow themes to enable appearance tools via theme_support.
[374] Fix | Delete
if ( current_theme_supports( 'appearance-tools' ) ) {
[375] Fix | Delete
$theme_support_data['settings']['appearanceTools'] = true;
[376] Fix | Delete
}
[377] Fix | Delete
}
[378] Fix | Delete
$with_theme_supports = new WP_Theme_JSON( $theme_support_data );
[379] Fix | Delete
$with_theme_supports->merge( static::$theme );
[380] Fix | Delete
return $with_theme_supports;
[381] Fix | Delete
}
[382] Fix | Delete
[383] Fix | Delete
/**
[384] Fix | Delete
* Gets the styles for blocks from the block.json file.
[385] Fix | Delete
*
[386] Fix | Delete
* @since 6.1.0
[387] Fix | Delete
*
[388] Fix | Delete
* @return WP_Theme_JSON
[389] Fix | Delete
*/
[390] Fix | Delete
public static function get_block_data() {
[391] Fix | Delete
$registry = WP_Block_Type_Registry::get_instance();
[392] Fix | Delete
$blocks = $registry->get_all_registered();
[393] Fix | Delete
[394] Fix | Delete
if ( null !== static::$blocks && static::has_same_registered_blocks( 'blocks' ) ) {
[395] Fix | Delete
return static::$blocks;
[396] Fix | Delete
}
[397] Fix | Delete
[398] Fix | Delete
$config = array( 'version' => WP_Theme_JSON::LATEST_SCHEMA );
[399] Fix | Delete
foreach ( $blocks as $block_name => $block_type ) {
[400] Fix | Delete
if ( isset( $block_type->supports['__experimentalStyle'] ) ) {
[401] Fix | Delete
$config['styles']['blocks'][ $block_name ] = static::remove_json_comments( $block_type->supports['__experimentalStyle'] );
[402] Fix | Delete
}
[403] Fix | Delete
[404] Fix | Delete
if (
[405] Fix | Delete
isset( $block_type->supports['spacing']['blockGap']['__experimentalDefault'] ) &&
[406] Fix | Delete
! isset( $config['styles']['blocks'][ $block_name ]['spacing']['blockGap'] )
[407] Fix | Delete
) {
[408] Fix | Delete
/*
[409] Fix | Delete
* Ensure an empty placeholder value exists for the block, if it provides a default blockGap value.
[410] Fix | Delete
* The real blockGap value to be used will be determined when the styles are rendered for output.
[411] Fix | Delete
*/
[412] Fix | Delete
$config['styles']['blocks'][ $block_name ]['spacing']['blockGap'] = null;
[413] Fix | Delete
}
[414] Fix | Delete
}
[415] Fix | Delete
[416] Fix | Delete
/**
[417] Fix | Delete
* Filters the data provided by the blocks for global styles & settings.
[418] Fix | Delete
*
[419] Fix | Delete
* @since 6.1.0
[420] Fix | Delete
*
[421] Fix | Delete
* @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data.
[422] Fix | Delete
*/
[423] Fix | Delete
$theme_json = apply_filters( 'wp_theme_json_data_blocks', new WP_Theme_JSON_Data( $config, 'blocks' ) );
[424] Fix | Delete
[425] Fix | Delete
/*
[426] Fix | Delete
* Backward compatibility for extenders returning a WP_Theme_JSON_Data
[427] Fix | Delete
* compatible class that is not a WP_Theme_JSON_Data object.
[428] Fix | Delete
*/
[429] Fix | Delete
if ( $theme_json instanceof WP_Theme_JSON_Data ) {
[430] Fix | Delete
static::$blocks = $theme_json->get_theme_json();
[431] Fix | Delete
} else {
[432] Fix | Delete
$config = $theme_json->get_data();
[433] Fix | Delete
static::$blocks = new WP_Theme_JSON( $config, 'blocks' );
[434] Fix | Delete
}
[435] Fix | Delete
[436] Fix | Delete
return static::$blocks;
[437] Fix | Delete
}
[438] Fix | Delete
[439] Fix | Delete
/**
[440] Fix | Delete
* When given an array, this will remove any keys with the name `//`.
[441] Fix | Delete
*
[442] Fix | Delete
* @since 6.1.0
[443] Fix | Delete
*
[444] Fix | Delete
* @param array $input_array The array to filter.
[445] Fix | Delete
* @return array The filtered array.
[446] Fix | Delete
*/
[447] Fix | Delete
private static function remove_json_comments( $input_array ) {
[448] Fix | Delete
unset( $input_array['//'] );
[449] Fix | Delete
foreach ( $input_array as $k => $v ) {
[450] Fix | Delete
if ( is_array( $v ) ) {
[451] Fix | Delete
$input_array[ $k ] = static::remove_json_comments( $v );
[452] Fix | Delete
}
[453] Fix | Delete
}
[454] Fix | Delete
[455] Fix | Delete
return $input_array;
[456] Fix | Delete
}
[457] Fix | Delete
[458] Fix | Delete
/**
[459] Fix | Delete
* Returns the custom post type that contains the user's origin config
[460] Fix | Delete
* for the active theme or an empty array if none are found.
[461] Fix | Delete
*
[462] Fix | Delete
* This can also create and return a new draft custom post type.
[463] Fix | Delete
*
[464] Fix | Delete
* @since 5.9.0
[465] Fix | Delete
*
[466] Fix | Delete
* @param WP_Theme $theme The theme object. If empty, it
[467] Fix | Delete
* defaults to the active theme.
[468] Fix | Delete
* @param bool $create_post Optional. Whether a new custom post
[469] Fix | Delete
* type should be created if none are
[470] Fix | Delete
* found. Default false.
[471] Fix | Delete
* @param array $post_status_filter Optional. Filter custom post type by
[472] Fix | Delete
* post status. Default `array( 'publish' )`,
[473] Fix | Delete
* so it only fetches published posts.
[474] Fix | Delete
* @return array Custom Post Type for the user's origin config.
[475] Fix | Delete
*/
[476] Fix | Delete
public static function get_user_data_from_wp_global_styles( $theme, $create_post = false, $post_status_filter = array( 'publish' ) ) {
[477] Fix | Delete
if ( ! $theme instanceof WP_Theme ) {
[478] Fix | Delete
$theme = wp_get_theme();
[479] Fix | Delete
}
[480] Fix | Delete
[481] Fix | Delete
/*
[482] Fix | Delete
* Bail early if the theme does not support a theme.json.
[483] Fix | Delete
*
[484] Fix | Delete
* Since wp_theme_has_theme_json() only supports the active
[485] Fix | Delete
* theme, the extra condition for whether $theme is the active theme is
[486] Fix | Delete
* present here.
[487] Fix | Delete
*/
[488] Fix | Delete
if ( $theme->get_stylesheet() === get_stylesheet() && ! wp_theme_has_theme_json() ) {
[489] Fix | Delete
return array();
[490] Fix | Delete
}
[491] Fix | Delete
[492] Fix | Delete
$user_cpt = array();
[493] Fix | Delete
$post_type_filter = 'wp_global_styles';
[494] Fix | Delete
$stylesheet = $theme->get_stylesheet();
[495] Fix | Delete
$args = array(
[496] Fix | Delete
'posts_per_page' => 1,
[497] Fix | Delete
'orderby' => 'date',
[498] Fix | Delete
'order' => 'desc',
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function