=' ) ) { 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' ) ) { // The translations bundled with the plugin are not found on their own: WordPress // looks in wp-content/languages, where the wordpress.org language pack lands, and // in whatever folder a plugin registers for itself, and nowhere else. Registering // ours means a locale is translated from the moment the plugin is installed rather // than whenever the language pack turns up. On init rather than plugins_loaded, // because WordPress 6.7 and later warn about a text domain loaded any earlier. add_action( 'init', function() { load_plugin_textdomain( 'adminease', false, dirname( ADMINEASE_BASENAME ) . '/languages' ); // phpcs:ignore PluginCheck.CodeAnalysis.DiscouragedFunctions.load_plugin_textdomainFound -- Needed for the 5.3 floor. } ); // Initialize the plugin after all plugins are loaded. add_action( 'plugins_loaded', function() { \AdminEase\Plugin::get_instance(); 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( '

%1$s

%2$s

', 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( '

%1$s

%2$s

', 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() { $FileHandler = new \AdminEase\FileHandler(); $wp_config_backup = $FileHandler->create_backup( 'wp-config' ); $htaccess_backup = $FileHandler->create_backup( 'htaccess' ); if ( ! $wp_config_backup || ! $htaccess_backup ) { $errors = $FileHandler->get_errors(); update_option( 'adminease_activation_status', 'backup_error' ); update_option( 'adminease_activation_errors', $errors ); return; } update_option( 'adminease_pending_reapply', 1, false ); 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. * * On a network the files are shared and only the main site writes them, so a * sub-site that turns the plugin off leaves them alone. Network deactivation * clears the cron events of every site. * * @param bool $network_wide Whether the plugin is being deactivated for the whole network. * * @return void */ function adminease_deactivation_handler( $network_wide = false ) { if ( ! is_multisite() || is_main_site() ) { $FileHandler = new \AdminEase\FileHandler(); $FileHandler->clear_all_stacks(); $cleanup_success = $FileHandler->cleanup_all_markers(); 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() ); } } if ( is_multisite() && $network_wide ) { foreach ( get_sites( [ 'fields' => 'ids', 'number' => 0 ] ) as $site_id ) { switch_to_blog( $site_id ); adminease_clear_scheduled_events(); restore_current_blog(); } return; } adminease_clear_scheduled_events(); } /** * Clears every scheduled cron event this plugin registers, on the current site. * * @return void */ function adminease_clear_scheduled_events() { 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' ); wp_clear_scheduled_hook( 'adminease_cleanup_http_request_logs' ); wp_clear_scheduled_hook( 'adminease_cleanup_audit_log' ); }