Widgets */ add_action( 'widgets_init', 'joy_about_me_widget_init' ); function joy_about_me_widget_init() { register_widget( 'JoyAboutMeWidget' ); } endif; if ( ! class_exists( 'JoyAboutMeWidget' ) ) : class JoyAboutMeWidget extends WP_Widget { var $default_title = ''; /** * Register widget with WordPress. */ public function __construct() { parent::__construct( 'joy-about-me', apply_filters( 'joy_widget_name', esc_html__( 'Brunch Pro: About Me', 'brunch-lite' ) ), array( 'classname' => 'widget_joy_about_me', 'description' => esc_html__( 'Display some info about you with an image.', 'brunch-lite' ) ) ); $this->default_title = esc_html__( 'About Me', 'brunch-lite' ); add_action( 'admin_init', array( $this, 'admin_init' ) ); } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget( $args, $instance ) { $instance = wp_parse_args( $instance, array( 'title' => '', 'name' => '', 'text' => '', ) ); $args['before_widget'] = substr( $args['before_widget'], 0, -1 ) . ' tabindex="0">'; echo $args['before_widget'] . "\n"; // The Background Image - empty string in case of error $thumb = wp_get_attachment_image_src( $instance['image_id'], 'joy-post-thumbnail-square-big' ); if ( false !== $thumb ) { $thumb = $thumb[0]; } else { $thumb = ''; } // The widget title $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); if ( ! empty( $title ) ) { echo $args['before_title'] . $title . $args['after_title'] . "\n"; } echo '
'; echo '
' . "\n"; echo '
' . "\n"; // The author's name if ( ! empty( $instance['name'] ) ) { echo '
' . $instance['name'] . '
' . "\n"; } // About the author if ( ! empty( $instance['filter'] ) ) { $text = wpautop( $instance['text'] ); } else { $text = $instance['text']; } echo '
' . $text . '
' . "\n"; echo '
' . "\n"; echo '
'; echo $args['after_widget'] . "\n"; } /** * Sanitize widget form values as they are saved. * * @see WP_Widget::update() * * @param array $new_instance Values just sent to be saved. * @param array $old_instance Previously saved values from database. * * @return array Updated safe values to be saved. */ public function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = wp_strip_all_tags( $new_instance['title'] ); $instance['name'] = wp_strip_all_tags( $new_instance['name'] ); $instance['image_id'] = absint( $new_instance['image_id'] ); $instance['text'] = stripslashes( wp_filter_post_kses( addslashes( $new_instance['text'] ) ) ); $instance['filter'] = isset( $new_instance['filter'] ); return $instance; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. */ public function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'image_id' => '', 'title' => '', 'name' => '', 'text' => '', ) ); $title = isset( $instance['title'] ) ? $instance['title'] : false; if ( false === $title ) { $title = $this->default_title; } $image_id = $instance['image_id']; $name = $instance['name']; $text = $instance['text']; ?>

/>