add_section( 'rivet_contact_info', array( 'title' => esc_html__( 'Contact Info', 'rivet' ), 'description' => esc_html__( 'Display your location, hours, and contact information.', 'rivet' ), 'priority' => 13, ) ); /* Display in Header */ $wp_customize->add_setting( 'rivet_contact_info_location', array( 'default' => 'header', 'sanitize_callback' => 'rivet_contact_info_sanitize_location', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'rivet_contact_info_location', array( 'label' => esc_html__( 'Where would you like to display your contact information?', 'rivet' ), 'section' => 'rivet_contact_info', 'type' => 'radio', 'choices' => array( 'header' => esc_html__( 'In the header', 'rivet' ), 'footer' => esc_html__( 'In the footer', 'rivet' ), ), ) ); /* Address */ $wp_customize->add_setting( 'rivet_contact_info_address', array( 'sanitize_callback' => 'sanitize_text_field', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'rivet_contact_info_address', array( 'label' => esc_html__( 'Address', 'rivet' ), 'section' => 'rivet_contact_info', 'type' => 'textarea', 'input_attrs' => array( 'placeholder' => esc_attr__( '123 Main St, Somewhere XY, 98765', 'rivet' ), ), ) ); /* Phone */ $wp_customize->add_setting( 'rivet_contact_info_phone', array( 'sanitize_callback' => 'sanitize_text_field', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'rivet_contact_info_phone', array( 'label' => esc_html__( 'Phone', 'rivet' ), 'section' => 'rivet_contact_info', 'type' => 'text', 'input_attrs' => array( 'placeholder' => esc_attr__( '(555) 123-4567', 'rivet' ), ), ) ); /* Email */ $wp_customize->add_setting( 'rivet_contact_info_email', array( 'sanitize_callback' => 'sanitize_email', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'rivet_contact_info_email', array( 'label' => esc_html__( 'Email', 'rivet' ), 'section' => 'rivet_contact_info', 'type' => 'email', 'input_attrs' => array( 'placeholder' => esc_attr__( 'email@example.com', 'rivet' ), ), ) ); /* Hours */ $wp_customize->add_setting( 'rivet_contact_info_hours', array( 'sanitize_callback' => 'sanitize_text_field', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'rivet_contact_info_hours', array( 'label' => esc_html__( 'Hours', 'rivet' ), 'section' => 'rivet_contact_info', 'type' => 'textarea', 'input_attrs' => array( 'placeholder' => esc_attr__( 'M-F: 9-5pm - Weekends: 10-4pm', 'rivet' ), ), ) ); } add_action( 'customize_register', 'rivet_contact_info_customize_register' ); /** * Sanitize the checkbox. * * @param boolean $input. * @return boolean */ function rivet_contact_info_sanitize_checkbox( $input ) { return ( 1 == $input ? true : false ); } /** * Sanitize the Contact Info location value. * * @param string $display. * @return string. */ function rivet_contact_info_sanitize_location( $display ) { if ( ! in_array( $display, array( 'header', 'footer' ) ) ) { $display = 'header'; } return $display; } /** * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. */ function rivet_contact_info_customize_preview_js() { wp_enqueue_script( 'rivet-contact-info-customizer', get_template_directory_uri() . '/contact-info/contact-info-customize-preview.js', array( 'jquery', 'customize-preview' ), '20170907', true ); } add_action( 'customize_preview_init', 'rivet_contact_info_customize_preview_js' );