register_hooks(); } /** * Constructor. * * @param string $plugin_file Absolute path to the main plugin file. */ private function __construct( string $plugin_file ) { $this->plugin_file = $plugin_file; } /** * Register WordPress hooks. */ private function register_hooks(): void { register_activation_hook( $this->plugin_file, array( $this, 'activate' ) ); register_deactivation_hook( $this->plugin_file, array( $this, 'deactivate' ) ); add_action( 'admin_notices', array( $this, 'multisite_notice' ) ); add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) ); // Run pending DB upgrades on every request after a plugin update. add_action( 'plugins_loaded', array( 'Robotstxt_Mlp2_Mlp5_Db_Upgrader', 'maybe_upgrade' ) ); // Register AJAX handlers for the batch migration runner. Robotstxt_Mlp2_Mlp5_Ajax::register(); // Register the Network Admin page (network_admin_menu hook fires inside). Robotstxt_Mlp2_Mlp5_Admin_Page::init(); } /** * Plugin activation callback. * * Prevents activation on non-Multisite installations. On Multisite, * creates the migration log table. */ public function activate(): void { if ( ! is_multisite() ) { deactivate_plugins( plugin_basename( $this->plugin_file ), true ); wp_die( esc_html__( 'MLP2 to MLP5 Migrator requires a WordPress Multisite installation.', 'robotstxt-mlp2-mlp5' ), esc_html__( 'Plugin Activation Error', 'robotstxt-mlp2-mlp5' ), array( 'back_link' => true ) ); } Robotstxt_Mlp2_Mlp5_Db_Upgrader::maybe_upgrade(); } /** * Plugin deactivation callback. */ public function deactivate(): void { // Reserved for future cleanup on deactivation. } /** * Display an admin notice when the plugin is loaded on a non-Multisite installation. * * Belt-and-suspenders guard in case the plugin ends up loaded outside of * the network activation flow. */ public function multisite_notice(): void { if ( is_multisite() ) { return; } printf( '

%s

', esc_html__( 'MLP2 to MLP5 Migrator requires a WordPress Multisite installation and has been deactivated.', 'robotstxt-mlp2-mlp5' ) ); } /** * Load the plugin text domain for internationalization. */ public function load_textdomain(): void { load_plugin_textdomain( 'robotstxt-mlp2-mlp5', false, dirname( plugin_basename( $this->plugin_file ) ) . '/languages' ); } }