Changeset 52080
- Timestamp:
- 11/09/2021 08:36:37 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/class-wp-rest-server.php
r52068 r52080 1230 1230 $this->add_active_theme_link_to_index( $response ); 1231 1231 $this->add_site_logo_to_index( $response ); 1232 $this->add_site_icon_to_index( $response ); 1232 1233 1233 1234 /** … … 1276 1277 /** 1277 1278 * Exposes the site logo through the WordPress REST API. 1279 * 1278 1280 * This is used for fetching this information when user has no rights 1279 1281 * to update settings. … … 1284 1286 */ 1285 1287 protected function add_site_logo_to_index( WP_REST_Response $response ) { 1286 $site_logo_id = get_theme_mod( 'custom_logo' ); 1287 $response->data['site_logo'] = $site_logo_id; 1288 if ( $site_logo_id ) { 1288 $site_logo_id = get_theme_mod( 'custom_logo', 0 ); 1289 1290 $this->add_image_to_index( $response, $site_logo_id, 'site_logo' ); 1291 } 1292 1293 /** 1294 * Exposes the site icon through the WordPress REST API. 1295 * 1296 * This is used for fetching this information when user has no rights 1297 * to update settings. 1298 * 1299 * @since 5.9.0 1300 * 1301 * @param WP_REST_Response $response REST API response. 1302 */ 1303 protected function add_site_icon_to_index( WP_REST_Response $response ) { 1304 $site_icon_id = get_option( 'site_icon', 0 ); 1305 1306 $this->add_image_to_index( $response, $site_icon_id, 'site_icon' ); 1307 } 1308 1309 /** 1310 * Exposes an image through the WordPress REST API. 1311 * This is used for fetching this information when user has no rights 1312 * to update settings. 1313 * 1314 * @since 5.9.0 1315 * 1316 * @param WP_REST_Response $response REST API response. 1317 * @param int $image_id Image attachment ID. 1318 * @param string $type Type of Image. 1319 */ 1320 protected function add_image_to_index( WP_REST_Response $response, $image_id, $type ) { 1321 $response->data[ $type ] = (int) $image_id; 1322 if ( $image_id ) { 1289 1323 $response->add_link( 1290 1324 'https://api.w.org/featuredmedia', 1291 rest_url( rest_get_route_for_post( $ site_logo_id ) ),1325 rest_url( rest_get_route_for_post( $image_id ) ), 1292 1326 array( 1293 1327 'embeddable' => true, 1328 'type' => $type, 1294 1329 ) 1295 1330 ); -
trunk/tests/phpunit/tests/rest-api/rest-server.php
r52068 r52080 11 11 */ 12 12 class Tests_REST_Server extends WP_Test_REST_TestCase { 13 protected static $icon_id; 14 15 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 16 $filename = DIR_TESTDATA . '/images/test-image-large.jpg'; 17 self::$icon_id = $factory->attachment->create_upload_object( $filename ); 18 } 19 13 20 public function set_up() { 14 21 parent::set_up(); … … 1008 1015 $this->assertArrayHasKey( 'help', $index->get_links() ); 1009 1016 $this->assertArrayNotHasKey( 'wp:active-theme', $index->get_links() ); 1017 1018 // Check site icon. 1019 $this->assertArrayHasKey( 'site_icon', $data ); 1020 } 1021 1022 /** 1023 * @ticket 52321 1024 */ 1025 public function test_get_index_with_site_icon() { 1026 $server = new WP_REST_Server(); 1027 update_option( 'site_icon', self::$icon_id ); 1028 1029 $request = new WP_REST_Request( 'GET', '/' ); 1030 $index = $server->dispatch( $request ); 1031 $data = $index->get_data(); 1032 1033 $this->assertArrayHasKey( 'site_icon', $data ); 1034 $this->assertEquals( self::$icon_id, $data['site_icon'] ); 1010 1035 } 1011 1036 -
trunk/tests/qunit/fixtures/wp-api-generated.js
r52079 r52080 10370 10370 } 10371 10371 }, 10372 "site_logo": false 10372 "site_logo": 0, 10373 "site_icon": 0 10373 10374 }; 10374 10375
Note: See TracChangeset
for help on using the changeset viewer.