Created
November 16, 2017 20:47
-
-
Save jcicero518/2add7e3368f01e02b49d3831580d6991 to your computer and use it in GitHub Desktop.
Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * mwcc Theme Customizer | |
| * | |
| * @package mwcc | |
| */ | |
| if ( class_exists( 'WP_Customize_Control' ) ): | |
| class WP_Customize_Alert_Post_Control extends WP_Customize_Control { | |
| public $type = 'site_alert_post'; | |
| public $post_type = 'alert'; | |
| public function render_content() { | |
| $args = [ | |
| 'post_type' => $this->post_type, | |
| 'post_status' => 'publish', | |
| 'order_by' => 'title', | |
| 'order' => 'ASC' | |
| ]; | |
| $alertPosts = new WP_Query( $args ); | |
| if ( $alertPosts->have_posts() ): ?> | |
| <label> | |
| <span class="customize-control-title"><?= esc_html( $this->label ); ?></span> | |
| <select <?php $this->link(); ?>> | |
| <?php | |
| while ( $alertPosts->have_posts() ): | |
| $alertPosts->the_post(); | |
| echo "<option " . selected( $this->value(), get_the_ID() ) . " value='" . get_the_ID() . "'>" . the_title( '', '', false ) . "</option>"; | |
| endwhile; | |
| ?> | |
| </select> | |
| </label> | |
| <?php | |
| endif; | |
| wp_reset_postdata(); | |
| } | |
| } | |
| class WP_Customize_Testimonial_Post_Control extends WP_Customize_Control { | |
| public $type = 'home_testimonial'; | |
| public $post_type = 'testimonial'; | |
| public function render_content() { | |
| $args = [ | |
| 'post_type' => $this->post_type, | |
| 'post_status' => 'publish', | |
| 'order_by' => 'title', | |
| 'order' => 'ASC' | |
| ]; | |
| $tPosts = new WP_Query( $args ); | |
| if ( $tPosts->have_posts() ): ?> | |
| <label> | |
| <span class="customize-control-title"><?= esc_html( $this->label ); ?></span> | |
| <select <?php $this->link(); ?>> | |
| <?php | |
| while ( $tPosts->have_posts() ): | |
| $tPosts->the_post(); | |
| echo "<option " . selected( $this->value(), get_the_ID() ) . " value='" . get_the_ID() . "'>" . the_title( '', '', false ) . "</option>"; | |
| endwhile; | |
| ?> | |
| </select> | |
| </label> | |
| <?php | |
| endif; | |
| wp_reset_postdata(); | |
| } | |
| } | |
| class WP_Customize_Textbox_Control extends WP_Customize_Control { | |
| public $type = 'textarea'; | |
| public function render_content() { | |
| ?> | |
| <label> | |
| <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> | |
| <textarea rows="5" style="width:100%;" <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea> | |
| </label> | |
| <?php | |
| } | |
| } | |
| endif; | |
| /** | |
| * Add postMessage support for site title and description for the Theme Customizer. | |
| * | |
| * @param WP_Customize_Manager $wp_customize Theme Customizer object. | |
| */ | |
| function mwcc_customize_register( $wp_customize ) { | |
| /** | |
| * Remove section panels that we are not using on this site | |
| */ | |
| $wp_customize->remove_section( 'colors' ); | |
| $wp_customize->remove_section( 'background_image' ); | |
| $wp_customize->remove_section( 'static_front_page' ); | |
| $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; | |
| $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; | |
| $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; | |
| $wp_customize->add_section( 'home_testimonial', [ | |
| 'title' => __( 'Testimonial', 'mwcc' ), | |
| 'description' => __( 'Testimonial to display on home page', 'mwcc' ), | |
| 'priority' => 102 | |
| ]); | |
| $wp_customize->add_setting( 'home_testimonial_post', [ | |
| 'capability' => 'edit_theme_options', | |
| 'default' => '', | |
| 'transport' => 'postMessage', | |
| 'sanitize_callback' => function( $page_id, $setting ) { | |
| // Ensure $input is an absolute integer. | |
| $page_id = absint( $page_id ); | |
| // If $page_id is an ID of a published page, return it; otherwise, return the default. | |
| return ( 'publish' == get_post_status( $page_id ) ? $page_id : $setting->default ); | |
| } | |
| ]); | |
| $wp_customize->add_control( new WP_Customize_Testimonial_Post_Control( $wp_customize, 'home_testimonial_poster', [ | |
| 'label' => esc_html__( 'Choose Testimonial', 'mwcc' ), | |
| 'section' => 'home_testimonial', | |
| 'settings' => 'home_testimonial_post', | |
| 'post_type' => 'testimonial', | |
| 'priority' => 12 | |
| ])); | |
| $wp_customize->add_section( 'footer_social', [ | |
| 'title' => __( 'Footer Social', 'mwcc' ), | |
| 'description' => __( 'Social icons in footer', 'mwcc' ), | |
| 'priority' => 101 | |
| ]); | |
| $wp_customize->add_setting( 'footer_social_settings', [ | |
| 'default' => '', | |
| 'transport' => 'postMessage' | |
| ]); | |
| $wp_customize->add_control( new WP_Customize_Textbox_Control( $wp_customize, 'footer_social_settings', [ | |
| 'label' => __( '', 'mwcc' ), | |
| 'section' => 'footer_social', | |
| 'settings' => 'footer_social_settings' | |
| ])); | |
| $wp_customize->add_section( 'home_images', [ | |
| 'title' => __( 'Home Images', 'mwcc' ), | |
| 'description' => __( 'Image row at top of home page', 'mwcc' ), | |
| 'priority' => 100 | |
| ]); | |
| $wp_customize->add_setting( 'home_image_first', [ | |
| 'default' => '', | |
| 'transport' => 'postMessage' | |
| ]); | |
| $wp_customize->add_setting( 'home_image_first_link', [ | |
| 'default' => '', | |
| 'transport' => 'postMessage' | |
| ]); | |
| $wp_customize->add_setting( 'home_image_second', [ | |
| 'default' => '', | |
| 'transport' => 'postMessage' | |
| ]); | |
| $wp_customize->add_setting( 'home_image_second_link', [ | |
| 'default' => '', | |
| 'transport' => 'postMessage' | |
| ]); | |
| $wp_customize->add_setting( 'home_image_third', [ | |
| 'default' => '', | |
| 'transport' => 'postMessage' | |
| ]); | |
| $wp_customize->add_setting( 'home_image_third_link', [ | |
| 'default' => '', | |
| 'transport' => 'postMessage' | |
| ]); | |
| $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'home_image_first', [ | |
| 'label' => 'First Image', | |
| 'section' => 'home_images', | |
| 'settings' => 'home_image_first' | |
| ])); | |
| $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'home_images_first', [ | |
| 'label' => 'First Image Link', | |
| 'section' => 'home_images', | |
| 'settings' => 'home_image_first_link', | |
| 'type' => 'text' | |
| ])); | |
| $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'home_image_second', [ | |
| 'label' => 'Second Image', | |
| 'section' => 'home_images', | |
| 'settings' => 'home_image_second' | |
| ])); | |
| $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'home_images_second', [ | |
| 'label' => 'Second Image Link', | |
| 'section' => 'home_images', | |
| 'settings' => 'home_image_second_link', | |
| 'type' => 'text' | |
| ])); | |
| $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'home_image_third', [ | |
| 'label' => 'Third Image', | |
| 'section' => 'home_images', | |
| 'settings' => 'home_image_third' | |
| ])); | |
| $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'home_images_third', [ | |
| 'label' => 'Third Image Link', | |
| 'section' => 'home_images', | |
| 'settings' => 'home_image_third_link', | |
| 'type' => 'text' | |
| ])); | |
| $wp_customize->add_section( 'site_alert', [ | |
| 'title' => __( 'Site Alert', 'mwcc' ), | |
| 'description' => __( 'Display alert at top of site', 'mwcc' ), | |
| 'priority' => 101 | |
| ]); | |
| $wp_customize->add_setting( 'site_alert_show', [ | |
| 'default' => false, | |
| 'transport' => 'postMessage', | |
| 'sanitize_callback' => function( $input ) { | |
| return ( $input === true ) ? true : false; | |
| } | |
| ]); | |
| $wp_customize->add_setting( 'site_alert_bgcolor', [ | |
| 'default' => '#fada0b', | |
| 'transport' => 'postMessage', | |
| 'sanitize_callback' => 'sanitize_hex_color', | |
| ]); | |
| $wp_customize->add_setting( 'site_alert_post', [ | |
| 'capability' => 'edit_theme_options', | |
| 'default' => '', | |
| 'transport' => 'postMessage', | |
| 'sanitize_callback' => function( $page_id, $setting ) { | |
| // Ensure $input is an absolute integer. | |
| $page_id = absint( $page_id ); | |
| // If $page_id is an ID of a published page, return it; otherwise, return the default. | |
| return ( 'publish' == get_post_status( $page_id ) ? $page_id : $setting->default ); | |
| } | |
| ]); | |
| $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'site_alert', [ | |
| 'label' => esc_html__( 'Display Alert?', 'mwcc' ), | |
| 'description' => esc_html__( 'Check to display site-wide alert message', 'mwcc' ), | |
| 'section' => 'site_alert', | |
| 'settings' => 'site_alert_show', | |
| 'type' => 'checkbox', | |
| 'priority' => 10 | |
| ]) ); | |
| $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'site_alert_bgcolor', [ | |
| 'label' => esc_html__( 'Background Color', 'mwcc' ), | |
| 'description' => esc_html__( 'Background color to use', 'mwcc' ), | |
| 'section' => 'site_alert', | |
| 'settings' => 'site_alert_bgcolor', | |
| 'priority' => 11 | |
| ]) ); | |
| /*$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'site_alert_post', [ | |
| 'label' => esc_html__( 'Post?', 'mwcc' ), | |
| 'description' => esc_html__( 'Post', 'mwcc' ), | |
| 'section' => 'site_alert', | |
| 'settings' => 'site_alert_post', | |
| 'type' => 'dropdown-pages', | |
| 'priority' => 12 | |
| ] ));*/ | |
| $wp_customize->add_control( new WP_Customize_Alert_Post_Control( $wp_customize, 'site_alert_poster', [ | |
| 'label' => esc_html__( 'Choose Alert Page', 'mwcc' ), | |
| 'section' => 'site_alert', | |
| 'settings' => 'site_alert_post', | |
| 'post_type' => 'alert', | |
| 'priority' => 12 | |
| ])); | |
| } | |
| add_action( 'customize_register', 'mwcc_customize_register' ); | |
| /** | |
| * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. | |
| */ | |
| function mwcc_customize_preview_js() { | |
| wp_enqueue_script( 'mwcc_customizer', get_stylesheet_directory_uri() . '/assets/scripts/vendor/customizer.js', array( 'customize-preview', 'wp-api' ), '20151215', true ); | |
| } | |
| add_action( 'customize_preview_init', 'mwcc_customize_preview_js' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment