/** * The main plugin class. * * This is the core class that orchestrates all functionality of the plugin. * * @since 1.0.0 * @package WP_Recover */ namespace WP_Recover; class WP_Recover { /** * The loader that's responsible for maintaining and registering all hooks. * * @since 1.0.0 * @access protected * @var \WP_Recover\WP_Recover_Loader $loader Maintains and registers all hooks for the plugin. */ protected $loader; /** * The unique identifier of this plugin. * * @since 1.0.0 * @access protected * @var string $plugin_name The string used to uniquely identify this plugin. */ protected $plugin_name; /** * The current version of the plugin. * * @since 1.0.0 * @access protected * @var string $version The current version of the plugin. */ protected $version; /** * The job manager instance. * * @since 1.0.0 * @access protected * @var \WP_Recover\Background\WP_Recover_Job_Manager $job_manager Handles job management. */ protected $job_manager; /** * The logger instance. * * @since 1.0.0 * @access protected * @var \WP_Recover\WP_Recover_Logger $logger Handles logging and notifications. */ protected $logger; /** * Define the core functionality of the plugin. * * Set the plugin name and the plugin version that can be used throughout the plugin. * Load the dependencies, define the locale, and set the hooks for the admin area and * the public-facing side of the site. * * @since 1.0.0 */ public function __construct() { $this->version = WP_RECOVER_VERSION; $this->plugin_name = 'wp-recover'; $this->load_dependencies(); $this->set_locale(); $this->define_admin_hooks(); } /** * Load the required dependencies for this plugin. * * Include the following files that make up the plugin: * * - WP_Recover_Loader. Orchestrates the hooks of the plugin. * - WP_Recover_i18n. Defines internationalization functionality. * - WP_Recover_Admin. Defines all hooks for the admin area. * - WP_Recover_API. Handles Internet Archive API interactions. * - WP_Recover_Content_Processor. Processes and cleans archived content. * - WP_Recover_Media_Handler. Handles media restoration. * - WP_Recover_Menu_Handler. Handles menu detection and restoration. * - WP_Recover_URL_Handler. Handles URL structure preservation. * - WP_Recover_Content_Cleaner. Provides advanced content cleaning and formatting. * - WP_Recover_Intelligent_Extractor. Provides intelligent content extraction. * - WP_Recover_Content_Analyzer. Provides content analysis capabilities. * - WP_Recover_ML_Bridge. Provides machine learning integration. * - WP_Recover_Logger. Provides detailed logging and notification system. * * @since 1.0.0 * @access private */ private function load_dependencies() { // Dependencies are now loaded via the autoloader in wp-recover.php // Instantiate necessary core components using fully qualified namespaces. $this->loader = new \WP_Recover\WP_Recover_Loader(); $this->job_manager = new \WP_Recover\Background\WP_Recover_Job_Manager(); $this->logger = new \WP_Recover\WP_Recover_Logger(); } /** * Define the locale for this plugin for internationalization. * * Uses the WP_Recover_i18n class in order to set the domain and to register the hook * with WordPress. * * @since 1.0.0 * @access private */ private function set_locale() { $plugin_i18n = new \WP_Recover\WP_Recover_i18n(); $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain'); } /** * Register all of the hooks related to the admin area functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_admin_hooks() { $plugin_admin = new \WP_Recover\Admin\WP_Recover_Admin($this->get_plugin_name(), $this->get_version()); // Admin menu and settings $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles'); $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts'); $this->loader->add_action('admin_menu', $plugin_admin, 'add_plugin_admin_menu'); $this->loader->add_action('admin_init', $plugin_admin, 'register_settings'); // AJAX handlers for admin interface $this->loader->add_action('wp_ajax_wp_recover_search_snapshots', $plugin_admin, 'ajax_search_snapshots'); $this->loader->add_action('wp_ajax_wp_recover_detect_themes', $plugin_admin, 'ajax_detect_themes'); $this->loader->add_action('wp_ajax_wp_recover_start_restoration', $plugin_admin, 'ajax_start_restoration'); $this->loader->add_action('wp_ajax_wp_recover_check_progress', $plugin_admin, 'ajax_check_progress'); $this->loader->add_action('wp_ajax_wp_recover_analyze_content', $plugin_admin, 'ajax_analyze_content'); $this->loader->add_action('wp_ajax_wp_recover_extract_content', $plugin_admin, 'ajax_extract_content'); $this->loader->add_action('wp_ajax_wp_recover_ml_extract_content', $plugin_admin, 'ajax_ml_extract_content'); $this->loader->add_action('wp_ajax_wp_recover_ml_classify_content', $plugin_admin, 'ajax_ml_classify_content'); // Initialize theme comparison handler new \WP_Recover\Admin\WP_Recover_Theme_Comparison_Handler(); // Initialize plugin comparison handler new \WP_Recover\Admin\WP_Recover_Plugin_Comparison_Handler(); // Initialize logger and register its AJAX handlers $this->loader->add_action('wp_ajax_wp_recover_get_activity_log', $this->logger, 'ajax_get_activity_log'); $this->loader->add_action('wp_ajax_wp_recover_export_logs', $this->logger, 'ajax_export_logs'); $this->loader->add_action('wp_ajax_wp_recover_clear_logs', $this->logger, 'ajax_clear_logs'); $this->loader->add_action('wp_ajax_wp_recover_test_notification', $this, 'ajax_test_notification'); // Register notification settings $this->loader->add_action('admin_init', $this, 'register_notification_settings'); $completion_report = new \WP_Recover\WP_Recover_Completion_Report(); $this->loader->add_action('wp_ajax_wp_recover_content_comparison', $completion_report, 'ajax_content_comparison'); $this->loader->add_action('wp_ajax_wp_recover_structure_analysis', $completion_report, 'ajax_structure_analysis'); $this->loader->add_action('wp_ajax_wp_recover_quality_analysis', $completion_report, 'ajax_quality_analysis'); $this->loader->add_action('wp_ajax_wp_recover_post_restoration_adjustment', $completion_report, 'ajax_post_restoration_adjustment'); $this->loader->add_action('wp_ajax_wp_recover_generate_report', $completion_report, 'ajax_generate_report'); $this->loader->add_action('wp_ajax_wp_recover_permalink_modal', $completion_report, 'ajax_permalink_modal'); $this->loader->add_action('wp_ajax_wp_recover_theme_customization_modal', $completion_report, 'ajax_theme_customization_modal'); $this->loader->add_action('wp_ajax_wp_recover_plugin_configuration_modal', $completion_report, 'ajax_plugin_configuration_modal'); $this->loader->add_action('wp_ajax_wp_recover_content_cleanup_modal', $completion_report, 'ajax_content_cleanup_modal'); $this->loader->add_action('wp_ajax_wp_recover_export_report', $completion_report, 'ajax_export_report'); } /** * Run the loader to execute all of the hooks with WordPress. * * @since 1.0.0 */ public function run() { $this->loader->run(); } /** * Register notification settings. * * @since 1.0.0 */ public function register_notification_settings() { register_setting( 'wp_recover_notification_settings', 'wp_recover_email_settings', array( 'sanitize_callback' => array($this, 'sanitize_notification_settings'), 'default' => array( 'enabled' => false, 'recipients' => get_option('admin_email'), 'notify_on_start' => true, 'notify_on_complete' => true, 'notify_on_error' => true, 'notify_on_pause' => false, 'notify_on_resume' => false, 'notify_progress_interval' => 0, ), ) ); } /** * Sanitize notification settings. * * @since 1.0.0 * @param array $input The settings array. * @return array The sanitized settings array. */ public function sanitize_notification_settings($input) { $output = array(); // Sanitize enabled $output['enabled'] = isset($input['enabled']) ? (bool) $input['enabled'] : false; // Sanitize recipients $recipients = isset($input['recipients']) ? sanitize_text_field($input['recipients']) : ''; $emails = explode(',', $recipients); $valid_emails = array(); foreach ($emails as $email) { $email = trim($email); if (!empty($email) && is_email($email)) { $valid_emails[] = $email; } } $output['recipients'] = implode(',', $valid_emails); // If no valid emails, use admin email if (empty($output['recipients'])) { $output['recipients'] = get_option('admin_email'); } // Sanitize notification options $output['notify_on_start'] = isset($input['notify_on_start']) ? (bool) $input['notify_on_start'] : false; $output['notify_on_complete'] = isset($input['notify_on_complete']) ? (bool) $input['notify_on_complete'] : false; $output['notify_on_error'] = isset($input['notify_on_error']) ? (bool) $input['notify_on_error'] : false; $output['notify_on_pause'] = isset($input['notify_on_pause']) ? (bool) $input['notify_on_pause'] : false; $output['notify_on_resume'] = isset($input['notify_on_resume']) ? (bool) $input['notify_on_resume'] : false; // Sanitize progress interval $output['notify_progress_interval'] = isset($input['notify_progress_interval']) ? absint($input['notify_progress_interval']) : 0; return $output; } /** * AJAX handler for testing email notifications. * * @since 1.0.0 */ public function ajax_test_notification() { // Check nonce if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'wp_recover_test_notification')) { wp_send_json_error(array('message' => __('Security check failed.', 'wp-recover'))); } // Get recipients $recipients = isset($_POST['recipients']) ? sanitize_text_field($_POST['recipients']) : ''; if (empty($recipients)) { $recipients = get_option('admin_email'); } // Send test email $subject = sprintf(__('[%s] WP-Recover Test Notification', 'wp-recover'), get_bloginfo('name')); $body = '
' . __('This is a test email from the WP-Recover plugin to confirm that email notifications are working correctly.', 'wp-recover') . '
'; $body .= '' . __('If you received this email, your notification settings are configured correctly.', 'wp-recover') . '
'; $body .= '' . __('Site URL:', 'wp-recover') . ' ' . site_url() . '
'; $body .= '' . __('Sent on:', 'wp-recover') . ' ' . date_i18n(get_option('date_format') . ' ' . get_option('time_format')) . '
'; $body .= '' . __('This is an automated notification from the WP-Recover plugin.', 'wp-recover') . '
'; $body .= '