Repository navigation
Expand file tree
/
Copy pathotw-2fa.php
More file actions
143 lines (123 loc) · 4.13 KB
/
Copy pathotw-2fa.php
File metadata and controls
143 lines (123 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/**
* Plugin Name: OTW 2FA
* Plugin URI: https://developer.starter.dev/
* Description: Two-Factor Authentication for WordPress with Google Authenticator, Email, and SMS options.
* Version: 1.0.0
* Author: Developer Starter
* Author URI: https://developer.starter.dev/
* Text Domain: otw-2fa
* License: GPL2
*/
namespace OTW\TwoFA;
if (!defined('ABSPATH')) {
exit;
}
// Plugin constants
define('OTW_2FA_VERSION', '1.0.0');
define('OTW_2FA_PLUGIN_FILE', __FILE__);
define('OTW_2FA_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('OTW_2FA_PLUGIN_URL', plugin_dir_url(__FILE__));
/**
* Main Plugin Class
*/
class Plugin {
/**
* Singleton instance
*/
private static $instance = null;
/**
* Get singleton instance
*/
public static function instance() {
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*/
private function __construct() {
$this->load_dependencies();
$this->init_hooks();
}
/**
* Load required files
*/
private function load_dependencies() {
require_once OTW_2FA_PLUGIN_DIR . 'includes/class-security.php';
require_once OTW_2FA_PLUGIN_DIR . 'includes/class-totp.php';
require_once OTW_2FA_PLUGIN_DIR . 'includes/class-email-otp.php';
require_once OTW_2FA_PLUGIN_DIR . 'includes/class-sms-otp.php';
require_once OTW_2FA_PLUGIN_DIR . 'includes/class-whatsapp-otp.php';
require_once OTW_2FA_PLUGIN_DIR . 'includes/class-user-settings.php';
require_once OTW_2FA_PLUGIN_DIR . 'includes/class-login-handler.php';
require_once OTW_2FA_PLUGIN_DIR . 'includes/class-admin.php';
}
/**
* Initialize hooks
*/
private function init_hooks() {
add_action('init', [$this, 'load_textdomain']);
// Initialize components
new User_Settings();
new Login_Handler();
new Admin();
}
/**
* Load plugin textdomain
*/
public function load_textdomain() {
load_plugin_textdomain('otw-2fa', false, dirname(plugin_basename(__FILE__)) . '/languages');
}
/**
* Activation hook
*/
public static function activate() {
// Default options - Methods
add_option('otw_2fa_enable_totp', 1);
add_option('otw_2fa_enable_email', 1);
add_option('otw_2fa_enable_sms', 0);
add_option('otw_2fa_enable_whatsapp', 0);
// SMS Settings
add_option('otw_2fa_sms_provider', 'twilio');
add_option('otw_2fa_twilio_sid', '');
add_option('otw_2fa_twilio_token', '');
add_option('otw_2fa_twilio_phone', '');
// WhatsApp Settings
add_option('otw_2fa_whatsapp_provider', 'webhook');
add_option('otw_2fa_whatsapp_api_url', 'https://graph.facebook.com/v18.0');
add_option('otw_2fa_whatsapp_api_token', '');
add_option('otw_2fa_whatsapp_phone_id', '');
add_option('otw_2fa_whatsapp_webhook_url', '');
// General Settings
add_option('otw_2fa_code_expiry', 300); // 5 minutes
add_option('otw_2fa_code_length', 6);
add_option('otw_2fa_required_roles', ['administrator']);
// Security Settings
add_option('otw_2fa_max_attempts', 5);
add_option('otw_2fa_lockout_duration', 5); // 5 minutes
add_option('otw_2fa_enable_logging', 1);
}
/**
* Deactivation hook
*/
public static function deactivate() {
// Clean up transients
global $wpdb;
$wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_otw_2fa_%'");
$wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_otw_2fa_%'");
}
}
// Activation/Deactivation hooks
register_activation_hook(__FILE__, [Plugin::class, 'activate']);
register_deactivation_hook(__FILE__, [Plugin::class, 'deactivate']);
/**
* Get plugin instance
*/
function otw_2fa() {
return Plugin::instance();
}
// Initialize plugin
add_action('plugins_loaded', 'OTW\\TwoFA\\otw_2fa');