t_user_data_from_wp_global_styles( $theme, $create_post = false, $post_status_filter = array( 'publish' ) ) {
if ( ! $theme instanceof WP_Theme ) {
$theme = wp_get_theme();
}
$user_cpt = array();
$post_type_filter = 'wp_global_styles';
$args = array(
'numberposts' => 1,
'orderby' => 'date',
'order' => 'desc',
'post_type' => $post_type_filter,
'post_status' => $post_status_filter,
'tax_query' => array(
array(
'taxonomy' => 'wp_theme',
'field' => 'name',
'terms' => $theme->get_stylesheet(),
),
),
);
$cache_key = sprintf( 'wp_global_styles_%s', md5( serialize( $args ) ) );
$post_id = wp_cache_get( $cache_key );
if ( (int) $post_id > 0 ) {
return get_post( $post_id, ARRAY_A );
}
// Special case: '-1' is a results not found.
if ( -1 === $post_id && ! $create_post ) {
return $user_cpt;
}
$recent_posts = wp_get_recent_posts( $args );
if ( is_array( $recent_posts ) && ( count( $recent_posts ) === 1 ) ) {
$user_cpt = $recent_posts[0];
} elseif ( $create_post ) {
$cpt_post_id = wp_insert_post(
array(
'post_content' => '{"version": ' . WP_Theme_JSON::LATEST_SCHEMA . ', "isGlobalStylesUserThemeJSON": true }',
'post_status' => 'publish',
'post_title' => 'Custom Styles',
'post_type' => $post_type_filter,
'post_name' => 'wp-global-styles-' . urlencode( wp_get_theme()->get_stylesheet() ),
'tax_input' => array(
'wp_theme' => array( wp_get_theme()->get_stylesheet() ),
),
),
true
);
$user_cpt = get_post( $cpt_post_id, ARRAY_A );
}
$cache_expiration = $user_cpt ? DAY_IN_SECONDS : HOUR_IN_SECONDS;
wp_cache_set( $cache_key, $user_cpt ? $user_cpt['ID'] : -1, '', $cache_expiration );
return $user_cpt;
}
/**
* Returns the user's origin config.
*
* @since 5.9.0
*
* @return WP_Theme_JSON Entity that holds styles for user data.
*/
public static function get_user_data() {
if ( null !== static::$user ) {
return static::$user;
}
$config = array();
$user_cpt = static::get_user_data_from_wp_global_styles( wp_get_theme() );
if ( array_key_exists( 'post_content', $user_cpt ) ) {
$decoded_data = json_decode( $user_cpt['post_content'], true );
$json_decoding_error = json_last_error();
if ( JSON_ERROR_NONE !== $json_decoding_error ) {
trigger_error( 'Error when decoding a theme.json schema for user data. ' . json_last_error_msg() );
return new WP_Theme_JSON( $config, 'custom' );
}
// Very important to verify that the flag isGlobalStylesUserThemeJSON is true.
// If it's not true then the content was not escaped and is not safe.
if (
is_array( $decoded_data ) &&
isset( $decoded_data['isGlobalStylesUserThemeJSON'] ) &&
$decoded_data['isGlobalStylesUserThemeJSON']
) {
unset( $decoded_data['isGlobalStylesUserThemeJSON'] );
$config = $decoded_data;
}
}
static::$user = new WP_Theme_JSON( $config, 'custom' );
return static::$user;
}
/**
* Returns the data merged from multiple origins.
*
* There are three sources of data (origins) for a site:
* default, theme, and custom. The custom's has higher priority
* than the theme's, and the theme's higher than default's.
*
* Unlike the getters
* {@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_core_data/ get_core_data},
* {@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_theme_data/ get_theme_data},
* and {@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_user_data/ get_user_data},
* this method returns data after it has been merged with the previous origins.
* This means that if the same piece of data is declared in different origins
* (user, theme, and core), the last origin overrides the previous.
*
* For example, if the user has set a background color
* for the paragraph block, and the theme has done it as well,
* the user preference wins.
*
* @since 5.8.0
* @since 5.9.0 Added user data, removed the `$settings` parameter,
* added the `$origin` parameter.
*
* @param string $origin Optional. To what level should we merge data.
* Valid values are 'theme' or 'custom'. Default 'custom'.
* @return WP_Theme_JSON
*/
public static function get_merged_data( $origin = 'custom' ) {
if ( is_array( $origin ) ) {
_deprecated_argument( __FUNCTION__, '5.9.0' );
}
$result = new WP_Theme_JSON();
$result->merge( static::get_core_data() );
$result->merge( static::get_theme_data() );
if ( 'custom' === $origin ) {
$result->merge( static::get_user_data() );
}
return $result;
}
/**
* Returns the ID of the custom post type
* that stores user data.
*
* @since 5.9.0
*
* @return integer|null
*/
public static function get_user_global_styles_post_id() {
if ( null !== static::$user_custom_post_type_id ) {
return static::$user_custom_post_type_id;
}
$user_cpt = static::get_user_data_from_wp_global_styles( wp_get_theme(), true );
if ( array_key_exists( 'ID', $user_cpt ) ) {
static::$user_custom_post_type_id = $user_cpt['ID'];
}
return static::$user_custom_post_type_id;
}
/**
* Determines whether the active theme has a theme.json file.
*
* @since 5.8.0
* @since 5.9.0 Added a check in the parent theme.
*
* @return bool
*/
public static function theme_has_support() {
if ( ! isset( static::$theme_has_support ) ) {
static::$theme_has_support = (
is_readable( static::get_file_path_from_theme( 'theme.json' ) ) ||
is_readable( static::get_file_path_from_theme( 'theme.json', true ) )
);
}
return static::$theme_has_support;
}
/**
* Builds the path to the given file and checks that it is readable.
*
* If it isn't, returns an empty string, otherwise returns the whole file path.
*
* @since 5.8.0
* @since 5.9.0 Adapted to work with child themes, added the `$template` argument.
*
* @param string $file_name Name of the file.
* @param bool $template Optional. Use template theme directory. Default false.
* @return string The whole file path or empty if the file doesn't exist.
*/
protected static function get_file_path_from_theme( $file_name, $template = false ) {
$path = $template ? get_template_directory() : get_stylesheet_directory();
$candidate = $path . '/' . $file_name;
return is_readable( $candidate ) ? $candidate : '';
}
/**
* Cleans the cached data so it can be recalculated.
*
* @since 5.8.0
* @since 5.9.0 Added the `$user`, `$user_custom_post_type_id`,
* and `$i18n_schema` variables to reset.
*/
public static function clean_cached_data() {
static::$core = null;
static::$theme = null;
static::$user = null;
static::$user_custom_post_type_id = null;
static::$theme_has_support = null;
static::$i18n_schema = null;
}
/**
* Returns the style variations defined by the theme.
*
* @since 6.0.0
*
* @return array
*/
public static function get_style_variations() {
$variations = array();
$base_directory = get_stylesheet_directory() . '/styles';
if ( is_dir( $base_directory ) ) {
$nested_files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $base_directory ) );
$nested_html_files = iterator_to_array( new RegexIterator( $nested_files, '/^.+\.json$/i', RecursiveRegexIterator::GET_MATCH ) );
ksort( $nested_html_files );
foreach ( $nested_html_files as $path => $file ) {
$decoded_file = wp_json_file_decode( $path, array( 'associative' => true ) );
if ( is_array( $decoded_file ) ) {
$translated = static::translate( $decoded_file, wp_get_theme()->get( 'TextDomain' ) );
$variation = ( new WP_Theme_JSON( $translated ) )->get_raw_data();
if ( empty( $variation['title'] ) ) {
$variation['title'] = basename( $path, '.json' );
}
$variations[] = $variation;
}
}
}
return $variations;
}
}
Fatal error: Uncaught Error: Class 'WP_Theme_JSON_Resolver' not found in /var/www/html/planilhando.com.br/web/forum/wp-includes/theme-templates.php:212
Stack trace:
#0 /var/www/html/planilhando.com.br/web/forum/wp-includes/class-wp-hook.php(307): wp_enable_block_templates('')
#1 /var/www/html/planilhando.com.br/web/forum/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters(NULL, Array)
#2 /var/www/html/planilhando.com.br/web/forum/wp-includes/plugin.php(476): WP_Hook->do_action(Array)
#3 /var/www/html/planilhando.com.br/web/forum/wp-settings.php(530): do_action('setup_theme')
#4 /var/www/html/planilhando.com.br/web/forum/wp-config.php(106): require_once('/var/www/html/p...')
#5 /var/www/html/planilhando.com.br/web/forum/wp-load.php(50): require_once('/var/www/html/p...')
#6 /var/www/html/planilhando.com.br/web/forum/wp-blog-header.php(13): require_once('/var/www/html/p...')
#7 /var/www/html/planilhando.com.br/web/forum/index.php(17): require('/var/www/html/p...')
#8 {main}
thrown in /var/www/html/planilhando.com.br/web/forum/wp-includes/theme-templates.php on line 212