mirror of
https://github.com/10h30/display-featured-image-genesis.git
synced 2026-06-05 15:08:20 +09:00
Move settings definitions to new class
This commit is contained in:
@@ -0,0 +1,268 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2017 Robin Cornett
|
||||
*/
|
||||
|
||||
class Display_Featured_Image_Genesis_Settings_Define extends Display_Featured_Image_Genesis_Helper {
|
||||
|
||||
/**
|
||||
* Define tabs for the settings page.
|
||||
* @return array
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function define_tabs() {
|
||||
return array(
|
||||
'main' => 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;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* @package DisplayFeaturedImageGenesis
|
||||
* @author Robin Cornett <hello@robincornett.com>
|
||||
* @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( '<p class="description">%s</p>', 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 );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user