Created
August 15, 2026 10:37
-
-
Save salvatorecapolupo/424a7ea5faf5b751234f71066ba4ee28 to your computer and use it in GitHub Desktop.
Non-Invasive Popup — Plugin WordPress leggero e senza pannello admin: mostra un popup non invasivo in footer dopo un delay configurabile, con cookie random per non ripresentarlo, opzioni "Chiudi" (temporaneo, 7gg) e "Non mostrare più" (permanente, 10 anni), più reset manuale. Config solo via costanti nel codice.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: Non-Invasive Popup | |
| * Description: Popup leggero, responsive, non invasivo, con cookie random rigenerabile dall'utente. Nessuna opzione admin: si configura editando le costanti nel codice. | |
| * Version: 1.1.0 | |
| * Author: Salvatore Capolupo | |
| * License: GPL-2.0+ | |
| * Requires PHP: 7.4 | |
| */ | |
| if ( ! defined( 'ABSPATH' ) ) exit; | |
| /* ============================================================ | |
| CONFIGURAZIONE — modifica solo qui, nessuna UI admin. | |
| ============================================================ */ | |
| define( 'NIP_COOKIE_NAME', 'nip_pref_5gf' ); | |
| define( 'NIP_COOKIE_DAYS', 7 ); // durata cookie su "chiudi" (temporaneo) | |
| define( 'NIP_COOKIE_DAYS_PERMANENT', 3650 ); // durata cookie su "non mostrare più" (~10 anni) | |
| define( 'NIP_DELAY_MS', 2000 ); // ritardo comparsa in millisecondi | |
| /* ============================================================ | |
| OUTPUT — hook in footer, su tutto il sito front-end. | |
| ============================================================ */ | |
| add_action( 'wp_footer', 'nip_render_popup' ); | |
| function nip_render_popup() { | |
| if ( is_admin() ) return; | |
| $cookie_name = esc_js( NIP_COOKIE_NAME ); | |
| $cookie_days = (int) NIP_COOKIE_DAYS; | |
| $cookie_days_permanent = (int) NIP_COOKIE_DAYS_PERMANENT; | |
| $delay_ms = (int) NIP_DELAY_MS; | |
| ?> | |
| <style> | |
| .nip-box { | |
| position: fixed; | |
| bottom: 20px; | |
| right: 20px; | |
| max-width: 320px; | |
| width: calc(100% - 40px); | |
| background: #fff; | |
| color: #111; | |
| border-radius: 12px; | |
| box-shadow: 0 8px 30px rgba(0,0,0,.18); | |
| padding: 22px 22px 20px; | |
| font-family: -apple-system, "Segoe UI", Roboto, sans-serif; | |
| font-size: 14px; | |
| line-height: 1.4; | |
| z-index: 999999; | |
| display: none; | |
| opacity: 0; | |
| transform: translateY(20px); | |
| transition: opacity .35s ease-out, transform .35s ease-out; | |
| } | |
| .nip-box.nip-visible { display: block; } | |
| .nip-box.nip-show { opacity: 1; transform: translateY(0); } | |
| .nip-close { | |
| position: absolute; | |
| top: 10px; | |
| right: 10px; | |
| width: 26px; | |
| height: 26px; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| background: #f0f0f0; | |
| border: none; | |
| border-radius: 50%; | |
| font-size: 16px; | |
| line-height: 1; | |
| cursor: pointer; | |
| color: #333; | |
| } | |
| .nip-close:hover { background: #e0e0e0; color: #000; } | |
| .nip-block { margin: 0 0 16px 0; text-align: center; } | |
| .nip-block:last-of-type { margin-bottom: 10px; } | |
| .nip-tg-link { | |
| display: block; | |
| text-decoration: none; | |
| color: #111; | |
| font-weight: 600; | |
| font-size: 13.5px; | |
| line-height: 1.35; | |
| } | |
| .nip-tg-link img { | |
| display: block; | |
| width: 100%; | |
| height: auto; | |
| max-height: 140px; | |
| object-fit: cover; | |
| border-radius: 8px; | |
| margin-top: 10px; | |
| } | |
| .nip-hr { | |
| border: none; | |
| border-top: 1px solid #eee; | |
| margin: 16px 0; | |
| } | |
| .nip-amazon { | |
| display: inline-block; | |
| background: #111; | |
| color: #fff; | |
| text-decoration: none; | |
| padding: 9px 14px; | |
| border-radius: 8px; | |
| font-size: 13px; | |
| font-weight: 600; | |
| line-height: 1.3; | |
| } | |
| .nip-amazon:hover { opacity: .85; } | |
| .nip-footer { | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| gap: 12px; | |
| margin-top: 4px; | |
| } | |
| .nip-reset, | |
| .nip-dismiss { | |
| background: none; | |
| border: none; | |
| color: #aaa; | |
| font-size: 11px; | |
| text-decoration: underline; | |
| cursor: pointer; | |
| padding: 0; | |
| } | |
| @media (max-width: 480px) { | |
| .nip-box { | |
| right: 10px; | |
| left: 10px; | |
| bottom: 10px; | |
| max-width: none; | |
| width: auto; | |
| } | |
| .nip-tg-link img { max-height: 110px; } | |
| } | |
| </style> | |
| <div class="nip-box" id="nipBox"> | |
| <button class="nip-close" id="nipClose" aria-label="Chiudi">×</button> | |
| <div class="nip-block"> | |
| <a class="nip-amazon" href="https://www.amazon.it/stores/author/B00RUC7VR6" rel="nofollow" target="_blank"> | |
| 👉 Scopri i miei saggi e le mie pubblicazioni (Salvatore Capolupo) | |
| </a> | |
| </div> | |
| <div class="nip-footer"> | |
| <button class="nip-dismiss" id="nipDismiss">Non mostrare più</button> | |
| <button class="nip-reset" id="nipReset">Reset</button> | |
| </div> | |
| </div> | |
| <script> | |
| (function () { | |
| var COOKIE_NAME = '<?php echo $cookie_name; ?>'; | |
| var DAYS = <?php echo $cookie_days; ?>; | |
| var DAYS_PERMANENT = <?php echo $cookie_days_permanent; ?>; | |
| var DELAY = <?php echo $delay_ms; ?>; | |
| function getCookie(name) { | |
| var m = document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)'); | |
| return m ? m.pop() : null; | |
| } | |
| function setCookie(name, value, days) { | |
| var d = new Date(); | |
| d.setTime(d.getTime() + days * 24 * 60 * 60 * 1000); | |
| document.cookie = name + '=' + value + ';expires=' + d.toUTCString() + ';path=/;SameSite=Lax'; | |
| } | |
| function deleteCookie(name) { | |
| document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 UTC;path=/'; | |
| } | |
| function randomValue() { | |
| return Math.random().toString(36).slice(2) + Date.now().toString(36); | |
| } | |
| function hideBox(box) { | |
| box.classList.remove('nip-show'); | |
| setTimeout(function () { box.classList.remove('nip-visible'); }, 350); | |
| } | |
| document.addEventListener('DOMContentLoaded', function () { | |
| var box = document.getElementById('nipBox'); | |
| if (!box) return; | |
| if (getCookie(COOKIE_NAME)) return; // già visto, non mostrare | |
| setTimeout(function () { | |
| box.classList.add('nip-visible'); | |
| requestAnimationFrame(function () { | |
| box.classList.add('nip-show'); | |
| }); | |
| }, DELAY); | |
| document.getElementById('nipClose').addEventListener('click', function () { | |
| setCookie(COOKIE_NAME, randomValue(), DAYS); | |
| hideBox(box); | |
| }); | |
| document.getElementById('nipDismiss').addEventListener('click', function () { | |
| setCookie(COOKIE_NAME, randomValue(), DAYS_PERMANENT); | |
| hideBox(box); | |
| }); | |
| document.getElementById('nipReset').addEventListener('click', function () { | |
| deleteCookie(COOKIE_NAME); | |
| hideBox(box); | |
| alert('Preferenze reimpostate. Il popup ricomparirà al prossimo caricamento.'); | |
| }); | |
| }); | |
| })(); | |
| </script> | |
| <?php | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment