=' ) ) {
add_action( 'admin_notices', 'adminease_fail_php_version' );
} else if ( ! version_compare( get_bloginfo( 'version' ), '5.3', '>=' ) ) {
add_action( 'admin_notices', 'adminease_fail_wp_version' );
} else if ( class_exists( '\AdminEase\Plugin' ) ) {
// Initialize the plugin after all plugins are loaded.
add_action( 'plugins_loaded', function() {
\AdminEase\Plugin::get_instance();
// Not a settings-tab feature - a one-off marketing touchpoint, so it's
// bootstrapped directly instead of going through Features.php.
if ( is_admin() ) {
new \AdminEase\Features\ReviewRequest();
}
} );
}
/**
* Outputs an error message informing the user that the PHP version is outdated.
* @return void
*/
function adminease_fail_php_version(): void {
$html_message = sprintf(
'
',
esc_html__( 'AdminEase isn’t running because PHP is outdated.', 'adminease' ),
sprintf(
/* translators: %s: PHP version. */
esc_html__( 'Update to version %s and get back to creating!', 'adminease' ),
'7.4'
),
);
echo wp_kses_post( $html_message );
}
/**
* Outputs an error message notifying the user that AdminEase cannot run due to an outdated WordPress version.
* @return void
*/
function adminease_fail_wp_version(): void {
$html_message = sprintf(
'',
esc_html__( 'AdminEase isn’t running because WordPress is outdated.', 'adminease' ),
sprintf(
/* translators: %s: WordPress version. */
esc_html__( 'Update to version %s and get back to creating!', 'adminease' ),
'5.3'
),
);
echo wp_kses_post( $html_message );
}
// Register the activation hook
register_activation_hook( __FILE__, 'adminease_activation_handler' );
/**
* Handles the activation process for the AdminEase plugin.
* This function initializes the FileHandler, creates backups of critical files,
* logs any errors encountered during the process, and updates the activation status
* to notify the system of the activation outcome.
* @return void
*/
function adminease_activation_handler() {
// Initialize the FileHandler
$FileHandler = new \AdminEase\FileHandler();
// Step 1: Create backups of original files
$wp_config_backup = $FileHandler->create_backup( 'wp-config' );
$htaccess_backup = $FileHandler->create_backup( 'htaccess' );
// Step 2: Check for errors and log them
if ( ! $wp_config_backup || ! $htaccess_backup ) {
$errors = $FileHandler->get_errors();
// Store activation status for admin notice
update_option( 'adminease_activation_status', 'backup_error' );
update_option( 'adminease_activation_errors', $errors );
return; // Exit if backup creation fails
}
// Step 3: Log successful backup creation
error_log( 'AdminEase: Backup files created successfully during activation' ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- Using error_log for debugging purposes
// Step 4: Flag the stored settings to be re-applied on the next admin request.
update_option( 'adminease_pending_reapply', 1, false );
// Step 5: Store activation status for admin notice
update_option( 'adminease_activation_status', 'success' );
}
register_deactivation_hook( __FILE__, 'adminease_deactivation_handler' );
/**
* Handles the deactivation process for the AdminEase plugin.
*
* Removes only AdminEase's own marker-delimited blocks from wp-config.php and
* .htaccess, then clears the plugin's scheduled cron events.
*
* It deliberately does NOT restore those files from the activation-time backup.
* FileHandler::create_backup() never overwrites an existing backup, so the backup
* is a snapshot frozen at the moment the plugin was first activated. Restoring it
* would silently revert every unrelated change made since - changed DB
* credentials, other plugins' constants, and (for .htaccess) the rewrite rules
* WordPress regenerates on every permalink save. The backups are left in place as
* a manual recovery aid.
*
* @return void
*/
function adminease_deactivation_handler() {
// Initialize the FileHandler
$FileHandler = new \AdminEase\FileHandler();
// Step 1: Drop any changes that were queued but never written
$FileHandler->clear_all_stacks();
// Step 2: Surgically remove AdminEase marker blocks only
$cleanup_success = $FileHandler->cleanup_all_markers();
// Step 3: Store deactivation results
if ( $cleanup_success ) {
update_option( 'adminease_deactivation_status', 'success' );
} else {
update_option( 'adminease_deactivation_status', 'partial_success' );
update_option( 'adminease_deactivation_errors', $FileHandler->get_errors() );
}
// Step 4: Clear every scheduled cron event this plugin registers
wp_clear_scheduled_hook( 'adminease_cleanup_network_viewer_logs' );
wp_clear_scheduled_hook( 'adminease_cleanup_email_logs' );
wp_clear_scheduled_hook( 'adminease_cleanup_cron_viewer_logs' );
}