diff --git a/includes/widgets/class-displayfeaturedimagegenesis-widgets-form.php b/includes/widgets/class-displayfeaturedimagegenesis-widgets-form.php index dff97f9..0d62a2b 100644 --- a/includes/widgets/class-displayfeaturedimagegenesis-widgets-form.php +++ b/includes/widgets/class-displayfeaturedimagegenesis-widgets-form.php @@ -29,7 +29,7 @@ class DisplayFeaturedImageGenesisWidgetsForm { /** * @return array */ - protected function get_image_size() { + public function get_image_size() { $sizes = genesis_get_image_sizes(); $options = array(); foreach ( (array) $sizes as $name => $size ) { @@ -42,7 +42,7 @@ class DisplayFeaturedImageGenesisWidgetsForm { /** * @return array */ - protected function get_image_alignment() { + public function get_image_alignment() { return array( 'alignnone' => __( 'None', 'display-featured-image-genesis' ), 'alignleft' => __( 'Left', 'display-featured-image-genesis' ), @@ -51,138 +51,6 @@ class DisplayFeaturedImageGenesisWidgetsForm { ); } - - /** - * Get image fields (used in CPT and term). - * - * @return array - */ - public function get_image_fields() { - return 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' => $this->get_image_size(), - ), - ), - array( - 'method' => 'select', - 'args' => array( - 'id' => 'image_alignment', - 'label' => __( 'Image Alignment', 'display-featured-image-genesis' ), - 'flex' => true, - 'choices' => $this->get_image_alignment(), - ), - ), - ); - } - - /** - * Get the image fields for the author widget. - * - * @return array - */ - public function get_author_image_fields() { - return array( - array( - 'method' => 'checkbox', - 'args' => array( - 'id' => 'show_featured_image', - 'label' => __( 'Show the user\'s featured image.', 'display-featured-image-genesis' ), - ), - ), - array( - 'method' => 'select', - 'args' => array( - 'id' => 'featured_image_size', - 'label' => __( 'Image Size:', 'display-featured-image-genesis' ), - 'flex' => true, - 'choices' => $this->get_image_size(), - ), - ), - array( - 'method' => 'select', - 'args' => array( - 'id' => 'featured_image_alignment', - 'label' => __( 'Image Alignment:', 'display-featured-image-genesis' ), - 'flex' => true, - 'choices' => $this->get_image_alignment(), - ), - ), - ); - } - - /** - * Get the text fields (used in CPT and term). - * - * @return array - */ - public function get_text_fields() { - $label = 'featured-taxonomy' === $this->parent->id_base ? __( 'Term', 'display-featured-image-genesis' ) : __( 'Archive', 'display-featured-image-genesis' ); - return array( - array( - 'method' => 'checkbox', - 'args' => array( - 'id' => 'show_title', - 'label' => sprintf( __( 'Show %s Title', 'display-featured-image-genesis' ), $label ), - ), - ), - array( - 'method' => 'select', - 'args' => array( - 'id' => 'show_content', - 'label' => sprintf( __( 'Show %s Intro Text', 'display-featured-image-genesis' ), $label ), - 'choices' => array( - '' => __( 'None', 'display-featured-image-genesis' ), - 1 => __( 'Intro Text', 'display-featured-image-genesis' ), - 'custom' => __( 'Custom Text (below)', 'display-featured-image-genesis' ), - ), - ), - ), - array( - 'method' => 'textarea', - 'args' => array( - 'id' => 'custom_content', - 'label' => __( 'Custom Intro Text', 'display-featured-image-genesis' ), - ), - ), - ); - } - - /** - * Get the archive fields (used in term and CPT widgets). - * - * @return array - */ - public function get_archive_fields() { - return array( - array( - 'method' => 'checkbox', - 'args' => array( - 'id' => 'archive_link', - 'label' => __( 'Show Archive Link', 'display-featured-image-genesis' ), - ), - ), - array( - 'method' => 'text', - 'args' => array( - 'id' => 'archive_link_text', - 'label' => __( 'Archive Link Text', 'display-featured-image-genesis' ), - ), - ), - ); - } - /** * Build boxes with fields. * @@ -223,10 +91,8 @@ class DisplayFeaturedImageGenesisWidgetsForm { */ public function do_fields( $instance, $fields ) { foreach ( $fields as $field ) { - $method = "do_{$field['method']}"; - if ( method_exists( $this, $method ) ) { - $this->$method( $instance, $field['args'] ); - } + $args = $field['args']; + include $this->path( $field['method'] ); } } @@ -250,36 +116,6 @@ class DisplayFeaturedImageGenesisWidgetsForm { include $this->path( 'select' ); } - /** - * Generic function to build a number input. - * - * @param $instance - * @param $args - */ - public function do_number( $instance, $args ) { - include $this->path( 'number' ); - } - - /** - * Generic function to build a checkbox input. - * - * @param $instance - * @param $args - */ - public function do_checkbox( $instance, $args ) { - include $this->path( 'checkbox' ); - } - - /** - * Generic function to build a textarea input - * - * @param $instance - * @param $args - */ - public function do_textarea( $instance, $args ) { - include $this->path( 'textarea' ); - } - /** * Get path for included files. * diff --git a/includes/widgets/displayfeaturedimagegenesis-author-widget.php b/includes/widgets/displayfeaturedimagegenesis-author-widget.php index 2b5da4f..cb7e22d 100644 --- a/includes/widgets/displayfeaturedimagegenesis-author-widget.php +++ b/includes/widgets/displayfeaturedimagegenesis-author-widget.php @@ -195,10 +195,10 @@ class Display_Featured_Image_Genesis_Author_Widget extends WP_Widget { $form = new DisplayFeaturedImageGenesisWidgetsForm( $this, $new_instance ); return array_merge( - $form->get_author_image_fields(), - $this->get_gravatar_fields(), - $this->get_description_fields(), - $this->get_archive_fields() + include 'fields/author-image.php', + include 'fields/author-gravatar.php', + include 'fields/author-description.php', + include 'fields/author-archive.php' ); } @@ -226,132 +226,22 @@ class Display_Featured_Image_Genesis_Author_Widget extends WP_Widget { ) ); $form->do_boxes( array( - 'author' => $form->get_author_image_fields(), + 'author' => include 'fields/author-image.php', ), 'genesis-widget-column-box-top' ); $form->do_boxes( array( - 'gravatar' => $this->get_gravatar_fields(), + 'gravatar' => include 'fields/author-gravatar.php', ) ); $form->do_boxes( array( - 'description' => $this->get_description_fields(), + 'description' => include 'fields/author-description.php', ) ); $form->do_boxes( array( - 'archive' => $this->get_archive_fields(), + 'archive' => include 'fields/author-archive.php', ) ); } - /** - * Get the gravatar fields. - * - * @return array - */ - protected function get_gravatar_fields() { - return array( - array( - 'method' => 'checkbox', - 'args' => array( - 'id' => 'show_gravatar', - 'label' => __( 'Show the user\'s gravatar.', 'display-featured-image-genesis' ), - ), - ), - array( - 'method' => 'select', - 'args' => array( - 'id' => 'size', - 'label' => __( 'Gravatar Size:', 'display-featured-image-genesis' ), - 'flex' => true, - 'choices' => $this->get_gravatar_sizes(), - ), - ), - array( - 'method' => 'select', - 'args' => array( - 'id' => 'gravatar_alignment', - 'label' => __( 'Gravatar Alignment:', 'display-featured-image-genesis' ), - 'flex' => true, - 'choices' => array( - '' => __( 'None', 'display-featured-image-genesis' ), - 'left' => __( 'Left', 'display-featured-image-genesis' ), - 'right' => __( 'Right', 'display-featured-image-genesis' ), - ), - ), - ), - ); - } - - /** - * Get the author description fields. - * - * @return array - */ - protected function get_description_fields() { - return array( - array( - 'method' => 'select', - 'args' => array( - 'id' => 'author_info', - 'label' => __( 'Text to use as the author description:', 'display-featured-image-genesis' ), - 'flex' => true, - 'choices' => array( - '' => __( 'None', 'display-featured-image-genesis' ), - 'bio' => __( 'Author Bio (from profile)', 'display-featured-image-genesis' ), - 'text' => __( 'Custom Text (below)', 'display-featured-image-genesis' ), - ), - ), - ), - array( - 'method' => 'textarea', - 'args' => array( - 'id' => 'bio_text', - 'label' => __( 'Custom Text Content', 'display-featured-image-genesis' ), - 'flex' => true, - 'rows' => 6, - ), - ), - ); - } - - /** - * Get the archive fields. - * - * @return array - */ - protected function get_archive_fields() { - return array( - array( - 'method' => 'select', - 'args' => array( - 'id' => 'page', - 'label' => __( 'Choose your extended "About Me" page from the list below. This will be the page linked to at the end of the author description.', 'display-featured-image-genesis' ), - 'choices' => $this->get_pages(), - ), - ), - array( - 'method' => 'text', - 'args' => array( - 'id' => 'page_link_text', - 'label' => __( 'Extended page link text', 'display-featured-image-genesis' ), - ), - ), - array( - 'method' => 'checkbox', - 'args' => array( - 'id' => 'posts_link', - 'label' => __( 'Show Author Archive Link?', 'display-featured-image-genesis' ), - ), - ), - array( - 'method' => 'text', - 'args' => array( - 'id' => 'link_text', - 'label' => __( 'Link Text:', 'display-featured-image-genesis' ), - ), - ), - ); - } - /** * Get the authors on the site. * diff --git a/includes/widgets/displayfeaturedimagegenesis-cpt-archive-widget.php b/includes/widgets/displayfeaturedimagegenesis-cpt-archive-widget.php index d2fe763..395f66c 100644 --- a/includes/widgets/displayfeaturedimagegenesis-cpt-archive-widget.php +++ b/includes/widgets/displayfeaturedimagegenesis-cpt-archive-widget.php @@ -319,10 +319,10 @@ class Display_Featured_Image_Genesis_Widget_CPT extends WP_Widget { $form = new DisplayFeaturedImageGenesisWidgetsForm( $this, $instance ); return array_merge( - $this->get_post_type_fields(), - $form->get_text_fields(), - $form->get_image_fields(), - $form->get_archive_fields() + include 'fields/cpt-post_type.php', + include 'fields/text.php', + include 'fields/image.php', + include 'fields/archive.php' ); } @@ -346,41 +346,23 @@ class Display_Featured_Image_Genesis_Widget_CPT extends WP_Widget { ) ); $form->do_boxes( array( - 'post_type' => $this->get_post_type_fields(), + 'post_type' => include 'fields/cpt-post_type.php', ), 'genesis-widget-column-box-top' ); + $label = __( 'Archive', 'display-featured-image-genesis' ); $form->do_boxes( array( - 'words' => $form->get_text_fields(), + 'words' => include 'fields/text.php', ) ); $form->do_boxes( array( - 'image' => $form->get_image_fields(), + 'image' => include 'fields/image.php', ) ); $form->do_boxes( array( - 'archive' => $form->get_archive_fields(), + 'archive' => include 'fields/archive.php', ) ); } - /** - * Get the post type fields. - * - * @return array - */ - protected function get_post_type_fields() { - return array( - array( - 'method' => 'select', - 'args' => array( - 'id' => 'post_type', - 'label' => __( 'Post Type:', 'display-featured-image-genesis' ), - 'flex' => true, - 'choices' => $this->get_post_types(), - ), - ), - ); - } - /** * Get the public registered post types on the site. * diff --git a/includes/widgets/displayfeaturedimagegenesis-taxonomy-widget.php b/includes/widgets/displayfeaturedimagegenesis-taxonomy-widget.php index ad8865a..ca170d2 100644 --- a/includes/widgets/displayfeaturedimagegenesis-taxonomy-widget.php +++ b/includes/widgets/displayfeaturedimagegenesis-taxonomy-widget.php @@ -228,10 +228,10 @@ class Display_Featured_Image_Genesis_Widget_Taxonomy extends WP_Widget { $form = new DisplayFeaturedImageGenesisWidgetsForm( $this, $instance ); return array_merge( - $form->get_text_fields(), - $this->get_taxonomy_fields( $instance ), - $form->get_image_fields(), - $form->get_archive_fields() + include 'fields/text.php', + include 'fields/term-taxonomy.php', + include 'fields/image.php', + include 'fields/archive.php' ); } @@ -257,51 +257,23 @@ class Display_Featured_Image_Genesis_Widget_Taxonomy extends WP_Widget { ) ); $form->do_boxes( array( - 'taxonomy' => $this->get_taxonomy_fields( $instance ), + 'taxonomy' => include 'fields/term-taxonomy.php', ), 'genesis-widget-column-box-top' ); + $label = __( 'Term', 'display-featured-image-genesis' ); $form->do_boxes( array( - 'words' => $form->get_text_fields(), + 'words' => include 'fields/text.php', ) ); $form->do_boxes( array( - 'image' => $form->get_image_fields(), + 'image' => include 'fields/image.php', ), 'genesis-widget-column-box-top' ); $form->do_boxes( array( - 'archive' => $form->get_archive_fields(), + 'archive' => include 'fields/archive.php', ) ); } - /** - * @param $instance - * - * @return array - */ - protected function get_taxonomy_fields( $instance ) { - return array( - array( - 'method' => 'select', - 'args' => array( - 'id' => 'taxonomy', - 'label' => __( 'Taxonomy:', 'display-featured-image-genesis' ), - 'flex' => true, - 'onchange' => sprintf( 'term_postback(\'%s\', this.value );', esc_attr( $this->get_field_id( 'term' ) ) ), - 'choices' => $this->get_taxonomies(), - ), - ), - array( - 'method' => 'select', - 'args' => array( - 'id' => 'term', - 'label' => __( 'Term:', 'display-featured-image-genesis' ), - 'flex' => true, - 'choices' => $this->get_term_lists( $instance, false ), - ), - ), - ); - } - /** * @return array */ diff --git a/includes/widgets/fields/archive.php b/includes/widgets/fields/archive.php new file mode 100644 index 0000000..71af04c --- /dev/null +++ b/includes/widgets/fields/archive.php @@ -0,0 +1,21 @@ + 'checkbox', + 'args' => array( + 'id' => 'archive_link', + 'label' => __( 'Show Archive Link', 'display-featured-image-genesis' ), + ), + ), + array( + 'method' => 'text', + 'args' => array( + 'id' => 'archive_link_text', + 'label' => __( 'Archive Link Text', 'display-featured-image-genesis' ), + ), + ), +); diff --git a/includes/widgets/fields/author-archive.php b/includes/widgets/fields/author-archive.php new file mode 100644 index 0000000..cbdb793 --- /dev/null +++ b/includes/widgets/fields/author-archive.php @@ -0,0 +1,36 @@ + 'select', + 'args' => array( + 'id' => 'page', + 'label' => __( 'Choose your extended "About Me" page from the list below. This will be the page linked to at the end of the author description.', 'display-featured-image-genesis' ), + 'choices' => $this->get_pages(), + ), + ), + array( + 'method' => 'text', + 'args' => array( + 'id' => 'page_link_text', + 'label' => __( 'Extended page link text', 'display-featured-image-genesis' ), + ), + ), + array( + 'method' => 'checkbox', + 'args' => array( + 'id' => 'posts_link', + 'label' => __( 'Show Author Archive Link?', 'display-featured-image-genesis' ), + ), + ), + array( + 'method' => 'text', + 'args' => array( + 'id' => 'link_text', + 'label' => __( 'Link Text:', 'display-featured-image-genesis' ), + ), + ), +); diff --git a/includes/widgets/fields/author-description.php b/includes/widgets/fields/author-description.php new file mode 100644 index 0000000..2b8329c --- /dev/null +++ b/includes/widgets/fields/author-description.php @@ -0,0 +1,29 @@ + 'select', + 'args' => array( + 'id' => 'author_info', + 'label' => __( 'Text to use as the author description:', 'display-featured-image-genesis' ), + 'flex' => true, + 'choices' => array( + '' => __( 'None', 'display-featured-image-genesis' ), + 'bio' => __( 'Author Bio (from profile)', 'display-featured-image-genesis' ), + 'text' => __( 'Custom Text (below)', 'display-featured-image-genesis' ), + ), + ), + ), + array( + 'method' => 'textarea', + 'args' => array( + 'id' => 'bio_text', + 'label' => __( 'Custom Text Content', 'display-featured-image-genesis' ), + 'flex' => true, + 'rows' => 6, + ), + ), +); diff --git a/includes/widgets/fields/author-gravatar.php b/includes/widgets/fields/author-gravatar.php new file mode 100644 index 0000000..f0bb075 --- /dev/null +++ b/includes/widgets/fields/author-gravatar.php @@ -0,0 +1,36 @@ + 'checkbox', + 'args' => array( + 'id' => 'show_gravatar', + 'label' => __( 'Show the user\'s gravatar.', 'display-featured-image-genesis' ), + ), + ), + array( + 'method' => 'select', + 'args' => array( + 'id' => 'size', + 'label' => __( 'Gravatar Size:', 'display-featured-image-genesis' ), + 'flex' => true, + 'choices' => $this->get_gravatar_sizes(), + ), + ), + array( + 'method' => 'select', + 'args' => array( + 'id' => 'gravatar_alignment', + 'label' => __( 'Gravatar Alignment:', 'display-featured-image-genesis' ), + 'flex' => true, + 'choices' => array( + '' => __( 'None', 'display-featured-image-genesis' ), + 'left' => __( 'Left', 'display-featured-image-genesis' ), + 'right' => __( 'Right', 'display-featured-image-genesis' ), + ), + ), + ), +); diff --git a/includes/widgets/fields/author-image.php b/includes/widgets/fields/author-image.php new file mode 100644 index 0000000..ed37e6c --- /dev/null +++ b/includes/widgets/fields/author-image.php @@ -0,0 +1,32 @@ + 'checkbox', + 'args' => array( + 'id' => 'show_featured_image', + 'label' => __( 'Show the user\'s featured image.', 'display-featured-image-genesis' ), + ), + ), + array( + 'method' => 'select', + 'args' => array( + 'id' => 'featured_image_size', + 'label' => __( 'Image Size:', 'display-featured-image-genesis' ), + 'flex' => true, + 'choices' => $form->get_image_size(), + ), + ), + array( + 'method' => 'select', + 'args' => array( + 'id' => 'featured_image_alignment', + 'label' => __( 'Image Alignment:', 'display-featured-image-genesis' ), + 'flex' => true, + 'choices' => $form->get_image_alignment(), + ), + ), +); diff --git a/includes/widgets/fields/cpt-post_type.php b/includes/widgets/fields/cpt-post_type.php new file mode 100644 index 0000000..cf0ab6f --- /dev/null +++ b/includes/widgets/fields/cpt-post_type.php @@ -0,0 +1,16 @@ + 'select', + 'args' => array( + 'id' => 'post_type', + 'label' => __( 'Post Type:', 'display-featured-image-genesis' ), + 'flex' => true, + 'choices' => $this->get_post_types(), + ), + ), +); diff --git a/includes/widgets/fields/image.php b/includes/widgets/fields/image.php new file mode 100644 index 0000000..56c6cbd --- /dev/null +++ b/includes/widgets/fields/image.php @@ -0,0 +1,32 @@ + '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(), + ), + ), +); diff --git a/includes/widgets/fields/term-taxonomy.php b/includes/widgets/fields/term-taxonomy.php new file mode 100644 index 0000000..0c918f8 --- /dev/null +++ b/includes/widgets/fields/term-taxonomy.php @@ -0,0 +1,26 @@ + 'select', + 'args' => array( + 'id' => 'taxonomy', + 'label' => __( 'Taxonomy:', 'display-featured-image-genesis' ), + 'flex' => true, + 'onchange' => sprintf( 'term_postback(\'%s\', this.value );', esc_attr( $this->get_field_id( 'term' ) ) ), + 'choices' => $this->get_taxonomies(), + ), + ), + array( + 'method' => 'select', + 'args' => array( + 'id' => 'term', + 'label' => __( 'Term:', 'display-featured-image-genesis' ), + 'flex' => true, + 'choices' => $this->get_term_lists( $instance, false ), + ), + ), +); diff --git a/includes/widgets/fields/text.php b/includes/widgets/fields/text.php new file mode 100644 index 0000000..08dcb69 --- /dev/null +++ b/includes/widgets/fields/text.php @@ -0,0 +1,38 @@ + 'checkbox', + 'args' => array( + 'id' => 'show_title', + /* translators: this will read Term or Archive */ + 'label' => sprintf( __( 'Show %s Title', 'display-featured-image-genesis' ), $label ), + ), + ), + array( + 'method' => 'select', + 'args' => array( + 'id' => 'show_content', + /* translators: this will read Term or Archive */ + 'label' => sprintf( __( 'Show %s Intro Text', 'display-featured-image-genesis' ), $label ), + 'choices' => array( + '' => __( 'None', 'display-featured-image-genesis' ), + 1 => __( 'Intro Text', 'display-featured-image-genesis' ), + 'custom' => __( 'Custom Text (below)', 'display-featured-image-genesis' ), + ), + ), + ), + array( + 'method' => 'textarea', + 'args' => array( + 'id' => 'custom_content', + 'label' => __( 'Custom Intro Text', 'display-featured-image-genesis' ), + ), + ), +);