query( 'TRUNCATE TABLE `' . $wpdb->prefix . 'dp_aicoso_price_cache`' ); // Clear transients. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Cache clearing operation $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s", '_transient_dp_aicoso_%' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Cache clearing operation $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s", '_transient_timeout_dp_aicoso_%' ) ); // Clear object cache. wp_cache_flush(); } /** * Log the deactivation event. */ private static function log_deactivation() { global $wpdb; // Check if table exists before inserting. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Table existence check, hardcoded table name if ( $wpdb->get_var( 'SHOW TABLES LIKE \'' . $wpdb->prefix . 'dp_aicoso_audit_log\'' ) === $wpdb->prefix . 'dp_aicoso_audit_log' ) { $wpdb->insert( $wpdb->prefix . 'dp_aicoso_audit_log', array( 'user_id' => get_current_user_id(), 'action' => 'plugin_deactivated', 'details' => wp_json_encode( array( 'version' => defined( 'DP_AICOSO_VERSION' ) ? DP_AICOSO_VERSION : '1.0.0', 'time' => current_time( 'mysql' ), ) ), 'ip_address' => self::get_user_ip_address(), 'created_at' => current_time( 'mysql' ), ) ); } } /** * Get user IP address safely. * * @return string IP address or empty string. */ private static function get_user_ip_address() { // Check for various IP headers in order of preference. $ip_headers = array( 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR', ); foreach ( $ip_headers as $header ) { // Check if header exists. if ( ! empty( $_SERVER[ $header ] ) ) { // Sanitize the IP value. $ip = sanitize_text_field( wp_unslash( $_SERVER[ $header ] ) ); // Validate as IP address (allow private ranges for local development). if ( filter_var( $ip, FILTER_VALIDATE_IP ) ) { return $ip; } } } return ''; } }