mirror of
https://github.com/10h30/display-featured-image-genesis.git
synced 2026-07-11 18:46:03 +09:00
Add customizer class/settings
This commit is contained in:
@@ -36,6 +36,7 @@ function display_featured_image_genesis_require() {
|
||||
'class-displayfeaturedimagegenesis-admin',
|
||||
'class-displayfeaturedimagegenesis-author',
|
||||
'class-displayfeaturedimagegenesis-common',
|
||||
'class-displayfeaturedimagegenesis-customizer',
|
||||
'class-displayfeaturedimagegenesis-description',
|
||||
'class-displayfeaturedimagegenesis-output',
|
||||
'class-displayfeaturedimagegenesis-postmeta',
|
||||
@@ -55,6 +56,7 @@ $displayfeaturedimagegenesis_helper = new Display_Featured_Image_Genesis_He
|
||||
$displayfeaturedimagegenesis_admin = new Display_Featured_Image_Genesis_Admin();
|
||||
$displayfeaturedimagegenesis_author = new Display_Featured_Image_Genesis_Author();
|
||||
$displayfeaturedimagegenesis_common = new Display_Featured_Image_Genesis_Common();
|
||||
$displayfeaturedimagegenesis_customizer = new Display_Featured_Image_Genesis_Customizer();
|
||||
$displayfeaturedimagegenesis_description = new Display_Featured_Image_Genesis_Description();
|
||||
$displayfeaturedimagegenesis_output = new Display_Featured_Image_Genesis_Output();
|
||||
$displayfeaturedimagegenesis_post_meta = new Display_Featured_Image_Genesis_Post_Meta();
|
||||
@@ -66,6 +68,7 @@ $displayfeaturedimage = new Display_Featured_Image_Genesis(
|
||||
$displayfeaturedimagegenesis_admin,
|
||||
$displayfeaturedimagegenesis_author,
|
||||
$displayfeaturedimagegenesis_common,
|
||||
$displayfeaturedimagegenesis_customizer,
|
||||
$displayfeaturedimagegenesis_description,
|
||||
$displayfeaturedimagegenesis_output,
|
||||
$displayfeaturedimagegenesis_post_meta,
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class to add customizer settings.
|
||||
* Class Display_Featured_Image_Genesis_Customizer
|
||||
* @package Display_Featured_Image_Genesis
|
||||
* @copyright 2016 Robin Cornett
|
||||
*/
|
||||
class Display_Featured_Image_Genesis_Customizer {
|
||||
|
||||
/**
|
||||
* Section for the Customizer.
|
||||
* @var string $section
|
||||
*/
|
||||
protected $section = 'displayfeaturedimagegenesis';
|
||||
|
||||
/**
|
||||
* Display Featured Image for Genesis Settings class.
|
||||
* @var $settings SuperSide_Me_Settings
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* Default plugin settings.
|
||||
* @var array $defaults
|
||||
*/
|
||||
protected $defaults;
|
||||
|
||||
/**
|
||||
* Adds the individual sections, settings, and controls to the theme customizer
|
||||
* @param $wp_customize WP_Customize_Manager
|
||||
* @uses add_section() adds a section to the customizer
|
||||
*/
|
||||
public function customizer( $wp_customize ) {
|
||||
|
||||
$this->settings = new Display_Featured_Image_Genesis_Settings();
|
||||
$this->defaults = $this->settings->defaults();
|
||||
$setting = get_option( 'displayfeaturedimagegenesis', false );
|
||||
if ( ! $setting ) {
|
||||
add_option( 'displayfeaturedimagegenesis', $this->defaults );
|
||||
}
|
||||
$wp_customize->add_section(
|
||||
$this->section,
|
||||
array(
|
||||
'title' => __( 'Display Featured Image for Genesis', 'display-featured-image-genesis' ),
|
||||
'description' => __( 'Only general settings are available in the Customizer; more can be found on the Display Featured Image for Genesis settings page.', 'display-featured-image-genesis' ),
|
||||
'priority' => 90,
|
||||
)
|
||||
);
|
||||
|
||||
$this->build_fields( $wp_customize );
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the Display Featured Image for Genesis Customizer settings panel.
|
||||
* @param $wp_customize
|
||||
*/
|
||||
protected function build_fields( $wp_customize ) {
|
||||
$fields = $this->number_fields();
|
||||
foreach ( $fields as $field ) {
|
||||
$this->add_control( $wp_customize, $field );
|
||||
}
|
||||
|
||||
$this->do_image_setting( $wp_customize, $this->default_image() );
|
||||
|
||||
$checkboxes = $this->checkbox_fields();
|
||||
foreach ( $checkboxes as $checkbox ) {
|
||||
$checkbox['sanitize_callback'] = array( $this, 'one_zero' );
|
||||
$checkbox['type'] = 'checkbox';
|
||||
$this->add_control( $wp_customize, $checkbox );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
function number_fields() {
|
||||
return array(
|
||||
array(
|
||||
'setting' => 'less_header',
|
||||
'label' => __( 'Height', 'display-featured-image-genesis' ),
|
||||
'sanitize_callback' => 'absint',
|
||||
'type' => 'number',
|
||||
),
|
||||
array(
|
||||
'setting' => 'max_height',
|
||||
'label' => __( 'Maximum Height', 'display-featured-image-genesis' ),
|
||||
'sanitize_callback' => 'absint',
|
||||
'type' => 'number',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
protected function checkbox_fields() {
|
||||
return array(
|
||||
array(
|
||||
'setting' => 'exclude_front',
|
||||
'label' => __( 'Do not show the Featured Image on the Front Page of the site.', 'display-featured-image-genesis' ),
|
||||
),
|
||||
array(
|
||||
'setting' => 'keep_titles',
|
||||
'label' => __( 'Do not move the titles to overlay the backstretch Featured Image.', 'display-featured-image-genesis' ),
|
||||
),
|
||||
array(
|
||||
'setting' => 'move_excerpts',
|
||||
'label' => __( 'Move excerpts (if used) on single pages and move archive/taxonomy descriptions to overlay the Featured Image.', 'display-featured-image-genesis' ),
|
||||
),
|
||||
array(
|
||||
'setting' => 'thumbnails',
|
||||
'label' => __( 'Use term/post type fallback images for content archive thumbnails?', 'display-featured-image-genesis' ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
protected function default_image() {
|
||||
return array(
|
||||
'setting' => 'default',
|
||||
'description' => __( 'Set the sitewide default image.', 'display-featured-image-genesis' ),
|
||||
'label' => __( 'Default Image', 'display-featured-image-genesis' ),
|
||||
'transport' => 'postMessage',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $wp_customize WP_Customize_Manager
|
||||
* @param $setting
|
||||
*/
|
||||
protected function do_color_setting( $wp_customize, $setting ) {
|
||||
|
||||
$this->add_setting( $wp_customize, $setting );
|
||||
$wp_customize->add_control(
|
||||
new WP_Customize_Color_Control(
|
||||
$wp_customize,
|
||||
$this->section . '[' . $setting['setting'] . ']',
|
||||
array(
|
||||
'description' => $setting['description'],
|
||||
'label' => $setting['label'],
|
||||
'section' => $this->section,
|
||||
'settings' => $this->section . '[' . $setting['setting'] . ']',
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $wp_customize WP_Customize_Manager
|
||||
* @param $setting
|
||||
*/
|
||||
protected function do_image_setting( $wp_customize, $setting ) {
|
||||
$this->add_setting( $wp_customize, $setting );
|
||||
$wp_customize->add_control(
|
||||
new WP_Customize_Image_Control(
|
||||
$wp_customize,
|
||||
$this->section . '[' . $setting['setting'] . ']',
|
||||
array(
|
||||
'label' => $setting['label'],
|
||||
'section' => $this->section,
|
||||
'settings' => $this->section . '[' . $setting['setting'] . ']',
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $wp_customize WP_Customize_Manager
|
||||
* @param $setting
|
||||
*/
|
||||
protected function add_control( $wp_customize, $setting ) {
|
||||
$this->add_setting( $wp_customize, $setting );
|
||||
$wp_customize->add_control(
|
||||
$this->section . '[' . $setting['setting'] . ']',
|
||||
array(
|
||||
'label' => $setting['label'],
|
||||
'section' => $this->section,
|
||||
'type' => isset( $setting['type'] ) ? $setting['type'] : '',
|
||||
'description' => isset( $setting['description'] ) ? $setting['description'] : '',
|
||||
'choices' => isset( $setting['choices'] ) ? $setting['choices'] : array(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $wp_customize WP_Customize_Manager
|
||||
* @param $setting
|
||||
*/
|
||||
protected function add_setting( $wp_customize, $setting ) {
|
||||
$wp_customize->add_setting(
|
||||
$this->section . '[' . $setting['setting'] . ']',
|
||||
array(
|
||||
'capability' => 'manage_options',
|
||||
'default' => $this->defaults[ $setting['setting'] ],
|
||||
'sanitize_callback' => $setting['sanitize_callback'],
|
||||
'type' => 'option',
|
||||
'transport' => isset( $setting['transport'] ) ? $setting['transport'] : 'refresh',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $input
|
||||
* @return int
|
||||
*/
|
||||
public function one_zero( $input ) {
|
||||
return (int) (bool) $input;
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,11 @@ class Display_Featured_Image_Genesis {
|
||||
*/
|
||||
protected $common;
|
||||
|
||||
/**
|
||||
* @var $customizer Display_Featured_Image_Genesis_Customizer
|
||||
*/
|
||||
protected $customizer;
|
||||
|
||||
/**
|
||||
* All archive description functions.
|
||||
* @var Display_Featured_Image_Genesis_Description $description
|
||||
@@ -76,16 +81,18 @@ class Display_Featured_Image_Genesis {
|
||||
* @param $admin
|
||||
* @param $author
|
||||
* @param $common
|
||||
* @param $customizer
|
||||
* @param $description
|
||||
* @param $output
|
||||
* @param $rss
|
||||
* @param $settings
|
||||
* @param $taxonomies
|
||||
*/
|
||||
function __construct( $admin, $author, $common, $description, $output, $post_meta, $rss, $settings, $taxonomies ) {
|
||||
function __construct( $admin, $author, $common, $customizer, $description, $output, $post_meta, $rss, $settings, $taxonomies ) {
|
||||
$this->admin = $admin;
|
||||
$this->author = $author;
|
||||
$this->common = $common;
|
||||
$this->customizer = $customizer;
|
||||
$this->description = $description;
|
||||
$this->output = $output;
|
||||
$this->post_meta = $post_meta;
|
||||
@@ -122,6 +129,8 @@ class Display_Featured_Image_Genesis {
|
||||
add_filter( 'admin_post_thumbnail_html', array( $this->post_meta, 'meta_box' ), 10, 2 );
|
||||
add_action( 'save_post', array( $this->post_meta, 'save_meta' ) );
|
||||
|
||||
add_action( 'customize_register', array( $this->customizer, 'customizer' ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user