/** * Define the sections and settings for the General panel * * @since 1.3.0. * * @param array $sections The master array of Customizer sections * @return array The augmented master array */ function ttfmake_customizer_define_typography_sections($sections) { $panel = 'ttfmake_typography'; $typography_sections = array(); /** * Typekit */ if (!ttfmake_is_plus()) { $typography_sections['font-typekit'] = array('panel' => $panel, 'title' => __('Typekit', 'make'), 'description' => __('Looking to add premium fonts from Typekit to your website?', 'make'), 'options' => array('font-typekit-update-text' => array('control' => array('control_type' => 'TTFMAKE_Customize_Misc_Control', 'type' => 'text', 'description' => sprintf('<a href="%1$s" target="_blank">%2$s</a>', esc_url(ttfmake_get_plus_link('typekit')), sprintf(__('Upgrade to %1$s', 'make'), 'Make Plus')))))); } /** * Google Web Fonts */ $typography_sections['font-google'] = array('panel' => $panel, 'title' => __('Google Web Fonts', 'make'), 'options' => array('font-subset' => array('setting' => array('sanitize_callback' => 'ttfmake_sanitize_font_subset'), 'control' => array('label' => __('Character Subset', 'make'), 'type' => 'select', 'choices' => ttfmake_get_google_font_subsets())), 'font-subset-text' => array('control' => array('control_type' => 'TTFMAKE_Customize_Misc_Control', 'type' => 'text', 'description' => __('Not all fonts provide each of these subsets.', 'make'))))); /** * Site Title & Tagline */ $typography_sections['font-site-title-tagline'] = array('panel' => $panel, 'title' => __('Site Title & Tagline', 'make'), 'options' => array('font-family-site-title' => array('setting' => array('sanitize_callback' => 'ttfmake_sanitize_font_choice'), 'control' => array('label' => __('Site Title Font Family', 'make'), 'type' => 'select', 'choices' => ttfmake_font_choices_placeholder())), 'font-size-site-title' => array('setting' => array('sanitize_callback' => 'absint'), 'control' => array('label' => __('Site Title Font Size (in px)', 'make'), 'type' => ttfmake_customizer_supports_panels() ? 'number' : 'text')), 'font-family-site-tagline' => array('setting' => array('sanitize_callback' => 'ttfmake_sanitize_font_choice'), 'control' => array('label' => __('Site Tagline Font Family', 'make'), 'type' => 'select', 'choices' => ttfmake_font_choices_placeholder())), 'font-size-site-tagline' => array('setting' => array('sanitize_callback' => 'absint'), 'control' => array('label' => __('Site Tagline Font Size (in px)', 'make'), 'type' => ttfmake_customizer_supports_panels() ? 'number' : 'text')))); /** * Main Navigation */ $typography_sections['font-main-menu'] = array('panel' => $panel, 'title' => __('Main Menu', 'make'), 'options' => array('font-family-nav' => array('setting' => array('sanitize_callback' => 'ttfmake_sanitize_font_choice'), 'control' => array('label' => __('Menu Item Font Family', 'make'), 'type' => 'select', 'choices' => ttfmake_font_choices_placeholder())), 'font-size-nav' => array('setting' => array('sanitize_callback' => 'absint'), 'control' => array('label' => __('Menu Item Font Size (in px)', 'make'), 'type' => ttfmake_customizer_supports_panels() ? 'number' : 'text')), 'font-family-subnav' => array('setting' => array('sanitize_callback' => 'ttfmake_sanitize_font_choice'), 'control' => array('label' => __('Sub-Menu Item Font Family', 'make'), 'type' => 'select', 'choices' => ttfmake_font_choices_placeholder())), 'font-size-subnav' => array('setting' => array('sanitize_callback' => 'absint'), 'control' => array('label' => __('Sub-Menu Item Font Size (in px)', 'make'), 'type' => ttfmake_customizer_supports_panels() ? 'number' : 'text')), 'font-subnav-option-heading' => array('control' => array('control_type' => 'TTFMAKE_Customize_Misc_Control', 'type' => 'heading', 'label' => __('Sub-Menu Item Options', 'make'))), 'font-subnav-mobile' => array('setting' => array('sanitize_callback' => 'absint'), 'control' => array('label' => __('Use Menu Item styles in mobile view', 'make'), 'type' => 'checkbox')))); /** * Widgets */ $typography_sections['font-widget'] = array('panel' => $panel, 'title' => __('Widgets', 'make'), 'options' => array('font-family-widget' => array('setting' => array('sanitize_callback' => 'ttfmake_sanitize_font_choice'), 'control' => array('label' => __('Widget Font Family', 'make'), 'type' => 'select', 'choices' => ttfmake_font_choices_placeholder())), 'font-size-widget' => array('setting' => array('sanitize_callback' => 'absint'), 'control' => array('label' => __('Widget Font Size (in px)', 'make'), 'type' => ttfmake_customizer_supports_panels() ? 'number' : 'text')))); /** * Headers & Body */ $typography_sections['font'] = array('panel' => $panel, 'title' => __('Headers & Body', 'make'), 'options' => array('font-family-h1' => array('setting' => array('sanitize_callback' => 'ttfmake_sanitize_font_choice'), 'control' => array('label' => __('H1 Font Family', 'make'), 'type' => 'select', 'choices' => ttfmake_font_choices_placeholder())), 'font-size-h1' => array('setting' => array('sanitize_callback' => 'absint'), 'control' => array('label' => __('H1 Font Size (in px)', 'make'), 'type' => ttfmake_customizer_supports_panels() ? 'number' : 'text')), 'font-family-h2' => array('setting' => array('sanitize_callback' => 'ttfmake_sanitize_font_choice'), 'control' => array('label' => __('H2 Font Family', 'make'), 'type' => 'select', 'choices' => ttfmake_font_choices_placeholder())), 'font-size-h2' => array('setting' => array('sanitize_callback' => 'absint'), 'control' => array('label' => __('H2 Font Size (in px)', 'make'), 'type' => ttfmake_customizer_supports_panels() ? 'number' : 'text')), 'font-family-h3' => array('setting' => array('sanitize_callback' => 'ttfmake_sanitize_font_choice'), 'control' => array('label' => __('H3 Font Family', 'make'), 'type' => 'select', 'choices' => ttfmake_font_choices_placeholder())), 'font-size-h3' => array('setting' => array('sanitize_callback' => 'absint'), 'control' => array('label' => __('H3 Font Size (in px)', 'make'), 'type' => ttfmake_customizer_supports_panels() ? 'number' : 'text')), 'font-family-h4' => array('setting' => array('sanitize_callback' => 'ttfmake_sanitize_font_choice'), 'control' => array('label' => __('H4 Font Family', 'make'), 'type' => 'select', 'choices' => ttfmake_font_choices_placeholder())), 'font-size-h4' => array('setting' => array('sanitize_callback' => 'absint'), 'control' => array('label' => __('H4 Font Size (in px)', 'make'), 'type' => ttfmake_customizer_supports_panels() ? 'number' : 'text')), 'font-family-h5' => array('setting' => array('sanitize_callback' => 'ttfmake_sanitize_font_choice'), 'control' => array('label' => __('H5 Font Family', 'make'), 'type' => 'select', 'choices' => ttfmake_font_choices_placeholder())), 'font-size-h5' => array('setting' => array('sanitize_callback' => 'absint'), 'control' => array('label' => __('H5 Font Size (in px)', 'make'), 'type' => ttfmake_customizer_supports_panels() ? 'number' : 'text')), 'font-family-h6' => array('setting' => array('sanitize_callback' => 'ttfmake_sanitize_font_choice'), 'control' => array('label' => __('H6 Font Family', 'make'), 'type' => 'select', 'choices' => ttfmake_font_choices_placeholder())), 'font-size-h6' => array('setting' => array('sanitize_callback' => 'absint'), 'control' => array('label' => __('H6 Font Size (in px)', 'make'), 'type' => ttfmake_customizer_supports_panels() ? 'number' : 'text')), 'font-family-body' => array('setting' => array('sanitize_callback' => 'ttfmake_sanitize_font_choice'), 'control' => array('label' => __('Body Font Family', 'make'), 'type' => 'select', 'choices' => ttfmake_font_choices_placeholder())), 'font-size-body' => array('setting' => array('sanitize_callback' => 'absint'), 'control' => array('label' => __('Body Font Size (in px)', 'make'), 'type' => ttfmake_customizer_supports_panels() ? 'number' : 'text')))); // Filter the definitions $typography_sections = apply_filters('make_customizer_typography_sections', $typography_sections); // Merge with master array return array_merge($sections, $typography_sections); }
/** * Configure settings and controls for the Site Title & Tagline section. * * @since 1.0.0. * * @return void */ function ttfmake_customizer_sitetitletagline() { global $wp_customize; $theme_prefix = 'ttfmake_'; $section_id = 'title_tagline'; $section = $wp_customize->get_section($section_id); $priority = new TTFMAKE_Prioritizer(10, 5); // Move Site Title & Tagline section to General panel $section->panel = $theme_prefix . 'general'; // Set Site Title & Tagline section priority $logo_priority = $wp_customize->get_section($theme_prefix . 'logo')->priority; $section->priority = $logo_priority - 5; // Adjust section title if no panel support if (!ttfmake_customizer_supports_panels()) { $panels = ttfmake_customizer_get_panels(); if (isset($panels['general']['title'])) { $section->title = $panels['general']['title'] . ': ' . $section->title; } } // Reset priorities on Site Title control $wp_customize->get_control('blogname')->priority = $priority->add(); // Hide Site Title option $options = array('hide-site-title' => array('setting' => array('sanitize_callback' => 'absint'), 'control' => array('label' => __('Hide Site Title', 'make'), 'type' => 'checkbox'))); $new_priority = ttfmake_customizer_add_section_options($section_id, $options, $priority->add()); $priority->set($new_priority); // Reset priorities on Tagline control $wp_customize->get_control('blogdescription')->priority = $priority->add(); // Hide Tagline option $options = array('hide-tagline' => array('setting' => array('sanitize_callback' => 'absint'), 'control' => array('label' => __('Hide Tagline', 'make'), 'type' => 'checkbox'))); $new_priority = ttfmake_customizer_add_section_options($section_id, $options, $priority->add()); $priority->set($new_priority); }
/** * Convert old theme mod values to their newer equivalents. * * @since 1.3.0. * * @return void */ function ttfmake_customizer_set_up_theme_mod_conversions() { // Don't run conversions if WordPress version doesn't support panels if (!ttfmake_customizer_supports_panels()) { return; } // Set up the necessary filters foreach (ttfmake_customizer_get_key_conversions() as $key => $value) { add_filter('theme_mod_' . $key, 'ttfmake_customizer_convert_theme_mods_filter', 11); } }
/** * Configure settings and controls for the Static Front Page section. * * @since 1.3.0. * * @return void */ function ttfmake_customizer_staticfrontpage() { global $wp_customize; $theme_prefix = 'ttfmake_'; $section_id = 'static_front_page'; $section = $wp_customize->get_section($section_id); $priority = new TTFMAKE_Prioritizer(10, 5); // Move Static Front Page section to General panel $section->panel = $theme_prefix . 'general'; // Set Static Front Page section priority $social_priority = $wp_customize->get_section($theme_prefix . 'social')->priority; $section->priority = $social_priority + 5; // Adjust section title if no panel support if (!ttfmake_customizer_supports_panels()) { $panels = ttfmake_customizer_get_panels(); if (isset($panels['general']['title'])) { $section->title = $panels['general']['title'] . ': ' . $section->title; } } }
/** * Configure settings and controls for the Navigation section. * * @since 1.0.0. * * @return void */ function ttfmake_customizer_navigation() { global $wp_customize; $theme_prefix = 'ttfmake_'; $section_id = 'nav'; // The Navigation section only exists if custom menus have been created. if (!isset($wp_customize->get_section($section_id)->title)) { $wp_customize->add_section('nav'); } $section = $wp_customize->get_section($section_id); $priority = new TTFMAKE_Prioritizer(10, 5); // Move Navigation section to Header panel $section->panel = $theme_prefix . 'header'; // Set Navigation section priority $layout_priority = $wp_customize->get_section($theme_prefix . 'header')->priority; $section->priority = $layout_priority - 5; // Adjust section title if no panel support if (!ttfmake_customizer_supports_panels()) { $panels = ttfmake_customizer_get_panels(); if (isset($panels['header']['title'])) { $section->title = $panels['header']['title'] . ': ' . $section->title; } } // Move the Social Profile Links option to the General > Social section $social_menu = $wp_customize->get_control('nav_menu_locations[social]'); $social_menu->section = $theme_prefix . 'social'; $social_menu->description = __('After you have created your custom menu for social profile links, select it here.', 'make'); $custom_menu_text_priority = $wp_customize->get_control($theme_prefix . 'social-custom-menu-text')->priority; $social_menu->priority = $custom_menu_text_priority + 1; /** * Adjust Navigation section description * * Since the Social Profile Links item gets moved to another section, the part of the description that * states the number of menu locations is misleading. */ $section->description = __('Select which menu appears in each location. You can edit your menu content on the Menus screen in the Appearance section.', 'make'); // Add new options $options = array('navigation-mobile-label' => array('setting' => array('sanitize_callback' => 'esc_html', 'theme_supports' => 'menus', 'transport' => 'postMessage'), 'control' => array('label' => __('Mobile Menu Label', 'make'), 'description' => __('Resize your browser window to preview the mobile menu label.', 'make'), 'type' => 'text'))); $new_priority = ttfmake_customizer_add_section_options($section_id, $options, $priority->add()); $priority->set($new_priority); }
/** * Configure settings and controls for the Background section. * * @since 1.0.0. * * @return void */ function ttfmake_customizer_background() { global $wp_customize; $theme_prefix = 'ttfmake_'; $section_id = 'background_image'; $section = $wp_customize->get_section($section_id); $priority = new TTFMAKE_Prioritizer(10, 5); // Move and rename Background Color control to General section of Color Scheme panel $wp_customize->get_control('background_color')->section = $theme_prefix . 'color-background'; $wp_customize->get_control('background_color')->label = __('Site Background Color', 'make'); // Move Background Image section to General panel $section->panel = $theme_prefix . 'general'; // Set Background Image section priority $logo_priority = $wp_customize->get_section($theme_prefix . 'logo')->priority; $section->priority = $logo_priority + 5; // Adjust section title if no panel support if (!ttfmake_customizer_supports_panels()) { $panels = ttfmake_customizer_get_panels(); if (isset($panels['general']['title'])) { $section->title = $panels['general']['title'] . ': ' . $section->title; } } // Rename Background Image controls $wp_customize->get_control('background_image')->label = __('Site Background Image', 'make'); $wp_customize->get_control('background_repeat')->label = __('Site Background Repeat', 'make'); $wp_customize->get_control('background_position_x')->label = __('Site Background Position', 'make'); $wp_customize->get_control('background_attachment')->label = __('Site Background Attachment', 'make'); // Reset priorities on existing controls $wp_customize->get_control('background_image')->priority = $priority->add(); $wp_customize->get_control('background_repeat')->priority = $priority->add(); $wp_customize->get_control('background_position_x')->priority = $priority->add(); $wp_customize->get_control('background_attachment')->priority = $priority->add(); // Add new option for Site background image $options = array('background_size' => array('setting' => array('sanitize_callback' => 'ttfmake_sanitize_choice'), 'control' => array('label' => __('Site Background Size', 'make'), 'type' => 'radio', 'choices' => ttfmake_get_choices('background_size')))); $new_priority = ttfmake_customizer_add_section_options($section_id, $options, $priority->add()); $priority->set($new_priority); // Add options for Main Column background image $options = array('main-background-image' => array('setting' => array('sanitize_callback' => 'esc_url_raw'), 'control' => array('control_type' => 'TTFMAKE_Customize_Image_Control', 'label' => __('Main Column Background Image', 'make'), 'context' => $theme_prefix . 'main-background-image')), 'main-background-repeat' => array('setting' => array('sanitize_callback' => 'ttfmake_sanitize_choice'), 'control' => array('label' => __('Main Column Background Repeat', 'make'), 'type' => 'radio', 'choices' => ttfmake_get_choices('main-background-repeat'))), 'main-background-position' => array('setting' => array('sanitize_callback' => 'ttfmake_sanitize_choice'), 'control' => array('label' => __('Main Column Background Position', 'make'), 'type' => 'radio', 'choices' => ttfmake_get_choices('main-background-position'))), 'main-background-size' => array('setting' => array('sanitize_callback' => 'ttfmake_sanitize_choice'), 'control' => array('label' => __('Main Column Background Size', 'make'), 'type' => 'radio', 'choices' => ttfmake_get_choices('main-background-size')))); $new_priority = ttfmake_customizer_add_section_options($section_id, $options, $priority->add()); $priority->set($new_priority); }
/** * Add sections and controls to the customizer. * * Hooked to 'customize_register' via ttfmake_customizer_init(). * * @since 1.0.0. * * @param WP_Customize_Manager $wp_customize Theme Customizer object. * @return void */ function ttfmake_customizer_add_sections($wp_customize) { // Use legacy sections instead if no panel support if (!ttfmake_customizer_supports_panels()) { ttfmake_customizer_add_legacy_sections($wp_customize); return; } $theme_prefix = 'ttfmake_'; $default_path = get_template_directory() . '/inc/customizer/sections'; $panels = ttfmake_customizer_get_panels(); // Load built-in section mods $builtin_mods = array('background', 'navigation', 'site-title-tagline', 'static-front-page'); if (!ttfmake_is_plus()) { $builtin_mods[] = 'stylekit'; } foreach ($builtin_mods as $slug) { $file = trailingslashit($default_path) . $slug . '.php'; if (file_exists($file)) { require_once $file; } } // Load section definition files foreach ($panels as $panel => $data) { if (!isset($data['path'])) { $data['path'] = $default_path; } $file = trailingslashit($data['path']) . $panel . '.php'; if (file_exists($file)) { require_once $file; } } // Compile the section definitions $sections = ttfmake_customizer_get_sections(); // Register each section and add its options $priority = array(); foreach ($sections as $section => $data) { // Get the non-prefixed ID of the current section's panel $panel = isset($data['panel']) ? str_replace($theme_prefix, '', $data['panel']) : 'none'; // Store the options if (isset($data['options'])) { $options = $data['options']; unset($data['options']); } // Determine the priority if (!isset($data['priority'])) { $panel_priority = 'none' !== $panel && isset($panels[$panel]['priority']) ? $panels[$panel]['priority'] : 1000; // Create a separate priority counter for each panel, and one for sections without a panel if (!isset($priority[$panel])) { $priority[$panel] = new TTFMAKE_Prioritizer($panel_priority, 10); } $data['priority'] = $priority[$panel]->add(); } // Adjust section title if no panel support if (!ttfmake_customizer_supports_panels() && isset($data['panel'])) { $existing_title = isset($data['title']) ? $data['title'] : ucfirst($section); $panel_prefix = isset($panels[$panel]['title']) ? $panels[$panel]['title'] . ': ' : ''; $data['title'] = $panel_prefix . $existing_title; } // Register section $wp_customize->add_section($theme_prefix . $section, $data); // Back compatibility if (isset($data['path'])) { $file = trailingslashit($data['path']) . $section . '.php'; if (file_exists($file)) { // First load the file require_once $file; // Then add the section $section_callback = 'ttfmake_customizer_'; $section_callback .= strpos($section, '-') ? str_replace('-', '_', $section) : $section; if (function_exists($section_callback)) { // Callback to populate the section call_user_func_array($section_callback, array($wp_customize, $theme_prefix . $section)); } } } // Add options to the section if (isset($options)) { ttfmake_customizer_add_section_options($theme_prefix . $section, $options); unset($options); } } }
/** * Build the HTTP request URL for Google Fonts. * * @since 1.0.0. * * @return string The URL for including Google Fonts. */ function ttfmake_get_google_font_uri() { // Grab the font choices if (ttfmake_customizer_supports_panels()) { $font_keys = array('font-family-site-title', 'font-family-site-tagline', 'font-family-nav', 'font-family-subnav', 'font-family-widget', 'font-family-h1', 'font-family-h2', 'font-family-h3', 'font-family-h4', 'font-family-h5', 'font-family-h6', 'font-family-body'); } else { $font_keys = array('font-site-title', 'font-header', 'font-body'); } $fonts = array(); foreach ($font_keys as $key) { $fonts[] = get_theme_mod($key, ttfmake_get_default($key)); } // De-dupe the fonts $fonts = array_unique($fonts); $allowed_fonts = ttfmake_get_google_fonts(); $family = array(); // Validate each font and convert to URL format foreach ($fonts as $font) { $font = trim($font); // Verify that the font exists if (array_key_exists($font, $allowed_fonts)) { // Build the family name and variant string (e.g., "Open+Sans:regular,italic,700") $family[] = urlencode($font . ':' . join(',', ttfmake_choose_google_font_variants($font, $allowed_fonts[$font]['variants']))); } } // Convert from array to string if (empty($family)) { return ''; } else { $request = '//fonts.googleapis.com/css?family=' . implode('|', $family); } // Load the font subset $subset = get_theme_mod('font-subset', ttfmake_get_default('font-subset')); if ('all' === $subset) { $subsets_available = ttfmake_get_google_font_subsets(); // Remove the all set unset($subsets_available['all']); // Build the array $subsets = array_keys($subsets_available); } else { $subsets = array('latin', $subset); } // Append the subset string if (!empty($subsets)) { $request .= urlencode('&subset=' . join(',', $subsets)); } /** * Filter the Google Fonts URL. * * @since 1.2.3. * * @param string $url The URL to retrieve the Google Fonts. */ return apply_filters('make_get_google_font_uri', esc_url($request)); }