From ab86156af53faa1fc35eebb6001be3da94df95b3 Mon Sep 17 00:00:00 2001 From: Robin Cornett Date: Mon, 24 Jun 2019 10:12:46 -0400 Subject: [PATCH] Change how authors are retrieved for the author widget/block --- ...playfeaturedimagegenesis-author-widget.php | 31 +++++-------------- includes/widgets/fields/author-user.php | 18 +++++++++++ 2 files changed, 26 insertions(+), 23 deletions(-) create mode 100644 includes/widgets/fields/author-user.php diff --git a/includes/widgets/displayfeaturedimagegenesis-author-widget.php b/includes/widgets/displayfeaturedimagegenesis-author-widget.php index eeec277..10e353b 100644 --- a/includes/widgets/displayfeaturedimagegenesis-author-widget.php +++ b/includes/widgets/displayfeaturedimagegenesis-author-widget.php @@ -89,8 +89,15 @@ class Display_Featured_Image_Genesis_Author_Widget extends WP_Widget { */ public function get_fields( $new_instance ) { $form = new DisplayFeaturedImageGenesisWidgetsForm( $this, $new_instance ); + $user = array( + array( + 'method' => 'select', + 'args' => include 'fields/author-user.php', + ), + ); return array_merge( + array( $user ), include 'fields/author-image.php', include 'fields/author-gravatar.php', include 'fields/author-description.php', @@ -114,12 +121,7 @@ class Display_Featured_Image_Genesis_Author_Widget extends WP_Widget { 'label' => __( 'Title:', 'display-featured-image-genesis' ), 'class' => 'widefat', ) ); - $form->do_select( $instance, array( - 'id' => 'user', - 'label' => __( 'Select a user. The email address for this account will be used to pull the Gravatar image.', 'display-featured-image-genesis' ), - 'flex' => true, - 'choices' => $this->get_users(), - ) ); + $form->do_select( $instance, include 'fields/author-user.php' ); $form->do_boxes( array( 'author' => include 'fields/author-image.php', @@ -138,23 +140,6 @@ class Display_Featured_Image_Genesis_Author_Widget extends WP_Widget { ) ); } - /** - * Get the authors on the site. - * - * @return array - */ - protected function get_users() { - $users = get_users( array( - 'who' => 'authors', - ) ); - $options = array(); - foreach ( $users as $user ) { - $options[ $user->ID ] = $user->data->display_name; - } - - return $options; - } - /** * Get gravatar sizes. * diff --git a/includes/widgets/fields/author-user.php b/includes/widgets/fields/author-user.php new file mode 100644 index 0000000..38e49d8 --- /dev/null +++ b/includes/widgets/fields/author-user.php @@ -0,0 +1,18 @@ + 'authors', + ) +); +$options = array(); +foreach ( $users as $user ) { + $options[ $user->ID ] = $user->data->display_name; +} + +return array( + 'id' => 'user', + 'label' => __( 'Select a user. The email address for this account will be used to pull the Gravatar image.', 'display-featured-image-genesis' ), + 'flex' => true, + 'choices' => $options, +);