/** * Loads the Hybrid theme settings once and allows the input of the specific field the user would * like to show. Hybrid theme settings are added with 'autoload' set to 'yes', so the settings are * only loaded once on each page load. * * @since 0.7.0 * @access public * @uses get_option() Gets an option from the database. * @uses hybrid_get_prefix() Gets the prefix of the theme. * @global object $hybrid The global Hybrid object. * @param string $option The specific theme setting the user wants. * @return mixed $settings[$option] Specific setting asked for. */ function hybrid_get_setting($option = '') { global $hybrid; /* If no specific option was requested, return false. */ if (!$option) { return false; } /* Get the default settings. */ $defaults = hybrid_get_default_theme_settings(); /* If the settings array hasn't been set, call get_option() to get an array of theme settings. */ if (!isset($hybrid->settings) || !is_array($hybrid->settings)) { $hybrid->settings = get_option(hybrid_get_prefix() . '_theme_settings', $defaults); } /* If the option isn't set but the default is, set the option to the default. */ if (!isset($hybrid->settings[$option]) && isset($defaults[$option])) { $hybrid->settings[$option] = $defaults[$option]; } /* If no option is found at this point, return false. */ if (!isset($hybrid->settings[$option])) { return false; } /* If the specific option is an array, return it. */ if (is_array($hybrid->settings[$option])) { return $hybrid->settings[$option]; } else { return wp_kses_stripslashes($hybrid->settings[$option]); } }
/** * Registers custom sections, settings, and controls for the $wp_customize instance. * * @param object $wp_customize * @since Cakifo 1.4 */ function cakifo_customize_register($wp_customize) { /* Get the theme prefix. */ $prefix = hybrid_get_prefix(); /* Get the default theme settings. */ $defaults = hybrid_get_default_theme_settings(); $wp_customize->get_setting('blogname')->transport = 'postMessage'; $wp_customize->get_setting('blogdescription')->transport = 'postMessage'; /* Add the Cakifo section */ $wp_customize->add_section('cakifo_customize_settings', array('title' => esc_html__('Cakifo settings', 'cakifo'), 'priority' => 35, 'capability' => 'edit_theme_options')); /** * Link color */ $wp_customize->add_setting("{$prefix}_theme_settings[link_color]", array('default' => cakifo_get_default_link_color(), 'type' => 'option', 'sanitize_callback' => 'sanitize_hex_color', 'capability' => 'edit_theme_options')); $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'link_color', array('label' => esc_html__('Link Color', 'cakifo'), 'section' => 'colors', 'settings' => "{$prefix}_theme_settings[link_color]"))); /** * Show slider? */ $wp_customize->add_setting("{$prefix}_theme_settings[featured_show]", array('default' => false, 'type' => 'option', 'capability' => 'edit_theme_options')); $wp_customize->add_control('featured_show', array('settings' => "{$prefix}_theme_settings[featured_show]", 'label' => esc_html__('Show "Featured Content" slider?', 'cakifo'), 'section' => 'cakifo_customize_settings', 'type' => 'checkbox')); /** * Slider categories */ // Create category array foreach (get_categories() as $cat) { $categories[$cat->term_id] = $cat->name; } /* Add setting and control */ $wp_customize->add_setting("{$prefix}_theme_settings[featured_category]", array('default' => '', 'type' => 'option', 'capability' => 'edit_theme_options')); $wp_customize->add_control('featured_category', array('settings' => "{$prefix}_theme_settings[featured_category]", 'label' => esc_html__('Featured Category:', 'cakifo'), 'section' => 'cakifo_customize_settings', 'type' => 'select', 'choices' => $categories)); /** * Number of posts in the slider */ $wp_customize->add_setting("{$prefix}_theme_settings[featured_posts]", array('default' => 5, 'type' => 'option', 'capability' => 'edit_theme_options')); $wp_customize->add_control('featured_posts', array('settings' => "{$prefix}_theme_settings[featured_posts]", 'label' => esc_html__('Number of posts', 'cakifo'), 'section' => 'cakifo_customize_settings', 'type' => 'text')); if ($wp_customize->is_preview() && !is_admin()) { add_action('wp_footer', 'cakifo_customize_preview', 21); } }
/** * Registers custom sections, settings, and controls for the $wp_customize instance. * * @since 1.4.0 * @access private * @param object $wp_customize */ function hybrid_customize_register($wp_customize) { /* Get supported theme settings. */ $supports = get_theme_support('hybrid-core-theme-settings'); /* Get the theme prefix. */ $prefix = hybrid_get_prefix(); /* Get the default theme settings. */ $default_settings = hybrid_get_default_theme_settings(); /* Add the footer section, setting, and control if theme supports the 'footer' setting. */ if (is_array($supports[0]) && in_array('footer', $supports[0])) { /* Add the footer section. */ $wp_customize->add_section('hybrid-core-footer', array('title' => esc_html__('Footer', 'hybrid-core'), 'priority' => 200, 'capability' => 'edit_theme_options')); /* Add the 'footer_insert' setting. */ $wp_customize->add_setting("{$prefix}_theme_settings[footer_insert]", array('default' => $default_settings['footer_insert'], 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'hybrid_customize_sanitize', 'sanitize_js_callback' => 'hybrid_customize_sanitize', 'transport' => 'postMessage')); /* Add the textarea control for the 'footer_insert' setting. */ $wp_customize->add_control(new Hybrid_Customize_Control_Textarea($wp_customize, 'hybrid-core-footer', array('label' => esc_html__('Footer', 'hybrid-core'), 'section' => 'hybrid-core-footer', 'settings' => "{$prefix}_theme_settings[footer_insert]"))); /* If viewing the customize preview screen, add a script to show a live preview. */ if ($wp_customize->is_preview() && !is_admin()) { add_action('wp_footer', 'hybrid_customize_preview_script', 21); } } }
/** * Loads the Hybrid theme settings once and allows the input of the specific field the user would * like to show. Hybrid theme settings are added with 'autoload' set to 'yes', so the settings are * only loaded once on each page load. * * @since 0.7.0 * @access public * @uses get_option() Gets an option from the database. * @uses hybrid_get_prefix() Gets the prefix of the theme. * @global object $hybrid The global Hybrid object. * @param string $option The specific theme setting the user wants. * @return mixed $settings[$option] Specific setting asked for. */ function hybrid_get_setting($option = '') { global $hybrid; /* If no specific option was requested, return false. */ if (!$option) { return false; } /* If the settings array hasn't been set, call get_option() to get an array of theme settings. */ if (!isset($hybrid->settings)) { $hybrid->settings = get_option(hybrid_get_prefix() . '_theme_settings', hybrid_get_default_theme_settings()); } /* If the settings isn't an array or the specific option isn't in the array, return false. */ if (!is_array($hybrid->settings) || empty($hybrid->settings[$option])) { return false; } /* If the specific option is an array, return it. */ if (is_array($hybrid->settings[$option])) { return $hybrid->settings[$option]; } else { return wp_kses_stripslashes($hybrid->settings[$option]); } }
/** * Registers the plugin settings and sets up the settings sections and fields. * * @since 2.0.0 * @access public * @return void */ public function register_settings() { /* Register theme settings. */ register_setting("{$this->prefix}_theme_settings", "{$this->prefix}_theme_settings", array($this, 'validate_settings')); /* Get the plugin settings from the database. */ $this->settings = get_option("{$this->prefix}_theme_settings", hybrid_get_default_theme_settings()); }
/** * @since 0.4.0 * @deprecated 1.0.0 */ function hybrid_theme_settings() { _deprecated_function(__FUNCTION__, '1.0.0', 'hybrid_get_default_theme_settings()'); return apply_filters(hybrid_get_prefix() . '_settings_args', hybrid_get_default_theme_settings()); }
/** * Saves the default theme settings in the {$wpdb->prefix}_options if none have been added. The * settings are given a unique name depending on the theme directory. They are always saved as * {$prefix}_theme_settings in the database. * * @since 0.7.0 */ function hybrid_load_settings_page() { $prefix = hybrid_get_prefix(); /* Get theme settings from the database. */ $settings = get_option( "{$prefix}_theme_settings" ); /* If no settings are available, add the default settings to the database. */ if ( false === $settings ) { $settings = hybrid_get_default_theme_settings(); add_option( "{$prefix}_theme_settings", $settings, '', 'yes' ); /* Redirect the page so that the settings are reflected on the settings page. */ wp_redirect( admin_url( 'themes.php?page=theme-settings' ) ); exit; } }
/** * Add a style block to the theme for the current link color. * * This function is attached to the wp_head action hook. * * @since Cakifo 1.4 */ function cakifo_print_link_color_style() { $defaults = hybrid_get_default_theme_settings(); $link_color = hybrid_get_setting('link_color'); // Don't do anything if the current link color is the default color for the current scheme if ($link_color == $defaults['link_color']) { return; } ?> <style> /* Link color */ a, .entry-title a { color: <?php echo esc_attr($link_color); ?> ; } </style> <?php }