i alterd popup.php file this way:
-adding onclick events in line 82 and 85
-added function newsletter_close_cookie in line 103
-changed condition to (newsletter_get_cookie(“newsletter”, null) == null && newsletter_get_cookie(“newsletter_close”, null) == null) in line 127
i set to restart counting after 0 days, so until now popup was visible on every pageview. after changing this file popup is hidden for 2,4 hour when user closes it. it works fine on every page except home page. can you tell what i did wrong?
<?php
class NewsletterPopup extends NewsletterModule {
static $instance;
/**
* @var NewsletterThemes
*/
var $themes;
/**
* @return NewsletterPopup
*/
static function instance() {
if (self::$instance == null) {
self::$instance = new NewsletterPopup();
}
return self::$instance;
}
function __construct() {
$this->themes = new NewsletterThemes('popup', true);
parent::__construct('popup', '1.0.5');
if (!is_admin() && $this->options['enabled'] == 1) {
add_action('wp_footer', array($this, 'hook_wp_footer'));
add_action('wp_head', array($this, 'hook_wp_head'), 1);
add_action('wp_enqueue_scripts', array($this, 'hook_wp_enqueue_scripts'));
}
}
function hook_wp_enqueue_scripts() {
wp_enqueue_script('jquery');
}
function admin_menu() {
if ($this->available_version > $this->version) {
$v = ' <span class="update-plugins"><span>!</span></span>';
}
$this->add_menu_page('index', 'Pop Up' . $v);
}
function hook_wp_head() {
?>
<style>
#newsletter-close{ font-family: verdana; font-size:18px; color:#333; font-weight:bold; position:absolute; right:0px; top:0px; cursor:pointer;width: 35px;height: 35px;}
.overlay{
background:#000;
position:fixed;
top:0px;
bottom:0px;
left:0px;
right:0px;
z-index:100000;
cursor:pointer;
opacity: .7;
filter: alpha(opacity=70);
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";
}
#box{
width:<?php echo $this->options['width']; ?>px;
height:<?php echo $this->options['height']; ?>px;
background-color:transparent;
display:none;
z-index:100003;
position:absolute;
left:30%;
top: <?php echo empty($this->options['top'])?'200px':($this->options['top'] . 'px'); ?>;
border: <?php echo $this->options['frame_width']; ?>px <?php echo $this->options['frame_type']; ?> <?php echo $this->options['frame_color']; ?>;
border-radius: <?php echo $this->options['frame_radius']; ?>px
}
</style>
<?php
}
function hook_wp_footer() {
if (is_user_logged_in() && !isset($_GET['newsletter_popup'])) return;
?>
<div class="overlay" id="overlay" style="display:none;" onclick="newsletter_close_cookie(0.1);"></div>
<div id="box">
<iframe id="newsletter-iframe" style="border:0; width: <?php echo $this->options['width']; ?>px; height:<?php echo $this->options['height']; ?>px;" data-src="<?php echo WP_CONTENT_URL . '/extensions/newsletter/popup/iframe.php'; ?>"></iframe>
<div id="newsletter-close" onclick="newsletter_close_cookie(0.1);"></div>
</div>
<script>
function newsletter_set_cookie(name, value, time){
var e = new Date();
e.setTime(e.getTime() + time*24*60*60*1000);
document.cookie = name + "=" + value + "; expires=" + e.toGMTString() + "; path=/";
}
function newsletter_get_cookie(name, def){
var cs = document.cookie.toString().split('; ');
var c, n, v;
for (var i=0; i<cs.length; i++){
c = cs[i].split("=");
n = c[0]; v = c[1];
if (n == name) return v;
}
return def;
}
function newsletter_close_cookie(time)
{
newsletter_set_cookie("newsletter_close", 1, time);
}
jQuery(document).ready(function() {
jQuery("#newsletter-close").click(
function(){
jQuery('#overlay').fadeOut('fast');
jQuery('#box').hide();
});
jQuery("#overlay").click(
function(){
jQuery(this).fadeOut('fast');
jQuery('#box').hide();
});
<?php if (isset($_GET['newsletter_popup'])) { ?>
jQuery('#newsletter-iframe').attr("src", jQuery('#newsletter-iframe').attr("data-src"));7
jQuery('#overlay').fadeIn('fast');
jQuery('#box').fadeIn('slow');
<?php } else { ?>
if (newsletter_get_cookie("newsletter", null) == null && newsletter_get_cookie("newsletter_close", null) == null){
var newsletter_popup = parseInt(newsletter_get_cookie("newsletter_popup", 0));
newsletter_set_cookie("newsletter_popup", newsletter_popup+1, <?php echo (int)$this->options['days']; ?>);
if (newsletter_popup == <?php echo (int)$this->options['count']; ?>) {
jQuery('#newsletter-iframe').attr("src", jQuery('#newsletter-iframe').attr("data-src"));
setTimeout(newsletter_popup_open,
<?php echo $this->options['delay']*1000; ?>);
}
}
<?php } ?>
});
function newsletter_popup_open() {
jQuery('#newsletter-iframe').attr("src", jQuery('#newsletter-iframe').attr("data-src"));
jQuery('#overlay').fadeIn('fast');
var windowW = jQuery(window).width();
var windowH = jQuery(window).height();
var modalW = jQuery('#box').width();
var modalH = jQuery('#box').height();
jQuery('#box').css({
"top": ((windowH-modalH)/2+jQuery(document).scrollTop())+"px",
"left": ((windowW-modalW)/2)+"px"
});
jQuery('#box').fadeIn('slow');
return false;
}
</script>
<?php
}
}
NewsletterPopup::instance();