request = $request; $this->flash = $flash; $this->url = $url; } /** * @return JSON_Response|Redirection_Response|View_Response */ public function handle() { $action = $this->request->action(); $nonce = $this->request->get_nonce(); if ( $this->request->is_post() && ! $this->check( $nonce, $action ) ) { if ( $this->request->is_ajax() ) { return $this->json( array( 'error' => 'Security token is invalid.', ), 403 ); } $this->flash->add_message( 'error', 'csrf' ); return $this->redirection( $this->request->page(), $this->request->referer_action() ); } return $this->next->handle(); } /** * @param string $nonce * @param string $action * * @return bool */ private function check( $nonce, $action ) { return false !== wp_verify_nonce( $nonce, $action ); } }