REST API: Expose all themes in the themes controller.
Previously, only the active theme was made available. This commit allows for all themes to be queried if the user has the `switch_themes` or `manage_network_themes` capabilities. This commit also no longer exposes the `page`, `per_page`, `search` and `context` query parameters since they are not supported by this controller. Props spacedmonkey, lpawlik, TimothyBlynJacobs. Fixes #50152. Built from https://develop.svn.wordpress.org/trunk@49925 git-svn-id: http://core.svn.wordpress.org/trunk@49624 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -1244,8 +1244,8 @@ class WP_REST_Server {
|
||||
);
|
||||
|
||||
$response = new WP_REST_Response( $available );
|
||||
|
||||
$response->add_link( 'help', 'http://v2.wp-api.org/' );
|
||||
$this->add_active_theme_link_to_index( $response );
|
||||
|
||||
/**
|
||||
* Filters the REST API root index data.
|
||||
@@ -1261,6 +1261,35 @@ class WP_REST_Server {
|
||||
return apply_filters( 'rest_index', $response );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a link to the active theme for users who have proper permissions.
|
||||
*
|
||||
* @since 5.7.0
|
||||
*
|
||||
* @param WP_REST_Response $response REST API response.
|
||||
*/
|
||||
protected function add_active_theme_link_to_index( WP_REST_Response $response ) {
|
||||
$should_add = current_user_can( 'switch_themes' ) || current_user_can( 'manage_network_themes' );
|
||||
|
||||
if ( ! $should_add && current_user_can( 'edit_posts' ) ) {
|
||||
$should_add = true;
|
||||
}
|
||||
|
||||
if ( ! $should_add ) {
|
||||
foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
|
||||
if ( current_user_can( $post_type->cap->edit_posts ) ) {
|
||||
$should_add = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $should_add ) {
|
||||
$theme = wp_get_theme();
|
||||
$response->add_link( 'https://api.w.org/active-theme', rest_url( 'wp/v2/themes/' . $theme->get_stylesheet() ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the index for a namespace.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user