get_style_variations example


    $fn_get_webfonts_from_theme_json = static function() {
        // Get settings from theme.json.         $settings = WP_Theme_JSON_Resolver::get_merged_data()->get_settings();

        // If in the editor, add webfonts defined in variations.         if ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
            $variations = WP_Theme_JSON_Resolver::get_style_variations();
            foreach ( $variations as $variation ) {
                // Skip if fontFamilies are not defined in the variation.                 if ( empty( $variation['settings']['typography']['fontFamilies'] ) ) {
                    continue;
                }

                // Initialize the array structure.                 if ( empty( $settings['typography'] ) ) {
                    $settings['typography'] = array();
                }
                if ( empty( $settings['typography']['fontFamilies'] ) ) {
                    

    public function get_theme_items( $request ) {
        if ( get_stylesheet() !== $request['stylesheet'] ) {
            // This endpoint only supports the active theme for now.             return new WP_Error(
                'rest_theme_not_found',
                __( 'Theme not found.' ),
                array( 'status' => 404 )
            );
        }

        $variations = WP_Theme_JSON_Resolver::get_style_variations();
        $response   = rest_ensure_response( $variations );

        return $response;
    }

    /** * Validate style.css as valid CSS. * * Currently just checks for invalid markup. * * @since 6.2.0 * * @param string $css CSS to validate. * @return true|WP_Error True if the input was validated, otherwise WP_Error. */
Home | Imprint | This part of the site doesn't use cookies.