-
-
Save kraftbj/4394479 to your computer and use it in GitHub Desktop.
Modal popup form
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 | |
/* | |
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