responseService = $responseService; } /** * @param RequestInterface $request * @param $next * @param string $capability * * @return mixed|ResponseService */ public function handle( RequestInterface $request, $next, string $capability = 'manage_options' ){ // ignore the request if the current user doesn't have sufficient permissions if ( ! current_user_can( $capability ) ) { return $this->responseService->json([ 'errors' => [ __( sprintf( "Sorry, insufficient permission to perform this action! '%s' capability is required!", $capability ), 'depicter' ) ] ])->withStatus(403); } return $next( $request ); } }