WP_REST_Themes_Controller::check_read_active_theme_permission()protectedWP 5.7.0

Checks if a theme can be read.

Method of the class: WP_REST_Themes_Controller{}

No Hooks.

Return

true|WP_Error. True if the theme can be read, WP_Error object otherwise.

Usage

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

Changelog

Since 5.7.0 Introduced.

WP_REST_Themes_Controller::check_read_active_theme_permission() code WP 6.5.2

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