action = $action; $this->request_key = $request_key; $this->generate_nonce( $action ); } public function verify( $request ) { if ( ! isset( $request[ $this->request_key ] ) ) { return false; } return false !== wp_verify_nonce( $request[ $this->request_key ], $this->action ); } public function generate_nonce() { $nonce = wp_create_nonce( $this->action ); static::save_generated_nonce( $this->action, $nonce ); return $nonce; } /** * Keep track of the nonces created using this class. * * @param string $action - The action where this nonce is used. * @param string $nonce - The nonce value. * * @return void */ private static function save_generated_nonce( $action, $nonce ) { static::$saved_nonces[ $action ] = $nonce; } /** * @return array Array of saved [action => nonce] pairs. */ public static function get_generated_nonces() { return static::$saved_nonces; } }