Example #1
0
/**
 * Helper function to return the theme option value.
 * If no value has been saved, it returns $default.
 * If no $default provided, it checks the default options array.
 * 
 * @since 1.0.0
 * @access public
 * @param string $name
 * @param mixed $default
 * @return mixed
 */
function hoot_get_option($name, $default = NULL)
{
    /*** Return option value if set ***/
    static $options = NULL;
    // cache
    // Get the values from database
    if ($options === NULL) {
        $option_name = hootoptions_option_name();
        $options = get_option($option_name);
    }
    // Ideally, this should not have any expensive function, as hoot_get_option() is used quite often.
    $options = apply_filters('hoot_get_option', $options);
    if (isset($options[$name])) {
        // Add exceptions: If a value has been set but is empty, this gives the option to return default values in such cases. Simply return $override as (bool)true.
        $override = apply_filters('hoot_get_option_empty_values', false, $options[$name]);
        if ($override !== true) {
            return $options[$name];
        }
    }
    /*** Return default if provided ***/
    if ($default !== NULL) {
        return $default;
    }
    /*** Return default theme option value ***/
    static $defaults = NULL;
    // cache
    // Get the default values from options array
    if ($defaults === NULL) {
        $options_array = hoot_get_theme_options_array();
        // $defaults is created similar to get_default_values() in class-hoot-options-admin
        if ($options_array) {
            foreach ($options_array as $op) {
                if (isset($op['id']) && isset($op['std']) && isset($op['type'])) {
                    if (has_filter('hoot_of_sanitize_' . $op['type'])) {
                        $defaults[$op['id']] = apply_filters('hoot_of_sanitize_' . $op['type'], $op['std'], $op);
                    } else {
                        $defaults[$op['id']] = $op['std'];
                    }
                }
            }
        }
    }
    if (isset($defaults[$name])) {
        return $defaults[$name];
    }
    /*** We dont have anything! ***/
    return false;
}
 /**
  * Wrapper for hoot_get_theme_options_array()
  *
  * @return array
  */
 static function _hootoptions_options()
 {
     return hoot_get_theme_options_array();
 }