WP_REST_Menus_Controller::check_has_read_only_accessprotectedWP 5.9.0

Checks whether the current user has read permission for the endpoint.

This allows for any user that can edit_theme_options or edit any REST API available post type.

Метод класса: WP_REST_Menus_Controller{}

Хуки из метода

Возвращает

true|WP_Error. True if the current user has permission, WP_Error object otherwise.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->check_has_read_only_access( $request );
$request(WP_REST_Request) (обязательный)
Full details about the request.

Список изменений

С версии 5.9.0 Введена.

Код WP_REST_Menus_Controller::check_has_read_only_access() WP 6.8.1

protected function check_has_read_only_access( $request ) {
	/** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php */
	$read_only_access = apply_filters( 'rest_menu_read_access', false, $request, $this );
	if ( $read_only_access ) {
		return true;
	}

	if ( current_user_can( 'edit_theme_options' ) ) {
		return true;
	}

	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',
		__( 'Sorry, you are not allowed to view menus.' ),
		array( 'status' => rest_authorization_required_code() )
	);
}