get_user_data_from_wp_global_styles example


    public static function get_user_data() {
        if ( null !== static::$user && static::has_same_registered_blocks( '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() );
                /** * Filters the data provided by the user for global styles & settings. * * @since 6.1.0 * * @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data. */
'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $theme->get_stylesheet() ) ),
            ),
            'collection' => array(
                'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
            ),
        );

        if ( $this->is_same_theme( $themewp_get_theme() ) ) {
            // This creates a record for the active theme if not existent.             $id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id();
        } else {
            $user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( $theme );
            $id       = isset( $user_cpt['ID'] ) ? $user_cpt['ID'] : null;
        }

        if ( $id ) {
            $links['https://api.w.org/user-global-styles'] = array(
                'href' => rest_url( 'wp/v2/global-styles/' . $id ),
            );
        }

        return $links;
    }

    
Home | Imprint | This part of the site doesn't use cookies.