110 lines
3.6 KiB
PHP
110 lines
3.6 KiB
PHP
<?php
|
|
/**
|
|
* Plugin Name: Two-Factor Extended
|
|
* Plugin URI: https://git.robotstxt.es/ROBOTSTXT/two-factor-extended
|
|
* Description: Extends the WordPress Two Factor plugin with advanced role-based controls, forced 2FA methods, and enhanced administrative features for single-site and Multisite installations.
|
|
* Version: 1.0.2
|
|
* Requires at least: 6.7
|
|
* Requires PHP: 8.2
|
|
* Requires Plugins: two-factor
|
|
* Author: ROBOTSTXT
|
|
* Author URI: https://www.robotstxt.es/
|
|
* License: GPL-3.0-or-later
|
|
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
|
* Text Domain: two-factor-extended
|
|
* Domain Path: /languages
|
|
* Network: true
|
|
* Gitea Plugin URI: https://git.robotstxt.es/ROBOTSTXT/two-factor-extended
|
|
* Primary Branch: main
|
|
*
|
|
* @package TwoFactorExtended
|
|
* @version 1.0.2
|
|
*/
|
|
|
|
// Prevent direct access.
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
// Define plugin constants.
|
|
define( 'TWO_FACTOR_EXTENDED_VERSION', '1.0.2' );
|
|
define( 'TWO_FACTOR_EXTENDED_PLUGIN_FILE', __FILE__ );
|
|
define( 'TWO_FACTOR_EXTENDED_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
|
define( 'TWO_FACTOR_EXTENDED_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
|
define( 'TWO_FACTOR_EXTENDED_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
|
define( 'TWO_FACTOR_EXTENDED_TEXT_DOMAIN', 'two-factor-extended' );
|
|
|
|
// Option keys.
|
|
define( 'TWO_FACTOR_EXTENDED_OPTION_SETTINGS', 'two_factor_extended_settings' );
|
|
define( 'TWO_FACTOR_EXTENDED_OPTION_VERSION', 'two_factor_extended_version' );
|
|
define( 'TWO_FACTOR_EXTENDED_OPTION_REMOVE_DATA', 'two_factor_extended_remove_data_on_uninstall' );
|
|
|
|
// Network options (Multisite).
|
|
define( 'TWO_FACTOR_EXTENDED_NETWORK_OPTION_SETTINGS', 'two_factor_extended_network_settings' );
|
|
define( 'TWO_FACTOR_EXTENDED_NETWORK_OPTION_VERSION', 'two_factor_extended_network_version' );
|
|
|
|
/**
|
|
* Plugin activation hook.
|
|
*
|
|
* @since 0.1.0
|
|
*/
|
|
function two_factor_extended_activate(): void {
|
|
// Store plugin version.
|
|
update_option( TWO_FACTOR_EXTENDED_OPTION_VERSION, TWO_FACTOR_EXTENDED_VERSION );
|
|
|
|
// Set default option for data retention (preserve by default).
|
|
// Using add_option so it only sets if not already exists.
|
|
add_option( TWO_FACTOR_EXTENDED_OPTION_REMOVE_DATA, false );
|
|
|
|
// For Multisite, store network version.
|
|
if ( is_multisite() ) {
|
|
update_site_option( TWO_FACTOR_EXTENDED_NETWORK_OPTION_VERSION, TWO_FACTOR_EXTENDED_VERSION );
|
|
}
|
|
|
|
// Trigger activation hook for extensibility.
|
|
do_action( 'two_factor_extended_activated' );
|
|
}
|
|
|
|
/**
|
|
* Plugin deactivation hook.
|
|
*
|
|
* @since 0.1.0
|
|
*/
|
|
function two_factor_extended_deactivate(): void {
|
|
// Clear any scheduled cron events.
|
|
wp_clear_scheduled_hook( 'two_factor_extended_daily_cleanup' );
|
|
|
|
// Trigger deactivation hook for extensibility.
|
|
do_action( 'two_factor_extended_deactivated' );
|
|
}
|
|
|
|
// Register activation and deactivation hooks.
|
|
register_activation_hook( __FILE__, 'two_factor_extended_activate' );
|
|
register_deactivation_hook( __FILE__, 'two_factor_extended_deactivate' );
|
|
|
|
// Load dependency checker.
|
|
require_once TWO_FACTOR_EXTENDED_PLUGIN_DIR . 'includes/class-dependency-checker.php';
|
|
|
|
// Display admin notices for dependency issues.
|
|
add_action( 'admin_notices', array( 'Two_Factor_Extended_Dependency_Checker', 'display_admin_notices' ) );
|
|
|
|
// Initialize the update system.
|
|
require_once __DIR__ . '/robotstxt-updater.php';
|
|
Robotstxt_Updater::init( __FILE__ );
|
|
|
|
// Initialize main plugin class.
|
|
require_once TWO_FACTOR_EXTENDED_PLUGIN_DIR . 'includes/class-two-factor-extended.php';
|
|
|
|
/**
|
|
* Get plugin instance.
|
|
*
|
|
* @since 0.1.0
|
|
*
|
|
* @return Two_Factor_Extended Plugin instance.
|
|
*/
|
|
function two_factor_extended() {
|
|
return Two_Factor_Extended::get_instance();
|
|
}
|
|
|
|
// Initialize plugin.
|
|
two_factor_extended();
|