Skip to content

Instantly share code, notes, and snippets.

@norcross
Created September 15, 2012 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norcross/3726056 to your computer and use it in GitHub Desktop.
Save norcross/3726056 to your computer and use it in GitHub Desktop.
widget examples
<?php
/*
Plugin Name: Mukulla Custom Widgets
Plugin URI: https://gist.github.com/3726056
Description: A test plugin for showing some example widgets
Version: 0.1
Author: norcross
Author URI: http://andrewnorcross.com
License: GPL2
*/
/*
Copyright 2012 WordPress Facebook Open Graph protocol plugin (email: chuck@rynoweb.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// custom social widgets
class rkv_social_proof extends WP_Widget {
function rkv_social_proof() {
$widget_ops = array( 'classname' => 'social_tabs', 'description' => 'Displays social icons' );
$this->WP_Widget( 'social_tabs', 'Social Tabs', $widget_ops );
}
function widget( $args, $instance ) {
extract( $args, EXTR_SKIP );
echo $before_widget;
$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
echo '<ul>';
echo '<li><a rel="external" class="img_opa twitter" target="_blank" href="http://twitter.com/'.$instance['twitter'].'" title="Follow me on Twitter">Follow me on Twitter</a></li>';
echo '<li><a rel="external" class="img_opa github" target="_blank" href="http://github.com/'.$instance['github'].'" title="Collaborate on Github">Collaborate on Github</a></li>';
echo '<li><a rel="external" class="img_opa gplus" target="_blank" href="https://plus.google.com/101309579396817654042/posts" title="Join me on Google Plus">Join me on Google Plus</a></li>';
echo '<li><a rel="external" class="img_opa stacko" target="_blank" href="http://wordpress.stackexchange.com/users/403/norcross/" title="WordPress StackExchange">WordPress StackExchange</a></li>';
echo '<li><a rel="external" class="img_opa tumblr" target="_blank" href="http://x.norcross.co/" title="My weird stuff on Tumblr">My weird stuff on Tumblr</a></li>';
echo '<li><a rel="external" class="img_opa instagram" target="_blank" href="http://instagrid.me/andrewnorcross" title="Hipster shit on Instagram">Hipster shit on Instagram</a></li>';
echo '<li><a rel="external" class="img_opa dailybooth" target="_blank" href="http://dailybooth.com/Norcross" title="My ugly mug on DailyBooth">My ugly mug on DailyBooth</a></li>';
// echo '<li><a rel="external" class="img_opa flickr" target="_blank" href="http://www.flickr.com/photos/norcross/" title="Random snapshots on Flickr">Random snapshots on Flickr</a></li>';
echo '<li><a class="img_opa feed" href="'.thesis_feed_url().'" title="Subscribe to the RSS feed">Subscribe to the RSS feed</a></li>';
echo '</ul>';
echo $after_widget;
?>
<?php }
/** @see WP_Widget::update */
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['twitter'] = strip_tags($new_instance['twitter']);
$instance['github'] = strip_tags($new_instance['github']);
return $instance;
}
/** @see WP_Widget::form */
function form($instance) {
$instance = wp_parse_args( (array) $instance, array(
'title' => '',
'twitter' => 'norcross',
'github' => 'norcross',
'gplus' => '101309579396817654042'
));
$title = strip_tags($instance['title']);
$twitter = strip_tags($instance['twitter']);
$github = strip_tags($instance['github']);
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>">Widget Title: <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); ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('twitter'); ?>">Twitter Username: <input class="widefat" id="<?php echo $this->get_field_id('twitter'); ?>" name="<?php echo $this->get_field_name('twitter'); ?>" type="text" value="<?php echo esc_attr($twitter); ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('github'); ?>">Github Username: <input class="widefat" id="<?php echo $this->get_field_id('github'); ?>" name="<?php echo $this->get_field_name('github'); ?>" type="text" value="<?php echo esc_attr($github); ?>" /></label></p>
<?php }
} // class
// register widget
add_action( 'widgets_init', create_function( '', "register_widget('rkv_social_proof');" ) );
// speaker badges
class rkv_speaking_badge extends WP_Widget {
function rkv_speaking_badge() {
$widget_ops = array( 'classname' => 'speaking_badge', 'description' => 'Displays the badge with link' );
$this->WP_Widget( 'speaking_badge', 'Speaker Badge', $widget_ops );
}
function widget( $args, $instance ) {
extract( $args, EXTR_SKIP );
echo $before_widget;
echo '<a href="'.$instance['link'].'" title="'.$instance['text'].'" target="_blank">';
echo '<img src="'.$instance['image'].'" title="'.$instance['text'].'" alt="'.$instance['text'].'">';
echo '</a>';
echo $after_widget;
?>
<?php }
/** @see WP_Widget::update */
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['link'] = strip_tags($new_instance['link']);
$instance['text'] = strip_tags($new_instance['text']);
$instance['image'] = strip_tags($new_instance['image']);
return $instance;
}
/** @see WP_Widget::form */
function form($instance) {
$instance = wp_parse_args( (array) $instance, array(
'link' => '',
'text' => 'I\'m Speaking!',
'image' => '',
));
$link = strip_tags($instance['link']);
$text = strip_tags($instance['text']);
$image = strip_tags($instance['image']);
?>
<p><label for="<?php echo $this->get_field_id('link'); ?>">Conference URL:<input class="widefat" id="<?php echo $this->get_field_id('link'); ?>" name="<?php echo $this->get_field_name('link'); ?>" type="text" value="<?php echo esc_attr($link); ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('text'); ?>">Anchor / Alt Text:<input class="widefat" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>" type="text" value="<?php echo esc_attr($text); ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('image'); ?>">Badge Image URL:<input class="widefat" id="<?php echo $this->get_field_id('image'); ?>" name="<?php echo $this->get_field_name('image'); ?>" type="text" value="<?php echo esc_attr($image); ?>" /></label></p>
<?php }
} // class
// register widget
add_action( 'widgets_init', create_function( '', "register_widget('rkv_speaking_badge');" ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment