Skip to content

Instantly share code, notes, and snippets.

@groucho75
Created May 29, 2014 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groucho75/983f1bfebcc1e08b72eb to your computer and use it in GitHub Desktop.
Save groucho75/983f1bfebcc1e08b72eb to your computer and use it in GitHub Desktop.
Prompt ALO EasyMail in a dialog: put this php into /wp-content/mu-plugins
<?php
/*
// -------------------------------------------------------------------------------
// EXTRA: add the "open-easymail-popup" class to have a link that opens newsletter dialog
// -------------------------------------------------------------------------------
<a href="" class="open-easymail-popup">Newsletter</a>
*/
function alo_easymail_dialog_enqueue_scripts() {
global $wp_scripts;
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui-core');
wp_enqueue_script ( 'jquery-ui-dialog' );
wp_enqueue_script ( 'jquery-ui-resizable' );
wp_enqueue_script ( 'jquery-ui-draggable' );
$queryui = $wp_scripts->query('jquery-ui-core');
// Choose a theme: http://jqueryui.com/themeroller/
$ui_theme = 'blitzer';
$url = "http://ajax.googleapis.com/ajax/libs/jqueryui/".$queryui->ver."/themes/".$ui_theme."/jquery-ui.css";
wp_enqueue_style('jquery-ui-'.$ui_theme, $url, false, null);
}
add_action( 'wp_enqueue_scripts', 'alo_easymail_dialog_enqueue_scripts' );
function alo_easymail_dialog_footer_scripts() {
global $alo_easymail_dialog_hide;
if ( $alo_easymail_dialog_hide ) return;
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
if ( $('.widget.alo_easymail_widget' ).length > 0 )
{
$('.widget.alo_easymail_widget' ).dialog({
title: "<?php esc_html_e( 'Newsletter', "alo-easymail")?>",
autoOpen: true,
zIndex: 999999,
modal: true
});
$('.open-easymail-popup').click( function(e) {
e.preventDefault();
$( ".widget.alo_easymail_widget" ).dialog( "open" );
});
}
});
</script>
<style type="text/css">
/* Input del form newsletter */
.alo_easymail_form_table input {
color: #000000;
background-color: #eeeeee;
}
</style>
<?php
}
add_action( 'wp_footer', 'alo_easymail_dialog_footer_scripts' );
/**
* Set cookie
*/
function alo_easymail_dialog_set_cookie () {
global $alo_easymail_dialog_hide;
$alo_easymail_dialog_hide = true;
$alo_dialog_cookie = "alo_bh_hide_popup";
if ( !isset($_COOKIE[ $alo_dialog_cookie ]) ) {
// Set a cookie to hide the newsletter untill tomorrow
setcookie ( $alo_dialog_cookie, "hide", time()+(60*60*24*1));
$alo_easymail_dialog_hide = false;
}
}
add_action('init', 'alo_easymail_dialog_set_cookie' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment