This commit is contained in:
Javier Casares 2026-06-05 14:06:16 +00:00
commit 968211baad

View file

@ -1,98 +1,99 @@
<?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' ) );
<?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.3.0
* Author: ROBOTSTXT
* Author URI: https://www.robotstxt.es/
* Text Domain: robotstxt-2fa
* Requires at least: 6.4
* Requires PHP: 8.2
* 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', '0.3.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__ ) );
}
$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' ) );