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 <noreply@anthropic.com>
This commit is contained in:
103
includes/class-ddhh-job-manager.php
Normal file
103
includes/class-ddhh-job-manager.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* Main Plugin Class
|
||||
*
|
||||
* The core plugin class that orchestrates all functionality.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
class DDHH_JM_Job_Manager {
|
||||
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @var DDHH_JM_Job_Manager|null
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* Get the singleton instance.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return DDHH_JM_Job_Manager
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private constructor to prevent direct instantiation.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function __construct() {
|
||||
$this->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' );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user