/** * Auto Top-up Ad with Close and Disable Options * Insert this code in your theme's functions.php file */ if (!defined('ABSPATH')) exit; // Security check /** * Register and initialize the ad system */ function gbwise_auto_topup_ad_init() { // Register script wp_register_script( 'gbwise-auto-topup-ad', false, array(), '2.0.0', true ); // Pass data to JavaScript wp_localize_script('gbwise-auto-topup-ad', 'gbwise_ad_config', array( 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('gbwise_ad_nonce'), 'ad_client' => 'ca-pub-6771133663623420', 'ad_slot' => '1759738250', 'debug' => WP_DEBUG // For testing )); wp_enqueue_script('gbwise-auto-topup-ad'); // Add inline script wp_add_inline_script('gbwise-auto-topup-ad', gbwise_get_ad_script()); } add_action('wp_enqueue_scripts', 'gbwise_auto_topup_ad_init'); /** * Main Ad Script with Close and Disable functionality */ function gbwise_get_ad_script() { return ' // GBWise Auto Top-up Ad System v2.0 (function() { "use strict"; const AD_CONFIG = { debug: typeof gbwise_ad_config !== "undefined" ? gbwise_ad_config.debug : false, checkInterval: 1000, // Check every second maxChecks: 10 // Check for 10 seconds }; // Check if ad should be shown function shouldShowAd() { // Check for debug mode if (AD_CONFIG.debug && window.location.hash === "#test-ad") { console.log("[GBWise Ad] Debug mode: Showing ad"); return true; } // Check if user disabled ad const disabledUntil = localStorage.getItem("gbwise_ad_disabled_until"); if (disabledUntil) { const now = new Date().getTime(); if (now < parseInt(disabledUntil)) { if (AD_CONFIG.debug) { const hoursLeft = Math.ceil((parseInt(disabledUntil) - now) / (60 * 60 * 1000)); console.log(`[GBWise Ad] Ad disabled for ${hoursLeft} more hours`); } return false; } else { // Disable period expired, remove from storage localStorage.removeItem("gbwise_ad_disabled_until"); } } // Check if ad was just closed (session only) if (sessionStorage.getItem("gbwise_ad_closed_session")) { return false; } return true; } // Show the ad function showAd() { if (!shouldShowAd()) return; // Remove any existing ad const existingAd = document.getElementById("gbwise-auto-topup-ad"); if (existingAd) existingAd.remove(); // Create ad container const adContainer = document.createElement("div"); adContainer.id = "gbwise-auto-topup-ad"; adContainer.className = "gbwise-ad-container"; // Create ad content adContainer.innerHTML = `
📢 Recommended For You
Loading recommendations...
`; document.body.appendChild(adContainer); // Prevent body scroll document.body.style.overflow = "hidden"; // Initialize AdSense with retry function initAdSense(attempts = 0) { if (attempts > 5) { console.log("[GBWise Ad] Failed to load AdSense after 5 attempts"); return; } try { if (typeof adsbygoogle !== "undefined") { (adsbygoogle = window.adsbygoogle || []).push({}); // Remove loading indicator after ad loads setTimeout(() => { const loading = document.querySelector(".gbwise-ad-loading"); if (loading) loading.style.display = "none"; }, 1000); } else { setTimeout(() => initAdSense(attempts + 1), 500); } } catch (e) { console.log("[GBWise Ad] AdSense error:", e); setTimeout(() => initAdSense(attempts + 1), 500); } } initAdSense(); // Mark as shown in session sessionStorage.setItem("gbwise_ad_shown_session", "true"); } // Handle ad actions window.gbwiseHandleAdAction = function(action) { const adContainer = document.getElementById("gbwise-auto-topup-ad"); if (!adContainer) return; switch(action) { case "close": // Just close the ad, remember in session only sessionStorage.setItem("gbwise_ad_closed_session", "true"); if (AD_CONFIG.debug) { console.log("[GBWise Ad] Ad closed (session only)"); } break; case "disable": // Disable for 24 hours const disableUntil = new Date().getTime() + (24 * 60 * 60 * 1000); localStorage.setItem("gbwise_ad_disabled_until", disableUntil.toString()); if (AD_CONFIG.debug) { console.log("[GBWise Ad] Ad disabled for 24 hours"); } break; case "continue": // Just close the ad sessionStorage.setItem("gbwise_ad_closed_session", "true"); break; } // Close animation adContainer.classList.add("gbwise-ad-closing"); setTimeout(() => { adContainer.remove(); document.body.style.overflow = ""; }, 300); }; // Check when to show ad function initAdDisplay() { if (AD_CONFIG.debug) { console.log("[GBWise Ad] System initialized"); } // Check if we should show ad on page load let checksDone = 0; function checkAndShowAd() { if (shouldShowAd()) { // Check if AdSense is loaded if (typeof adsbygoogle !== "undefined" || checksDone >= AD_CONFIG.maxChecks) { showAd(); return; } checksDone++; if (checksDone <= AD_CONFIG.maxChecks) { setTimeout(checkAndShowAd, AD_CONFIG.checkInterval); } } } // Show ad after 3 seconds setTimeout(checkAndShowAd, 2000); } // Start the system when page loads if (document.readyState === "complete") { initAdDisplay(); } else { window.addEventListener("load", initAdDisplay); } // Optional: Show on exit intent document.addEventListener("mouseleave", function(e) { if (e.clientY < 0 && shouldShowAd()) { // Check if not already shown in session if (!sessionStorage.getItem("gbwise_ad_shown_session") && !sessionStorage.getItem("gbwise_ad_closed_session")) { showAd(); } } }); })(); '; } /** * CSS Styles for the Ad */ function gbwise_auto_topup_ad_styles() { ?> https://businessoutstanders.co.uk/wp-sitemap-posts-post-1.xmlhttps://businessoutstanders.co.uk/wp-sitemap-posts-page-1.xmlhttps://businessoutstanders.co.uk/wp-sitemap-posts-frenify-podcast-1.xmlhttps://businessoutstanders.co.uk/wp-sitemap-taxonomies-category-1.xmlhttps://businessoutstanders.co.uk/wp-sitemap-taxonomies-post_tag-1.xmlhttps://businessoutstanders.co.uk/wp-sitemap-users-1.xml