WP_Theme_JSON_Resolver::get_user_data() – Returns the user’s origin config.

You appear to be a bot. Output may be restricted

Description

Returns the user's origin config.

Usage

$WP_Theme_JSON = WP_Theme_JSON_Resolver::get_user_data();

Parameters

Returns

WP_Theme_JSON Entity that holds styles for user data.

Source

File name: wordpress/wp-includes/class-wp-theme-json-resolver.php
Lines:

1 to 32 of 32
  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;
  }
 

 View on GitHub View on Trac