412 lines
8.5 KiB
PHP
412 lines
8.5 KiB
PHP
<?php
|
|
/**
|
|
* Main plugin class
|
|
*
|
|
* @package TwoFactorExtended
|
|
* @since 0.1.0
|
|
*/
|
|
|
|
// Prevent direct access.
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Class Two_Factor_Extended
|
|
*
|
|
* Main plugin class implementing singleton pattern.
|
|
*
|
|
* @since 0.1.0
|
|
*/
|
|
class Two_Factor_Extended {
|
|
|
|
/**
|
|
* Plugin instance.
|
|
*
|
|
* @since 0.1.0
|
|
* @var Two_Factor_Extended|null
|
|
*/
|
|
private static $instance = null;
|
|
|
|
/**
|
|
* Plugin version.
|
|
*
|
|
* @since 0.1.0
|
|
* @var string
|
|
*/
|
|
private string $version = '1.0.0';
|
|
|
|
/**
|
|
* Plugin directory path.
|
|
*
|
|
* @since 0.1.0
|
|
* @var string
|
|
*/
|
|
private string $plugin_path;
|
|
|
|
/**
|
|
* Plugin directory URL.
|
|
*
|
|
* @since 0.1.0
|
|
* @var string
|
|
*/
|
|
private string $plugin_url;
|
|
|
|
/**
|
|
* Plugin basename.
|
|
*
|
|
* @since 0.1.0
|
|
* @var string
|
|
*/
|
|
private string $plugin_basename;
|
|
|
|
/**
|
|
* Settings instance.
|
|
*
|
|
* @since 0.1.0
|
|
* @var Two_Factor_Extended_Settings|null
|
|
*/
|
|
private $settings = null;
|
|
|
|
/**
|
|
* Enforcement instance.
|
|
*
|
|
* @since 0.1.0
|
|
* @var Two_Factor_Extended_Enforcement|null
|
|
*/
|
|
private $enforcement = null;
|
|
|
|
/**
|
|
* Provider filter instance.
|
|
*
|
|
* @since 0.1.0
|
|
* @var Two_Factor_Extended_Provider_Filter|null
|
|
*/
|
|
private $provider_filter = null;
|
|
|
|
/**
|
|
* Network settings instance.
|
|
*
|
|
* @since 0.1.0
|
|
* @var Two_Factor_Extended_Network_Settings|null
|
|
*/
|
|
private $network_settings = null;
|
|
|
|
/**
|
|
* Audit log instance.
|
|
*
|
|
* @since 0.1.0
|
|
* @var Two_Factor_Extended_Audit_Log|null
|
|
*/
|
|
private $audit_log = null;
|
|
|
|
/**
|
|
* Compliance report instance.
|
|
*
|
|
* @since 0.1.0
|
|
* @var Two_Factor_Extended_Compliance_Report|null
|
|
*/
|
|
private $compliance_report = null;
|
|
|
|
/**
|
|
* Bulk actions instance.
|
|
*
|
|
* @since 0.1.0
|
|
* @var Two_Factor_Extended_Bulk_Actions|null
|
|
*/
|
|
private $bulk_actions = null;
|
|
|
|
/**
|
|
* REST API instance.
|
|
*
|
|
* @since 0.1.0
|
|
* @var Two_Factor_Extended_REST_API|null
|
|
*/
|
|
private $rest_api = null;
|
|
|
|
/**
|
|
* Get plugin instance (singleton).
|
|
*
|
|
* @since 0.1.0
|
|
*
|
|
* @return Two_Factor_Extended Plugin instance.
|
|
*/
|
|
public static function get_instance(): Two_Factor_Extended {
|
|
if ( null === self::$instance ) {
|
|
self::$instance = new self();
|
|
}
|
|
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* Constructor.
|
|
*
|
|
* Private to enforce singleton pattern.
|
|
*
|
|
* @since 0.1.0
|
|
*/
|
|
private function __construct() {
|
|
$this->plugin_path = plugin_dir_path( dirname( __FILE__ ) );
|
|
$this->plugin_url = plugin_dir_url( dirname( __FILE__ ) );
|
|
$this->plugin_basename = plugin_basename( dirname( dirname( __FILE__ ) ) . '/two-factor-extended.php' );
|
|
|
|
$this->init();
|
|
}
|
|
|
|
/**
|
|
* Initialize the plugin.
|
|
*
|
|
* @since 0.1.0
|
|
*/
|
|
private function init(): void {
|
|
// Load dependencies.
|
|
$this->load_dependencies();
|
|
|
|
// Initialize components.
|
|
$this->init_hooks();
|
|
}
|
|
|
|
/**
|
|
* Load plugin dependencies.
|
|
*
|
|
* @since 0.1.0
|
|
*/
|
|
private function load_dependencies(): void {
|
|
require_once $this->plugin_path . 'includes/class-dependency-checker.php';
|
|
require_once $this->plugin_path . 'includes/class-role-manager.php';
|
|
require_once $this->plugin_path . 'includes/class-provider-detector.php';
|
|
require_once $this->plugin_path . 'includes/class-enforcement.php';
|
|
require_once $this->plugin_path . 'includes/class-provider-filter.php';
|
|
require_once $this->plugin_path . 'includes/class-network-settings.php';
|
|
require_once $this->plugin_path . 'includes/class-audit-log.php';
|
|
require_once $this->plugin_path . 'includes/class-compliance-report.php';
|
|
require_once $this->plugin_path . 'includes/class-bulk-actions.php';
|
|
require_once $this->plugin_path . 'includes/class-rest-api.php';
|
|
require_once $this->plugin_path . 'includes/class-settings.php';
|
|
|
|
// Load CLI commands if WP-CLI is available.
|
|
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
|
require_once $this->plugin_path . 'includes/class-cli-commands.php';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Initialize WordPress hooks.
|
|
*
|
|
* @since 0.1.0
|
|
*/
|
|
private function init_hooks(): void {
|
|
// Plugin loaded hook.
|
|
add_action( 'plugins_loaded', array( $this, 'on_plugins_loaded' ) );
|
|
|
|
// Load text domain.
|
|
add_action( 'init', array( $this, 'load_textdomain' ) );
|
|
}
|
|
|
|
/**
|
|
* Actions to run when all plugins are loaded.
|
|
*
|
|
* @since 0.1.0
|
|
*/
|
|
public function on_plugins_loaded(): void {
|
|
// Check dependencies.
|
|
if ( ! Two_Factor_Extended_Dependency_Checker::check_dependencies() ) {
|
|
return;
|
|
}
|
|
|
|
// Initialize network settings (Multisite).
|
|
$this->network_settings = new Two_Factor_Extended_Network_Settings();
|
|
|
|
// Initialize audit log.
|
|
$this->audit_log = new Two_Factor_Extended_Audit_Log();
|
|
|
|
// Initialize compliance report.
|
|
$this->compliance_report = new Two_Factor_Extended_Compliance_Report();
|
|
|
|
// Initialize settings.
|
|
$this->settings = new Two_Factor_Extended_Settings();
|
|
|
|
// Initialize enforcement.
|
|
$this->enforcement = new Two_Factor_Extended_Enforcement();
|
|
|
|
// Initialize provider filter.
|
|
$this->provider_filter = new Two_Factor_Extended_Provider_Filter();
|
|
|
|
// Initialize bulk actions.
|
|
$this->bulk_actions = new Two_Factor_Extended_Bulk_Actions();
|
|
|
|
// Initialize REST API.
|
|
$this->rest_api = new Two_Factor_Extended_REST_API();
|
|
|
|
// Register WP-CLI commands if available.
|
|
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
|
WP_CLI::add_command( 'two-factor-extended', 'Two_Factor_Extended_CLI_Commands' );
|
|
}
|
|
|
|
// Plugin is ready to work.
|
|
do_action( 'two_factor_extended_loaded' );
|
|
}
|
|
|
|
/**
|
|
* Get settings instance.
|
|
*
|
|
* @since 0.1.0
|
|
*
|
|
* @return Two_Factor_Extended_Settings Settings instance.
|
|
*/
|
|
public function get_settings(): Two_Factor_Extended_Settings {
|
|
return $this->settings;
|
|
}
|
|
|
|
/**
|
|
* Get enforcement instance.
|
|
*
|
|
* @since 0.1.0
|
|
*
|
|
* @return Two_Factor_Extended_Enforcement Enforcement instance.
|
|
*/
|
|
public function get_enforcement(): Two_Factor_Extended_Enforcement {
|
|
return $this->enforcement;
|
|
}
|
|
|
|
/**
|
|
* Get provider filter instance.
|
|
*
|
|
* @since 0.1.0
|
|
*
|
|
* @return Two_Factor_Extended_Provider_Filter Provider filter instance.
|
|
*/
|
|
public function get_provider_filter(): Two_Factor_Extended_Provider_Filter {
|
|
return $this->provider_filter;
|
|
}
|
|
|
|
/**
|
|
* Get network settings instance.
|
|
*
|
|
* @since 0.1.0
|
|
*
|
|
* @return Two_Factor_Extended_Network_Settings Network settings instance.
|
|
*/
|
|
public function get_network_settings(): Two_Factor_Extended_Network_Settings {
|
|
return $this->network_settings;
|
|
}
|
|
|
|
/**
|
|
* Get audit log instance.
|
|
*
|
|
* @since 0.1.0
|
|
*
|
|
* @return Two_Factor_Extended_Audit_Log Audit log instance.
|
|
*/
|
|
public function get_audit_log(): Two_Factor_Extended_Audit_Log {
|
|
return $this->audit_log;
|
|
}
|
|
|
|
/**
|
|
* Get compliance report instance.
|
|
*
|
|
* @since 0.1.0
|
|
*
|
|
* @return Two_Factor_Extended_Compliance_Report Compliance report instance.
|
|
*/
|
|
public function get_compliance_report(): Two_Factor_Extended_Compliance_Report {
|
|
return $this->compliance_report;
|
|
}
|
|
|
|
/**
|
|
* Get bulk actions instance.
|
|
*
|
|
* @since 0.1.0
|
|
*
|
|
* @return Two_Factor_Extended_Bulk_Actions Bulk actions instance.
|
|
*/
|
|
public function get_bulk_actions(): Two_Factor_Extended_Bulk_Actions {
|
|
return $this->bulk_actions;
|
|
}
|
|
|
|
/**
|
|
* Get REST API instance.
|
|
*
|
|
* @since 0.1.0
|
|
*
|
|
* @return Two_Factor_Extended_REST_API REST API instance.
|
|
*/
|
|
public function get_rest_api(): Two_Factor_Extended_REST_API {
|
|
return $this->rest_api;
|
|
}
|
|
|
|
/**
|
|
* Load plugin text domain.
|
|
*
|
|
* @since 0.1.0
|
|
*/
|
|
public function load_textdomain(): void {
|
|
// phpcs:ignore PluginCheck.CodeAnalysis.DiscouragedFunctions.load_plugin_textdomainFound -- Needed for custom translation loading
|
|
load_plugin_textdomain(
|
|
'two-factor-extended',
|
|
false,
|
|
dirname( $this->plugin_basename ) . '/languages'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get plugin version.
|
|
*
|
|
* @since 0.1.0
|
|
*
|
|
* @return string Plugin version.
|
|
*/
|
|
public function get_version(): string {
|
|
return $this->version;
|
|
}
|
|
|
|
/**
|
|
* Get plugin directory path.
|
|
*
|
|
* @since 0.1.0
|
|
*
|
|
* @return string Plugin directory path with trailing slash.
|
|
*/
|
|
public function get_plugin_path(): string {
|
|
return $this->plugin_path;
|
|
}
|
|
|
|
/**
|
|
* Get plugin directory URL.
|
|
*
|
|
* @since 0.1.0
|
|
*
|
|
* @return string Plugin directory URL with trailing slash.
|
|
*/
|
|
public function get_plugin_url(): string {
|
|
return $this->plugin_url;
|
|
}
|
|
|
|
/**
|
|
* Get plugin basename.
|
|
*
|
|
* @since 0.1.0
|
|
*
|
|
* @return string Plugin basename (e.g., 'two-factor-extended/two-factor-extended.php').
|
|
*/
|
|
public function get_plugin_basename(): string {
|
|
return $this->plugin_basename;
|
|
}
|
|
|
|
/**
|
|
* Prevent cloning.
|
|
*
|
|
* @since 0.1.0
|
|
*/
|
|
private function __clone() {
|
|
}
|
|
|
|
/**
|
|
* Prevent unserialization.
|
|
*
|
|
* @since 0.1.0
|
|
*/
|
|
public function __wakeup() {
|
|
}
|
|
}
|