Skip to content

Instantly share code, notes, and snippets.

@benbalter
Created May 13, 2012 17:11
Show Gist options
  • Save benbalter/2689338 to your computer and use it in GitHub Desktop.
Save benbalter/2689338 to your computer and use it in GitHub Desktop.
Photo Credit Widget
<?php
/*
Plugin Name: Photo Credit Widget
Description: Displays photo credit only on pages without custom header images
Version: 1.0
Author URI: http://ben.balter.com/
*/
class BB_Photo_Credit_Widget extends WP_Widget {
function __construct(){
parent::__construct();
$widget_ops = array('classname' => 'photo-credit', 'description' => 'Displays photo credit only on pages without custom header images' );
$this->WP_Widget( 'BB_Photo_Credit_Widget', 'Photo Credit', $widget_ops);
}
function widget($args, $instance) {
extract($args, EXTR_SKIP);
global $post;
echo $before_widget;
if ( !is_singular() || !has_post_thumbnail( $post->ID ) )
echo $instance['content'];
echo $after_widget;
}
function form( $instance ) {
$instance = wp_parse_args((array) $instance, array( 'title' => '' ) );
$content = $instance['content'];
?>
<p><label for="<?php echo $this->get_field_id('content'); ?>">Content: <input class="widefat" id="<?php echo $this->get_field_id('content'); ?>" name="<?php echo $this->get_field_name('content'); ?>" type="text" value="<?php echo attribute_escape( $content ); ?>" /></label></p>
<?php
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['content'] = $new_instance['content'];
return $instance;
}
}
add_action( 'widgets_init', create_function('', 'return register_widget("BB_Photo_Credit_Widget");') );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment