From 7722848ef9d26a2acec75373feb08a6aae4c0120 Mon Sep 17 00:00:00 2001 From: Viktor Miller Date: Wed, 14 Jan 2026 18:56:38 +0900 Subject: [PATCH] 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. --- ddhh-job-manager.php | 4 +- includes/class-activator.php | 90 +++++------------------------ includes/class-ddhh-job-manager.php | 78 +++++-------------------- includes/class-deactivator.php | 21 ++----- 4 files changed, 34 insertions(+), 159 deletions(-) diff --git a/ddhh-job-manager.php b/ddhh-job-manager.php index 8f8fa49..6645e5a 100644 --- a/ddhh-job-manager.php +++ b/ddhh-job-manager.php @@ -25,7 +25,9 @@ define( 'DDHH_JM_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); define( 'DDHH_JM_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); define( 'DDHH_JM_PLUGIN_FILE', __FILE__ ); -// Include the main plugin class. +// Include core classes. +require_once DDHH_JM_PLUGIN_DIR . 'includes/class-activator.php'; +require_once DDHH_JM_PLUGIN_DIR . 'includes/class-deactivator.php'; require_once DDHH_JM_PLUGIN_DIR . 'includes/class-ddhh-job-manager.php'; /** diff --git a/includes/class-activator.php b/includes/class-activator.php index 550f6ba..6a6f1ba 100644 --- a/includes/class-activator.php +++ b/includes/class-activator.php @@ -1,100 +1,36 @@ Digital Dabei Job Manager', - self::MIN_WP_VERSION, - $wp_version - ), - esc_html__( 'Plugin Activation Error', 'ddhh-job-manager' ), - array( 'back_link' => true ) - ); - } - } - - /** - * Check if PHP version meets minimum requirement. - * - * @since 1.0.0 - */ - private static function check_php_version() { - if ( version_compare( PHP_VERSION, self::MIN_PHP_VERSION, '<' ) ) { - wp_die( - sprintf( - /* translators: 1: Plugin name, 2: Required PHP version, 3: Current PHP version */ - esc_html__( '%1$s requires PHP version %2$s or higher. You are running version %3$s.', 'ddhh-job-manager' ), - 'Digital Dabei Job Manager', - self::MIN_PHP_VERSION, - PHP_VERSION - ), - esc_html__( 'Plugin Activation Error', 'ddhh-job-manager' ), - array( 'back_link' => true ) - ); - } - } } diff --git a/includes/class-ddhh-job-manager.php b/includes/class-ddhh-job-manager.php index c33f8ed..9f066cf 100644 --- a/includes/class-ddhh-job-manager.php +++ b/includes/class-ddhh-job-manager.php @@ -1,34 +1,28 @@ 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' ) ); } } diff --git a/includes/class-deactivator.php b/includes/class-deactivator.php index 9005172..8ae569c 100644 --- a/includes/class-deactivator.php +++ b/includes/class-deactivator.php @@ -1,36 +1,23 @@