Created
May 31, 2014 12:43
-
-
Save anonymous/8d652f3fa109c335624b to your computer and use it in GitHub Desktop.
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: Genesis Simple Aweber Form | |
Plugin URI: http://DesignsByNicktheGeek.com | |
Version: 0.1 | |
Author: Nick_theGeek | |
Author URI: http://DesignsByNicktheGeek.com | |
Description: Allows Aweber form to be used in place of the eNews and Updates widget | |
Text Domain: gsaf | |
Domain Path /languages/ | |
*/ | |
/* | |
* To Do: | |
* Create and setup screen shots | |
*/ | |
/** Load textdomain for translation */ | |
load_plugin_textdomain( ‘gsaf’, false, basename( dirname( __FILE__ ) ) . ‘/languages/’ ); | |
define( ‘GSAF_PLUGIN_DIR’, dirname( __FILE__ ) ); | |
/* Prevent direct access to the plugin */ | |
if ( !defined( ‘ABSPATH’ ) ) { | |
wp_die( __( “Sorry, you are not allowed to access this page directly.”, ‘gfwa’ ) ); | |
} | |
register_activation_hook( __FILE__, ‘gsaf_activation_check’ ); | |
/** | |
* Checks for minimum Genesis Theme version before allowing plugin to activate | |
* | |
* @author Nathan Rice | |
* @uses gsaf_truncate() | |
* @since 0.1 | |
* @version 0.2 | |
*/ | |
function gsaf_activation_check() { | |
$latest = ’1.8′; | |
$theme_info = get_theme_data( TEMPLATEPATH . ‘/style.css’ ); | |
if ( basename( TEMPLATEPATH ) != ‘genesis’ ) { | |
deactivate_plugins( plugin_basename( __FILE__ ) ); // Deactivate ourself | |
wp_die( sprintf( __( ‘Sorry, you can\’t activate unless you have installed %1$sGenesis%2$s’, ‘gfwa’ ), ‘‘, ‘‘ ) ); | |
} | |
$version = gsaf_truncate( $theme_info['Version'], 3 ); | |
if ( version_compare( $version, $latest, ‘<’ ) ) { | |
deactivate_plugins( plugin_basename( __FILE__ ) ); // Deactivate ourself | |
wp_die( sprintf( __( ‘Sorry, you can\’t activate without %1$sGenesis %2$s%3$s or greater’, ‘gfwa’ ), ‘‘, $latest, ‘‘ ) ); | |
} | |
} | |
/** | |
* | |
* Used to cutoff a string to a set length if it exceeds the specified length | |
* | |
* @author Nick Croft | |
* @since 0.1 | |
* @version 0.2 | |
* @param string $str Any string that might need to be shortened | |
* @param string $length Any whole integer | |
* @return string | |
*/ | |
function gsaf_truncate( $str, $length=10 ) { | |
if ( strlen( $str ) > $length ) { | |
return substr( $str, 0, $length ); | |
} else { | |
$res = $str; | |
} | |
return $res; | |
} | |
// Include files | |
require_once(GSAF_PLUGIN_DIR . ‘/widget.php’); |
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 | |
/** | |
* Adds the Genesis Simple Aweber Form widget. | |
* | |
* @category Genesis | |
* @package Widgets | |
* @author Nick the Geek | |
* @license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later) | |
*/ | |
/* Prevent direct access to the plugin */ | |
if ( !defined( ‘ABSPATH’ ) ) { | |
wp_die( __( “Sorry, you are not allowed to access this page directly.”, ‘gfwa’ ) ); | |
} | |
add_action( ‘widgets_init’, create_function( ”, “register_widget(‘Genesis_Simple_Aweber_Form’);” ) ); | |
/** | |
* Genesis Simple Aweber Form Class | |
* @category Genesis | |
* @package Widgets | |
* | |
* @since 0.1 | |
*/ | |
class Genesis_Simple_Aweber_Form extends WP_Widget { | |
/** | |
* Holds widget settings defaults, populated in constructor. | |
* | |
* @var array | |
*/ | |
protected $defaults; | |
/** | |
* Constructor. Set the default widget options and create widget. | |
*/ | |
function __construct() { | |
$this->defaults = array( | |
‘title’ => ”, | |
‘text’ => ”, | |
‘id’ => ”, | |
‘name_text’ => ”, | |
‘input_text’ => ”, | |
‘button_text’ => ”, | |
‘thank_you’ => ‘text’, | |
‘custom_url’ => ”, | |
); | |
$widget_ops = array( | |
‘classname’ => ‘enews-widget’, | |
‘description’ => __( ‘Displays Aweber subscribe form’, ‘gsaf’ ), | |
); | |
$this->WP_Widget( ‘gsaf’, __( ‘Genesis Simple Aweber Form’, ‘gsaf’ ), $widget_ops ); | |
} | |
/** | |
* Echo the widget content. | |
* | |
* @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. | |
* @param array $instance The settings for the particular instance of the widget | |
*/ | |
function widget( $args, $instance ) { | |
extract( $args ); | |
/** Merge with defaults */ | |
$instance = wp_parse_args( (array) $instance, $this->defaults ); | |
echo $before_widget . ‘<div class=”enews aweber”>’; | |
if ( ! empty( $instance['title'] ) ) | |
echo $before_title . apply_filters( ‘widget_title’, $instance['title'], $instance, $this->id_base ) . $after_title; | |
echo wpautop( $instance['text'] ); // We run KSES on update | |
if ( ! empty( $instance['id'] ) ) : ?> | |
<form method=”post” class=”af-form-wrapper” action=”http://www.aweber.com/scripts/addlead.pl” id=”subscribe” target=”popupwindow”> | |
<div style=”display: none;”> | |
<input type=”hidden” name=”listname” value=”<?php echo $instance['id']; ?>” /> | |
<?php | |
if( ‘custom’ == $instance['thank_you'] ) | |
$value = $instance['custom_url']; | |
else | |
$value = ‘http://www.aweber.com/thankyou-coi.htm?m=’ .$instance['thank_you']; | |
?> | |
<input type=”hidden” name=”redirect” value=”http://www.aweber.com/thankyou-coi.htm?m=<?php echo $value ?>” id=”redirect_ee2c9df8de97f9c416c33b210b47c0bc” /> | |
<input type=”hidden” name=”meta_adtracking” value=”Genesis_Simple_Aweber_Form” /> | |
<input type=”hidden” name=”meta_message” value=”1″ /> | |
<input type=”hidden” name=”meta_required” value=”name,email” /> | |
</div> | |
<span id=”subbox”> | |
<input type=”text” name=”name” class=”text name” tabindex=”500″ value=”<?php echo esc_attr( $instance['name_text'] ); ?>” onfocus=”if ( this.value == ‘<?php echo esc_js( $instance['name_text'] ); ?>’) { this.value = ”; }” onblur=”if ( this.value == ” ) { this.value = ‘<?php echo esc_js( $instance['name_text'] ); ?>’; }” /> | |
<input type=”text” name=”email” class=”text email” tabindex=”501″ value=”<?php echo esc_attr( $instance['input_text'] ); ?>” onfocus=”if ( this.value == ‘<?php echo esc_js( $instance['input_text'] ); ?>’) { this.value = ”; }” onblur=”if ( this.value == ” ) { this.value = ‘<?php echo esc_js( $instance['input_text'] ); ?>’; }” /> | |
</span> | |
<input name=”submit” class=”submit” type=”submit” value=”<?php echo esc_attr( $instance['button_text'] ); ?>” tabindex=”502″ id=”subbutton” /> | |
</form> | |
<?php endif; | |
echo ‘</div>’ . $after_widget; | |
} | |
/** | |
* Update a particular instance. | |
* | |
* This function should check that $new_instance is set correctly. | |
* The newly calculated value of $instance should be returned. | |
* If “false” is returned, the instance won’t be saved/updated. | |
* | |
* @param array $new_instance New settings for this instance as input by the user via form() | |
* @param array $old_instance Old settings for this instance | |
* @return array Settings to save or bool false to cancel saving | |
*/ | |
function update( $new_instance, $old_instance ) { | |
$new_instance['title'] = strip_tags( $new_instance['title'] ); | |
$new_instance['text'] = wp_kses( $new_instance['text'], genesis_formatting_allowedtags() ); | |
return $new_instance; | |
} | |
/** | |
* Echo the settings update form. | |
* | |
* @param array $instance Current settings | |
*/ | |
function form( $instance ) { | |
/** Merge with defaults */ | |
$instance = wp_parse_args( (array) $instance, $this->defaults ); | |
?> | |
<p> | |
<label for=”<?php echo $this->get_field_id( ‘title’ ); ?>”><?php _e( ‘Title’, ‘genesis’ ); ?>:</label><br /> | |
<input type=”text” id=”<?php echo $this->get_field_id( ‘title’ ); ?>” name=”<?php echo $this->get_field_name( ‘title’ ); ?>” value=”<?php echo esc_attr( $instance['title'] ); ?>” class=”widefat” /> | |
</p> | |
<p> | |
<label for=”<?php echo $this->get_field_id( ‘text’ ); ?>”><?php _e( ‘Text To Show’, ‘genesis’ ); ?>:</label><br /> | |
<textarea id=”<?php echo $this->get_field_id( ‘text’ ); ?>” name=”<?php echo $this->get_field_name( ‘text’ ); ?>” class=”widefat” rows=”6″ cols=”4″><?php echo htmlspecialchars( $instance['text'] ); ?></textarea> | |
</p> | |
<p> | |
<label for=”<?php echo $this->get_field_id( ‘id’ ); ?>”><?php _e( ‘Aweber List ID’, ‘gsaf’ ); ?>:</label> | |
<input type=”text” id=”<?php echo $this->get_field_id( ‘id’ ); ?>” name=”<?php echo $this->get_field_name( ‘id’ ); ?>” value=”<?php echo esc_attr( $instance['id'] ); ?>” class=”widefat” /> | |
</p> | |
<p> | |
<?php $name_text = empty( $instance['name_text'] ) ? __( ‘Name’, ‘gsaf’ ) : $instance['name_text']; ?> | |
<label for=”<?php echo $this->get_field_id( ‘name_text’ ); ?>”><?php _e( ‘Name Text’, ‘gsaf’ ); ?>:</label> | |
<input type=”text” id=”<?php echo $this->get_field_id( ‘name_text’ ); ?>” name=”<?php echo $this->get_field_name( ‘name_text’ ); ?>” value=”<?php echo esc_attr( $name_text ); ?>” class=”widefat” /> | |
</p> | |
<p> | |
<?php $input_text = empty( $instance['input_text'] ) ? __( ‘Enter your email address…’, ‘genesis’ ) : $instance['input_text']; ?> | |
<label for=”<?php echo $this->get_field_id( ‘input_text’ ); ?>”><?php _e( ‘Input Text’, ‘genesis’ ); ?>:</label> | |
<input type=”text” id=”<?php echo $this->get_field_id( ‘input_text’ ); ?>” name=”<?php echo $this->get_field_name( ‘input_text’ ); ?>” value=”<?php echo esc_attr( $input_text ); ?>” class=”widefat” /> | |
</p> | |
<p> | |
<?php $button_text = empty( $instance['button_text'] ) ? __( ‘Go’, ‘genesis’ ) : $instance['button_text']; ?> | |
<label for=”<?php echo $this->get_field_id( ‘button_text’ ); ?>”><?php _e( ‘Button Text’, ‘genesis’ ); ?>:</label> | |
<input type=”text” id=”<?php echo $this->get_field_id( ‘button_text’ ); ?>” name=”<?php echo $this->get_field_name( ‘button_text’ ); ?>” value=”<?php echo esc_attr( $button_text ); ?>” class=”widefat” /> | |
</p> | |
<p> | |
<label for=”<?php echo $this->get_field_id( ‘thank_you’ ); ?>”><?php _e( ‘Thank You Page’, ‘gfsa’ ); ?>:</label> | |
<select id=”<?php echo $this->get_field_id( ‘thank_you’ ); ?>” name=”<?php echo $this->get_field_name( ‘thank_you’ ); ?>”> | |
<option value=”text” <?php selected( ‘text’, $instance['thank_you'] ); ?>><?php _e( ‘Basic Version’, ‘gfsa’ ); ?></option> | |
<option value=”audio” <?php selected( ‘audio’, $instance['thank_you'] ); ?>><?php _e( ‘Audio Version’, ‘gfsa’ ); ?></option> | |
<option value=”video” <?php selected( ‘video’, $instance['thank_you'] ); ?>><?php _e( ‘”Smart” Video Version’, ‘gfsa’ ); ?></option> | |
<option value=”custom” <?php selected( ‘custom’, $instance['thank_you'] ); ?>><?php _e( ‘Custom Page’, ‘gfsa’ ); ?></option> | |
</select> | |
</p> | |
<p> | |
<label for=”<?php echo $this->get_field_id( ‘custom_url’ ); ?>”><?php _e( ‘Custom URL’, ‘gsaf’ ); ?>:</label> | |
<input type=”text” id=”<?php echo $this->get_field_id( ‘custom_url’ ); ?>” name=”<?php echo $this->get_field_name( ‘custom_url’ ); ?>” value=”<?php echo esc_attr( $instance['custom_url'] ); ?>” class=”widefat” /> | |
</p> | |
<?php | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment