Created
May 4, 2014 00:15
-
-
Save anneallen/741fdf99807f51d95cdd to your computer and use it in GitHub Desktop.
Optin Form Code
This file contains hidden or 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
/** | |
*This creates a box for optin, with separate text and form | |
*/ | |
/** Register Opt in Widget **/ | |
function lob_signup_box_load_widgets() { | |
register_widget( 'lob_signup_box_Widget' ); | |
} | |
add_action( 'widgets_init', 'lob_signup_box_load_widgets' ); | |
/** Define the Widget as an extension of WP_Widget **/ | |
class lob_signup_box_Widget extends WP_Widget { | |
function lob_signup_box_Widget() { | |
/* Widget settings. */ | |
$widget_ops = array( | |
'classname' => 'widget_lob_signup_box', | |
'description' => 'Used for Sidebar Optin Box' | |
); | |
/* Widget control settings. */ | |
$control_ops = array( 'id_base' => 'lob-signup-box-widget' ); | |
/* Create the widget. */ | |
$this->WP_Widget( 'lob-signup-box-widget', 'LOB Opt-in Widget', $widget_ops, $control_ops ); | |
} | |
function widget( $args, $instance ) { | |
extract( $args ); | |
/**these are the widget options*/ | |
$title = apply_filters('widget_title', $instance['title']); | |
$cta_textarea = $instance['cta_textarea']; | |
$form_code = $instance['form_code']; | |
echo $before_widget; | |
// Display the widget | |
//Check if class is set | |
echo '<div class="optin">'; | |
// Check if title is set | |
if ( $title ) { | |
echo $before_title . $title . $after_title; | |
} | |
// Check if textarea is set | |
if( $cta_textarea ) { | |
echo wpautop($cta_textarea); | |
} | |
// Check if formcode is set | |
if( $form_code ) { | |
echo $form_code; | |
} | |
echo '</div>'; | |
echo $after_widget; | |
} | |
function update( $new_instance, $old_instance ) { | |
$instance = $old_instance; | |
// Fields | |
$instance['title'] = strip_tags($new_instance['title'],'<br />'); | |
if ( current_user_can('unfiltered_html') ) | |
$instance['cta_textarea'] = $new_instance['cta_textarea']; | |
else | |
$instance['cta_textarea'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['cta_textarea'])) ); | |
if ( current_user_can('unfiltered_html') ) | |
$instance['form_code'] =$new_instance['form_code']; | |
else | |
$instance['form_code'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['form_code']) ) ); | |
return $instance; | |
} | |
function form( $instance ) { | |
// Check values | |
if( $instance) { | |
$title = esc_attr($instance['title']); | |
$cta_textarea = esc_textarea($instance['cta_textarea']); | |
$form_code = esc_textarea($instance['form_code']); | |
} | |
else { | |
$title = ''; | |
$cta_textarea = ''; | |
$form_code=''; | |
} | |
?> | |
<p> | |
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'wp_widget_plugin'); ?></label> | |
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id('cta_textarea'); ?>"><?php _e('Call to Action Text:', 'wp_widget_plugin'); ?></label> | |
<textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('cta_textarea'); ?>" name="<?php echo $this->get_field_name('cta_textarea'); ?>"><?php echo $cta_textarea; ?></textarea> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id('form_code'); ?>"><?php _e('Form Code:', 'wp_widget_plugin'); ?></label> | |
<textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('form_code'); ?>" name="<?php echo $this->get_field_name('form_code'); ?>"><?php echo $form_code; ?></textarea> | |
</p> | |
<?php | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment