WP_REST_Server::add_active_theme_link_to_index() WordPress Method

The WP_REST_Server::add_active_theme_link_to_index() function is used to add a link to the current active theme in the WordPress REST API index. This can be used by clients to easily discover the REST API endpoints for the active theme.

WP_REST_Server::add_active_theme_link_to_index( WP_REST_Response $response ) #

Adds a link to the active theme for users who have proper permissions.


Parameters

$response

(WP_REST_Response)(Required)REST API response.


Top ↑

Source

File: wp-includes/rest-api/class-wp-rest-server.php

	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() ) );
		}
	}


Top ↑

Changelog

Changelog
VersionDescription
5.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.