From 2028fc8e95f08f7e49e9571af1f00b852e6e55cc Mon Sep 17 00:00:00 2001 From: Robin Cornett Date: Wed, 25 Oct 2017 11:13:39 -0400 Subject: [PATCH] Move settings definitions to new class --- ...ayfeaturedimagegenesis-settings-define.php | 268 ++++++++++++++++++ ...s-displayfeaturedimagegenesis-settings.php | 255 +---------------- 2 files changed, 276 insertions(+), 247 deletions(-) create mode 100644 includes/settings/class-displayfeaturedimagegenesis-settings-define.php diff --git a/includes/settings/class-displayfeaturedimagegenesis-settings-define.php b/includes/settings/class-displayfeaturedimagegenesis-settings-define.php new file mode 100644 index 0000000..3def23e --- /dev/null +++ b/includes/settings/class-displayfeaturedimagegenesis-settings-define.php @@ -0,0 +1,268 @@ + array( + 'id' => 'main', + 'tab' => __( 'Main', 'display-featured-image-genesis' ), + ), + 'style' => array( + 'id' => 'style', + 'tab' => __( 'Backstretch Output', 'display-featured-image-genesis' ), + ), + 'cpt' => array( + 'id' => 'cpt', + 'tab' => __( 'Content Types', 'display-featured-image-genesis' ), + ), + ); + } + + /** + * Register plugin settings page sections + * + * @since 2.3.0 + */ + public function register_sections() { + return array( + 'main' => array( + 'id' => 'main', + 'title' => __( 'Optional Sitewide Settings', 'display-featured-image-genesis' ), + ), + 'style' => array( + 'id' => 'style', + 'title' => __( 'Display Settings', 'display-featured-image-genesis' ), + ), + 'cpt' => array( + 'id' => 'cpt', + 'title' => __( 'Featured Images for Custom Content Types', 'display-featured-image-genesis' ), + ), + ); + } + + /** + * Register plugin settings fields + * @return array all settings fields + * + * @since 2.3.0 + */ + public function register_fields() { + + return array_merge( $this->define_main_fields(), $this->define_style_fields(), $this->define_cpt_fields() ); + } + + /** + * Define the fields for the main/first tab. + * @return array + */ + protected function define_main_fields() { + $common = new Display_Featured_Image_Genesis_Common(); + $large = $common->minimum_backstretch_width(); + + return array( + array( + 'id' => 'default', + 'title' => __( 'Default Featured Image', 'display-featured-image-genesis' ), + 'callback' => 'set_default_image', + 'section' => 'main', + ), + array( + 'id' => 'always_default', + 'title' => __( 'Always Use Default', 'display-featured-image-genesis' ), + 'callback' => 'do_checkbox', + 'section' => 'main', + 'label' => __( 'Always use the default image, even if a featured image is set.', 'display-featured-image-genesis' ), + 'description' => sprintf( + /* translators: placeholder is a number equivalent to the width of the site's Large image (Settings > Media) */ + esc_html__( 'If you would like to use a default image for the featured image, upload it here. Must be at least %1$s pixels wide.', 'display-featured-image-genesis' ), + absint( $large + 1 ) + ), + ), + array( + 'id' => 'exclude_front', + 'title' => __( 'Skip Front Page', 'display-featured-image-genesis' ), + 'callback' => 'do_checkbox', + 'section' => 'main', + 'label' => __( 'Do not show the Featured Image on the Front Page of the site.', 'display-featured-image-genesis' ), + ), + array( + 'id' => 'keep_titles', + 'title' => __( 'Do Not Move Titles', 'display-featured-image-genesis' ), + 'callback' => 'do_checkbox', + 'section' => 'main', + 'label' => __( 'Do not move the titles to overlay the backstretch Featured Image.', 'display-featured-image-genesis' ), + ), + array( + 'id' => 'move_excerpts', + 'title' => __( 'Move Excerpts/Archive Descriptions', 'display-featured-image-genesis' ), + 'callback' => 'do_checkbox', + 'section' => 'main', + 'label' => __( 'Move excerpts (if used) on single pages and move archive/taxonomy descriptions to overlay the Featured Image.', 'display-featured-image-genesis' ), + ), + array( + 'id' => 'is_paged', + 'title' => __( 'Show Featured Image on Subsequent Blog Pages', 'display-featured-image-genesis' ), + 'callback' => 'do_checkbox', + 'section' => 'main', + 'label' => __( 'Show featured image on pages 2+ of blogs and archives.', 'display-featured-image-genesis' ), + ), + array( + 'id' => 'feed_image', + 'title' => __( 'Add Featured Image to Feed?', 'display-featured-image-genesis' ), + 'callback' => 'do_checkbox', + 'section' => 'main', + 'label' => __( 'Optionally, add the featured image to your RSS feed.', 'display-featured-image-genesis' ), + ), + array( + 'id' => 'thumbnails', + 'title' => __( 'Archive Thumbnails', 'display-featured-image-genesis' ), + 'callback' => 'do_checkbox', + 'section' => 'main', + 'label' => __( 'Use term/post type fallback images for content archives?', 'display-featured-image-genesis' ), + ), + array( + 'id' => 'shortcode', + 'title' => __( 'Add Shortcode Buttons', 'display-featured-image-genesis' ), + 'callback' => 'do_checkbox_array', + 'section' => 'main', + 'options' => array( + 'displayfeaturedimagegenesis_term' => __( 'Featured Term Widget', 'display-featured-image-genesis' ), + 'displayfeaturedimagegenesis_author' => __( 'Featured Author Widget', 'display-featured-image-genesis' ), + 'displayfeaturedimagegenesis_post_type' => __( 'Featured Post Type Widget', 'display-featured-image-genesis' ), + ), + ), + ); + } + + /** + * Define the fields for the style tab. + * @return array + */ + protected function define_style_fields() { + return array( + array( + 'id' => 'less_header', + 'title' => __( 'Height', 'display-featured-image-genesis' ), + 'callback' => 'do_number', + 'section' => 'style', + 'label' => __( 'pixels to remove', 'display-featured-image-genesis' ), + 'min' => 0, + 'max' => 400, + ), + array( + 'id' => 'max_height', + 'title' => __( 'Maximum Height', 'display-featured-image-genesis' ), + 'callback' => 'do_number', + 'section' => 'style', + 'label' => __( 'pixels', 'display-featured-image-genesis' ), + 'min' => 100, + 'max' => 1000, + ), + array( + 'id' => 'centeredX', + 'title' => __( 'Center Horizontally', 'display-featured-image-genesis' ), + 'callback' => 'do_radio_buttons', + 'section' => 'style', + 'buttons' => $this->pick_center(), + 'legend' => __( 'Center the backstretch image on the horizontal axis?', 'display-featured-image-genesis' ), + ), + array( + 'id' => 'centeredY', + 'title' => __( 'Center Vertically', 'display-featured-image-genesis' ), + 'callback' => 'do_radio_buttons', + 'section' => 'style', + 'buttons' => $this->pick_center(), + 'legend' => __( 'Center the backstretch image on the vertical axis?', 'display-featured-image-genesis' ), + ), + array( + 'id' => 'fade', + 'title' => __( 'Fade', 'display-featured-image-genesis' ), + 'callback' => 'do_number', + 'section' => 'style', + 'label' => __( 'milliseconds', 'display-featured-image-genesis' ), + 'min' => 0, + 'max' => 20000, + ), + ); + } + + /** + * Define the fields for the content types tab. + * @return array + */ + protected function define_cpt_fields() { + $fields = array( + array( + 'id' => 'post_types][search', + 'title' => __( 'Search Results', 'display-featured-image-genesis' ), + 'callback' => 'set_cpt_image', + 'section' => 'cpt', + 'post_type' => 'search', + ), + array( + 'id' => 'post_types][fourohfour', + 'title' => __( '404 Page', 'display-featured-image-genesis' ), + 'callback' => 'set_cpt_image', + 'section' => 'cpt', + 'post_type' => 'fourohfour', + ), + array( + 'id' => 'skip', + 'title' => __( 'Skip Content Types', 'display-featured-image-genesis' ), + 'callback' => 'do_checkbox_array', + 'section' => 'cpt', + 'options' => $this->get_post_types(), + ), + ); + + $post_types = $this->get_post_types(); + if ( $post_types ) { + unset( $post_types['post'] ); + foreach ( $post_types as $post_type => $label ) { + $fields[] = array( + 'id' => 'post_types][' . esc_attr( $post_type ), + 'title' => esc_attr( $label ), + 'callback' => 'set_cpt_image', + 'section' => 'cpt', + 'post_type' => $post_type, + ); + } + } + + return $fields; + } + + /** + * @return array + */ + public function pick_center() { + return array( + 1 => __( 'Center', 'display-featured-image-genesis' ), + 0 => __( 'Do Not Center', 'display-featured-image-genesis' ), + ); + } + + /** + * Get the post types as options. + * @return array + */ + protected function get_post_types() { + $post_types = $this->get_content_types_built_in(); + $options = array(); + foreach ( $post_types as $post_type ) { + $object = get_post_type_object( $post_type ); + $options[ $post_type ] = $object->label; + } + + return $options; + } +} diff --git a/includes/settings/class-displayfeaturedimagegenesis-settings.php b/includes/settings/class-displayfeaturedimagegenesis-settings.php index eee7fc7..b607a53 100644 --- a/includes/settings/class-displayfeaturedimagegenesis-settings.php +++ b/includes/settings/class-displayfeaturedimagegenesis-settings.php @@ -1,10 +1,6 @@ - * @license GPL-2.0+ - * @link https://robincornett.com - * @copyright 2014-2017 Robin Cornett Creative, LLC + * Copyright (c) 2017 Robin Cornett */ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Genesis_Helper { @@ -65,8 +61,10 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen * Build out the settings page sections/fields. */ public function build_settings_page() { - $sections = $this->register_sections(); - $this->fields = $this->register_fields(); + include_once plugin_dir_path( __FILE__ ) . 'class-displayfeaturedimagegenesis-settings-define.php'; + $definitions = new Display_Featured_Image_Genesis_Settings_Define(); + $sections = $definitions->register_sections(); + $this->fields = $definitions->register_fields(); $this->add_sections( $sections ); $this->add_fields( $this->fields, $sections ); } @@ -173,219 +171,6 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen ); } - /** - * Register plugin settings page sections - * - * @since 2.3.0 - */ - protected function register_sections() { - return array( - 'main' => array( - 'id' => 'main', - 'title' => __( 'Optional Sitewide Settings', 'display-featured-image-genesis' ), - ), - 'style' => array( - 'id' => 'style', - 'title' => __( 'Display Settings', 'display-featured-image-genesis' ), - ), - 'cpt' => array( - 'id' => 'cpt', - 'title' => __( 'Featured Images for Custom Content Types', 'display-featured-image-genesis' ), - ), - ); - } - - /** - * Register plugin settings fields - * @return array all settings fields - * - * @since 2.3.0 - */ - protected function register_fields() { - - return array_merge( $this->define_main_fields(), $this->define_style_fields(), $this->define_cpt_fields() ); - } - - /** - * Define the fields for the main/first tab. - * @return array - */ - protected function define_main_fields() { - $large = $this->common->minimum_backstretch_width(); - - return array( - array( - 'id' => 'default', - 'title' => __( 'Default Featured Image', 'display-featured-image-genesis' ), - 'callback' => 'set_default_image', - 'section' => 'main', - ), - array( - 'id' => 'always_default', - 'title' => __( 'Always Use Default', 'display-featured-image-genesis' ), - 'callback' => 'do_checkbox', - 'section' => 'main', - 'label' => __( 'Always use the default image, even if a featured image is set.', 'display-featured-image-genesis' ), - 'description' => sprintf( - /* translators: placeholder is a number equivalent to the width of the site's Large image (Settings > Media) */ - esc_html__( 'If you would like to use a default image for the featured image, upload it here. Must be at least %1$s pixels wide.', 'display-featured-image-genesis' ), - absint( $large + 1 ) - ), - ), - array( - 'id' => 'exclude_front', - 'title' => __( 'Skip Front Page', 'display-featured-image-genesis' ), - 'callback' => 'do_checkbox', - 'section' => 'main', - 'label' => __( 'Do not show the Featured Image on the Front Page of the site.', 'display-featured-image-genesis' ), - ), - array( - 'id' => 'keep_titles', - 'title' => __( 'Do Not Move Titles', 'display-featured-image-genesis' ), - 'callback' => 'do_checkbox', - 'section' => 'main', - 'label' => __( 'Do not move the titles to overlay the backstretch Featured Image.', 'display-featured-image-genesis' ), - ), - array( - 'id' => 'move_excerpts', - 'title' => __( 'Move Excerpts/Archive Descriptions', 'display-featured-image-genesis' ), - 'callback' => 'do_checkbox', - 'section' => 'main', - 'label' => __( 'Move excerpts (if used) on single pages and move archive/taxonomy descriptions to overlay the Featured Image.', 'display-featured-image-genesis' ), - ), - array( - 'id' => 'is_paged', - 'title' => __( 'Show Featured Image on Subsequent Blog Pages', 'display-featured-image-genesis' ), - 'callback' => 'do_checkbox', - 'section' => 'main', - 'label' => __( 'Show featured image on pages 2+ of blogs and archives.', 'display-featured-image-genesis' ), - ), - array( - 'id' => 'feed_image', - 'title' => __( 'Add Featured Image to Feed?', 'display-featured-image-genesis' ), - 'callback' => 'do_checkbox', - 'section' => 'main', - 'label' => __( 'Optionally, add the featured image to your RSS feed.', 'display-featured-image-genesis' ), - ), - array( - 'id' => 'thumbnails', - 'title' => __( 'Archive Thumbnails', 'display-featured-image-genesis' ), - 'callback' => 'do_checkbox', - 'section' => 'main', - 'label' => __( 'Use term/post type fallback images for content archives?', 'display-featured-image-genesis' ), - ), - array( - 'id' => 'shortcode', - 'title' => __( 'Add Shortcode Buttons', 'display-featured-image-genesis' ), - 'callback' => 'do_checkbox_array', - 'section' => 'main', - 'options' => array( - 'displayfeaturedimagegenesis_term' => __( 'Featured Term Widget', 'display-featured-image-genesis' ), - 'displayfeaturedimagegenesis_author' => __( 'Featured Author Widget', 'display-featured-image-genesis' ), - 'displayfeaturedimagegenesis_post_type' => __( 'Featured Post Type Widget', 'display-featured-image-genesis' ), - ), - ), - ); - } - - /** - * Define the fields for the style tab. - * @return array - */ - protected function define_style_fields() { - return array( - array( - 'id' => 'less_header', - 'title' => __( 'Height', 'display-featured-image-genesis' ), - 'callback' => 'do_number', - 'section' => 'style', - 'label' => __( 'pixels to remove', 'display-featured-image-genesis' ), - 'min' => 0, - 'max' => 400, - ), - array( - 'id' => 'max_height', - 'title' => __( 'Maximum Height', 'display-featured-image-genesis' ), - 'callback' => 'do_number', - 'section' => 'style', - 'label' => __( 'pixels', 'display-featured-image-genesis' ), - 'min' => 100, - 'max' => 1000, - ), - array( - 'id' => 'centeredX', - 'title' => __( 'Center Horizontally', 'display-featured-image-genesis' ), - 'callback' => 'do_radio_buttons', - 'section' => 'style', - 'buttons' => $this->pick_center(), - 'legend' => __( 'Center the backstretch image on the horizontal axis?', 'display-featured-image-genesis' ), - ), - array( - 'id' => 'centeredY', - 'title' => __( 'Center Vertically', 'display-featured-image-genesis' ), - 'callback' => 'do_radio_buttons', - 'section' => 'style', - 'buttons' => $this->pick_center(), - 'legend' => __( 'Center the backstretch image on the vertical axis?', 'display-featured-image-genesis' ), - ), - array( - 'id' => 'fade', - 'title' => __( 'Fade', 'display-featured-image-genesis' ), - 'callback' => 'do_number', - 'section' => 'style', - 'label' => __( 'milliseconds', 'display-featured-image-genesis' ), - 'min' => 0, - 'max' => 20000, - ), - ); - } - - /** - * Define the fields for the content types tab. - * @return array - */ - protected function define_cpt_fields() { - $fields = array( - array( - 'id' => 'post_types][search', - 'title' => __( 'Search Results', 'display-featured-image-genesis' ), - 'callback' => 'set_cpt_image', - 'section' => 'cpt', - 'post_type' => 'search', - ), - array( - 'id' => 'post_types][fourohfour', - 'title' => __( '404 Page', 'display-featured-image-genesis' ), - 'callback' => 'set_cpt_image', - 'section' => 'cpt', - 'post_type' => 'fourohfour', - ), - array( - 'id' => 'skip', - 'title' => __( 'Skip Content Types', 'display-featured-image-genesis' ), - 'callback' => 'do_checkbox_array', - 'section' => 'cpt', - 'options' => $this->get_post_types(), - ), - ); - - if ( $this->post_types ) { - - foreach ( $this->post_types as $post ) { - $object = get_post_type_object( $post ); - $fields[] = array( - 'id' => 'post_types][' . esc_attr( $object->name ), - 'title' => esc_attr( $object->label ), - 'callback' => 'set_cpt_image', - 'section' => 'cpt', - 'post_type' => $object, - ); - } - } - - return $fields; - } - /** * Section description * @@ -497,31 +282,6 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen printf( '

%s

', wp_kses_post( $description ) ); } - /** - * @return array - */ - public function pick_center() { - return array( - 1 => __( 'Center', 'display-featured-image-genesis' ), - 0 => __( 'Do Not Center', 'display-featured-image-genesis' ), - ); - } - - /** - * Get the post types as options. - * @return array - */ - protected function get_post_types() { - $post_types = $this->get_content_types_built_in(); - $options = array(); - foreach ( $post_types as $post_type ) { - $object = get_post_type_object( $post_type ); - $options[ $post_type ] = $object->label; - } - - return $options; - } - /** * validate all inputs * @@ -543,9 +303,10 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen check_admin_referer( $action, $nonce ); $new_value = array_merge( $this->setting, $new_value ); + include_once plugin_dir_path( __FILE__ ) . 'class-displayfeaturedimagegenesis-settings-define.php'; include_once plugin_dir_path( __FILE__ ) . 'class-displayfeaturedimagegenesis-settings-validate.php'; - - $validation = new Display_Featured_Image_Genesis_Settings_Validate( $this->register_fields(), $this->setting ); + $definitions = new Display_Featured_Image_Genesis_Settings_Define(); + $validation = new Display_Featured_Image_Genesis_Settings_Validate( $definitions->register_fields(), $this->setting ); return $validation->validate( $new_value ); }