add_panel('mh_theme_options', array('title' => esc_html__('Theme Options', 'benews'), 'description' => '', 'capability' => 'edit_theme_options', 'theme_supports' => '', 'priority' => 1,)); /***** Add Sections *****/ $wp_customize->add_section('fc_benews_general', array('title' => esc_html__('General', 'benews'), 'priority' => 1, 'panel' => 'mh_theme_options')); $wp_customize->add_section('fc_benews_upgrade', array('title' => esc_html__('More Features', 'benews'), 'priority' => 2, 'panel' => 'mh_theme_options')); /***** Add Settings *****/ $wp_customize->add_setting('fc_benews_options[excerpt_length]', array('default' => 35, 'type' => 'option', 'sanitize_callback' => 'fc_benews_sanitize_integer')); $wp_customize->add_setting('fc_benews_options[excerpt_more]', array('default' => esc_html__('Read More', 'benews'), 'type' => 'option', 'sanitize_callback' => 'fc_benews_sanitize_text')); $wp_customize->add_setting('fc_benews_options[sidebar]', array('default' => 'right', 'type' => 'option', 'sanitize_callback' => 'fc_benews_sanitize_select')); $wp_customize->add_setting('fc_benews_options[premium_version_upgrade]', array('default' => '', 'type' => 'option', 'sanitize_callback' => 'esc_attr')); /***** Add Controls *****/ $wp_customize->add_control('excerpt_length', array('label' => esc_html__('Custom Excerpt Length in Words', 'benews'), 'section' => 'fc_benews_general', 'settings' => 'fc_benews_options[excerpt_length]', 'priority' => 1, 'type' => 'text')); $wp_customize->add_control('excerpt_more', array('label' => esc_html__('Custom Excerpt More-Text', 'benews'), 'section' => 'fc_benews_general', 'settings' => 'fc_benews_options[excerpt_more]', 'priority' => 2, 'type' => 'text')); $wp_customize->add_control('sidebar', array('label' => esc_html__('Sidebar', 'benews'), 'section' => 'fc_benews_general', 'settings' => 'fc_benews_options[sidebar]', 'priority' => 3, 'type' => 'select', 'choices' => array('right' => esc_html__('Right Sidebar', 'benews'), 'left' => esc_html__('Left Sidebar', 'benews')))); $wp_customize->add_control(new fc_benews_Upgrade($wp_customize, 'premium_version_upgrade', array('section' => 'fc_benews_upgrade', 'settings' => 'fc_benews_options[premium_version_upgrade]', 'priority' => 1))); } add_action('customize_register', 'fc_benews_customize_register'); /***** Data Sanitization *****/ function fc_benews_sanitize_text($input) { return wp_kses_post(force_balance_tags($input)); } function fc_benews_sanitize_integer($input) { return strip_tags(intval($input)); } function fc_benews_sanitize_checkbox($input) { if ($input == 1) { return 1; } else { return ''; } } function fc_benews_sanitize_select($input) { $valid = array( 'enable' => esc_html__('Enable', 'benews'), 'disable' => esc_html__('Disable', 'benews'), 'right' => esc_html__('Right Sidebar', 'benews'), 'left' => esc_html__('Left Sidebar', 'benews') ); if (array_key_exists($input, $valid)) { return $input; } else { return ''; } } /***** Return Theme Options / Set Default Options *****/ if (!function_exists('fc_benews_theme_options')) { function fc_benews_theme_options() { $theme_options = wp_parse_args( get_option('fc_benews_options', array()), fc_benews_default_options() ); return $theme_options; } } if (!function_exists('fc_benews_default_options')) { function fc_benews_default_options() { $default_options = array( 'excerpt_length' => 35, 'excerpt_more' => esc_html__('Read More', 'benews'), 'sidebar' => 'right' ); return $default_options; } } /***** Enqueue Customizer CSS *****/ function fc_benews_customizer_css() { wp_enqueue_style('be-customizer', get_template_directory_uri() . '/admin/customizer.css', array()); } add_action('customize_controls_print_styles', 'fc_benews_customizer_css'); /***** Enqueue Customizer JS *****/ function fc_benews_customizer_js() { wp_enqueue_script('be-customizer', get_template_directory_uri() . '/js/be-customizer.js', array(), '1.0.0', true); wp_localize_script('be-customizer', 'fc_benews_links', array( 'upgradeURL' => esc_url('http://www.mhthemes.com/themes/mh/benews/'), 'upgradeLabel' => esc_html__('Upgrade to MH benews Pro', 'benews'), 'title' => esc_html__('Theme Related Links:', 'benews'), 'themeURL' => esc_url('http://www.mhthemes.com/themes/mh/benews/'), 'themeLabel' => esc_html__('Theme Info Page', 'benews'), 'docsURL' => esc_url('http://www.mhthemes.com/support/documentation-be-benews/'), 'docsLabel' => esc_html__('Theme Documentation', 'benews'), 'supportURL' => esc_url('https://wordpress.org/support/theme/benews'), 'supportLabel' => esc_html__('Support Forum', 'benews'), 'rateURL' => esc_url('https://wordpress.org/support/view/theme-reviews/benews?filter=5'), 'rateLabel' => esc_html__('Rate this theme', 'benews'), )); } add_action('customize_controls_enqueue_scripts', 'fc_benews_customizer_js'); ?>