Changeset 49925 for trunk/src/wp-includes/rest-api/class-wp-rest-server.php
- Timestamp:
- 01/03/2021 09:45:42 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/class-wp-rest-server.php
r49918 r49925 1245 1245 1246 1246 $response = new WP_REST_Response( $available ); 1247 1248 1247 $response->add_link( 'help', 'http://v2.wp-api.org/' ); 1248 $this->add_active_theme_link_to_index( $response ); 1249 1249 1250 1250 /** … … 1260 1260 */ 1261 1261 return apply_filters( 'rest_index', $response ); 1262 } 1263 1264 /** 1265 * Adds a link to the active theme for users who have proper permissions. 1266 * 1267 * @since 5.7.0 1268 * 1269 * @param WP_REST_Response $response REST API response. 1270 */ 1271 protected function add_active_theme_link_to_index( WP_REST_Response $response ) { 1272 $should_add = current_user_can( 'switch_themes' ) || current_user_can( 'manage_network_themes' ); 1273 1274 if ( ! $should_add && current_user_can( 'edit_posts' ) ) { 1275 $should_add = true; 1276 } 1277 1278 if ( ! $should_add ) { 1279 foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) { 1280 if ( current_user_can( $post_type->cap->edit_posts ) ) { 1281 $should_add = true; 1282 break; 1283 } 1284 } 1285 } 1286 1287 if ( $should_add ) { 1288 $theme = wp_get_theme(); 1289 $response->add_link( 'https://api.w.org/active-theme', rest_url( 'wp/v2/themes/' . $theme->get_stylesheet() ) ); 1290 } 1262 1291 } 1263 1292
Note: See TracChangeset
for help on using the changeset viewer.