Skip to content

Instantly share code, notes, and snippets.

@tonylegrone
Created October 21, 2010 19:05
Show Gist options
  • Save tonylegrone/639090 to your computer and use it in GitHub Desktop.
Save tonylegrone/639090 to your computer and use it in GitHub Desktop.
WP Feedburner Widget
// Place in your themes functions.php
// feedburner subscription form
add_action( 'widgets_init', 'custom_load_widgets' );
function custom_load_widgets() {
register_widget( 'FB_subscribe' );
}
class FB_subscribe extends WP_Widget {
// Widget setup.
function FB_subscribe() {
/* Widget settings. */
$widget_ops = array( 'classname' => 'fb_subscribe', 'description' => __('Creates an email subscription form for Feedburner.', 'fb_subscribe') );
/* Widget control settings. */
$control_ops = array( 'id_base' => 'fb_subscribe-widget' );
/* Create the widget. */
$this->WP_Widget( 'fb_subscribe-widget', __('Feedburner Subscribe', 'fb_subscribe'), $widget_ops, $control_ops );
}
// How to display the widget on the screen.
function widget( $args, $instance ) {
extract( $args );
/* Our variables from the widget settings. */
$title = apply_filters('widget_title', $instance['title'] );
$fb_id = $instance['fb_id'];
/* Before widget (defined by themes). */
echo $before_widget;
/* Display the widget title if one was input (before and after defined by themes). */
if ( $title )
echo $before_title . $title . $after_title;
/* Display name from widget settings if one was input. */
if ( $fb_id )
printf( __('
<form action="http://feedburner.google.com/fb/a/mailverify" method="post" target="popupwindow" onsubmit="window.open(\'http://feedburner.google.com/fb/a/mailverify?uri=%1$s\', \'popupwindow\', \'scrollbars=yes,width=550,height=520\');return true">
<input type="hidden" value="%1$s" name="uri"/>
<input type="hidden" name="loc" value="en_US"/>
<input type="text" name="email" />
<input type="submit" id="searchsubmit" value="Subscribe" class="btn_search" onmouseover="this.className=\'btn_search over\'" onmouseout="this.className=\'btn_search\'" />
</form>', 'example'), $fb_id );
/* After widget (defined by themes). */
echo $after_widget;
}
// Update the widget settings.
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
/* Strip tags for title and name to remove HTML (important for text inputs). */
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['fb_id'] = strip_tags( $new_instance['fb_id'] );
return $instance;
}
/**
* Displays the widget settings controls on the widget panel.
* Make use of the get_field_id() and get_field_name() function
* when creating your form elements. This handles the confusing stuff.
*/
function form( $instance ) {
/* Set up some default widget settings. */
$defaults = array( 'title' => __('Subscribe by Email', 'example'), 'fb_id' => __('', 'example'));
$instance = wp_parse_args( (array) $instance, $defaults ); ?>
<!-- Widget Title: Text Input -->
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'hybrid'); ?></label>
<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
</p>
<!-- Your Name: Text Input -->
<p>
<label for="<?php echo $this->get_field_id( 'fb_id' ); ?>"><?php _e('Feedburner ID:', 'example'); ?></label>
<input id="<?php echo $this->get_field_id( 'fb_id' ); ?>" name="<?php echo $this->get_field_name( 'fb_id' ); ?>" value="<?php echo $instance['fb_id']; ?>" style="width:100%;" />
</p>
<?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment