/*-----------------------------------------------------------------------------------*/ /* AAWP Cache Helper Functions - Added to speed up page load */ /*-----------------------------------------------------------------------------------*/ function pros_cons_get_aawp_cached_product($asin) { global $wpdb; static $cache = array(); if (empty($asin) || $asin == "-") { return false; } // Check static cache first if (isset($cache[$asin])) { return $cache[$asin]; } // Check database $table = $wpdb->prefix . "aawp_products"; $product = $wpdb->get_row($wpdb->prepare( "SELECT * FROM $table WHERE asin = %s AND status = 'active' LIMIT 1", $asin ), ARRAY_A); if ($product && \!empty($product["url"])) { $cache[$asin] = $product; return $product; } $cache[$asin] = false; return false; } function pros_cons_aawp_field_cached($asin, $field, $fallback = "") { $product = pros_cons_get_aawp_cached_product($asin); if (\!$product) { return $fallback; } switch ($field) { case "url": // Replace placeholder with actual tag $url = str_replace("AAWP_PLACEHOLDER_TRACKING_ID", "systoaellc-20", $product["url"]); return \!empty($url) ? $url : $fallback; case "price": return \!empty($product["price"]) ? "$" . $product["price"] : $fallback; case "title": return \!empty($product["title"]) ? $product["title"] : $fallback; case "is_prime": case "prime": return $product["is_prime"] == "1"; case "image": // Build image URL from image_ids if available $image_ids = maybe_unserialize($product["image_ids"]); if (\!empty($image_ids) && is_array($image_ids)) { return "https://m.media-amazon.com/images/I/" . $image_ids[0] . "._SL500_.jpg"; } return $fallback; default: return isset($product[$field]) ? $product[$field] : $fallback; } } function pros_cons_should_skip_aawp($asin) { // Skip AAWP API calls if product is not properly cached $product = pros_cons_get_aawp_cached_product($asin); return \!$product || empty($product["url"]) || empty($product["price"]); }