Make WordPress Core


Ignore:
Timestamp:
06/02/2024 07:25:03 PM (10 months ago)
Author:
TimothyBlynJacobs
Message:

REST API: Add stylesheet and template URI fields to the Themes API.

Props andrewserong, timothyblynjacobs, noisysocks, ramonopoly, peterwilsoncc, Dharm1025.
Fixes #61021.

File:
1 edited

Legend:

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

    r56586 r58282  
    225225     * @since 5.0.0
    226226     * @since 5.9.0 Renamed `$theme` to `$item` to match parent class for PHP 8 named parameter support.
     227     * @since 6.6.0 Added `stylesheet_uri` and `template_uri` fields.
    227228     *
    228229     * @param WP_Theme        $item    Theme object.
     
    330331        if ( rest_is_field_included( 'is_block_theme', $fields ) ) {
    331332            $data['is_block_theme'] = $theme->is_block_theme();
     333        }
     334
     335        if ( rest_is_field_included( 'stylesheet_uri', $fields ) ) {
     336            if ( $this->is_same_theme( $theme, $current_theme ) ) {
     337                $data['stylesheet_uri'] = get_stylesheet_directory_uri();
     338            } else {
     339                $data['stylesheet_uri'] = $theme->get_stylesheet_directory_uri();
     340            }
     341        }
     342
     343        if ( rest_is_field_included( 'template_uri', $fields ) ) {
     344            if ( $this->is_same_theme( $theme, $current_theme ) ) {
     345                $data['template_uri'] = get_template_directory_uri();
     346            } else {
     347                $data['template_uri'] = $theme->get_template_directory_uri();
     348            }
    332349        }
    333350
     
    448465                    'readonly'    => true,
    449466                ),
     467                'stylesheet_uri' => array(
     468                    'description' => __( 'The uri for the theme\'s stylesheet directory.' ),
     469                    'type'        => 'string',
     470                    'format'      => 'uri',
     471                    'readonly'    => true,
     472                ),
    450473                'template'       => array(
    451474                    'description' => __( 'The theme\'s template. If this is a child theme, this refers to the parent theme, otherwise this is the same as the theme\'s stylesheet.' ),
    452475                    'type'        => 'string',
     476                    'readonly'    => true,
     477                ),
     478                'template_uri'       => array(
     479                    'description' => __( 'The uri for the theme\'s template directory. If this is a child theme, this refers to the parent theme, otherwise this is the same as the theme\'s stylesheet directory.' ),
     480                    'type'        => 'string',
     481                    'format'      => 'uri',
    453482                    'readonly'    => true,
    454483                ),
Note: See TracChangeset for help on using the changeset viewer.