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 )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user