/** * Register settings and controls for a section. * * @since 1.3.0. * * @param string $section Section ID * @param array $args Array of setting and control definitions * @param int $initial_priority The initial priority to use for controls * @return int The last priority value assigned */ function ttfmake_customizer_add_section_options($section, $args, $initial_priority = 100) { global $wp_customize; $priority = new TTFMAKE_Prioritizer($initial_priority, 5); $theme_prefix = 'ttfmake_'; foreach ($args as $setting_id => $option) { // Add setting if (isset($option['setting'])) { $defaults = array('type' => 'theme_mod', 'capability' => 'edit_theme_options', 'theme_supports' => '', 'default' => ttfmake_get_default($setting_id), 'transport' => 'refresh', 'sanitize_callback' => '', 'sanitize_js_callback' => ''); $setting = wp_parse_args($option['setting'], $defaults); // Add the setting arguments inline so Theme Check can verify the presence of sanitize_callback $wp_customize->add_setting($setting_id, array('type' => $setting['type'], 'capability' => $setting['capability'], 'theme_supports' => $setting['theme_supports'], 'default' => $setting['default'], 'transport' => $setting['transport'], 'sanitize_callback' => $setting['sanitize_callback'], 'sanitize_js_callback' => $setting['sanitize_js_callback'])); } // Add control if (isset($option['control'])) { $control_id = $theme_prefix . $setting_id; $defaults = array('settings' => $setting_id, 'section' => $section, 'priority' => $priority->add()); if (!isset($option['setting'])) { unset($defaults['settings']); } $control = wp_parse_args($option['control'], $defaults); // Check for a specialized control class if (isset($control['control_type'])) { $class = $control['control_type']; $control_path = apply_filters('make_customizer_control_path', get_template_directory() . '/inc/customizer/controls/', $control); $control_file = $control_path . $class . '.php'; if (file_exists($control_file)) { require_once $control_file; } if (class_exists($class)) { unset($control['control_type']); // Dynamically generate a new class instance $reflection = new ReflectionClass($class); $class_instance = $reflection->newInstanceArgs(array($wp_customize, $control_id, $control)); $wp_customize->add_control($class_instance); } } else { $wp_customize->add_control($control_id, $control); } } } return $priority->get(); }
/** * Register settings and controls for a section. * * @since 1.3.0. * * @param string $section Section ID * @param array $args Array of setting and control definitions * @param int $initial_priority The initial priority to use for controls * @return int The last priority value assigned */ function ttfmake_customizer_add_section_options($section, $args, $initial_priority = 100) { global $wp_customize; $priority = new TTFMAKE_Prioritizer($initial_priority, 5); $theme_prefix = 'ttfmake_'; foreach ($args as $setting_id => $option) { // Add setting if (isset($option['setting'])) { $defaults = array('default' => ttfmake_get_default($setting_id), 'type' => 'theme_mod'); $setting = wp_parse_args($option['setting'], $defaults); $wp_customize->add_setting($setting_id, $setting); } // Add control if (isset($option['control'])) { $control_id = $theme_prefix . $setting_id; $defaults = array('settings' => $setting_id, 'section' => $section, 'priority' => $priority->add()); if (!isset($option['setting'])) { unset($defaults['settings']); } $control = wp_parse_args($option['control'], $defaults); // Check for a specialized control class if (isset($control['control_type'])) { $class = $control['control_type']; unset($control['control_type']); $wp_customize->add_control(new $class($wp_customize, $control_id, $control)); } else { $wp_customize->add_control($control_id, $control); } } } return $priority->get(); }