From 68034ae957274c4f254de901b8a742d84cc8b43a Mon Sep 17 00:00:00 2001 From: Robin Cornett Date: Fri, 19 May 2017 07:46:11 -0400 Subject: [PATCH] Refactor CPT widget --- ...eaturedimagegenesis-cpt-archive-widget.php | 172 ++++++++++-------- 1 file changed, 92 insertions(+), 80 deletions(-) diff --git a/includes/widgets/displayfeaturedimagegenesis-cpt-archive-widget.php b/includes/widgets/displayfeaturedimagegenesis-cpt-archive-widget.php index 409998c..f6a86cb 100644 --- a/includes/widgets/displayfeaturedimagegenesis-cpt-archive-widget.php +++ b/includes/widgets/displayfeaturedimagegenesis-cpt-archive-widget.php @@ -30,7 +30,7 @@ class Display_Featured_Image_Genesis_Widget_CPT extends WP_Widget { * * @since 2.0.0 */ - function __construct() { + public function __construct() { $this->defaults = array( 'title' => '', @@ -67,7 +67,7 @@ class Display_Featured_Image_Genesis_Widget_CPT extends WP_Widget { * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. * @param array $instance The settings for the particular instance of the widget */ - function widget( $args, $instance ) { + public function widget( $args, $instance ) { // Merge with defaults $instance = wp_parse_args( (array) $instance, $this->defaults ); @@ -191,94 +191,106 @@ class Display_Featured_Image_Genesis_Widget_CPT extends WP_Widget { * * @param array $instance Current settings */ - function form( $instance ) { + public function form( $instance ) { //* Merge with defaults $instance = wp_parse_args( (array) $instance, $this->defaults ); + $form = new DisplayFeaturedImageGenesisWidgets( $this, $instance ); - ?> -

- - -

+ $form->do_text( $instance, array( + 'id' => 'title', + 'label' => __( 'Title:', 'display-featured-image-genesis' ), + 'class' => 'widefat', + ) ); -
+ echo '
'; -
+ $form->do_boxes( array( + 'post_type' => array( + array( + 'method' => 'select', + 'args' => array( + 'id' => 'post_type', + 'label' => __( 'Post Type:', 'display-featured-image-genesis' ), + 'flex' => true, + 'choices' => $this->get_post_types(), + ), + ), + ), + ), 'genesis-widget-column-box-top' ); -

- - -

+ echo '
'; + echo '
'; -
- -
- -

- /> - -

- -

- /> - -

- -
- -
- -
- -
- -

- /> - -

- -

- - -

- -

- - -

- -
- -
- do_boxes( array( + 'image' => array( + array( + 'method' => 'checkbox', + 'args' => array( + 'id' => 'show_image', + 'label' => __( 'Show Featured Image', 'display-featured-image-genesis' ), + ), + ), + array( + 'method' => 'select', + 'args' => array( + 'id' => 'image_size', + 'label' => __( 'Image Size:', 'display-featured-image-genesis' ), + 'flex' => true, + 'choices' => $form->get_image_size(), + ), + ), + array( + 'method' => 'select', + 'args' => array( + 'id' => 'image_alignment', + 'label' => __( 'Image Alignment', 'display-featured-image-genesis' ), + 'flex' => true, + 'choices' => $form->get_image_alignment(), + ), + ), + ), + ), 'genesis-widget-column-box-top' ); + echo '
'; } + /** + * @return mixed + */ + protected function get_post_types() { + $args = array( + 'public' => true, + '_builtin' => false, + 'has_archive' => true, + ); + $output = 'objects'; + $post_types = get_post_types( $args, $output ); + + $options['post'] = __( 'Posts', 'display-featured-image-genesis' ); + foreach ( $post_types as $post_type ) { + $options[ $post_type->name ] = $post_type->label; + } + + return $options; + } }