method = $method; $this->scope = $scope; $this->client_id = $client_id; $this->client_name = $client_name; } /** * Sets the context of the current request. * * @param Context $context Context. */ public static function set( Context $context ): void { self::$current = $context; } /** * The context of the current request. */ public static function current(): Context { return null === self::$current ? new self( self::NONE, self::SCOPE_READ ) : self::$current; } /** * Back to the default (end of request, tests). */ public static function reset(): void { self::$current = null; } /** * Authentication method. */ public function method(): string { return $this->method; } /** * Scope. */ public function scope(): string { return $this->scope; } /** * Whether the credential may write. */ public function allows_writes(): bool { return self::SCOPE_WRITE === $this->scope; } /** * The access AI tools get on a site: write only while its Access for AI tools is Read and propose changes (writes * on) and the scope (the connection's, or an app's) is write; read otherwise. * * @param bool $writes_enabled Whether writes are on (WpPolicy::writes_enabled()). * @param string $scope A scope constant. * @return string SCOPE_READ or SCOPE_WRITE. */ public static function access( bool $writes_enabled, string $scope ): string { return $writes_enabled && self::SCOPE_WRITE === $scope ? self::SCOPE_WRITE : self::SCOPE_READ; } /** * Client id. */ public function client_id(): string { return $this->client_id; } /** * Client name. */ public function client_name(): string { return $this->client_name; } }