* * @wordpress-plugin * Plugin Name: Canuck Author Widget * Plugin URI: http://kevinsspace.ca/canuckdemo/ * Description: A widget for the Canuck Theme that displays a WordPress Author * Version: 1.1.3 * Author: Kevin Archibald * Author URI: http://kevinsspace.ca/ * License: GPLv2 or later * License URI: http://www.gnu.org/licenses/gpl-2.0.txt */ // Use widgets_init action hook to execute custom function. add_action( 'widgets_init', 'canuck_author_register_widget' ); /** * Register our widget. */ function canuck_author_register_widget() { register_widget( 'Canuck_Author_Widget' ); } /** * Widget Class */ class Canuck_Author_Widget extends WP_Widget { /** * Sets up the widgets name etc. */ public function __construct() { $widget_ops = array( 'classname' => 'canuck_author_widget_class', 'description' => esc_html__( 'Display author biography', 'canuck' ), ); parent::__construct( 'canuck_author_widget', esc_html__( 'Canuck Author Widget', 'canuck' ), $widget_ops ); } /** * Outputs the options form on admin * * @param array $instance The widget options. */ public function form( $instance ) { $canuck_author_defaults = array( 'canuck_author_title' => esc_html__( 'About the Author', 'canuck' ), 'canuck_author_name' => '', 'canuck_author_email' => '', 'canuck_author_website' => '', 'canuck_author_bio' => '', ); $instance = wp_parse_args( (array) $instance, $canuck_author_defaults ); $title = $instance['canuck_author_title']; $name = $instance['canuck_author_name']; $email = $instance['canuck_author_email']; $website = $instance['canuck_author_website']; $bio = $instance['canuck_author_bio']; echo '

' . esc_html__( 'Title : ', 'canuck' ) . '

'; echo '

' . esc_html__( 'Name : ', 'canuck' ) . '

'; echo '

' . esc_html__( 'Email : ', 'canuck' ) . '

'; echo '

' . esc_html__( 'Website : ', 'canuck' ) . '

'; echo '

' . esc_html__( 'Biography : ', 'canuck' ) . '

'; } /** * Processing widget options on save * * @param array $new_instance The new options. * @param array $old_instance The previous options. */ public function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['canuck_author_title'] = sanitize_text_field( $new_instance['canuck_author_title'] ); $instance['canuck_author_name'] = sanitize_text_field( $new_instance['canuck_author_name'] ); $instance['canuck_author_email'] = sanitize_email( $new_instance['canuck_author_email'] ); $instance['canuck_author_website'] = esc_url_raw( $new_instance['canuck_author_website'] ); $instance['canuck_author_bio'] = wp_kses_post( $new_instance['canuck_author_bio'] ); return $instance; } /** * Outputs the content of the widget * * @param array $args Arguments for widget. * @param array $instance Instance. */ public function widget( $args, $instance ) { echo wp_kses_post( $args['before_widget'] ); $titlename = empty( $instance['canuck_author_title'] ) ? '' : $instance['canuck_author_title']; $title = apply_filters( 'widget_title', $titlename, $instance, $this->id_base ); if ( ! empty( $title ) ) { echo wp_kses_post( $args['before_title'] ) . wp_kses_post( $title ) . wp_kses_post( $args['after_title'] ); } $canuck_author_name = $instance['canuck_author_name']; $canuck_author_email = $instance['canuck_author_email']; $canuck_author_website = $instance['canuck_author_website']; $canuck_author_bio = $instance['canuck_author_bio']; ?>
' . get_avatar( $canuck_author_email, 150 ) . ''; } ?> ' . esc_html( $canuck_author_name ) . '
'; } if ( '' !== $canuck_author_bio ) { echo '' . wp_kses_post( $canuck_author_bio ) . ''; } else { echo esc_html__( 'You should probably put a few nice words here...it is a bio after all :)', 'canuck' ); } if ( '' !== $canuck_author_website ) { echo '
' . esc_html__( 'Website', 'canuck' ) . ''; } ?>