REST API: Expose the site icon in the REST API index.

Props spacedmonkey, palmiak.
Fixes #52321.

Built from https://develop.svn.wordpress.org/trunk@52080


git-svn-id: http://core.svn.wordpress.org/trunk@51672 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
TimothyBlynJacobs 2021-11-09 20:37:59 +00:00
parent e2d4385a4f
commit d224b7cf10
2 changed files with 40 additions and 5 deletions

View File

@ -1229,6 +1229,7 @@ class WP_REST_Server {
$response->add_link( 'help', 'https://developer.wordpress.org/rest-api/' ); $response->add_link( 'help', 'https://developer.wordpress.org/rest-api/' );
$this->add_active_theme_link_to_index( $response ); $this->add_active_theme_link_to_index( $response );
$this->add_site_logo_to_index( $response ); $this->add_site_logo_to_index( $response );
$this->add_site_icon_to_index( $response );
/** /**
* Filters the REST API root index data. * Filters the REST API root index data.
@ -1275,6 +1276,7 @@ class WP_REST_Server {
/** /**
* Exposes the site logo through the WordPress REST API. * Exposes the site logo through the WordPress REST API.
*
* This is used for fetching this information when user has no rights * This is used for fetching this information when user has no rights
* to update settings. * to update settings.
* *
@ -1283,14 +1285,47 @@ class WP_REST_Server {
* @param WP_REST_Response $response REST API response. * @param WP_REST_Response $response REST API response.
*/ */
protected function add_site_logo_to_index( WP_REST_Response $response ) { protected function add_site_logo_to_index( WP_REST_Response $response ) {
$site_logo_id = get_theme_mod( 'custom_logo' ); $site_logo_id = get_theme_mod( 'custom_logo', 0 );
$response->data['site_logo'] = $site_logo_id;
if ( $site_logo_id ) { $this->add_image_to_index( $response, $site_logo_id, 'site_logo' );
}
/**
* Exposes the site icon through the WordPress REST API.
*
* This is used for fetching this information when user has no rights
* to update settings.
*
* @since 5.9.0
*
* @param WP_REST_Response $response REST API response.
*/
protected function add_site_icon_to_index( WP_REST_Response $response ) {
$site_icon_id = get_option( 'site_icon', 0 );
$this->add_image_to_index( $response, $site_icon_id, 'site_icon' );
}
/**
* Exposes an image through the WordPress REST API.
* This is used for fetching this information when user has no rights
* to update settings.
*
* @since 5.9.0
*
* @param WP_REST_Response $response REST API response.
* @param int $image_id Image attachment ID.
* @param string $type Type of Image.
*/
protected function add_image_to_index( WP_REST_Response $response, $image_id, $type ) {
$response->data[ $type ] = (int) $image_id;
if ( $image_id ) {
$response->add_link( $response->add_link(
'https://api.w.org/featuredmedia', 'https://api.w.org/featuredmedia',
rest_url( rest_get_route_for_post( $site_logo_id ) ), rest_url( rest_get_route_for_post( $image_id ) ),
array( array(
'embeddable' => true, 'embeddable' => true,
'type' => $type,
) )
); );
} }

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.9-alpha-52079'; $wp_version = '5.9-alpha-52080';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.