diff --git a/includes/output/class-displayfeaturedimagegenesis-output-author.php b/includes/output/class-displayfeaturedimagegenesis-output-author.php new file mode 100644 index 0000000..58c0768 --- /dev/null +++ b/includes/output/class-displayfeaturedimagegenesis-output-author.php @@ -0,0 +1,162 @@ +instance = $instance; + $this->args = $this->update_args( $args ); + $this->id_base = $id_base ? $id_base : 'display-featured-image-genesis-author'; + $this->init(); + } + + /** + * Output the featured author. + * @since 3.1.0 + */ + private function init() { + if ( ! empty( $this->instance['title'] ) ) { + echo wp_kses_post( $this->args['before_title'] . apply_filters( 'widget_title', $this->instance['title'], $this->instance, $this->id_base ) . $this->args['after_title'] ); + } + + $this->do_featured_image(); + + $text = $this->get_gravatar(); + $text .= $this->get_author_description(); + echo wp_kses_post( wpautop( $text ) ); + + $this->do_author_link(); + } + + /** + * Echo the author featured image. + */ + protected function do_featured_image() { + if ( ! $this->instance['show_featured_image'] ) { + return; + } + $image_id = get_the_author_meta( 'displayfeaturedimagegenesis', $this->instance['user'] ); + if ( ! $image_id ) { + return; + } + echo wp_get_attachment_image( + $image_id, + $this->instance['featured_image_size'], + false, + array( + 'alt' => get_the_author_meta( 'display_name', $this->instance['user'] ), + 'class' => $this->instance['featured_image_alignment'], + ) + ); + } + + /** + * Return the author gravatar. + * + * @return string + */ + protected function get_gravatar() { + if ( ! $this->instance['show_gravatar'] ) { + return ''; + } + + $gravatar = get_avatar( $this->instance['user'], $this->instance['size'] ); + if ( empty( $this->instance['gravatar_alignment'] ) ) { + return $gravatar; + } + + return '' . $gravatar . ''; + } + + /** + * Return the author bio/info. + * + * @param $this ->instance + * + * @return string + */ + public function get_author_description() { + if ( ! $this->instance['author_info'] ) { + return ''; + } + + return 'text' === $this->instance['author_info'] ? $this->instance['bio_text'] : get_the_author_meta( 'description', $this->instance['user'] ); + } + + /** + * Return the author link. + * + * @return string + */ + protected function get_author_link() { + return $this->instance['page'] ? sprintf( ' %s', get_page_link( $this->instance['page'] ), $this->instance['page_link_text'] ) : ''; + } + + /** + * Output the author link. + */ + protected function do_author_link() { + if ( ! $this->instance['posts_link'] || ! $this->instance['link_text'] ) { + return; + } + // If posts link option checked, add posts link to output + $display_name = get_the_author_meta( 'display_name', $this->instance['user'] ); + $user_name = ! empty( $display_name ) && function_exists( 'genesis_a11y' ) && genesis_a11y() ? '' . $display_name . ': ' : ''; + + printf( + '', + esc_url( get_author_posts_url( $this->instance['user'] ) ), + wp_kses_post( $user_name ), + esc_attr( $this->instance['link_text'] ) + ); + } + + /** + * Update the "sidebar" args with some defaults (really only needed for the title). + * + * @param array $args + * + * @return array + * @since 1.7.0 + * + */ + private function update_args( $args ) { + $defaults = array( + 'before_title' => '', + ); + + return wp_parse_args( $args, $defaults ); + } +} diff --git a/includes/widgets/displayfeaturedimagegenesis-author-widget.php b/includes/widgets/displayfeaturedimagegenesis-author-widget.php index 6b76105..a2198c7 100644 --- a/includes/widgets/displayfeaturedimagegenesis-author-widget.php +++ b/includes/widgets/displayfeaturedimagegenesis-author-widget.php @@ -69,97 +69,12 @@ class Display_Featured_Image_Genesis_Author_Widget extends WP_Widget { echo $args['before_widget']; - if ( ! empty( $instance['title'] ) ) { - echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title']; - } - - $this->do_featured_image( $instance ); - - $text = $this->get_gravatar( $instance ); - $text .= $this->get_author_description( $instance ); - echo wp_kses_post( wpautop( $text ) ); - - $this->do_author_link( $instance ); + include plugin_dir_path( dirname( __FILE__ ) ) . 'output/class-displayfeaturedimagegenesis-output-author.php'; + new DisplayFeaturedImageGenesisOutputAuthor( $instance, $args, $this->id_base ); echo $args['after_widget']; } - /** - * Echo the author featured image. - * - * @param $instance - */ - protected function do_featured_image( $instance ) { - if ( ! $instance['show_featured_image'] ) { - return; - } - $image_id = get_the_author_meta( 'displayfeaturedimagegenesis', $instance['user'] ); - echo wp_get_attachment_image( $image_id, $instance['featured_image_size'], false, array( - 'alt' => get_the_author_meta( 'display_name', $instance['user'] ), - 'class' => $instance['featured_image_alignment'], - ) ); - } - - /** - * Return the author gravatar. - * - * @param $instance - * - * @return string - */ - protected function get_gravatar( $instance ) { - if ( ! $instance['show_gravatar'] ) { - return ''; - } - - $gravatar = get_avatar( $instance['user'], $instance['size'] ); - if ( empty( $instance['gravatar_alignment'] ) ) { - return $gravatar; - } - - return '' . $gravatar . ''; - } - - /** - * Return the author bio/info. - * - * @param $instance - * - * @return string - */ - public function get_author_description( $instance ) { - if ( ! $instance['author_info'] ) { - return ''; - } - - return 'text' === $instance['author_info'] ? $instance['bio_text'] : get_the_author_meta( 'description', $instance['user'] ); - } - - /** - * Return the author link. - * - * @param $instance - * - * @return string - */ - protected function get_author_link( $instance ) { - return $instance['page'] ? sprintf( ' %s', get_page_link( $instance['page'] ), $instance['page_link_text'] ) : ''; - } - - /** - * @param $instance - */ - protected function do_author_link( $instance ) { - if ( ! $instance['posts_link'] || ! $instance['link_text'] ) { - return; - } - // If posts link option checked, add posts link to output - $display_name = get_the_author_meta( 'display_name', $instance['user'] ); - $user_name = ! empty( $display_name ) && function_exists( 'genesis_a11y' ) && genesis_a11y() ? '' . $display_name . ': ' : ''; - - printf( '', esc_url( get_author_posts_url( $instance['user'] ) ), wp_kses_post( $user_name ), esc_attr( $instance['link_text'] ) ); - } - /** * Update a particular instance. *