How to create custom options in WordPress customization panel

/*==================================
PANEL & OPTIONS CREATED IN CUSTOMIZATION tAB
====================================*/

if ( ! function_exists( ‘ak_popup_panel_customize’ ) ) {

add_action( ‘customize_register’, ‘ak_popup_panel_customize’ );

function ak_popup_panel_customize( $wp_customize ) {
$wp_customize->add_panel( ‘ak_popup_panel_customize’, array(
‘priority’ => 10,
‘title’ => __( ‘Popup Settings’, ‘WPC’ ),
‘description’ => __( ‘From here you can change all content of the popup’, ‘WPC’ ),
‘capability’ => ‘edit_theme_options’
) );
}
}

if ( ! function_exists( ‘ak_popup_panel_settings’ ) ) {

add_action( ‘customize_register’, ‘ak_popup_panel_settings’ );

function ak_popup_panel_settings( $wp_customize ) {

$wp_customize->add_section( ‘ak_popup_panel_customize’, array(
‘priority’ => 10,
// ‘panel’ => ‘ak_popup_panel_customize’,
‘title’ => __( ‘Popup Settings’, ‘WPC’ ),
‘capability’ => ‘edit_theme_options’
) );

$wp_customize->add_setting( ‘ak_section_show_hide’, array(
‘type’ => ‘theme_mod’,
‘transport’ => ‘refresh’,
‘capability’ => ‘edit_theme_options’,
‘sanitize_callback’ => ‘esc_attr’
) );
$wp_customize->add_control( ‘ak_show_hide_control’, array(
‘label’ => __( ‘Show/Hide’, ‘WPC’ ),
‘description’ => __( ‘Click the checkbox to display the popup.’, ‘WPC’ ),
‘section’ => ‘ak_popup_panel_customize’,
‘settings’ => ‘ak_section_show_hide’,
‘type’ => ‘checkbox’
) );

$wp_customize->add_setting( ‘ak_section_sub_heading’, array(
‘type’ => ‘theme_mod’,
‘transport’ => ‘refresh’,
‘capability’ => ‘edit_theme_options’,
‘sanitize_callback’ => ‘esc_attr’
) );
$wp_customize->add_control( ‘ak_section_sub_heading_control’, array(
‘label’ => __( ‘Sub Heading’, ‘WPC’ ),
‘section’ => ‘ak_popup_panel_customize’,
‘settings’ => ‘ak_section_sub_heading’,
‘type’ => ‘text’
) );

$wp_customize->add_setting( ‘ak_section_heading’, array(
‘type’ => ‘theme_mod’,
‘default’ => ‘Placeholder.’,
‘transport’ => ‘refresh’,
‘capability’ => ‘edit_theme_options’,
‘sanitize_callback’ => ‘esc_attr’
) );
$wp_customize->add_control( ‘ak_section_heading_control’, array(
‘label’ => __( ‘Main Heading’, ‘WPC’ ),
‘section’ => ‘ak_popup_panel_customize’,
‘settings’ => ‘ak_section_heading’,
‘type’ => ‘text’
) );

$wp_customize->add_setting( ‘ak_section_description’, array(
‘type’ => ‘theme_mod’,
‘default’ => ‘Placeholder Description.’,
‘transport’ => ‘refresh’,
‘capability’ => ‘edit_theme_options’,
‘sanitize_callback’ => ‘esc_attr’
) );
$wp_customize->add_control( ‘ak_section_description_control’, array(
‘label’ => __( ‘Popup content will come here’, ‘WPC’ ),
‘section’ => ‘ak_popup_panel_customize’,
‘settings’ => ‘ak_section_description’,
‘type’ => ‘textarea’,
‘input_attrs’ => array(
‘rows’ => ’15’
),
) );

$wp_customize->add_setting( ‘ak_section_button_text’, array(
‘type’ => ‘theme_mod’,
‘default’ => ‘Placeholder btn.’,
‘transport’ => ‘refresh’,
‘capability’ => ‘edit_theme_options’,
‘sanitize_callback’ => ‘esc_attr’
) );
$wp_customize->add_control( ‘ak_section_button_text_control’, array(
‘label’ => __( ‘Button Text’, ‘WPC’ ),
‘section’ => ‘ak_popup_panel_customize’,
‘settings’ => ‘ak_section_button_text’,
‘type’ => ‘text’,
) );
$wp_customize->add_setting( ‘ak_section_button_link’, array(
‘type’ => ‘theme_mod’,
‘default’ => ‘#’,
‘transport’ => ‘refresh’,
‘capability’ => ‘edit_theme_options’,
‘sanitize_callback’ => ‘esc_attr’
) );
$wp_customize->add_control( ‘ak_section_button_link_control’, array(
‘label’ => __( ‘Button Link’, ‘WPC’ ),
‘section’ => ‘ak_popup_panel_customize’,
‘settings’ => ‘ak_section_button_link’,
‘type’ => ‘text’,
) );

$wp_customize->add_setting( ‘ak_section_image’, array(
‘type’ => ‘theme_mod’,
‘transport’ => ‘refresh’,
‘capability’ => ‘edit_theme_options’,
‘sanitize_callback’ => ‘esc_attr’
) );
$wp_customize->add_control( new WP_Customize_Cropped_Image_Control( $wp_customize, ‘ak_section_image_control’, array(
‘label’ => __( ‘Select Popup Image’, ‘WPC’ ),
‘section’ => ‘ak_popup_panel_customize’,
‘settings’ => ‘ak_section_image’,
‘mime_type’ => ‘image’,
‘height’=>1000,
‘width’=>1000,
‘flex_width’=>true,
‘flex_height’=>true,
) ) );

}

}

Leave a Reply

Your email address will not be published.