From 2471c7f7e8f1e5981c6851a9710a6fd458808a1b Mon Sep 17 00:00:00 2001 From: Viktor Miller Date: Wed, 14 Jan 2026 18:56:02 +0900 Subject: [PATCH] feat(01-01): create main plugin class with activation/deactivation - Add main singleton class DDHH_JM_Job_Manager - Implement activation handler with WP/PHP version checks - Implement deactivation handler with rewrite flush - Use transient-based rewrite flush to avoid multiple flushes - Add comprehensive security checks and documentation Co-Authored-By: Claude Sonnet 4.5 --- includes/class-activator.php | 100 +++++++++++++++++++++++++++ includes/class-ddhh-job-manager.php | 103 ++++++++++++++++++++++++++++ includes/class-deactivator.php | 36 ++++++++++ 3 files changed, 239 insertions(+) create mode 100644 includes/class-activator.php create mode 100644 includes/class-ddhh-job-manager.php create mode 100644 includes/class-deactivator.php diff --git a/includes/class-activator.php b/includes/class-activator.php new file mode 100644 index 0000000..550f6ba --- /dev/null +++ b/includes/class-activator.php @@ -0,0 +1,100 @@ +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 new file mode 100644 index 0000000..c33f8ed --- /dev/null +++ b/includes/class-ddhh-job-manager.php @@ -0,0 +1,103 @@ +register_hooks(); + $this->check_rewrite_flush(); + } + + /** + * Prevent cloning of the instance. + * + * @since 1.0.0 + */ + private function __clone() {} + + /** + * 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' ); + } + } +} diff --git a/includes/class-deactivator.php b/includes/class-deactivator.php new file mode 100644 index 0000000..9005172 --- /dev/null +++ b/includes/class-deactivator.php @@ -0,0 +1,36 @@ +