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:
@@ -1,100 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Activation Handler
|
||||
*
|
||||
* Handles plugin activation logic including version checks and initial setup.
|
||||
* Plugin activation handler
|
||||
*
|
||||
* @package DDHH_Job_Manager
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class DDHH_JM_Activator
|
||||
*
|
||||
* Handles plugin activation.
|
||||
* Handles plugin activation
|
||||
*/
|
||||
class DDHH_JM_Activator {
|
||||
|
||||
/**
|
||||
* Minimum WordPress version required.
|
||||
*
|
||||
* @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
|
||||
* Activation logic
|
||||
*/
|
||||
public static function activate() {
|
||||
// Check WordPress version.
|
||||
self::check_wordpress_version();
|
||||
// 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.
|
||||
self::check_php_version();
|
||||
// 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 );
|
||||
|
||||
// Set a transient to trigger rewrite flush on next init.
|
||||
// This is better than flushing immediately during activation.
|
||||
// Set flag to flush rewrite rules on next init
|
||||
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
|
||||
/**
|
||||
* 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' ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Deactivation Handler
|
||||
*
|
||||
* Handles plugin deactivation logic.
|
||||
* Plugin deactivation handler
|
||||
*
|
||||
* @package DDHH_Job_Manager
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class DDHH_JM_Deactivator
|
||||
*
|
||||
* Handles plugin deactivation.
|
||||
* Handles plugin deactivation
|
||||
*/
|
||||
class DDHH_JM_Deactivator {
|
||||
|
||||
/**
|
||||
* Deactivate the plugin.
|
||||
*
|
||||
* 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
|
||||
* Deactivation logic
|
||||
*/
|
||||
public static function deactivate() {
|
||||
// Remove the rewrite flush transient if it exists.
|
||||
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