Last active
September 15, 2015 19:30
-
-
Save webmasterninjay/6982b3c02c9ebf132e60 to your computer and use it in GitHub Desktop.
wordpress optin form widget
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 | |
class WendiePett_Optin extends WP_Widget { | |
/** | |
* Sets up the widgets name etc | |
*/ | |
public function __construct() { | |
// widget actual processes | |
parent::__construct( | |
'pett_optin', // Base ID | |
__( 'Wendie Pett - Optin', 'wendiepett' ), // Name | |
array( 'description' => __( 'Social Media Widget of Wendie Pett Theme.', 'wendiepett' ), ) // Args | |
); | |
} | |
/** | |
* Outputs the content of the widget | |
*/ | |
public function widget( $args, $instance ) { | |
// outputs the content of the widget | |
extract($args); | |
$hidetitle = $instance['hidetitle'] ? 'on' : 'off'; | |
$pettFormAction = $instance['pett_optin_action']; | |
$pettFormExtra = $instance['pett_optin_extra']; | |
$pettFormName = $instance['pett_optin_name']; | |
$pettFormEmail = $instance['pett_optin_email']; | |
$pettFormNameHolder = $instance['pett_optin_name_holder']; | |
$pettFormEmailHolder = $instance['pett_optin_email_holder']; | |
$pettFormText = $instance['pett_optin_text']; | |
$getSubmitImage = get_stylesheet_directory_uri() . '/images/submit.png'; | |
echo $args['before_widget']; | |
if ( $hidetitle == 'off' ) { | |
if ( ! empty( $instance['title'] ) ) { | |
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title']; | |
} | |
} ?> | |
<div class="pett-form-widget-wrapper"> | |
<div class="pett-form-text"> | |
<p><?php echo $pettFormText; ?></p> | |
</div> | |
<div class="pett-form-html"> | |
<form action="<?php echo $pettFormAction; ?>" method="post"> | |
<?php echo $pettFormExtra; ?> | |
<input type="text" name="<?php echo $pettFormName; ?>" placeholder="<?php echo $pettFormNameHolder; ?>" /> | |
<input type="email" name="<?php echo $pettFormEmail; ?>" placeholder="<?php echo $pettFormEmailHolder; ?>" /> | |
<input type="image" src="<?php echo esc_url($getSubmitImage); ?>"/> | |
</form> | |
</div> | |
</div> | |
<?php echo $args['after_widget']; | |
} | |
/** | |
* Outputs the options form on admin | |
*/ | |
public function form( $instance ) { | |
// outputs the options form on admin | |
$getURL = get_bloginfo('url'); | |
$default = array( | |
'title' => '', | |
'hidetitle' => 'on', | |
'pett_optin_action' => $getURL, | |
'pett_optin_extra' => '', | |
'pett_optin_name' => 'FNAME', | |
'pett_optin_email' => 'EMAIL', | |
'pett_optin_name_holder' => 'Your name', | |
'pett_optin_email_holder' => 'Your email address', | |
'pett_optin_text' => 'Enter your form text here' | |
); | |
$instance = wp_parse_args( (array) $instance, $default ); | |
$title = $instance['title']; | |
$hidetitle = $instance['hidetitle'] ? 'on' : 'off'; | |
$pettFormAction = $instance['pett_optin_action']; | |
$pettFormExtra = $instance['pett_optin_extra']; | |
$pettFormName = $instance['pett_optin_name']; | |
$pettFormEmail = $instance['pett_optin_email']; | |
$pettFormNameHolder = $instance['pett_optin_name_holder']; | |
$pettFormEmailHolder = $instance['pett_optin_email_holder']; | |
$pettFormText = $instance['pett_optin_text']; ?> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></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 esc_attr( $title ); ?>"> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'pett_optin_text' ); ?>"><?php _e( 'Form Text:' ); ?></label> | |
<textarea class="widefat" id="<?php echo $this->get_field_id( 'pett_optin_text' ); ?>" name="<?php echo $this->get_field_name( 'pett_optin_text' ); ?>"><?php echo $pettFormText; ?></textarea> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'pett_optin_action' ); ?>"><?php _e( 'Form Action:' ); ?></label> | |
<input class="widefat" id="<?php echo $this->get_field_id( 'pett_optin_action' ); ?>" name="<?php echo $this->get_field_name( 'pett_optin_action' ); ?>" type="text" value="<?php echo esc_url( $pettFormAction ); ?>"> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'pett_optin_extra' ); ?>"><?php _e( 'Form Extra Field:' ); ?></label> | |
<textarea class="widefat" id="<?php echo $this->get_field_id( 'pett_optin_extra' ); ?>" name="<?php echo $this->get_field_name( 'pett_optin_extra' ); ?>"><?php echo $pettFormExtra; ?></textarea> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'pett_optin_name' ); ?>"><?php _e( 'Form Name:' ); ?></label> | |
<input class="widefat" id="<?php echo $this->get_field_id( 'pett_optin_name' ); ?>" name="<?php echo $this->get_field_name( 'pett_optin_name' ); ?>" type="text" value="<?php echo esc_attr( $pettFormName ); ?>"> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'pett_optin_name_holder' ); ?>"><?php _e( 'Form Name Placeholder:' ); ?></label> | |
<input class="widefat" id="<?php echo $this->get_field_id( 'pett_optin_name_holder' ); ?>" name="<?php echo $this->get_field_name( 'pett_optin_name_holder' ); ?>" type="text" value="<?php echo esc_attr($pettFormNameHolder); ?>"> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'pett_optin_email' ); ?>"><?php _e( 'Form Email:' ); ?></label> | |
<input class="widefat" id="<?php echo $this->get_field_id( 'pett_optin_email' ); ?>" name="<?php echo $this->get_field_name( 'pett_optin_email' ); ?>" type="email" value="<?php echo $pettFormEmail; ?>"> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'pett_optin_email_holder' ); ?>"><?php _e( 'Form Email Address Placeholder:' ); ?></label> | |
<input class="widefat" id="<?php echo $this->get_field_id( 'pett_optin_email_holder' ); ?>" name="<?php echo $this->get_field_name( 'pett_optin_email_holder' ); ?>" type="text" value="<?php echo esc_attr($pettFormEmailHolder); ?>"> | |
</p> | |
<p> | |
<input class="checkbox" id="<?php echo $this->get_field_id( 'hidetitle' ); ?>" name="<?php echo $this->get_field_name( 'hidetitle' ); ?>" type="checkbox" <?php checked($instance['hidetitle'], 'on'); ?>> | |
<label for="<?php echo $this->get_field_id( 'hidetitle' ); ?>"><?php _e( 'Hide this widget title?' ); ?></label> | |
</p> | |
<?php } | |
/** | |
* Processing widget options on save | |
*/ | |
public function update( $new_instance, $old_instance ) { | |
// processes widget options to be saved | |
$instance = array(); | |
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : ''; | |
$instance['hidetitle'] = $new_instance['hidetitle']; | |
$instance['pett_optin_action'] = $new_instance['pett_optin_action']; | |
$instance['pett_optin_extra'] = $new_instance['pett_optin_extra']; | |
$instance['pett_optin_name'] = $new_instance['pett_optin_name']; | |
$instance['pett_optin_email'] = $new_instance['pett_optin_email']; | |
$instance['pett_optin_name_holder'] = $new_instance['pett_optin_name_holder']; | |
$instance['pett_optin_email_holder'] = $new_instance['pett_optin_email_holder']; | |
$instance['pett_optin_text'] = $new_instance ['pett_optin_text']; | |
return $instance; | |
} | |
} | |
add_action('widgets_init', | |
create_function('', 'return register_widget("WendiePett_Optin");') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment