basename = plugin_basename( __FILE__ ); $this->url = plugin_dir_url( __FILE__ ); $names = explode( '/', $this->basename ); $this->name = $names[0]; } /** * Call the constructor of all the Patchstack related classes. * * @return void */ public function plugin_classes() { // Define the array of the classes. foreach ( array( 'admin_options' => 'P_Admin_Options', 'cron' => 'P_Cron', 'api' => 'P_Api', 'login' => 'P_Login', 'ban' => 'P_Ban', 'hardening' => 'P_Hardening', 'htaccess' => 'P_Htaccess', 'hacker_log' => 'P_Hacker_Log', 'upload' => 'P_Upload', 'rules' => 'P_Rules', 'hide_login' => 'P_Hide_Login', 'listener' => 'P_Listener', 'event_log' => 'P_Event_Log', 'activation' => 'P_Activation', 'multisite' => 'P_Multisite', 'notice' => 'P_Cookie_Notice', 'admin_ajax' => 'P_Admin_Ajax', 'admin_general' => 'P_Admin_General', 'admin_menu' => 'P_Admin_Menu', ) as $var => $class ) { $this->$var = new $class( $this ); } $this->firewall_base = new P_Firewall( true, $this, true ); } /** * Activate the plugin. * * @return void */ public function activate() { $this->plugin_classes(); $this->activation->activate( $this ); } /** * Deactivate the plugin. * * @return void */ public function deactivate() { $this->plugin_classes(); $this->activation->deactivate(); } /** * Boot Patchstack and its classes. * * @return void */ public function hooks() { add_action( 'init', array( $this, 'init' ), ~PHP_INT_MAX ); } /** * Boot Patchstack * * @return void */ public function init() { // Load translated strings for plugin. load_plugin_textdomain( 'patchstack', false, dirname( $this->basename ) . '/languages/' ); // Initialize plugin classes. $this->plugin_classes(); // Perform migrations if necessary. $this->activation->migrate_check(); // If license expiration has not been fetched yet while the plugin is active, update it. if ( get_option( 'patchstack_api_token', '' ) == '' && get_option( 'patchstack_license_expiry', '' ) == '' ) { $this->api->update_license_status(); } // Determine if the license is activated and not expired. if ( get_option( 'patchstack_license_activated', 0 ) == 1 && get_option( 'patchstack_basic_firewall', 0 ) == 1 && get_option( 'patchstack_license_free', 0 ) == 0 ) { $this->firewall = new P_Firewall( true, $this ); } } /** * Creates or returns an instance of this class. * * @return Patchstack */ public static function get_instance() { if ( null === self::$single_instance ) { self::$single_instance = new self(); } return self::$single_instance; } /** * Magic getter. * * @param string $field The field to magically get. * @return mixed */ public function __get( $field ) { switch ( $field ) { case 'version': return self::VERSION; case 'api_url': return self::API_URL; case 'auth_url': return self::AUTH_URL; case 'client_id': return self::CLIENT_ID; case 'private_key': return self::PRIVATE_KEY; default: try { return $this->$field; } catch ( \Exception $e ) { return null; } } } } } if ( ! function_exists( 'patchstack_uninstall' ) ) { /** * Called when the plugin is uninstalled/removed from the site. * This is not the same as deactivation, where the plugin still resides on the site. * * @return void */ function patchstack_uninstall() { // Delete most of the Patchstack options. $options = array( 'patchstack_eventlog_lastid', 'patchstack_api_token', 'patchstack_dashboardlock', 'patchstack_pluginedit', 'patchstack_move_logs', 'patchstack_userenum', 'patchstack_basicscanblock', 'patchstack_hidewpcontent', 'patchstack_hidewpversionk', 'patchstack_prevent_default_file_access', 'patchstack_basic_firewall', 'patchstack_known_blacklist', 'patchstack_block_debug_log_access', 'patchstack_block_fake_bots', 'patchstack_index_views', 'patchstack_proxy_comment_posting', 'patchstack_bad_query_strings', 'patchstack_advanced_character_string_filter', 'patchstack_advanced_blacklist_firewall', 'patchstack_forbid_rfi', 'patchstack_image_hotlinking', 'patchstack_add_security_headers', 'patchstack_firewall_log_lastid', 'patchstack_user_log_lastid', 'patchstack_captcha_public_key', 'patchstack_captcha_private_key', 'patchstack_scan_interval', 'patchstack_scan_day', 'patchstack_scan_time', 'patchstack_hackers_log', 'patchstack_users_log', 'patchstack_visitors_log', 'external_updates-webarx', 'patchstack_wp_stats', 'patchstack_captcha_login_form', 'patchstack_license_activated', 'patchstack_license_expiry', 'patchstack_software_data_hash', 'patchstack_mv_wp_login', 'patchstack_rename_wp_login', 'patchstack_googledrive_backup_is_running', 'patchstack_googledrive_upload_state', 'patchstack_googledrive_access_token', 'patchstack_googledrive_refresh_token', 'patchstack_cron_offset', 'patchstack_htaccess_rules_hash' ); foreach ( $options as $option ) { delete_option( $option ); if ( is_multisite() ) { delete_site_option( $option ); } } // Drop all Patchstack tables. global $wpdb; $tables = array( 'patchstack_user_log', 'patchstack_visitor_log', 'patchstack_firewall_log', 'patchstack_file_hashes', 'patchstack_logic', 'patchstack_ip', 'patchstack_event_log' ); foreach ( $tables as $table ) { $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . $table ); } } } if ( ! function_exists( 'patchstack' ) ) { /** * Grab the Patchstack object and return it. * * @return Patchstack */ function patchstack() { return patchstack::get_instance(); } } // Kick it off. add_action( 'plugins_loaded', array( patchstack(), 'hooks' ) ); // Activation and deactivation hooks. register_activation_hook( __FILE__, array( patchstack(), 'activate' ) ); register_deactivation_hook( __FILE__, array( patchstack(), 'deactivate' ) ); register_uninstall_hook( __FILE__, 'patchstack_uninstall' );