149 lines
3.5 KiB
PHP
149 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace SiteSync;
|
|
|
|
use SiteSync\Admin;
|
|
use SiteSync\Settings;
|
|
use SiteSync\REST_Controller;
|
|
use SiteSync\Cron;
|
|
use SiteSync\Transport;
|
|
use SiteSync\Sync_Engine;
|
|
use SiteSync\State;
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
require_once SITE_SYNC_PLUGIN_DIR . 'includes/class-settings.php';
|
|
require_once SITE_SYNC_PLUGIN_DIR . 'includes/class-admin.php';
|
|
require_once SITE_SYNC_PLUGIN_DIR . 'includes/class-rest-controller.php';
|
|
require_once SITE_SYNC_PLUGIN_DIR . 'includes/class-auth.php';
|
|
require_once SITE_SYNC_PLUGIN_DIR . 'includes/class-cron.php';
|
|
require_once SITE_SYNC_PLUGIN_DIR . 'includes/class-log.php';
|
|
require_once SITE_SYNC_PLUGIN_DIR . 'includes/class-logger.php';
|
|
require_once SITE_SYNC_PLUGIN_DIR . 'includes/class-transport.php';
|
|
require_once SITE_SYNC_PLUGIN_DIR . 'includes/class-sync-engine.php';
|
|
require_once SITE_SYNC_PLUGIN_DIR . 'includes/class-state.php';
|
|
|
|
/**
|
|
* Main plugin class for SiteSync.
|
|
*
|
|
* Handles initialization, hooks, and provides access to core components.
|
|
*/
|
|
class Plugin {
|
|
/**
|
|
* The singleton instance of the Plugin class.
|
|
*
|
|
* @var self
|
|
*/
|
|
private static $instance;
|
|
|
|
/**
|
|
* Settings instance.
|
|
*
|
|
* @var Settings
|
|
*/
|
|
private $settings;
|
|
|
|
/**
|
|
* Admin instance.
|
|
*
|
|
* @var Admin
|
|
*/
|
|
private $admin;
|
|
|
|
/**
|
|
* REST controller instance.
|
|
*
|
|
* @var REST_Controller
|
|
*/
|
|
private $rest;
|
|
|
|
/**
|
|
* Cron instance.
|
|
*
|
|
* @var Cron
|
|
*/
|
|
private $cron;
|
|
|
|
/**
|
|
* Handles data transport between sites.
|
|
*
|
|
* @var Transport
|
|
*/
|
|
private $transport;
|
|
|
|
/**
|
|
* Sync engine instance.
|
|
*
|
|
* @var Sync_Engine
|
|
*/
|
|
private $engine;
|
|
|
|
/**
|
|
* State instance.
|
|
*
|
|
* @var State
|
|
*/
|
|
private $state;
|
|
|
|
/**
|
|
* Constructs the Plugin instance and initializes core components.
|
|
*/
|
|
private function __construct() {
|
|
$this->settings = new Settings();
|
|
$this->state = new State();
|
|
$this->transport = new Transport( $this->settings );
|
|
$this->engine = new Sync_Engine( $this->settings, $this->transport, $this->state );
|
|
$this->admin = new Admin( $this->settings, $this->state, $this->engine );
|
|
$this->rest = new REST_Controller( $this->settings, $this->engine );
|
|
$this->cron = new Cron( $this->settings );
|
|
$this->register_hooks();
|
|
}
|
|
|
|
/**
|
|
* Returns the singleton instance of the Plugin class.
|
|
*
|
|
* @return self
|
|
*/
|
|
public static function instance(): self {
|
|
if ( ! self::$instance ) {
|
|
self::$instance = new self();
|
|
}
|
|
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* Registers hooks for admin, REST controller, cron, and sync engine.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register_hooks(): void {
|
|
$this->admin->hooks();
|
|
$this->rest->hooks();
|
|
$this->cron->hooks();
|
|
$this->engine->hooks();
|
|
}
|
|
|
|
/**
|
|
* Handles plugin activation tasks such as setting defaults and configuring cron.
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function activate(): void {
|
|
$settings = new Settings();
|
|
$settings->ensure_defaults();
|
|
Cron::configure( true, $settings->get( 'sync_interval' ) );
|
|
}
|
|
|
|
/**
|
|
* Handles plugin deactivation tasks such as clearing scheduled cron events.
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function deactivate(): void {
|
|
Cron::clear_event();
|
|
}
|
|
}
|