/** * Output Inline Styles in Head * * Hooks into the 'wp_head' action and outputs specific * inline styles relevant to each font option. * * @link http://codex.wordpress.org/Function_Reference/add_action add_action() * * @since 1.2 * @version 1.3.6 * */ public function output_styles() { global $wp_customize; $transient = isset($wp_customize) ? false : true; $options = EGF_Register_Options::get_options($transient); $default_options = EGF_Register_Options::get_option_parameters(); ?> <?php if (!isset($wp_customize)) { ?> <style id="tt-easy-google-font-styles" type="text/css"> <?php } ?> <?php foreach ($options as $key => $value) { ?> <?php $force_styles = isset($default_options[$key]['properties']['force_styles']) ? $default_options[$key]['properties']['force_styles'] : false; ?> <?php if (isset($wp_customize) && !empty($options[$key])) { ?> <?php echo $this->generate_customizer_css($options[$key], $default_options[$key]['properties']['selector'], $key, $force_styles); ?> <?php } else { ?> <?php if (!empty($default_options[$key])) { ?> <?php echo $default_options[$key]['properties']['selector']; ?> { <?php echo $this->generate_css($options[$key], $force_styles); ?> } <?php } ?> <?php } ?> <?php } ?> <?php if (!isset($wp_customize)) { ?> </style> <?php } ?> <?php }
/** * Theme Customizer Controls Implementation * * Implement the Theme Customizer for the Theme Settings * in this theme. * * @link http://ottopress.com/2012/how-to-leverage-the-theme-customizer-in-your-own-themes/ Otto * * @see final class WP_Customize_Manager defined in \{root}\wp-includes\class-wp-customize-manager.php * * @param object $wp_customize Object that holds the customizer data * * @since 1.3 * @version 1.3.6 * */ public function register_controls($wp_customize) { if (!isset($wp_customize)) { return; } $tt_font_options = EGF_Register_Options::get_options(false); // Get the array of option parameters $option_parameters = EGF_Register_Options::get_option_parameters(); // Get customizer panels $panels = EGF_Register_Options::get_panels(); // Get list of tabs $tabs = EGF_Register_Options::get_setting_tabs(); /** * 1. Add Panels * * Add the panels to the customizer: * Add panels to the customizer based on each $panel * from EGF_Register_Options::get_panels() using the * new panels API in the customizer. * */ if (method_exists($wp_customize, 'add_panel')) { foreach ($panels as $panel) { $wp_customize->add_panel($panel['name'], array('priority' => $panel['priority'], 'capability' => $panel['capability'], 'title' => $panel['title'], 'description' => $panel['description'])); } } /** * 2. Register Sections * * Add Each Customizer Section: * Add each customizer section based on each $tab section * from EGF_Register_Options::get_setting_tabs() * */ foreach ($tabs as $tab) { // Add $tab section $wp_customize->add_section('tt_font_' . $tab['name'], array('title' => $tab['title'], 'description' => $tab['description'], 'panel' => $tab['panel'])); } /** * 3. Add Settings to Sections * 4. Register Control for Each Setting * */ $priority = 0; foreach ($option_parameters as $option_parameter) { /** * Set Transport Method: * * Default is to reload the iframe when the option is * modified in the customizer. * * DEVELOPER NOTE: To change the transport type for each * option modify the 'transport' value for the appropriate * option in the $options array found in: * tt_font_get_option_parameters() * */ $transport = empty($option_parameter['transport']) ? 'refresh' : $option_parameter['transport']; /** * Add Setting To Customizer: * * Adds $option_parameter setting to customizer * further properties are registered below. * */ $wp_customize->add_setting('tt_font_theme_options[' . $option_parameter['name'] . ']', array('default' => $option_parameter['default'], 'type' => 'option', 'transport' => $transport)); /** * Section Prefix: * * Add the 'tt_font_' prefix to prevent namespace * collisions. Removes the prefix if we are adding * this option to a default WordPress section. * */ $prefix = empty($option_parameter['wp_section']) ? 'tt_font_' : ''; // Set control $priority $priority += 20; switch ($option_parameter['type']) { case 'font': $wp_customize->add_control(new EGF_Font_Control($wp_customize, $option_parameter['name'], array('id' => '', 'label' => $option_parameter['title'], 'section' => 'tt_font_' . $option_parameter['tab'], 'settings' => 'tt_font_theme_options[' . $option_parameter['name'] . ']', 'priority' => $priority, 'option' => $option_parameter))); break; // Here in case we decide to implement // an additional lightweight control. // Here in case we decide to implement // an additional lightweight control. case 'font_basic': break; } } }
/** * Theme Settings Theme Customizer Implementation * * Implement the Theme Customizer for the Theme Settings * in this theme. * * @link http://ottopress.com/2012/how-to-leverage-the-theme-customizer-in-your-own-themes/ Otto * * @see final class WP_Customize_Manager defined in \{root}\wp-includes\class-wp-customize-manager.php * * @param object $wp_customize Object that holds the customizer data * * @since 1.2 * @version 1.2.3 * */ public function register_theme_customizer($wp_customize) { // Failsafe is safe if (!isset($wp_customize)) { return; } $tt_font_options = EGF_Register_Options::get_options(false); // Get the array of option parameters $option_parameters = EGF_Register_Options::get_option_parameters(); // Get list of tabs $tabs = EGF_Register_Options::get_setting_tabs(); /** * 1. Register Section * * Add Each Customizer Section: * Add each customizer section based on each $tab section * from EGF_Register_Options::get_setting_tabs() * */ foreach ($tabs as $tab) { // Add $tab section $wp_customize->add_section('tt_font_' . $tab['name'], array('title' => $tab['title'], 'description' => $tab['description'])); } /** * 2. Add Settings to Sections * 3. Register Control for Each Setting * */ $priority = 0; foreach ($option_parameters as $option_parameter) { /** * Set Transport Method: * * Default is to reload the iframe when the option is * modified in the customizer. * * DEVELOPER NOTE: To change the transport type for each * option modify the 'transport' value for the appropriate * option in the $options array found in tt_font_get_option_parameters() * */ $transport = empty($option_parameter['transport']) ? 'refresh' : $option_parameter['transport']; /** * Add Setting To Customizer: * * Adds $option_parameter setting to customizer * further properties are registered below. The * color properties are registered as separate * settings for performance reasons. * */ $wp_customize->add_setting('tt_font_theme_options[' . $option_parameter['name'] . ']', array('default' => $option_parameter['default'], 'type' => 'option', 'transport' => $transport)); $wp_customize->add_setting('tt_font_theme_options[' . $option_parameter['name'] . '][font_color]', array('default' => $option_parameter['default']['font_color'], 'type' => 'option', 'transport' => $transport)); $wp_customize->add_setting('tt_font_theme_options[' . $option_parameter['name'] . '][background_color]', array('default' => $option_parameter['default']['background_color'], 'type' => 'option', 'transport' => $transport)); /** * Section Prefix: * * Add the 'tt_font_' prefix to prevent namespace * collisions. Removes the prefix if we are adding * this option to a default WordPress section. * */ $prefix = empty($option_parameter['wp_section']) ? 'tt_font_' : ''; // Set control $priority $priority += 20; // Include font control class if it hasn't been loaded if (!class_exists('EGF_Font_Control')) { include plugin_dir_path(__FILE__) . 'controls/class-egf-font-control.php'; } switch ($option_parameter['type']) { case 'font': $wp_customize->add_control(new EGF_Font_Control($wp_customize, $option_parameter['name'], array('label' => $option_parameter['title'], 'section' => 'tt_font_' . $option_parameter['tab'], 'settings' => 'tt_font_theme_options[' . $option_parameter['name'] . ']', 'priority' => $priority, 'option' => $option_parameter))); break; // Here in case we decide to implement an additional lightweight control // Here in case we decide to implement an additional lightweight control case 'font_basic': break; } } }