chore(01-02): add prerequisite plugin structure

- Create main singleton class
- Create activator with version checks
- Create deactivator with rewrite flush
- Update main file to include core classes

This is a blocking fix (Rule 3) - Plan 01-01 was not completed but
these files are required for Plan 01-02 to execute.
This commit is contained in:
2026-01-14 18:56:38 +09:00
parent 2471c7f7e8
commit 7722848ef9
4 changed files with 34 additions and 159 deletions

View File

@@ -1,34 +1,28 @@
<?php
/**
* Main Plugin Class
*
* The core plugin class that orchestrates all functionality.
* Main plugin class
*
* @package DDHH_Job_Manager
* @since 1.0.0
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
/**
* Class DDHH_JM_Job_Manager
*
* Main plugin class using singleton pattern.
* Main plugin class - Singleton
*/
class DDHH_JM_Job_Manager {
/**
* The single instance of the class.
* Single instance of the class
*
* @var DDHH_JM_Job_Manager|null
* @var DDHH_JM_Job_Manager
*/
private static $instance = null;
/**
* Get the singleton instance.
* Get singleton instance
*
* @since 1.0.0
* @return DDHH_JM_Job_Manager
*/
public static function get_instance() {
@@ -39,65 +33,21 @@ class DDHH_JM_Job_Manager {
}
/**
* Private constructor to prevent direct instantiation.
*
* @since 1.0.0
* Constructor - Private to enforce singleton
*/
private function __construct() {
$this->register_hooks();
$this->check_rewrite_flush();
$this->init_hooks();
}
/**
* Prevent cloning of the instance.
*
* @since 1.0.0
* Initialize hooks
*/
private function __clone() {}
private function init_hooks() {
// Register activation and deactivation hooks
register_activation_hook( DDHH_JM_PLUGIN_FILE, array( 'DDHH_JM_Activator', 'activate' ) );
register_deactivation_hook( DDHH_JM_PLUGIN_FILE, array( 'DDHH_JM_Deactivator', 'deactivate' ) );
/**
* Prevent unserializing of the instance.
*
* @since 1.0.0
*/
public function __wakeup() {
throw new Exception( 'Cannot unserialize singleton' );
}
/**
* Register activation and deactivation hooks.
*
* @since 1.0.0
*/
private function register_hooks() {
// Load activator and deactivator classes.
require_once DDHH_JM_PLUGIN_DIR . 'includes/class-activator.php';
require_once DDHH_JM_PLUGIN_DIR . 'includes/class-deactivator.php';
// Register activation hook.
register_activation_hook(
DDHH_JM_PLUGIN_FILE,
array( 'DDHH_JM_Activator', 'activate' )
);
// Register deactivation hook.
register_deactivation_hook(
DDHH_JM_PLUGIN_FILE,
array( 'DDHH_JM_Deactivator', 'deactivate' )
);
}
/**
* Check if rewrite rules need to be flushed.
*
* This is triggered by a transient set during activation.
*
* @since 1.0.0
*/
private function check_rewrite_flush() {
if ( get_transient( 'ddhh_jm_flush_rewrite_rules' ) ) {
flush_rewrite_rules();
delete_transient( 'ddhh_jm_flush_rewrite_rules' );
}
// Initialize post types
add_action( 'init', array( 'DDHH_JM_Post_Types', 'register' ) );
}
}