Plugin - Source Excerpt 01
Summary
This source excerpt preserves a bounded section of Antichrist.net/wp-content/plugins/uaix-locale-router/src/Plugin.php so readers can inspect the evidence without opening the full source file.
**Source path:** Antichrist.net/wp-content/plugins/uaix-locale-router/src/Plugin.php
<?php
namespace UAIXLocaleRouter;
use UAIXLocaleRouter\Admin\AdminPages;
use UAIXLocaleRouter\Admin\Notices;
use UAIXLocaleRouter\Diagnostics\LinkReviewScanner;
use UAIXLocaleRouter\Diagnostics\LocalizedHomeDiagnostics;
use UAIXLocaleRouter\Diagnostics\SiteHealth;
use UAIXLocaleRouter\Rewrite\HtaccessManager;
use UAIXLocaleRouter\Support\Path;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
final class Plugin {
/**
* Main plugin file.
*
* @var string
*/
private static $plugin_file = '';
/**
* Whether runtime hooks have been registered.
*
* @var bool
*/
private static $runtime_booted = false;
/**
* Boot the plugin.
*
* @param string $plugin_file Plugin file path.
* @return void
*/
public static function boot( $plugin_file ) {
self::$plugin_file = $plugin_file;
register_activation_hook( $plugin_file, array( __CLASS__, 'activate' ) );
register_deactivation_hook( $plugin_file, array( __CLASS__, 'deactivate' ) );
add_action( 'plugins_loaded', array( __CLASS__, 'bootstrap_runtime' ), 1 );
add_action( 'init', array( __CLASS__, 'maybe_install' ), 1 );
add_action( 'admin_notices', array( __CLASS__, 'render_bootstrap_notice' ) );
}
/**
* Activation callback.
*
* @return void
*/
public static function activate() {
Migrator::run();
Settings::reset_cache();
self::ensure_default_options();
update_option( 'uaixlr_install_version', '' );
self::clear_localized_home_diagnostics();
self::clear_link_review_diagnostics();
self::clear_bootstrap_notice();
}
/**
* Deactivation callback.
*
* @return void
*/
public static function deactivate() {
self::$runtime_booted = false;
self::clear_localized_home_diagnostics();
self::clear_link_review_diagnostics();
}
/**
* Bootstrap runtime services after WordPress finishes loading plugins.
*
* @return void
*/
public static function bootstrap_runtime() {
if ( self::$runtime_booted ) {
return;
}
$preflight = self::preflight();
if ( is_wp_error( $preflight ) ) {
self::store_bootstrap_notice( $preflight->get_error_message() );
self::log_bootstrap_issue( 'preflight', $preflight->get_error_message() );
return;
}
try {
self::load_textdomain();
self::register_hooks();
self::$runtime_booted = true;
self::clear_bootstrap_notice();
} catch ( \Throwable $throwable ) {
self::store_bootstrap_notice(
sprintf(
'UAIX Locale Router could not finish booting: %s',
$throwable->getMessage()
)
);
self::log_bootstrap_issue( 'bootstrap', $throwable->getMessage() );
}
}
/**
* Run non-blocking install tasks for the current plugin version.
*
* @return void
*/
public static function maybe_install() {
Migrator::run();
Settings::reset_cache();
$installed_version = get_option( 'uaixlr_install_version', '' );
if ( UAIXLR_VERSION === $installed_version ) {
return;
}
self::ensure_default_options();
try {
self::ensure_upload_directories();
} catch ( \Throwable $throwable ) {
self::store_bootstrap_notice(
sprintf(
'UAIX Locale Router could not prepare its upload directories: %s',
$throwable->getMessage()
),
'warning'
);
self::log_bootstrap_issue( 'uploads', $throwable->getMessage() );
}
try {
self::maybe_repair_htaccess_on_install();
} catch ( \Throwable $throwable ) {
self::log_bootstrap_issue( 'htaccess_install', $throwable->getMessage() );
}
self::maybe_create_validation_table();
update_option( 'uaixlr_install_version', UAIXLR_VERSION );
}
/**
* Repair .htaccess during install when diagnostics say it is safe.
*
* @return void
*/
private static function maybe_repair_htaccess_on_install() {
LocalizedHomeDiagnostics::maybe_repair_htaccess_on_install();
}
/**
* Repair locale-prefixed handoff during a reachable bare request when possible.
*
* @param string $request_path Current request path.
* @return void
*/
public static function maybe_self_heal_localized_handoff( $request_path = '/' ) {
LocalizedHomeDiagnostics::maybe_self_heal_localized_handoff( $request_path );
}
/**
* Register runtime hooks.
*
* @return void
*/
public static function register_hooks() {
Router::register();
DictionaryRepository::register();
LinkLocalizer::register();
SeoMetadata::register();
Switcher::register();
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_front_assets' ) );
add_action( 'wp_footer', array( __CLASS__, 'render_frontend_debug_banner' ), 100 );
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_admin_assets' ) );
add_filter( 'plugin_action_links_' . plugin_basename( UAIXLR_PLUGIN_FILE ), array( __CLASS__, 'filter_plugin_action_links' ) );
add_filter( 'debug_information', array( __CLASS__, 'filter_debug_information' ) );
add_filter( 'site_status_tests', array( __CLASS__, 'filter_site_status_tests' ) );
if ( is_admin() ) {
AdminPages::register();
}
}
/**
* Load plugin translations from the bundled languages directory.
*
* @return void
*/
public static function load_textdomain() {
load_plugin_textdomain(
'uaix-locale-router',
false,
dirname( plugin_basename( UAIXLR_PLUGIN_FILE ) ) . '/languages'
);
}
/**
* Check the minimum runtime requirements before full boot.
*
* @return true|\WP_Error
*/
public static function preflight() {
global $wp_version;
if ( version_compare( PHP_VERSION, '7.4', '<' ) ) {
return new \WP_Error( 'uaixlr_php_version', 'UAIX Locale Router requires PHP 7.4 or newer.' );
}
if ( ! isset( $wp_version ) || version_compare( $wp_version, '6.6', '<' ) ) {
return new \WP_Error( 'uaixlr_wp_version', 'UAIX Locale Router requires WordPress 6.6 or newer.' );
}
$required_functions = array(
'add_action',
'add_filter',
'determine_locale',
'wp_safe_redirect',
'wp_mkdir_p',
);
foreach ( $required_functions as $required_function ) {
if ( ! function_exists( $required_function ) ) {
return new \WP_Error(
'uaixlr_missing_function',
sprintf( 'UAIX Locale Router is missing the required WordPress function %s.', $required_function )
);
}
}
return true;
}
/**
* Enqueue front-end assets when needed.
*
* @return void
*/
public static function enqueue_front_assets() {
Assets::enqueue_front_assets();
}
/**
* Render the front-end diagnostics banner.
*
* @return void
*/
public static function render_frontend_debug_banner() {
Assets::render_frontend_debug_banner();
}
/**
* Enqueue admin assets.
*
* @return void
*/
public static function enqueue_admin_assets() {
Assets::enqueue_admin_assets();
}
/**
* Default settings payload.
*
* @return array
*/
public static function default_settings() {
return Settings::defaults();
}
/**
* Ensure required options exist.
*
* @return void
*/
public static function ensure_default_options() {
Settings::ensure_defaults();
}
/**
* Ensure runtime upload directories exist.
*
* @return void
*/
public static function ensure_upload_directories() {
wp_mkdir_p( self::dictionaries_dir() );
}
/**
* Create the validation history table.
*
* @return void
*/
public static function create_validation_table() {
global $wpdb;
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$table_name = self::validation_table_name();
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE {$table_name} (
ValidationId bigint(20) unsigned NOT NULL AUTO_INCREMENT,
LocaleTag varchar(64) NOT NULL,
FileHash varchar(64) NOT NULL,
TemplateVersion int(11) unsigned NOT NULL DEFAULT 1,
Status varchar(32) NOT NULL DEFAULT 'draft',
IssueCount int(11) unsigned NOT NULL DEFAULT 0,
IssuesJson longtext NOT NULL,
CreatedUtc datetime NOT NULL,
CreatedByUserId bigint(20) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (ValidationId),
KEY LocaleTag (LocaleTag),
KEY Status (Status)
) {$charset_collate};";
dbDelta( $sql );
}
/**
* Try to create the validation table without blocking plugin activation.
*
* @return void
*/
public static function maybe_create_validation_table() {
try {
self::create_validation_table();
} catch ( \Throwable $throwable ) {
self::store_bootstrap_notice(
sprintf(
'UAIX Locale Router could not initialize validation storage: %s',
$throwable->getMessage()
),
'warning'
);
self::log_bootstrap_issue( 'validation_table', $throwable->getMessage() );
}
}
/**
* Read merged plugin settings.
*
* @return array
*/
public static function settings() {