WordPress at Your Fingertips
function is not described

WP_REST_Themes_Controller::check_read_active_theme_permission() protected WP 5.7.0

Checks if a theme can be read.

{} It's a method of the class: WP_REST_Themes_Controller{}

No Hooks.

Return

true|false|WP_Error. Whether the theme can be read.

Usage

// protected - for code of main (parent) or child class
$result = $this->check_read_active_theme_permission();

Changelog

Since 5.7.0 Introduced.

Code of WP_REST_Themes_Controller::check_read_active_theme_permission() WP 5.8

<?php
protected function check_read_active_theme_permission() {
	if ( current_user_can( 'edit_posts' ) ) {
		return true;
	}

	foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
		if ( current_user_can( $post_type->cap->edit_posts ) ) {
			return true;
		}
	}

	return new WP_Error(
		'rest_cannot_view_active_theme',
		__( 'Sorry, you are not allowed to view the active theme.' ),
		array( 'status' => rest_authorization_required_code() )
	);
}