wp-domain-mapping/wp-domain-mapping.php

166 lines
4.5 KiB
PHP
Raw Normal View History

2025-03-16 01:03:10 +08:00
<?php
/**
* Plugin Name: WP Domain Mapping
2025-03-21 11:00:48 +08:00
* Plugin URI: https://wenpai.org/plugins/wp-domain-mapping/
2025-03-16 01:03:10 +08:00
* Description: Map any site on a WordPress website to another domain with enhanced management features.
2025-05-26 22:47:52 +08:00
* Version: 2.0.0
2025-03-16 01:03:10 +08:00
* Author: WPDomain.com
* Author URI: https://wpdomain.com/
* Network: true
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: wp-domain-mapping
* Domain Path: /languages
* Requires at least: 6.7.2
*/
2025-05-20 22:52:24 +08:00
// Prevent direct access
if ( ! defined( 'ABSPATH' ) ) {
2025-04-15 09:58:06 +08:00
exit;
}
2025-05-20 22:52:24 +08:00
// Define plugin constants
2025-05-26 22:47:52 +08:00
define( 'WP_DOMAIN_MAPPING_VERSION', '2.0.0' );
2025-05-20 22:52:24 +08:00
define( 'WP_DOMAIN_MAPPING_DIR_URL', plugin_dir_url( __FILE__ ) );
define( 'WP_DOMAIN_MAPPING_DIR_PATH', plugin_dir_path( __FILE__ ) );
define( 'WP_DOMAIN_MAPPING_BASENAME', plugin_basename( __FILE__ ) );
2025-04-15 09:58:06 +08:00
2025-05-23 16:10:39 +08:00
// Define table name constants if not already defined
if ( ! defined( 'WP_DOMAIN_MAPPING_TABLE_DOMAINS' ) ) {
define( 'WP_DOMAIN_MAPPING_TABLE_DOMAINS', 'domain_mapping' );
define( 'WP_DOMAIN_MAPPING_TABLE_LOGINS', 'domain_mapping_logins' );
define( 'WP_DOMAIN_MAPPING_TABLE_LOGS', 'domain_mapping_logs' );
}
// Include required files
require_once WP_DOMAIN_MAPPING_DIR_PATH . 'includes/functions.php';
require_once WP_DOMAIN_MAPPING_DIR_PATH . 'includes/class-core.php';
require_once WP_DOMAIN_MAPPING_DIR_PATH . 'includes/class-admin.php';
require_once WP_DOMAIN_MAPPING_DIR_PATH . 'includes/class-tools.php';
2025-05-20 22:52:24 +08:00
/**
* Main Domain Mapping Class
*/
class WP_Domain_Mapping {
/**
* Plugin instance
*
* @var WP_Domain_Mapping
*/
private static $instance = null;
/**
2025-05-23 16:10:39 +08:00
* Core instance
*
* @var WP_Domain_Mapping_Core
*/
public $core;
/**
* Admin instance
2025-05-20 22:52:24 +08:00
*
2025-05-23 16:10:39 +08:00
* @var WP_Domain_Mapping_Admin
2025-05-20 22:52:24 +08:00
*/
2025-05-23 16:10:39 +08:00
public $admin;
/**
* Tools instance
*
* @var WP_Domain_Mapping_Tools
*/
public $tools;
2025-05-20 22:52:24 +08:00
/**
* Get plugin instance
*
* @return WP_Domain_Mapping
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
2025-04-15 09:58:06 +08:00
2025-05-20 22:52:24 +08:00
/**
* Constructor
*/
private function __construct() {
$this->init();
}
2025-03-21 11:25:09 +08:00
2025-05-20 22:52:24 +08:00
/**
* Initialize plugin
*/
private function init() {
// Load text domain
add_action( 'init', array( $this, 'load_textdomain' ) );
2025-03-21 11:25:09 +08:00
2025-05-20 22:52:24 +08:00
// Initialize plugin update checker
$this->setup_updater();
2025-03-16 01:03:10 +08:00
2025-05-23 16:10:39 +08:00
// Initialize components
$this->core = WP_Domain_Mapping_Core::get_instance();
$this->admin = WP_Domain_Mapping_Admin::get_instance();
$this->tools = WP_Domain_Mapping_Tools::get_instance();
2025-05-20 22:52:24 +08:00
// Check plugin requirements on activation
register_activation_hook( __FILE__, array( $this, 'plugin_activation' ) );
2025-05-23 16:10:39 +08:00
register_deactivation_hook( __FILE__, array( $this, 'plugin_deactivation' ) );
2025-03-16 01:03:10 +08:00
}
2025-05-20 22:52:24 +08:00
/**
* Load plugin textdomain
*/
public function load_textdomain() {
load_plugin_textdomain( 'wp-domain-mapping', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
2025-03-16 01:03:10 +08:00
}
2025-05-20 22:52:24 +08:00
/**
* Setup plugin updater
*/
private function setup_updater() {
// Only include the updater if the PUC library exists
if ( file_exists( plugin_dir_path( __FILE__ ) . 'lib/plugin-update-checker/plugin-update-checker.php' ) ) {
require_once plugin_dir_path( __FILE__ ) . 'lib/plugin-update-checker/plugin-update-checker.php';
if ( class_exists( 'YahnisElsts\PluginUpdateChecker\v5p3\PucFactory' ) ) {
\YahnisElsts\PluginUpdateChecker\v5p3\PucFactory::buildUpdateChecker(
'https://updates.weixiaoduo.com/wp-domain-mapping.json',
__FILE__,
'wp-domain-mapping'
);
}
}
2025-03-16 01:03:10 +08:00
}
2025-05-20 22:52:24 +08:00
/**
* Actions to perform on plugin activation
*/
public function plugin_activation() {
// Create database tables
2025-05-23 16:10:39 +08:00
$this->core->create_tables();
2025-05-20 22:52:24 +08:00
// Initialize remote login hash
2025-05-23 16:10:39 +08:00
$this->core->get_hash();
2025-05-20 22:52:24 +08:00
2025-05-23 16:10:39 +08:00
// Schedule health check
$this->tools->schedule_health_check();
2025-03-16 01:03:10 +08:00
}
2025-05-20 22:52:24 +08:00
/**
2025-05-23 16:10:39 +08:00
* Actions to perform on plugin deactivation
2025-05-20 22:52:24 +08:00
*/
2025-05-23 16:10:39 +08:00
public function plugin_deactivation() {
// Unschedule health check
$this->tools->unschedule_health_check();
2025-03-16 01:03:10 +08:00
}
}
2025-05-20 22:52:24 +08:00
// Initialize the plugin
function wp_domain_mapping_init() {
return WP_Domain_Mapping::get_instance();
2025-03-16 01:03:10 +08:00
}
2025-05-20 22:52:24 +08:00
wp_domain_mapping_init();