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:
@@ -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_URL', plugin_dir_url( __FILE__ ) );
|
||||||
define( 'DDHH_JM_PLUGIN_FILE', __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';
|
require_once DDHH_JM_PLUGIN_DIR . 'includes/class-ddhh-job-manager.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,100 +1,36 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Plugin Activation Handler
|
* Plugin activation handler
|
||||||
*
|
|
||||||
* Handles plugin activation logic including version checks and initial setup.
|
|
||||||
*
|
*
|
||||||
* @package DDHH_Job_Manager
|
* @package DDHH_Job_Manager
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Exit if accessed directly.
|
// Exit if accessed directly.
|
||||||
defined( 'ABSPATH' ) || exit;
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class DDHH_JM_Activator
|
* Handles plugin activation
|
||||||
*
|
|
||||||
* Handles plugin activation.
|
|
||||||
*/
|
*/
|
||||||
class DDHH_JM_Activator {
|
class DDHH_JM_Activator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minimum WordPress version required.
|
* Activation logic
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
const MIN_WP_VERSION = '6.0';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Minimum PHP version required.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
const MIN_PHP_VERSION = '7.4';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Activate the plugin.
|
|
||||||
*
|
|
||||||
* Runs on plugin activation. Checks system requirements and sets up initial plugin state.
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
*/
|
||||||
public static function activate() {
|
public static function activate() {
|
||||||
// Check WordPress version.
|
// Check WordPress version
|
||||||
self::check_wordpress_version();
|
if ( version_compare( get_bloginfo( 'version' ), '6.0', '<' ) ) {
|
||||||
|
wp_die( esc_html__( 'This plugin requires WordPress 6.0 or higher.', 'ddhh-job-manager' ) );
|
||||||
|
}
|
||||||
|
|
||||||
// Check PHP version.
|
// Check PHP version
|
||||||
self::check_php_version();
|
if ( version_compare( PHP_VERSION, '7.4', '<' ) ) {
|
||||||
|
wp_die( esc_html__( 'This plugin requires PHP 7.4 or higher.', 'ddhh-job-manager' ) );
|
||||||
|
}
|
||||||
|
|
||||||
// Store plugin version in options.
|
// Store plugin version
|
||||||
update_option( 'ddhh_jm_version', DDHH_JM_VERSION );
|
update_option( 'ddhh_jm_version', DDHH_JM_VERSION );
|
||||||
|
|
||||||
// Set a transient to trigger rewrite flush on next init.
|
// Set flag to flush rewrite rules on next init
|
||||||
// This is better than flushing immediately during activation.
|
|
||||||
set_transient( 'ddhh_jm_flush_rewrite_rules', 1, 60 );
|
set_transient( 'ddhh_jm_flush_rewrite_rules', 1, 60 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if WordPress version meets minimum requirement.
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private static function check_wordpress_version() {
|
|
||||||
global $wp_version;
|
|
||||||
|
|
||||||
if ( version_compare( $wp_version, self::MIN_WP_VERSION, '<' ) ) {
|
|
||||||
wp_die(
|
|
||||||
sprintf(
|
|
||||||
/* translators: 1: Plugin name, 2: Required WordPress version, 3: Current WordPress version */
|
|
||||||
esc_html__( '%1$s requires WordPress version %2$s or higher. You are running version %3$s.', 'ddhh-job-manager' ),
|
|
||||||
'<strong>Digital Dabei Job Manager</strong>',
|
|
||||||
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' ),
|
|
||||||
'<strong>Digital Dabei Job Manager</strong>',
|
|
||||||
self::MIN_PHP_VERSION,
|
|
||||||
PHP_VERSION
|
|
||||||
),
|
|
||||||
esc_html__( 'Plugin Activation Error', 'ddhh-job-manager' ),
|
|
||||||
array( 'back_link' => true )
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,28 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Main Plugin Class
|
* Main plugin class
|
||||||
*
|
|
||||||
* The core plugin class that orchestrates all functionality.
|
|
||||||
*
|
*
|
||||||
* @package DDHH_Job_Manager
|
* @package DDHH_Job_Manager
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Exit if accessed directly.
|
// Exit if accessed directly.
|
||||||
defined( 'ABSPATH' ) || exit;
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class DDHH_JM_Job_Manager
|
* Main plugin class - Singleton
|
||||||
*
|
|
||||||
* Main plugin class using singleton pattern.
|
|
||||||
*/
|
*/
|
||||||
class DDHH_JM_Job_Manager {
|
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;
|
private static $instance = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the singleton instance.
|
* Get singleton instance
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
|
||||||
* @return DDHH_JM_Job_Manager
|
* @return DDHH_JM_Job_Manager
|
||||||
*/
|
*/
|
||||||
public static function get_instance() {
|
public static function get_instance() {
|
||||||
@@ -39,65 +33,21 @@ class DDHH_JM_Job_Manager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private constructor to prevent direct instantiation.
|
* Constructor - Private to enforce singleton
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
*/
|
||||||
private function __construct() {
|
private function __construct() {
|
||||||
$this->register_hooks();
|
$this->init_hooks();
|
||||||
$this->check_rewrite_flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prevent cloning of the instance.
|
* Initialize hooks
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
*/
|
||||||
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' ) );
|
||||||
|
|
||||||
/**
|
// Initialize post types
|
||||||
* Prevent unserializing of the instance.
|
add_action( 'init', array( 'DDHH_JM_Post_Types', 'register' ) );
|
||||||
*
|
|
||||||
* @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' );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,36 +1,23 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Plugin Deactivation Handler
|
* Plugin deactivation handler
|
||||||
*
|
|
||||||
* Handles plugin deactivation logic.
|
|
||||||
*
|
*
|
||||||
* @package DDHH_Job_Manager
|
* @package DDHH_Job_Manager
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Exit if accessed directly.
|
// Exit if accessed directly.
|
||||||
defined( 'ABSPATH' ) || exit;
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class DDHH_JM_Deactivator
|
* Handles plugin deactivation
|
||||||
*
|
|
||||||
* Handles plugin deactivation.
|
|
||||||
*/
|
*/
|
||||||
class DDHH_JM_Deactivator {
|
class DDHH_JM_Deactivator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deactivate the plugin.
|
* Deactivation logic
|
||||||
*
|
|
||||||
* Runs on plugin deactivation. Cleans up transients and flushes rewrite rules.
|
|
||||||
* Does NOT delete user data as the user may reactivate the plugin.
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
*/
|
||||||
public static function deactivate() {
|
public static function deactivate() {
|
||||||
// Remove the rewrite flush transient if it exists.
|
// Flush rewrite rules
|
||||||
delete_transient( 'ddhh_jm_flush_rewrite_rules' );
|
|
||||||
|
|
||||||
// Flush rewrite rules to clean up any custom rules added by the plugin.
|
|
||||||
flush_rewrite_rules();
|
flush_rewrite_rules();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user