Example #1
0
/**
 * Return option from the options table and cache result.
 *
 * Applies `genesis_pre_get_option_$key` and `genesis_options` filters.
 *
 * Values pulled from the database are cached on each request, so a second request for the same value won't cause a
 * second DB interaction.
 *
 * @since 0.1.3
 *
 * @uses GENESIS_SETTINGS_FIELD
 *
 * @param string  $key        Option name.
 * @param string  $setting    Optional. Settings field name. Eventually defaults to `GENESIS_SETTINGS_FIELD` if not
 *                            passed as an argument.
 * @param boolean $use_cache  Optional. Whether to use the Genesis cache value or not. Default is true.
 *
 * @return mixed The value of this $key in the database.
 */
function genesis_get_option($key, $setting = null, $use_cache = true)
{
    //* The default is set here, so it doesn't have to be repeated in the function arguments for genesis_option() too.
    $setting = $setting ? $setting : GENESIS_SETTINGS_FIELD;
    //* Allow child theme to short-circuit this function
    $pre = apply_filters("genesis_pre_get_option_{$key}", null, $setting);
    if (null !== $pre) {
        return $pre;
    }
    //* Bypass cache if viewing site in customizer
    if (genesis_is_customizer()) {
        $use_cache = false;
    }
    //* If we need to bypass the cache
    if (!$use_cache) {
        $options = get_option($setting);
        if (!is_array($options) || !array_key_exists($key, $options)) {
            return '';
        }
        return is_array($options[$key]) ? stripslashes_deep($options[$key]) : stripslashes(wp_kses_decode_entities($options[$key]));
    }
    //* Setup caches
    static $settings_cache = array();
    static $options_cache = array();
    //* Check options cache
    if (isset($options_cache[$setting][$key])) {
        //* Option has been cached
        return $options_cache[$setting][$key];
    }
    //* Check settings cache
    if (isset($settings_cache[$setting])) {
        //* Setting has been cached
        $options = apply_filters('genesis_options', $settings_cache[$setting], $setting);
    } else {
        //* Set value and cache setting
        $options = $settings_cache[$setting] = apply_filters('genesis_options', get_option($setting), $setting);
    }
    //* Check for non-existent option
    if (!is_array($options) || !array_key_exists($key, (array) $options)) {
        //* Cache non-existent option
        $options_cache[$setting][$key] = '';
    } else {
        //* Option has not been previously been cached, so cache now
        $options_cache[$setting][$key] = is_array($options[$key]) ? stripslashes_deep($options[$key]) : stripslashes(wp_kses_decode_entities($options[$key]));
    }
    return $options_cache[$setting][$key];
}
Example #2
0
 /**
  * Output an <img> tag of the site logo, at the size specified
  * in the theme's add_theme_support() declaration.
  *
  * @since 0.1.0
  * @uses GenLib_Logo::logo
  * @uses GenLib_Logo::theme_size()
  * @uses GenLib_Logo::has_site_logo()
  * @uses genesis_is_customizer()
  * @uses esc_url()
  * @uses home_url()
  * @uses esc_attr()
  * @uses wp_get_attachment_image()
  * @uses apply_filters()
  */
 public function the_site_logo()
 {
     $logo = $this->logo;
     $size = $this->theme_size();
     // Bail if no logo is set. Leave a placeholder if we're in the Customizer, though (needed for the live preview).
     if (!$this->has_site_logo()) {
         if (genesis_is_customizer()) {
             printf('<a href="%1$s" class="site-logo-link" style="display:none;"><img class="site-logo" data-size="%2$s" /></a>', esc_url(home_url('/')), esc_attr($size));
         }
         return;
     }
     // We have a logo. Logo is go.
     $html = sprintf('<a href="%1$s" class="site-logo-link" rel="home">%2$s</a>', esc_url(home_url('/')), wp_get_attachment_image(absint($logo['id']), esc_attr($size), false, array('class' => 'site-logo attachment-' . esc_attr($size), 'data-size' => esc_attr($size))));
     echo apply_filters('the_site_logo', $html, $logo, $size);
 }
Example #3
0
 /**
  * Load all library functions.
  *
  * @since  0.1.0
  * @access protected
  * @return void
  */
 protected function includes()
 {
     if (!is_admin()) {
         require_once "{$this->dir}inc/template-tags.php";
     }
     if (genesis_is_customizer()) {
         require_once "{$this->dir}inc/class-site-logo-control.php";
     }
 }