v0.2.0
This commit is contained in:
commit
f936aeb807
1 changed files with 15710 additions and 0 deletions
98
robotstxt-2fa.php
Normal file
98
robotstxt-2fa.php
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
/**
|
||||
* Plugin Name: 2FA (by ROBOTSTXT)
|
||||
* Plugin URI: https://www.robotstxt.es/plugins/robotstxt-2fa/
|
||||
* Description: Adds two-factor authentication to the WordPress login flow.
|
||||
* Version: 0.2.0
|
||||
* Author: ROBOTSTXT
|
||||
* Author URI: https://www.robotstxt.es/
|
||||
* Text Domain: robotstxt-2fa
|
||||
* Requires at least: 6.4
|
||||
* Requires PHP: 8.2
|
||||
* License: GPLv2 or later
|
||||
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* @package Robotstxt_2FA
|
||||
*/
|
||||
|
||||
use Robotstxt\TwoFA\Plugin;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! defined( 'ROBOTSTXT_2FA_VERSION' ) ) {
|
||||
define( 'ROBOTSTXT_2FA_VERSION', '0.2.0' );
|
||||
}
|
||||
|
||||
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__ ) );
|
||||
}
|
||||
|
||||
$autoload = ROBOTSTXT_2FA_PATH . 'vendor/autoload.php';
|
||||
|
||||
if ( file_exists( $autoload ) ) {
|
||||
require_once $autoload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple autoloader for the plugin classes.
|
||||
*
|
||||
* @param string $class Fully qualified class name requested by PHP.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function robotstxt_2fa_autoload( string $class ): void {
|
||||
$prefix = 'Robotstxt\\TwoFA\\';
|
||||
|
||||
if ( strncmp( $prefix, $class, strlen( $prefix ) ) !== 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$relative_class = substr( $class, 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' ) );
|
||||
Loading…
Reference in a new issue