Created
March 28, 2014 13:12
-
-
Save Manoz/9832367 to your computer and use it in GitHub Desktop.
Simple "Blog info" Widget snippet for WordPress. Not very good, but it's a test =)
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 | |
/** | |
* Simple "blog info" widget snippet | |
* @todo rebuild it =) | |
* @author Kevin Legrand : http://k-legrand.fr | |
* @copyright Copyright (c) 2014, Kevin Legrand | |
* @link http://k-legrand.fr | |
* @license http://www.gnu.org/licenses/gpl-3.0.html | |
*/ | |
// The prefix 'AM' mean "AntiMony", a theme I built | |
add_action( 'widgets_init', array( 'AM_Blog_Infos', 'register_bloginfo' ) ); | |
class AM_Blog_Infos extends WP_Widget { | |
function __construct() { | |
parent::__construct( | |
'am_blog_info', // Widget ID | |
__( 'AM Blog info - Footer', 'antimony' ), // Widget name | |
array( | |
'classname' => 'am-blog-info', | |
'description' => __( 'A simple About widget with social media links for your footer.', 'antimony' ) | |
) | |
); | |
} | |
// I think this method is not very good. I'll rethink it, one day ... | |
public static function register_bloginfo() { | |
register_widget( 'AM_Blog_Infos' ); | |
} | |
// Build the front stuff | |
function widget( $args, $instance ) { | |
extract( $args ); | |
$title = apply_filters( | |
'widget_title', | |
empty( $instance['title'] ) ? | |
__( 'About me', 'antimony' ) : | |
$instance['title'] | |
); | |
$text = $instance['text']; | |
$check = $instance['check']; | |
$rss = $instance['rss']; | |
$fb = $instance['fb']; | |
$tw = $instance['tw']; | |
$insta = $instance['insta']; | |
$dribb = $instance['dribb']; | |
$pin = $instance['pin']; | |
$gplus = $instance['gplus']; | |
echo $before_widget; | |
if( $title ) echo $before_title . $title . $after_title; | |
// A better way is to include all the html content into another file. | |
// Ex: include( plugin_dir_path( __FILE__ ).'/front-bloginfo.php' ); ?> | |
<p> | |
<?php echo $text; ?> | |
</p> | |
<?php | |
if( $check != 'on' ) { ?> | |
<ul> | |
<?php if($rss != '') { ?> | |
<li><a class="bi-rss" href="<?php echo $rss; ?>" target="_blank"><i class="icon-rss"></i></a></li> | |
<?php } if($fb != '') { ?> | |
<li><a class="bi-fb" href="<?php echo $fb; ?>" target="_blank"><i class="icon-facebook"></i></a></li> | |
<?php } if($tw != '') { ?> | |
<li><a class="bi-tw" href="<?php echo $tw; ?>" target="_blank"><i class="icon-twitter"></i></a></li> | |
<?php } if($insta != '') { ?> | |
<li><a class="bi-insta" href="<?php echo $insta; ?>" target="_blank"><i class="icon-instagram"></i></a></li> | |
<?php } if($dribb != '') { ?> | |
<li><a class="bi-dribb" href="<?php echo $dribb; ?>" target="_blank"><i class="icon-dribbble"></i></a></li> | |
<?php } if($pin != '') { ?> | |
<li><a class="bi-pin" href="<?php echo $pin; ?>" target="_blank"><i class="icon-pinterest"></i></a></li> | |
<?php } if($gplus != '') { ?> | |
<li><a class="bi-gplus" href="<?php echo $gplus; ?>" target="_blank"><i class="icon-gplus"></i></a></li> | |
<?php } ?> | |
</ul> | |
<?php } ?> | |
<?php echo $after_widget; | |
} | |
function update( $new_instance, $old_instance ) { | |
$instance = $old_instance; | |
$instance['title'] = strip_tags( $new_instance['title'] ); | |
$instance['text'] = $new_instance['text']; | |
$instance['check'] = $new_instance['check']; | |
$instance['rss'] = $new_instance['rss']; | |
$instance['fb'] = $new_instance['fb']; | |
$instance['tw'] = $new_instance['tw']; | |
$instance['insta'] = $new_instance['insta']; | |
$instance['dribb'] = $new_instance['dribb']; | |
$instance['pin'] = $new_instance['pin']; | |
$instance['gplus'] = $new_instance['gplus']; | |
return $instance; | |
} | |
// Build the admin form | |
function form( $instance ) { | |
$defaults = array( | |
'title' => __( 'About me', 'antimony' ), | |
'text' => __( 'You can add some content here about your blog or about you.', 'antimony' ), | |
'check' => '', | |
'rss' => 'http://www.your-url.com/feed', | |
'fb' => 'http://www.facebook.com/lboldair', | |
'tw' => 'http://www.twitter.com/Manoz', | |
'insta' => 'http://instagram.com/manoz_', | |
'dribb' => 'http://dribbble.com/Manoz', | |
'pin' => 'http://www.pinterest.com/manoz/', | |
'gplus' => 'https://plus.google.com/+KvinLegrand/posts' | |
); | |
$instance = wp_parse_args( (array) $instance, $defaults ); | |
// A better way is to include all the html content into another file. | |
// Ex: include( plugin_dir_path( __FILE__ ).'/admin-bloginfo.php' ); ?> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'antimony' ) ?></label> | |
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" /> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'text' ); ?>"><?php _e( 'Widget content:', 'antimony' ); ?></label> | |
<textarea class="widefat" rows="8" cols="20" id="<?php echo $this->get_field_id( 'text' ); ?>" name="<?php echo $this->get_field_name( 'text' ); ?>"><?php echo $instance['text']; ?></textarea> | |
</p> | |
<p> | |
<input class="checkbox" type="checkbox" <?php checked( $instance['check'], 'on' ); ?> id="<?php echo $this->get_field_id( 'check' ); ?>" name="<?php echo $this->get_field_name( 'check' ); ?>" /> | |
<label for="<?php echo $this->get_field_id( 'check' ); ?>"><?php _e( 'Hide social links?', 'antimony' ); ?></label> | |
</p> | |
<!-- RSS --> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'rss' ); ?>"><?php _e( 'RSS URL:', 'antimony' ); ?></label> | |
<input class="widefat" id="<?php echo $this->get_field_id( 'rss' ); ?>" name="<?php echo $this->get_field_name( 'rss' ); ?>" type="text" value="<?php echo $instance['rss']; ?>" /> | |
</p> | |
<!-- Facebook --> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'fb' ); ?>"><?php _e( 'Facebook URL:', 'antimony' ); ?></label> | |
<input class="widefat" id="<?php echo $this->get_field_id( 'fb' ); ?>" name="<?php echo $this->get_field_name( 'fb' ); ?>" type="text" value="<?php echo $instance['fb']; ?>" /> | |
</p> | |
<!-- Twitter --> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'tw' ); ?>"><?php _e( 'Twitter URL:', 'antimony' ); ?></label> | |
<input class="widefat" id="<?php echo $this->get_field_id( 'tw' ); ?>" name="<?php echo $this->get_field_name( 'tw' ); ?>" type="text" value="<?php echo $instance['tw']; ?>" /> | |
</p> | |
<!-- Instagram --> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'insta' ); ?>"><?php _e( 'Instagram URL:', 'antimony' ); ?></label> | |
<input class="widefat" id="<?php echo $this->get_field_id( 'insta' ); ?>" name="<?php echo $this->get_field_name( 'insta' ); ?>" type="text" value="<?php echo $instance['insta']; ?>" /> | |
</p> | |
<!-- Dribbble --> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'dribb' ); ?>"><?php _e( 'Dribbble URL:', 'antimony' ); ?></label> | |
<input class="widefat" id="<?php echo $this->get_field_id( 'dribb' ); ?>" name="<?php echo $this->get_field_name( 'dribb' ); ?>" type="text" value="<?php echo $instance['dribb']; ?>" /> | |
</p> | |
<!-- Pinterest --> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'pin' ); ?>"><?php _e( 'Pinterest URL:', 'antimony' ); ?></label> | |
<input class="widefat" id="<?php echo $this->get_field_id( 'pin' ); ?>" name="<?php echo $this->get_field_name( 'pin' ); ?>" type="text" value="<?php echo $instance['pin']; ?>" /> | |
</p> | |
<!-- Google+ --> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'gplus' ); ?>"><?php _e( 'Google+ URL:', 'antimony' ); ?></label> | |
<input class="widefat" id="<?php echo $this->get_field_id( 'gplus' ); ?>" name="<?php echo $this->get_field_name( 'gplus' ); ?>" type="text" value="<?php echo $instance['gplus']; ?>" /> | |
</p> | |
<?php } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment