PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 2.7.0
WP 2FA – Two-factor authentication for WordPress v2.7.0
4.0.0 1.7.1 2.0.0 2.0.1 2.1.0 2.2.0 2.2.1 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.8.0 2.9.0 2.9.1 2.9.2 2.9.3 3.0.0 3.0.1 3.1.0 3.1.1 3.1.1.2 trunk 1.2.0 1.3.0 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.7.0
wp-2fa / wp-2fa.php
wp-2fa Last commit date
dist 2 years ago includes 2 years ago languages 2 years ago vendor 2 years ago index.php 2 years ago license.txt 2 years ago readme.txt 2 years ago wp-2fa.php 2 years ago
wp-2fa.php
208 lines
1 <?php
2 /**
3 * WP 2FA - Two-factor authentication for WordPress .
4 *
5 * @copyright Copyright (C) 2013-2024, Melapress - support@melapress.com
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License, version 3 or higher
7 *
8 * @wordpress-plugin
9 * Plugin Name: WP 2FA - Two-factor authentication for WordPress
10 * Version: 2.7.0
11 * Plugin URI: https://melapress.com/
12 * Description: Easily add an additional layer of security to your WordPress login pages. Enable Two-Factor Authentication for you and all your website users with this easy to use plugin.
13 * Author: Melapress
14 * Author URI: https://melapress.com/
15 * Text Domain: wp-2fa
16 * Domain Path: /languages/
17 * License: GPL v3
18 * Requires at least: 5.0
19 * Requires PHP: 7.2
20 * Network: true
21 *
22 * @package WP2FA
23 *
24 * This program is free software: you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation, either version 3 of the License, or
27 * (at your option) any later version.
28 *
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
33 *
34 * You should have received a copy of the GNU General Public License
35 * along with this program. If not, see <http://www.gnu.org/licenses/>.
36 *
37 * @fs_ignore /dist/, /extensions/, /freemius/, /includes/, /languages/, /third-party/, /vendor/
38 */
39
40 use WP2FA\WP2FA;
41 use WP2FA\Utils\Migration;
42 use WP2FA\Extensions_Loader;
43 use WP2FA\Admin\Helpers\WP_Helper;
44 use WP2FA\Freemius\Freemius_Helper;
45 use WP2FA\Admin\Helpers\File_Writer;
46
47 if ( ! defined( 'ABSPATH' ) ) {
48 exit;
49 }
50
51 if ( defined( '\DISABLE_2FA_LOGIN' ) && \DISABLE_2FA_LOGIN ) {
52 return;
53 }
54
55 // Useful global constants.
56 if ( ! defined( 'WP_2FA_VERSION' ) ) {
57 define( 'WP_2FA_VERSION', '2.7.0' );
58 define( 'WP_2FA_BASE', plugin_basename( __FILE__ ) );
59 define( 'WP_2FA_URL', plugin_dir_url( __FILE__ ) );
60 define( 'WP_2FA_PATH', WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . dirname( WP_2FA_BASE ) . DIRECTORY_SEPARATOR );
61 define( 'WP_2FA_INC', WP_2FA_PATH . 'includes/' );
62 define( 'WP_2FA_FILE', __FILE__ );
63 define( 'WP_2FA_LOGS_DIR', 'wp-2fa-logs' );
64
65 // Prefix used in usermetas, settings and transients.
66 define( 'WP_2FA_PREFIX', 'wp_2fa_' );
67 define( 'WP_2FA_POLICY_SETTINGS_NAME', WP_2FA_PREFIX . 'policy' );
68 define( 'WP_2FA_SETTINGS_NAME', WP_2FA_PREFIX . 'settings' );
69 define( 'WP_2FA_WHITE_LABEL_SETTINGS_NAME', WP_2FA_PREFIX . 'white_label' );
70 define( 'WP_2FA_EMAIL_SETTINGS_NAME', WP_2FA_PREFIX . 'email_settings' );
71
72 define( 'WP_2FA_PREFIX_PAGE', 'wp-2fa-' );
73 }
74
75 // phpcs:disable
76 // phpcs:enable
77 // Include files.
78 require_once WP_2FA_INC . 'functions/core.php';
79
80 // Require Composer autoloader if it exists.
81 if ( file_exists( WP_2FA_PATH . 'vendor/autoload.php' ) ) {
82 require_once WP_2FA_PATH . 'vendor/autoload.php';
83 }
84
85 // run any required update routines.
86 Migration::migrate();
87
88 // Setup_Wizard.
89 if ( WP_Helper::is_multisite() ) {
90 add_action( 'network_admin_menu', array( '\WP2FA\Admin\Setup_Wizard', 'network_admin_menus' ), 10 );
91 add_action( 'admin_menu', array( '\WP2FA\Admin\Setup_Wizard', 'admin_menus' ), 10 );
92 } else {
93 add_action( 'admin_menu', array( '\WP2FA\Admin\Setup_Wizard', 'admin_menus' ), 10 );
94 }
95
96 // Activation/Deactivation.
97 register_activation_hook( WP_2FA_FILE, '\WP2FA\Core\activate' );
98 register_deactivation_hook( WP_2FA_FILE, '\WP2FA\Core\deactivate' );
99 // Register our uninstallation hook.
100 register_uninstall_hook( WP_2FA_FILE, '\WP2FA\Core\uninstall' );
101
102 add_filter( 'plugins_loaded', array( '\WP2FA\WP2FA', 'init' ) );
103 add_action( 'plugins_loaded', array( '\WP2FA\WP2FA', 'add_wizard_actions' ), 10 );
104
105
106 // phpcs:disable
107 // phpcs:enable
108
109 if ( ! defined( File_Writer::SECRET_NAME ) ) {
110 define( File_Writer::SECRET_NAME, WP2FA::get_secret_key() );
111
112 define( 'WP2FA_SECRET_IS_IN_DB', true );
113 }
114
115 // phpcs:disable
116 /* @free:start */
117 // phpcs:enable
118 if ( ! function_exists( 'wp2fa_free_on_plugin_activation' ) ) {
119 /**
120 * Takes care of deactivation of the premium plugin when the free plugin is activated.
121 *
122 * Note: This code MUST NOT be present in the premium version an is removed automatically during the build process.
123 *
124 * @since 2.0.0
125 */
126 function wp2fa_free_on_plugin_activation() {
127 $premium_version_slug = 'wp-2fa-premium/wp-2fa.php';
128 if ( is_plugin_active( $premium_version_slug ) ) {
129 deactivate_plugins( $premium_version_slug, true );
130 }
131 check_ssl();
132 }
133
134 register_activation_hook( __FILE__, 'wp2fa_free_on_plugin_activation' );
135 }
136 // phpcs:disable
137 /* @free:end */
138 // phpcs:enable
139
140 /*
141 * Clears the config cache from the DB
142 *
143 * @return void
144 *
145 * @since 2.2.0
146 */
147 add_action(
148 'upgrader_process_complete',
149 function () {
150 delete_transient( 'wp_2fa_config_file_hash' );
151 },
152 10,
153 2
154 );
155
156 if ( ! function_exists( 'check_ssl' ) ) {
157 /**
158 * Checks if the required library is installed and cancels the process if not.
159 *
160 * @return void
161 *
162 * @since 2.2.0
163 */
164 function check_ssl() {
165 if ( ! \WP2FA\Authenticator\Open_SSL::is_ssl_available() ) {
166 $html = '<div class="updated notice is-dismissible">
167 <p>' . \esc_html__( 'This plugin requires OpenSSL. Contact your web host or website administrator so they can enable OpenSSL. Re-activate the plugin once the library has been enabled.', 'wp-2fa' )
168 . '</p>
169 </div>';
170
171 echo $html; // phpcs:ignore
172
173 exit();
174 }
175 }
176 }
177
178 if ( \PHP_VERSION_ID < 80000 && ! \interface_exists( 'Stringable' ) ) {
179 interface Stringable { // phpcs:ignore
180 /**
181 * Mockup function for PHP versions lower than 8.
182 *
183 * @return string
184 */
185 public function __toString();
186 }
187 }
188
189 if ( ! function_exists( 'str_starts_with' ) ) {
190 /**
191 * PHP lower than 8 is missing that function but it required in the newer versions of our plugin.
192 *
193 * @param string $haystack - The string to search in.
194 * @param string $needle - The needle to search for.
195 *
196 * @return bool
197 *
198 * @since 2.6.4
199 */
200 function str_starts_with( $haystack, $needle ): bool {
201 if ( '' === $needle ) {
202 return true;
203 }
204
205 return 0 === strpos( $haystack, $needle );
206 }
207 }
208