/** * Sanitize a font choice. * * @since 1.0.0. * * @param string $value The font choice. * @return string The sanitized font choice. */ function tokopress_customizer_library_sanitize_font_choice($value) { if (is_int($value)) { // The array key is an integer, so the chosen option is a heading, not a real choice return ''; } else { if (array_key_exists($value, tokopress_customizer_library_get_font_choices())) { return $value; } else { return ''; } } }
function tokopress_theme_customizer_register($wp_customize) { // Rename Colors Sections Into General Colors $wp_customize->get_section('colors')->title = __('General Colors', 'tokopress'); $wp_customize->get_control('background_color')->priority = 0; $wp_customize->get_section('header_image')->priority = 30; $wp_customize->get_section('background_image')->priority = 35; $tk_sections = array(); $tk_colors = array(); $tk_panels = array(); $tk_sections = tokopress_get_customizer_sections($tk_sections); $tk_colors = tokopress_get_customizer_data($tk_colors); $tk_panels = tokopress_get_customizer_panel($tk_panels); // create panel from array data foreach ($tk_panels as $panels) { if (isset($panels['priority'])) { $priority = $panels['priority']; } else { $priority = ''; } $wp_customize->add_panel($panels['ID'], array('priority' => $panels['priority'], 'capability' => 'edit_theme_options', 'title' => $panels['title'], 'description' => $panels['description'])); } //create the section from array data foreach ($tk_sections as $section) { if (isset($section['priority'])) { $priority = $section['priority']; } else { $priority = ''; } if (isset($section['panel_id'])) { $panel = $section['panel_id']; } else { $panel = ''; } $wp_customize->add_section($section['slug'], array('title' => $section['label'], 'priority' => $priority, 'panel' => $panel)); } //create the componen from array data foreach ($tk_colors as $color) { if (isset($color['transport'])) { $transport = $color['transport']; } else { $transport = 'refresh'; // $transport = 'postMessage'; } if (isset($color['priority'])) { $priority = $color['priority']; } else { $priority = ''; } // Define each customizer type switch ($color['type']) { case 'color': $wp_customize->add_setting($color['slug'], array('default' => $color['default'], 'type' => 'theme_mod', 'transport' => $transport, 'capability' => 'edit_theme_options', 'sanitize_callback' => 'esc_attr')); $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, $color['slug'], array('label' => $color['label'], 'section' => $color['section'], 'priority' => $priority, 'settings' => $color['slug']))); break; case 'select': $wp_customize->add_setting($color['slug'], array('default' => $color['default'], 'type' => 'theme_mod', 'transport' => $transport, 'capability' => 'edit_theme_options', 'sanitize_callback' => 'esc_attr')); $wp_customize->add_control(new WP_Customize_Control($wp_customize, $color['slug'], array('label' => $color['label'], 'section' => $color['section'], 'default' => $color['default'], 'priority' => $priority, 'settings' => $color['slug'], 'choices' => $color['choices'], 'type' => 'select'))); break; case 'select_font': $wp_customize->add_setting($color['slug'], array('default' => $color['default'], 'type' => 'theme_mod', 'transport' => $transport, 'capability' => 'edit_theme_options', 'sanitize_callback' => 'esc_attr')); $wp_customize->add_control(new WP_Customize_Control($wp_customize, $color['slug'], array('label' => $color['label'], 'section' => $color['section'], 'default' => $color['default'], 'priority' => $priority, 'settings' => $color['slug'], 'choices' => tokopress_customizer_library_get_font_choices(), 'type' => 'select'))); break; case 'text': $wp_customize->add_setting($color['slug'], array('default' => $color['default'], 'type' => 'theme_mod', 'transport' => $transport, 'capability' => 'edit_theme_options', 'sanitize_callback' => 'esc_attr')); $wp_customize->add_control($color['slug'], array('label' => $color['label'], 'section' => $color['section'], 'priority' => $priority, 'settings' => $color['slug'], 'type' => 'text')); break; case 'textarea': $wp_customize->add_setting($color['slug'], array('default' => $color['default'], 'sanitize_callback' => 'esc_attr')); $wp_customize->add_control(new Tokopress_Customize_Textarea_Control($wp_customize, $color['slug'], array('label' => $color['label'], 'section' => $color['section'], 'priority' => $priority, 'settings' => $color['slug']))); break; case 'images': $wp_customize->add_setting($color['slug'], array('default' => $color['default'], 'capability' => 'edit_theme_options', 'type' => 'theme_mod', 'sanitize_callback' => 'esc_attr')); $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, $color['slug'], array('label' => $color['label'], 'section' => $color['section'], 'priority' => $priority, 'settings' => $color['slug']))); break; case 'font': $wp_customize->add_setting($color['slug'], array('default' => $color['label'], 'sanitize_callback' => 'esc_attr')); $wp_customize->add_control(new Google_Font_Dropdown_Custom_Control($wp_customize, $color['slug'], array('label' => $color['label'], 'section' => $color['section'], 'priority' => $priority, 'settings' => $color['slug']))); break; default: break; } } }