From 7376d48739837e5d4f12e1fc1371afd518c5417d Mon Sep 17 00:00:00 2001 From: Robin Cornett Date: Mon, 6 Nov 2017 12:21:27 -0500 Subject: [PATCH] Refactor author widget output --- ...playfeaturedimagegenesis-author-widget.php | 116 +++++++++++++----- 1 file changed, 83 insertions(+), 33 deletions(-) diff --git a/includes/widgets/displayfeaturedimagegenesis-author-widget.php b/includes/widgets/displayfeaturedimagegenesis-author-widget.php index 7e21cc7..6e37e13 100644 --- a/includes/widgets/displayfeaturedimagegenesis-author-widget.php +++ b/includes/widgets/displayfeaturedimagegenesis-author-widget.php @@ -78,46 +78,95 @@ class Display_Featured_Image_Genesis_Author_Widget extends WP_Widget { echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title']; } - if ( $instance['show_featured_image'] ) { - $image_id = get_the_author_meta( 'displayfeaturedimagegenesis', $instance['user'] ); - echo wp_get_attachment_image( $image_id, $instance['featured_image_size'], array( - 'alt' => get_the_author_meta( 'display_name', $instance['user'] ), - ) ); - } + $this->do_featured_image( $instance ); - $text = ''; - - if ( $instance['show_gravatar'] ) { - if ( ! empty( $instance['gravatar_alignment'] ) ) { - $text .= ''; - } - - $text .= get_avatar( $instance['user'], $instance['size'] ); - - if ( ! empty( $instance['gravatar_alignment'] ) ) { - $text .= ''; - } - } - - if ( $instance['author_info'] ) { - $text .= 'text' === $instance['author_info'] ? $instance['bio_text'] : get_the_author_meta( 'description', $instance['user'] ); - } - - $text .= $instance['page'] ? sprintf( ' %s', get_page_link( $instance['page'] ), $instance['page_link_text'] ) : ''; - - // Echo $text + $text = $this->get_gravatar( $instance ); + $text .= $this->get_author_description( $instance ); echo wp_kses_post( wpautop( $text ) ); + $this->do_author_link( $instance ); + + 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'], array( + 'alt' => get_the_author_meta( 'display_name', $instance['user'] ), + ) ); + } + + /** + * Return the author gravatar. + * + * @param $instance + * + * @return string + */ + protected function get_gravatar( $instance ) { + $text = ''; + if ( ! $instance['show_gravatar'] ) { + return $text; + } + if ( ! empty( $instance['gravatar_alignment'] ) ) { + $text .= ''; + } + + $text .= get_avatar( $instance['user'], $instance['size'] ); + + if ( ! empty( $instance['gravatar_alignment'] ) ) { + $text .= ''; + } + + return $text; + } + + /** + * 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 . ': ' : ''; - if ( $instance['posts_link'] && $instance['link_text'] ) { - printf( '', esc_url( get_author_posts_url( $instance['user'] ) ), wp_kses_post( $user_name ), esc_attr( $instance['link_text'] ) ); - } - - echo $args['after_widget']; - + printf( '', esc_url( get_author_posts_url( $instance['user'] ) ), wp_kses_post( $user_name ), esc_attr( $instance['link_text'] ) ); } /** @@ -216,6 +265,7 @@ class Display_Featured_Image_Genesis_Author_Widget extends WP_Widget { */ protected function get_image_fields() { $form = $this->get_form_class(); + return array( array( 'method' => 'checkbox',