add_section( 'rivet_hero_area', array( 'title' => esc_html__( 'Featured Prompt', 'rivet' ), 'description' => esc_html__( 'Use this area to promote your most important message to site visitors. You can use a headline, a brief description and prominent link to help drive visitors where you’d like them to go.', 'rivet' ), 'priority' => 12, 'active_callback' => 'is_front_page', ) ); /* Display on Front Page */ $wp_customize->add_setting( 'rivet_hero_area_display', array( 'sanitize_callback' => 'rivet_hero_area_sanitize_checkbox', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'rivet_hero_area_display', array( 'label' => esc_html__( 'Display on the Front Page', 'rivet' ), 'section' => 'rivet_hero_area', 'type' => 'checkbox', ) ); /* Title */ $wp_customize->add_setting( 'rivet_hero_area_title', array( 'sanitize_callback' => 'sanitize_text_field', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'rivet_hero_area_title', array( 'label' => esc_html__( 'Title', 'rivet' ), 'section' => 'rivet_hero_area', 'type' => 'text', 'input_attrs' => array( 'placeholder' => esc_attr__( 'Write a headline', 'rivet' ), ), ) ); /* Content */ $wp_customize->add_setting( 'rivet_hero_area_content', array( 'sanitize_callback' => 'wp_kses_post', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'rivet_hero_area_content', array( 'label' => esc_html__( 'Description', 'rivet' ), 'section' => 'rivet_hero_area', 'type' => 'textarea', 'input_attrs' => array( 'placeholder' => esc_attr__( 'Write some compelling text to encourage people to click the button below', 'rivet' ), ), ) ); /* Button Text */ $wp_customize->add_setting( 'rivet_hero_area_button_text', array( 'sanitize_callback' => 'sanitize_text_field', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'rivet_hero_area_button_text', array( 'label' => esc_html__( 'Button Text', 'rivet' ), 'section' => 'rivet_hero_area', 'type' => 'text', 'input_attrs' => array( 'placeholder' => esc_attr__( 'Click Me!', 'rivet' ), ), ) ); /* Button URL */ $wp_customize->add_setting( 'rivet_hero_area_button_url', array( 'sanitize_callback' => 'esc_url_raw', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'rivet_hero_area_button_url', array( 'label' => esc_html__( 'Button URL Link', 'rivet' ), 'section' => 'rivet_hero_area', 'type' => 'url', 'input_attrs' => array( 'placeholder' => esc_attr__( 'http://www.example.com/', 'rivet' ), ), ) ); /* Background Image */ $wp_customize->add_setting( 'rivet_hero_area_background', array( 'sanitize_callback' => 'esc_url_raw', 'transport' => 'postMessage', ) ); $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'rivet_hero_area_background', array( 'label' => esc_html__( 'Background Image', 'rivet' ), 'section' => 'rivet_hero_area', ) ) ); /* Background Image Overlay Opacity */ $wp_customize->add_setting( 'rivet_hero_overlay_opacity', array( 'default' => 40, 'type' => 'theme_mod', 'transport' => 'postMessage', 'sanitize_callback' => 'absint', 'sanitize_js_callback' => 'absint', ) ); $wp_customize->add_control( 'rivet_hero_overlay_opacity', array( 'label' => esc_html__( 'Background Overlay', 'rivet' ), 'description' => esc_html__( 'Adjust the darkness of the overlay over the background image.', 'rivet' ), 'section' => 'rivet_hero_area', 'type' => 'range', 'input_attrs' => array( 'step' => 10, 'min' => 0, 'max' => 90, 'aria-valuemin' => 0, 'aria-valuemax' => 90, 'aria-valuenow' => 40, 'aria-orientation' => 'horizontal', ), ) ); } add_action( 'customize_register', 'rivet_hero_area_customize_register' ); /** * Sanitize the checkbox. * * @param boolean $input. * @return boolean */ function rivet_hero_area_sanitize_checkbox( $input ) { return ( 1 == $input ? true : false ); } /** * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. */ function rivet_hero_customize_preview_js() { wp_enqueue_script( 'rivet-hero-customizer', get_template_directory_uri() . '/hero-area/hero-area-customize-preview.js', array( 'jquery', 'customize-preview' ), '20170823', true ); } add_action( 'customize_preview_init', 'rivet_hero_customize_preview_js' );