101 lines
2.7 KiB
PHP
101 lines
2.7 KiB
PHP
<?php
|
|
/**
|
|
* Plugin Name: 2FA (by ROBOTSTXT)
|
|
* Plugin URI: https://www.robotstxt.software/plugins/robotstxt-2fa/
|
|
* Update URI: https://www.robotstxt.software/plugins/robotstxt-2fa/
|
|
* Description: Adds two-factor authentication to the WordPress login flow.
|
|
* Version: 1.6.6
|
|
* Author: ROBOTSTXT
|
|
* Author URI: https://www.robotstxt.software/
|
|
* Text Domain: robotstxt-2fa
|
|
* Domain Path: /languages
|
|
* Requires at least: 5.6
|
|
* Requires PHP: 8.0
|
|
* Network: true
|
|
* License: GPLv3 or later
|
|
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
|
*
|
|
* @package Robotstxt_2FA
|
|
*/
|
|
|
|
use Robotstxt\TwoFA\Plugin;
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
if ( ! defined( 'ROBOTSTXT_2FA_VERSION' ) ) {
|
|
define( 'ROBOTSTXT_2FA_VERSION', '1.6.6' );
|
|
}
|
|
|
|
if ( ! defined( 'ROBOTSTXT_2FA_FILE' ) ) {
|
|
define( 'ROBOTSTXT_2FA_FILE', __FILE__ );
|
|
}
|
|
|
|
if ( ! defined( 'ROBOTSTXT_2FA_PATH' ) ) {
|
|
define( 'ROBOTSTXT_2FA_PATH', plugin_dir_path( __FILE__ ) );
|
|
}
|
|
|
|
if ( ! defined( 'ROBOTSTXT_2FA_URL' ) ) {
|
|
define( 'ROBOTSTXT_2FA_URL', plugin_dir_url( __FILE__ ) );
|
|
}
|
|
|
|
$robotstxt_2fa_autoload = ROBOTSTXT_2FA_PATH . 'vendor/autoload.php';
|
|
|
|
if ( file_exists( $robotstxt_2fa_autoload ) ) {
|
|
require_once $robotstxt_2fa_autoload;
|
|
}
|
|
|
|
/**
|
|
* Simple autoloader for the plugin classes.
|
|
*
|
|
* @param string $class_name Fully qualified class name requested by PHP.
|
|
*
|
|
* @return void
|
|
*/
|
|
function robotstxt_2fa_autoload( string $class_name ): void {
|
|
$prefix = 'Robotstxt\\TwoFA\\';
|
|
|
|
if ( strncmp( $prefix, $class_name, strlen( $prefix ) ) !== 0 ) {
|
|
return;
|
|
}
|
|
|
|
$relative_class = substr( $class_name, strlen( $prefix ) );
|
|
$relative_parts = explode( '\\', $relative_class );
|
|
$filename = array_pop( $relative_parts );
|
|
|
|
$directories = '';
|
|
|
|
if ( ! empty( $relative_parts ) ) {
|
|
$relative_parts = array_map(
|
|
static function ( string $part ): string {
|
|
return strtolower( str_replace( '_', '-', $part ) );
|
|
},
|
|
$relative_parts
|
|
);
|
|
|
|
$directories = trailingslashit( implode( '/', $relative_parts ) );
|
|
}
|
|
|
|
$filename = 'class-' . strtolower( str_replace( '_', '-', $filename ) ) . '.php';
|
|
$path = trailingslashit( ROBOTSTXT_2FA_PATH . 'includes' ) . $directories . $filename;
|
|
|
|
if ( file_exists( $path ) ) {
|
|
require_once $path;
|
|
}
|
|
}
|
|
|
|
spl_autoload_register( 'robotstxt_2fa_autoload' );
|
|
|
|
/**
|
|
* Bootstrap the plugin once all plugins are loaded.
|
|
*
|
|
* @return void
|
|
*/
|
|
function robotstxt_2fa_bootstrap() {
|
|
Plugin::get_instance()->init();
|
|
}
|
|
add_action( 'plugins_loaded', 'robotstxt_2fa_bootstrap' );
|
|
|
|
register_activation_hook( __FILE__, array( Plugin::class, 'activate' ) );
|
|
register_deactivation_hook( __FILE__, array( Plugin::class, 'deactivate' ) );
|