Files
Digital-Dabei-Hamburg-Job-M…/includes/class-activator.php
Viktor Miller 2471c7f7e8 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>
2026-01-14 18:56:02 +09:00

101 lines
2.4 KiB
PHP

<?php
/**
* Plugin Activation Handler
*
* Handles plugin activation logic including version checks and initial setup.
*
* @package DDHH_Job_Manager
* @since 1.0.0
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
/**
* Class DDHH_JM_Activator
*
* 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
*/
public static function activate() {
// Check WordPress version.
self::check_wordpress_version();
// Check PHP version.
self::check_php_version();
// Store plugin version in options.
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_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 )
);
}
}
}