SiteWatchman: %s', esc_html( 'Activation failed. SiteWatchman Pro is already active. Please deactivate the Pro version first.' ) ); wp_die( wp_kses_post( $message ), 'Plugin Activation Error', array( 'back_link' => true ) ); } } if ( is_plugin_active( 'sitewatchman-pro/sitewatchman.php' ) ) { return; } /** * Registers the system autoloader for internal plugin classes. * * Maps the `sitewatchman\swm7` namespace hierarchy to physical file paths * using the WordPress standard (class- prefix and underscores replaced with dashes) * and safely includes them via require_once. * * @since 1.0.0 * @param string $class_name The fully qualified name of the requested class. * @return void */ spl_autoload_register( function ( $class_name ) { if ( 0 !== strpos( $class_name, 'sitewatchman\\swm7\\' ) ) { return; } $relative_class = str_replace( 'sitewatchman\\swm7\\', '', $class_name ); $file_parts = explode( '\\', $relative_class ); $single_class = array_pop( $file_parts ); $file_name = 'class-' . strtolower( str_replace( '_', '-', $single_class ) ) . '.php'; $path = plugin_dir_path( __FILE__ ); if ( ! empty( $file_parts ) ) { $path .= strtolower( implode( '/', $file_parts ) ) . '/'; } $full_path = $path . $file_name; if ( file_exists( $full_path ) ) { require_once $full_path; } } ); /** * Bootstraps the plugin core logic, includes procedural files, and registers AJAX hooks. * * Fires on 'plugins_loaded' to verify version isolation, load functional assets * from includes and settings directories, instantiate core lifecycle objects, * and establish active administrative backend endpoints. * * @since 1.0.0 * @see \sitewatchman\swm7\Swm7_Cron * @see \sitewatchman\swm7\Swm7_Core * @return void */ add_action( 'plugins_loaded', function () { if ( ! function_exists( 'is_plugin_active' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } if ( is_plugin_active( 'sitewatchman-pro/sitewatchman.php' ) ) { return; } // Safe inclusion of procedural files. require_once __DIR__ . '/includes/swm-io-interface.php'; require_once __DIR__ . '/includes/swm-btns-service.php'; require_once __DIR__ . '/settings/swm-countries.php'; require_once __DIR__ . '/settings/swm-create-tables.php'; require_once __DIR__ . '/includes/swm-sse-backend.php'; require_once __DIR__ . '/includes/swm-ajax-table.php'; require_once __DIR__ . '/includes/swm-ajax-blacklist.php'; require_once __DIR__ . '/includes/swm-ajax-statistic.php'; require_once __DIR__ . '/includes/swm-ajax-cron.php'; require_once __DIR__ . '/includes/swm-ip-info.php'; require_once __DIR__ . '/includes/swm-core-help.php'; require_once __DIR__ . '/includes/swm-settings-help.php'; // Instantiate Cron and Core classes. if ( class_exists( '\sitewatchman\swm7\Swm7_Cron' ) ) { new \sitewatchman\swm7\Swm7_Cron(); } if ( class_exists( '\sitewatchman\swm7\Swm7_Core' ) ) { global $swm7_core; $swm7_core = new \sitewatchman\swm7\Swm7_Core(); } // Register core system AJAX hooks. add_action( 'wp_ajax_swm7_backend', 'sitewatchman\swm7\swm7_sse_backend' ); add_action( 'wp_ajax_swm7_filter_table_ajax', 'sitewatchman\swm7\swm7_filter_table_ajax_handler' ); add_action( 'wp_ajax_swm7_blacklist_ajax', 'sitewatchman\swm7\swm7_blacklist_ajax_handler' ); add_action( 'wp_ajax_swm7_get_popup_stat_ajax', 'sitewatchman\swm7\swm7_get_popup_stat_ajax_handler' ); add_action( 'wp_ajax_swm7_manage_cron_tasks_ajax', 'sitewatchman\swm7\swm7_manage_cron_tasks_ajax_handler' ); } ); /** * Registers and loads structural scripts, external styles, and runtime parameters for the admin dashboard. * * Fires on 'admin_enqueue_scripts' to isolate asset delivery strictly to the plugin's * target administration pages, inject operational nonces, and expose configuration states to JavaScript. * * @since 1.0.0 * @param string $hook The current admin page layout identifier. * @return void */ add_action( 'admin_enqueue_scripts', function ( $hook ) { if ( ! function_exists( 'is_plugin_active' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } if ( is_plugin_active( 'sitewatchman-pro/sitewatchman.php' ) ) { return; } if ( 'toplevel_page_swm7_visitors' !== $hook && 'visitors_page_swm7_settings' !== $hook ) { return; } wp_enqueue_style( 'leaflet-css', plugins_url( 'css/leaflet.css', __FILE__ ), array(), '1.9.4' ); wp_enqueue_script( 'leaflet-js', plugins_url( 'js/leaflet.js', __FILE__ ), array(), '1.9.4', true ); wp_enqueue_script( 'swm-chart-js', plugins_url( 'js/chart.umd.js', __FILE__ ), array(), '4.5.1', false ); wp_enqueue_script( 'sitewatchman-admin-js', plugins_url( 'js/swm7.js', __FILE__ ), array( 'swm-chart-js', 'leaflet-js' ), '1.0.0', false ); wp_enqueue_style( 'sitewatchman-admin-css', plugins_url( 'css/swm7.css', __FILE__ ), array(), '1.0.0' ); $main_settings = get_option( 'swm7_main_settings' ); wp_localize_script( 'sitewatchman-admin-js', 'swm7Settings', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'swm7_admin_nonce' ), 'sound_alert' => ! empty( $main_settings['visit_sound_signal'] ), ) ); } ); /** * Executes environment checks and structure definitions during global plugin activation. * * Enforces the minimum PHP 8.0 requirement, dynamically provisions database schemas, * and registers core scheduling routines within the WordPress Cron subsystem. * * @since 1.0.0 * @see \sitewatchman\swm7\swm7_create_tables * @see \sitewatchman\swm7\Swm7_Cron::activate() * @return void */ register_activation_hook( __FILE__, function () { if ( version_compare( PHP_VERSION, '8.0.0', '<' ) ) { deactivate_plugins( plugin_basename( __FILE__ ) ); wp_die( esc_html( 'SiteWatchman requires PHP version 8.0 or higher. Please upgrade PHP before activating this plugin.' ), esc_html( 'Plugin Activation Error' ), array( 'back_link' => true ) ); } $plugin_dir = plugin_dir_path( __FILE__ ); if ( file_exists( $plugin_dir . 'settings/swm-create-tables.php' ) ) { require_once $plugin_dir . 'settings/swm-create-tables.php'; } if ( function_exists( 'sitewatchman\swm7\swm7_create_tables' ) ) { \sitewatchman\swm7\swm7_create_tables(); } if ( class_exists( '\sitewatchman\swm7\Swm7_Cron' ) ) { \sitewatchman\swm7\Swm7_Cron::activate(); } } ); /** * Orchestrates resource cleanup upon plugin deactivation. * * Unregisters all scheduled background events and maintenance tasks * safely from the native WordPress Cron registry. * * @since 1.0.0 * @see \sitewatchman\swm7\Swm7_Cron::deactivate() * @return void */ register_deactivation_hook( __FILE__, function () { if ( class_exists( '\sitewatchman\swm7\Swm7_Cron' ) ) { \sitewatchman\swm7\Swm7_Cron::deactivate(); } } ); /** * Intercepts POST payloads to trigger print-ready A4 PDF report compilation. * * Hooks into 'admin_post_swm7_generate_report' to initialize the data rendering * subsystem and dispatch processed telemetry to the active file export engine. * * @since 1.0.0 * @see \sitewatchman\swm7\Swm7_Visitors::swm7_create_report() * @return void */ add_action( 'admin_post_swm7_generate_report', function () { if ( class_exists( 'sitewatchman\swm7\Swm7_Visitors' ) ) { $visitors_table = new \sitewatchman\swm7\Swm7_Visitors(); $visitors_table->swm7_create_report(); } } );