Created
July 5, 2017 07:29
-
-
Save ravishakya/dbb12c97ddb094505a2866d04098f51f to your computer and use it in GitHub Desktop.
This file contains 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
add_action( 'init' , 'hotelica_get_kirki_fields' ); | |
function hotelica_get_kirki_fields(){ | |
Kirki::add_config( 'my_theme', | |
array( | |
'capability' => 'edit_theme_options', | |
'option_type' => 'theme_mod', | |
) | |
); | |
Kirki::add_panel( 'theme_options', array( | |
'title' => esc_html__( 'Theme Options', 'hotelica' ), | |
) ); | |
Kirki::add_section( 'homepage_settings' , | |
array( | |
'title' => esc_html__( 'Homepage Settings' , 'hotelica' ), | |
'priority' => 1, | |
'capability' => 'edit_theme_options', | |
'panel' => 'theme_options', | |
) | |
); | |
Kirki::add_section( 'header_settings' , | |
array( | |
'title' => esc_html__( 'Banner / Slider' , 'hotelica' ), | |
'priority' => 1, | |
'capability' => 'edit_theme_options', | |
'section' => 'homepage_settings', | |
) | |
); | |
Kirki::add_field( 'my_theme', array( | |
'type' => 'radio-buttonset', | |
'settings' => 'option_banner_slider', | |
'label' => esc_html__( 'Banner / Slider', 'hotelica' ), | |
'section' => 'header_settings', | |
'default' => 'banner', | |
'choices' => array( | |
'banner' => esc_html__( 'Banner', 'hotelica' ), | |
'slider' => esc_html__( 'Slider', 'hotelica' ), | |
), | |
'priority' => 1, | |
) ); | |
Kirki::add_field( 'my_theme', array( | |
'type' => 'repeater', | |
'label' => esc_html__( 'Sliders', 'hotelica' ), | |
'section' => 'header_settings', | |
'row_label' => array( | |
'type' => 'text', | |
'value' => esc_html__('Slider', 'hotelica' ), | |
), | |
'settings' => 'slider_settings', | |
'fields' => array( | |
'image' => array( | |
'type' => 'image', | |
'label' => esc_html__( 'Image', 'hotelica' ), | |
), | |
'title' => array( | |
'type' => 'text', | |
'label' => esc_html__( 'Title', 'hotelica' ), | |
), | |
'subtitle' => array( | |
'type' => 'textarea', | |
'label' => esc_html__( 'Subtitle', 'hotelica' ), | |
), | |
'link_text' => array( | |
'type' => 'text', | |
'label' => esc_html__( 'Link Label', 'hotelica' ), | |
'default' => esc_html__( 'Read More', 'hotelica' ), | |
), | |
'url' => array( | |
'type' => 'text', | |
'label' => esc_html__( 'Link', 'hotelica' ), | |
) | |
), | |
'choices' => apply_filters( 'hotelica_slider_limit', array( 'limit' => 2 ) ), | |
'active_callback' => array( | |
array( | |
'setting' => 'option_banner_slider', | |
'operator' => '==', | |
'value' => 'slider', | |
), | |
), | |
) ); | |
Kirki::add_field( 'my_theme', array( | |
'type' => 'text', | |
'settings' => 'slider_animationSpeed', | |
'label' => esc_html__( 'Animation Speed', 'hotelica' ), | |
'section' => 'header_settings', | |
'default' => 600, | |
'description' => esc_html__( 'Set the speed of animations, in milliseconds', 'hotelica' ), | |
'active_callback' => array( | |
array( | |
'setting' => 'option_banner_slider', | |
'operator' => '==', | |
'value' => 'slider', | |
), | |
), | |
) ); | |
Kirki::add_field( 'my_theme', array( | |
'type' => 'radio-buttonset', | |
'settings' => 'slider_randomize', | |
'label' => esc_html__( 'Randomize', 'hotelica' ), | |
'section' => 'header_settings', | |
'default' => 'disable', | |
'choices' => array( | |
'enable' => esc_html__( 'Enable', 'hotelica' ), | |
'disable' => esc_html__( 'Disable', 'hotelica' ), | |
), | |
'description' => esc_html__( 'Randomize slide order, on load.', 'hotelica' ), | |
'active_callback' => array( | |
array( | |
'setting' => 'option_banner_slider', | |
'operator' => '==', | |
'value' => 'slider', | |
), | |
), | |
) ); | |
Kirki::add_field( 'my_theme', array( | |
'type' => 'image', | |
'settings' => 'banner_image', | |
'label' => esc_html__( 'Banner Image', 'hotelica' ), | |
'section' => 'header_settings', | |
'priority' => 2, | |
'active_callback' => array( | |
array( | |
'setting' => 'option_banner_slider', | |
'operator' => '==', | |
'value' => 'banner', | |
), | |
), | |
) ); | |
Kirki::add_field( 'my_theme', array( | |
'type' => 'text', | |
'settings' => 'banner_title', | |
'label' => esc_html__( 'Banner Title', 'hotelica' ), | |
'section' => 'header_settings', | |
'default' => esc_attr__( 'Welcome to hotelica', 'hotelica' ), | |
'priority' => 4, | |
'partial_refresh' => array( | |
'banner_title' => array( | |
'selector' => '.banner_title_text', | |
'render_callback' => function() { | |
return esc_html( get_theme_mod( 'banner_title' ) ); | |
}, | |
), | |
), | |
'active_callback' => array( | |
array( | |
'setting' => 'option_banner_slider', | |
'operator' => '==', | |
'value' => 'banner', | |
), | |
), | |
) ); | |
// if you are using nested panels or sections then a blank field is needed | |
Kirki::add_field( 'my_theme', array( | |
'type' => 'notice', | |
'section' => 'homepage_settings', | |
)); | |
} | |
add_action( 'customize_register', function( $wp_customize ) { | |
class Hotelica_blank_content extends WP_Customize_Control { | |
public $type = 'notice'; | |
public function render_content() { | |
echo ''; | |
} | |
} | |
// Register our custom control with Kirki | |
add_filter( 'kirki/control_types', function( $controls ) { | |
$controls['notice'] = 'Hotelica_blank_content'; | |
return $controls; | |
} ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment