WP_REST_View_Config_Controller::get_items_permissions_check │ public │ WP 7.1.0

Checks if a given request has access to read view config.

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

Хуков нет.

Возвращает

true|WP_Error. True if the request has read access, WP_Error object otherwise.

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

$WP_REST_View_Config_Controller = new WP_REST_View_Config_Controller();
$WP_REST_View_Config_Controller->get_items_permissions_check( $request );
$request(WP_REST_Request) (обязательный)
Full details about the request.

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

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

Код WP_REST_View_Config_Controller::get_items_permissions_check() WP 7.1.2

public function get_items_permissions_check( $request ) {
	$kind = $request->get_param( 'kind' );
	$name = $request->get_param( 'name' );

	$capability = $this->get_required_capability( $kind, $name );

	if ( null === $capability ) {
		return new WP_Error(
			'rest_view_config_invalid_entity',
			__( 'Invalid entity kind or name.' ),
			array( 'status' => 404 )
		);
	}

	if ( ! current_user_can( $capability ) ) {
		return new WP_Error(
			'rest_cannot_read',
			__( 'Sorry, you are not allowed to read view config.' ),
			array( 'status' => rest_authorization_required_code() )
		);
	}

	return true;
}