REST API: Add stylesheet and template URI fields to the Themes API.
Props andrewserong, timothyblynjacobs, noisysocks, ramonopoly, peterwilsoncc, Dharm1025. Fixes #61021. Built from https://develop.svn.wordpress.org/trunk@58282 git-svn-id: http://core.svn.wordpress.org/trunk@57742 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9fc546b2ce
commit
53e041b361
|
@ -224,6 +224,7 @@ class WP_REST_Themes_Controller extends WP_REST_Controller {
|
|||
*
|
||||
* @since 5.0.0
|
||||
* @since 5.9.0 Renamed `$theme` to `$item` to match parent class for PHP 8 named parameter support.
|
||||
* @since 6.6.0 Added `stylesheet_uri` and `template_uri` fields.
|
||||
*
|
||||
* @param WP_Theme $item Theme object.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
|
@ -331,6 +332,22 @@ class WP_REST_Themes_Controller extends WP_REST_Controller {
|
|||
$data['is_block_theme'] = $theme->is_block_theme();
|
||||
}
|
||||
|
||||
if ( rest_is_field_included( 'stylesheet_uri', $fields ) ) {
|
||||
if ( $this->is_same_theme( $theme, $current_theme ) ) {
|
||||
$data['stylesheet_uri'] = get_stylesheet_directory_uri();
|
||||
} else {
|
||||
$data['stylesheet_uri'] = $theme->get_stylesheet_directory_uri();
|
||||
}
|
||||
}
|
||||
|
||||
if ( rest_is_field_included( 'template_uri', $fields ) ) {
|
||||
if ( $this->is_same_theme( $theme, $current_theme ) ) {
|
||||
$data['template_uri'] = get_template_directory_uri();
|
||||
} else {
|
||||
$data['template_uri'] = $theme->get_template_directory_uri();
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
|
||||
// Wrap the data in a response object.
|
||||
|
@ -447,11 +464,23 @@ class WP_REST_Themes_Controller extends WP_REST_Controller {
|
|||
'type' => 'string',
|
||||
'readonly' => true,
|
||||
),
|
||||
'stylesheet_uri' => array(
|
||||
'description' => __( 'The uri for the theme\'s stylesheet directory.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'uri',
|
||||
'readonly' => true,
|
||||
),
|
||||
'template' => array(
|
||||
'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.' ),
|
||||
'type' => 'string',
|
||||
'readonly' => true,
|
||||
),
|
||||
'template_uri' => array(
|
||||
'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.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'uri',
|
||||
'readonly' => true,
|
||||
),
|
||||
'author' => array(
|
||||
'description' => __( 'The theme author.' ),
|
||||
'type' => 'object',
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.6-alpha-58281';
|
||||
$wp_version = '6.6-alpha-58282';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue