Example #1
0
/**
 * Load and return some specific config or it's part
 *
 * @param string $path <config_name>[.<name1>[.<name2>[...]]]
 * @oaram mixed $default Value to return if no data is found
 *
 * @return mixed
 */
function us_config($path, $default = NULL)
{
    global $us_template_directory;
    // Caching configuration values in a inner static value within the same request
    static $configs = array();
    // Defined paths to configuration files
    $configs_paths = apply_filters('us_configs_paths', array());
    $path = explode('.', $path);
    $config_name = $path[0];
    if (!isset($configs[$config_name])) {
        if (!isset($configs_paths[$config_name])) {
            $configs_paths[$config_name] = $us_template_directory . '/framework/config/' . $config_name . '.php';
        }
        us_maybe_load_theme_textdomain();
        $configs[$config_name] = (require $configs_paths[$config_name]);
        $configs[$config_name] = apply_filters('us_config_' . $config_name, $configs[$config_name]);
    }
    $value = $configs[$config_name];
    for ($i = 1; $i < count($path); $i++) {
        if (is_array($value) and isset($value[$path[$i]])) {
            $value = $value[$path[$i]];
        } else {
            $value = $default;
            break;
        }
    }
    return $value;
}
Example #2
0
function us_theme_setup()
{
    global $content_width;
    if (!isset($content_width)) {
        $content_width = 1500;
    }
    add_theme_support('automatic-feed-links');
    add_theme_support('post-formats', array('quote', 'image', 'gallery', 'video'));
    // Add post thumbnail functionality
    add_theme_support('post-thumbnails');
    /**
     * Dev note: you can overload theme's image sizes config using filter 'us_config_image-sizes'
     */
    $tnail_sizes = us_config('image-sizes');
    foreach ($tnail_sizes as $size_name => $size) {
        add_image_size($size_name, $size['width'], $size['height'], $size['crop']);
    }
    // Excerpt length
    add_filter('excerpt_length', 'us_excerpt_length', 100);
    function us_excerpt_length($length)
    {
        $excerpt_length = us_get_option('excerpt_length');
        if ($excerpt_length === NULL) {
            return $length;
        } elseif ($excerpt_length === '') {
            // If not set, showing the full excerpt
            return 9999;
        } else {
            return intval($excerpt_length);
        }
    }
    // Remove [...] from excerpt
    add_filter('excerpt_more', 'us_excerpt_more');
    function us_excerpt_more($more)
    {
        return '...';
    }
    // Theme localization
    us_maybe_load_theme_textdomain();
}