Make WordPress Core


Ignore:
Timestamp:
11/08/2021 08:58:56 PM (3 years ago)
Author:
jorgefilipecosta
Message:

Add: Global Styles Rest endpoints.

This commit ports the global styles rest endpoints from the Gutenberg plugin into the core.

See #54336.
Props oandregal, aristath, timothyblynjacobs, spacedmonkey, youknowriad.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php

    r52017 r52051  
    317317        $response->add_links( $this->prepare_links( $theme ) );
    318318
     319        if ( $theme->get_stylesheet() === wp_get_theme()->get_stylesheet() ) {
     320            // This creates a record for the current theme if not existent.
     321            $id = WP_Theme_JSON_Resolver::get_user_custom_post_type_id();
     322        } else {
     323            $wp_query_args       = array(
     324                'post_status'    => 'publish',
     325                'post_type'      => 'wp_global_styles',
     326                'posts_per_page' => 1,
     327                'no_found_rows'  => true,
     328                'fields'         => 'ids',
     329                'tax_query'      => array(
     330                    array(
     331                        'taxonomy' => 'wp_theme',
     332                        'field'    => 'name',
     333                        'terms'    => $theme->get_stylesheet(),
     334                    ),
     335                ),
     336            );
     337            $global_styles_query = new WP_Query( $wp_query_args );
     338            $id                  = ! empty( $global_styles_query->posts ) ? array_shift( $global_styles_query->posts ) : null;
     339        }
     340
     341        if ( $id ) {
     342            $response->add_link(
     343                'https://api.w.org/user-global-styles',
     344                rest_url( 'wp/v2/global-styles/' . $id )
     345            );
     346        }
     347
    319348        /**
    320349         * Filters theme data returned from the REST API.
Note: See TracChangeset for help on using the changeset viewer.