/**
  * Class constructor.
  *
  * @since 0.1-dev
  */
 protected function __construct()
 {
     require_once TWO_FACTOR_DIR . 'includes/Yubico/U2F.php';
     self::$u2f = new u2flib_server\U2F(set_url_scheme('//' . $_SERVER['HTTP_HOST']));
     require_once TWO_FACTOR_DIR . 'providers/class.two-factor-fido-u2f-admin.php';
     Two_Factor_FIDO_U2F_Admin::add_hooks();
     add_action('login_enqueue_scripts', array($this, 'login_enqueue_assets'));
     add_action('two-factor-user-options-' . __CLASS__, array($this, 'user_options'));
     return parent::__construct();
 }
 /**
  * Set up a test case.
  *
  * @see WP_UnitTestCase::setup()
  */
 function setUp()
 {
     parent::setUp();
     try {
         require_once 'includes/Yubico/U2F.php';
         $this->u2f = new u2flib_server\U2F("http://demo.example.com");
         $this->provider = Two_Factor_FIDO_U2F::get_instance();
     } catch (Exception $e) {
         $this->markTestSkipped('Could not create U2F provider!');
     }
 }
 /**
  * Class constructor.
  *
  * @since 0.1-dev
  */
 protected function __construct()
 {
     $app_url_parts = parse_url(home_url());
     $app_url = sprintf('%s://%s', $app_url_parts['scheme'], $app_url_parts['host']);
     require_once TWO_FACTOR_DIR . 'includes/Yubico/U2F.php';
     self::$u2f = new u2flib_server\U2F($app_url);
     require_once TWO_FACTOR_DIR . 'providers/class.two-factor-fido-u2f-admin.php';
     Two_Factor_FIDO_U2F_Admin::add_hooks();
     add_action('login_enqueue_scripts', array($this, 'login_enqueue_assets'));
     add_action('two-factor-user-options-' . __CLASS__, array($this, 'user_options'));
     return parent::__construct();
 }
 /**
  * Ajax handler for quick edit saving for a security key.
  *
  * @since 0.1-dev
  *
  * @access public
  * @static
  */
 public static function wp_ajax_inline_save()
 {
     check_ajax_referer('keyinlineeditnonce', '_inline_edit');
     require TWO_FACTOR_DIR . 'providers/class.two-factor-fido-u2f-admin-list-table.php';
     $wp_list_table = new Two_Factor_FIDO_U2F_Admin_List_Table();
     if (!isset($_POST['keyHandle'])) {
         wp_die();
     }
     $user_id = get_current_user_id();
     $security_keys = Two_Factor_FIDO_U2F::get_security_keys($user_id);
     if (!$security_keys) {
         wp_die();
     }
     foreach ($security_keys as &$key) {
         if ($key->keyHandle === $_POST['keyHandle']) {
             break;
         }
     }
     $key->name = $_POST['name'];
     $updated = Two_Factor_FIDO_U2F::update_security_key($user_id, $key);
     if (!$updated) {
         wp_die(esc_html__('Item not updated.'));
     }
     $wp_list_table->single_row($key);
     wp_die();
 }
 /**
  * Catch the delete security key request.
  *
  * This executes during the `load-profile.php` & `load-user-edit.php` actions.
  *
  * @since 0.1-dev
  *
  * @access public
  * @static
  */
 public static function catch_delete_security_key()
 {
     $user_id = get_current_user_id();
     if (!empty($_REQUEST['delete_security_key'])) {
         $slug = $_REQUEST['delete_security_key'];
         check_admin_referer("delete_security_key-{$slug}", '_nonce_delete_security_key');
         Two_Factor_FIDO_U2F::delete_security_key($user_id, $slug);
         wp_safe_redirect(remove_query_arg('new_app_pass', wp_get_referer()) . '#security-keys-section');
     }
 }