Created
September 30, 2020 20:16
-
-
Save bnecreative/ab6d9829e03ee86cc4f3886035c8d9f2 to your computer and use it in GitHub Desktop.
BNE Panels - Autoload a panel on a certain page once per day using a cookie.
This file contains 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 // Don't copy this line... | |
// Sets up a cookie to autoload a BNE Panel */ | |
add_action( 'wp', function() { | |
$page_id = 890; | |
$panel_id = 940; | |
$expires = 86400; // 86400 = 1 day | |
// Check if a cookie exists | |
if( !isset( $_COOKIE['panel-autoload-page-'.$page_id] ) ) { | |
// Check if we're on the correct page | |
if( is_page( $page_id ) ) { | |
// Set the cookie! | |
setcookie( 'panel-autoload-page-'.$page_id, 'panel-'.$panel_id, time() + $expires, "/" ); | |
// Open the Panel | |
add_action( 'wp_footer', function() use ($panel_id) { | |
?> | |
<script type="text/javascript"> | |
jQuery(document).ready(function($) { | |
setTimeout(function() { | |
BNEPanelTrigger( 'open', <?php echo $panel_id; ?> ) | |
}, 1000); | |
}); | |
</script> | |
<?php | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment