v1.0.0
This commit is contained in:
parent
8caa140991
commit
5cdf7f48e5
29 changed files with 6526 additions and 0 deletions
115
includes/class-robotstxt-mlp2-mlp5.php
Normal file
115
includes/class-robotstxt-mlp2-mlp5.php
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
/**
|
||||
* Main plugin bootstrap class.
|
||||
*
|
||||
* @package Robotstxt_Mlp2_Mlp5
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Robotstxt_Mlp2_Mlp5
|
||||
*
|
||||
* Bootstraps the MLP2 to MLP5 Migrator plugin. Handles activation,
|
||||
* deactivation, Multisite-only enforcement, and text domain loading.
|
||||
*/
|
||||
class Robotstxt_Mlp2_Mlp5 {
|
||||
|
||||
/**
|
||||
* Absolute path to the main plugin file.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private string $plugin_file;
|
||||
|
||||
/**
|
||||
* Initialize the plugin.
|
||||
*
|
||||
* @param string $plugin_file Absolute path to the main plugin file.
|
||||
*/
|
||||
public static function init( string $plugin_file ): void {
|
||||
$instance = new self( $plugin_file );
|
||||
$instance->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(
|
||||
'<div class="notice notice-error"><p>%s</p></div>',
|
||||
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'
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue