PluginProbe
Two Factor Authentication / 1.12.2
Two Factor Authentication v1.12.2
1.12.2 1.13.0 1.14.10 1.14.11 1.14.14 1.14.15 1.14.16 1.14.17 1.14.23 1.14.24 1.14.26 1.14.27 1.14.3 1.14.4 1.14.5 1.14.7 1.14.8 1.15.5 1.16.0 1.2.10 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 All 98 releases
two-factor-authentication / includes / login-form-integrations.php

login-form-integrations.php in Two Factor Authentication 1.12.2, at includes/login-form-integrations.php

124 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) die('No direct access.');
4
5 /**
6 * Purpose of this class: abstract out code handling integrations with login forms
7 */
8
9 class Simba_TFA_Login_Form_Integrations {
10
11 // Main class
12 private $tfa;
13
14 /**
15 * Plugin constructor
16 *
17 * @param Object $tfa
18 */
19 public function __construct($tfa) {
20
21 $this->tfa = $tfa;
22
23 $enqueue_upon_actions = array(
24 // This is needed for the login form on the dedicated payment page (e.g. /checkout/order-pay/123456/?pay_for_order=true&key=wc_order_blahblahblah)
25 'woocommerce_login_form_start',
26 'woocommerce_before_customer_login_form',
27 // The login form on the checkout doesn't call the woocommerce_before_customer_login_form action
28 'woocommerce_before_checkout_form',
29 'affwp_login_fields_before',
30 );
31
32 foreach ($enqueue_upon_actions as $action) {
33 add_action($action, array($this->tfa, 'login_enqueue_scripts'));
34 }
35
36 if (!defined('TWO_FACTOR_DISABLE') || !TWO_FACTOR_DISABLE) {
37 add_action('affwp_process_login_form', array($this, 'affwp_process_login_form'));
38 }
39
40 add_filter('tml_display', array($this, 'tml_display'));
41
42 // We want to run first if possible, so that we're not aborted by JavaScript exceptions in other components (our code is critical to the login process for TFA users)
43 // Unfortunately, though, people start enqueuing from init onwards (before that is buggy - https://core.trac.wordpress.org/ticket/11526), so, we try to detect the login page and go earlier there.
44 if (isset($GLOBALS['pagenow']) && 'wp-login.php' === $GLOBALS['pagenow']) {
45 add_action('init', array($this->tfa, 'login_enqueue_scripts'), -99999999999);
46 } else {
47 add_action('login_enqueue_scripts', array($this->tfa, 'login_enqueue_scripts'), -99999999999);
48 }
49
50 add_filter('do_shortcode_tag', array($this, 'do_shortcode_tag'), 10, 2);
51
52 add_filter('simba_tfa_login_enqueue_localize', array($this, 'simba_tfa_login_enqueue_localize'), 9);
53
54 }
55
56 // Catch TML login widgets (other TML login forms already trigger)
57 public function tml_display($whatever) {
58 $this->tfa->login_enqueue_scripts();
59 return $whatever;
60 }
61
62 /**
63 * Runs upon the WP filter simba_tfa_login_enqueue_localize.
64 *
65 * @param Array $localize
66 *
67 * @return Array
68 */
69 public function simba_tfa_login_enqueue_localize($localize) {
70 // WP login form is #loginform
71 // Ultimate Membership Pro - April 2018
72 // Theme My Login 6.x - .tml-login form[name="loginform"]
73 // Theme My Login 7.x - .tml-login form[name="login"] (July 2018)
74 // WP Members - March 2018
75 // bbPress - June 2021
76 // WooCommerce - ported over from the separate wooextend.js code, June 2021
77 // Affiliates WP - ported over from the separate wooextend.js code, June 2021
78 $localize['login_form_selectors'] .= '.tml-login form[name="loginform"], .tml-login form[name="login"], #loginform, #wpmem_login form, form#ihc_login_form, .bbp-login-form, .woocommerce form.login, #affwp-login-form';
79 $localize['login_form_off_selectors'] .= '#ihc_login_form';
80 return $localize;
81 }
82
83 /**
84 * Runs upon the WP action affwp_process_login_form
85 */
86 public function affwp_process_login_form() {
87
88 if (!function_exists('affiliate_wp')) return;
89
90 $affiliate_wp = affiliate_wp();
91 $login = $affiliate_wp->login;
92
93 $params = array(
94 'log' => stripslashes($_POST['affwp_user_login']),
95 'caller'=> $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['REQUEST_URI'],
96 'two_factor_code' => stripslashes((string) $_POST['two_factor_code'])
97 );
98 $code_ok = $GLOBALS['simba_two_factor_authentication']->authorise_user_from_login($params, true);
99
100 $code_ok = apply_filters('simbatfa_affwp_process_login_form_auth_result', $code_ok, $params);
101
102 if (is_wp_error($code_ok)) {
103 $login->add_error($code_ok->get_error_code, $code_ok->get_error_message());
104 } elseif (!$code_ok) {
105 $login->add_error('authentication_failed', __('Error:', 'two-factor-authentication').' '.__('The one-time password (TFA code) you entered was incorrect.', 'two-factor-authentication'));
106 }
107
108 }
109
110 /**
111 * Ultimate Membership Pro support
112 *
113 * @param String $output
114 * @param String $tag
115 *
116 * @return String
117 */
118 public function do_shortcode_tag($output, $tag) {
119 if ('ihc-login-form' == $tag) $this->tfa->login_enqueue_scripts();
120 return $output;
121 }
122
123 }
124