|
<?php # -*- coding: utf-8 -*- |
|
declare ( encoding = 'UTF-8' ); |
|
/** |
|
* Plugin Name: T5 Author Data |
|
* Plugin URI: http://wordpress.stackexchange.com/q/47418/73 |
|
* Description: Simple Widget to display author data on singular pages (posts and pages) and author archives. |
|
* Version: 2012.03.31 |
|
* Author: Thomas Scholz <[email protected]> and Jasper Frumau <[email protected]> |
|
* Author URI: http://toscho.de and http://imagewize.com |
|
* License: MIT |
|
* License URI: http://www.opensource.org/licenses/mit-license.php |
|
*/ |
|
|
|
add_action( 'widgets_init', array ( 'T5_Author_Data', 'register' ) ); |
|
|
|
/** |
|
* Basic Author Data Widget. |
|
* |
|
* @author Thoams Scholz http://toscho.de |
|
*/ |
|
class T5_Author_Data extends WP_Widget |
|
{ |
|
/** |
|
* Constructor. Calls the parent constructor |
|
*/ |
|
public function __construct() |
|
{ |
|
parent::__construct( 't5_author_data', 'Author Data' ); |
|
} |
|
|
|
/** |
|
* Display the content on front. |
|
* |
|
* @see WP_Widget::widget() |
|
*/ |
|
public function widget( $args, $instance ) |
|
{ |
|
// Set up $before_title, $after_title, $before_widget and $after_widget. |
|
extract( $args ); |
|
|
|
global $authordata; |
|
if ( ! ( is_author() or is_singular() ) // wrong page |
|
or ! is_object( $authordata ) // wrong type |
|
or ! isset ( $authordata->ID ) // wrong object |
|
) |
|
{ |
|
return; // Nothing to do. |
|
} |
|
|
|
// Build the title. |
|
$name = esc_html( $authordata->display_name ); |
|
|
|
// Important! Never omit this filter in your widgets. |
|
$name = apply_filters( 'widget_title', $name, $instance, $this->id_base ); |
|
|
|
// Link to archive. |
|
! is_author() and $name = sprintf( |
|
'<a href="%1$s" rel="author">%2$s</a>', |
|
get_author_posts_url( $authordata->ID ), |
|
$name |
|
); |
|
$title = $before_title . $name . $after_title; |
|
|
|
// Description. |
|
// See http://wordpress.stackexchange.com/a/43742/73 for a rich text |
|
// editor option as an alternative. |
|
$desc = trim( get_the_author_meta( 'description', $authordata->ID ) ); |
|
'' !== $desc and $desc = '<div class="author-text">' . wpautop( $desc ) . '</div>'; |
|
|
|
// Image |
|
$img = get_avatar( $authordata->ID, $size = 128 ); |
|
|
|
//Twitter Data |
|
$twitter = trim(get_the_author_meta( 'twitter', $authordata->ID ) ); |
|
'' !== $twitter and $twitter = '<div class="author-tweets">Follow <a href="https://twitter.com/' . $twitter . '">' . $twitter . '</a></div>'; |
|
|
|
// Now we have everything we need. |
|
print $before_widget |
|
. "<div class='author-image'>$img</div>" |
|
//. $title |
|
. $twitter |
|
. "<div class='author-text'><h3>Description:</h3><br />$desc</div>" |
|
|
|
. $after_widget |
|
; |
|
} |
|
|
|
/** |
|
* Handler for backend wp-admin/widget.php. |
|
* |
|
* @see WP_Widget::form() |
|
*/ |
|
public function form( $instance ) |
|
{ |
|
printf( |
|
'<p class="no-options-widget">%s</p>', |
|
__( 'There are no options for this widget.' ) |
|
); |
|
} |
|
|
|
/** |
|
* Register this widget. |
|
* |
|
* @wp-hook widgets_init |
|
*/ |
|
public static function register() |
|
{ |
|
register_widget( __CLASS__ ); |
|
} |
|
} |
</ br>
looks wrong. ;)