Skip to content

Instantly share code, notes, and snippets.

@technosailor
Created December 28, 2012 04:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save technosailor/4394411 to your computer and use it in GitHub Desktop.
Save technosailor/4394411 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Pop Up Once
Plugin URI: https://gist.github.com/4394411
Description: Quick plugin to create a modal popup form
Author: Aaron Brazell
Author URI: http://technosailor.com
Version: 1.0
*/
class AB_Popup_Once {
public function __construct()
{
$this->hooks();
}
public function hooks() {
add_action( 'wp_head', array( $this, 'popup' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'js' ) );
add_action( 'wp_head', array( $this, 'css' ) );
}
public function js()
{
wp_enqueue_script('jquery');
}
public function css()
{
?>
<style>
.ab-popup-layer { position: absolute; top: 100px; left: 100px; background: #fff; height: 300px; width: 300px; border: 1px solid #000;}
</style>
<?php
}
public function get_form_html()
{
// Do your form HTML here
$html .= '<div class="ab-popup-layer">';
$html .= '<form action"" method="post">';
$html .= ' <label for="ab-form-field">Field 1</label>';
$html .= ' <input type="text" name="ab-form-field" id="ab-form-field" />';
$html .= '</form>';
$html .= '</label>';
return $html;
}
public function popup()
{
if( isset( $_COOKIE['ab_popup_done'] ) )
return false;
setcookie( 'ab_popup_done', 'yes', time() + (60*60*24*365) );
$html = $this->get_form_html();
?>
<script>
jQuery(document).ready(function() {
jQuery('body').append('<?php echo $html ?>');
});
</script>
<?php
}
}
$ab_popup_once = new AB_Popup_Once;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment