Example #1
0
/**
 * Filters the WordPress body class with a better set of classes that are more consistently handled and 
 * are backwards compatible with the original body class functionality that existed prior to WordPress 
 * core adopting this feature.
 *
 * @since  2.0.0
 * @access public
 * @param  array        $classes
 * @param  string|array $class
 * @return array
 */
function hybrid_body_class_filter($classes, $class)
{
    /* WordPress class for uses when WordPress isn't always the only system on the site. */
    $classes = array('wordpress');
    /* Text direction. */
    $classes[] = is_rtl() ? 'rtl' : 'ltr';
    /* Locale and language. */
    $locale = get_locale();
    $lang = hybrid_get_language($locale);
    if ($locale !== $lang) {
        $classes[] = $lang;
    }
    $classes[] = strtolower(str_replace('_', '-', $locale));
    /* Check if the current theme is a parent or child theme. */
    $classes[] = is_child_theme() ? 'child-theme' : 'parent-theme';
    /* Multisite check adds the 'multisite' class and the blog ID. */
    if (is_multisite()) {
        $classes[] = 'multisite';
        $classes[] = 'blog-' . get_current_blog_id();
    }
    /* Date classes. */
    $time = time() + get_option('gmt_offset') * 3600;
    $classes[] = strtolower(gmdate('\\yY \\mm \\dd \\hH l', $time));
    /* Is the current user logged in. */
    $classes[] = is_user_logged_in() ? 'logged-in' : 'logged-out';
    /* WP admin bar. */
    if (is_admin_bar_showing()) {
        $classes[] = 'admin-bar';
    }
    /* Use the '.custom-background' class to integrate with the WP background feature. */
    if (get_background_image() || get_background_color()) {
        $classes[] = 'custom-background';
    }
    /* Add the '.custom-header' class if the user is using a custom header. */
    if (get_header_image() || display_header_text() && get_header_textcolor()) {
        $classes[] = 'custom-header';
    }
    /* Add the '.display-header-text' class if the user chose to display it. */
    if (display_header_text()) {
        $classes[] = 'display-header-text';
    }
    /* Plural/multiple-post view (opposite of singular). */
    if (is_home() || is_archive() || is_search()) {
        $classes[] = 'plural';
    }
    /* Merge base contextual classes with $classes. */
    $classes = array_merge($classes, hybrid_get_context());
    /* Singular post (post_type) classes. */
    if (is_singular()) {
        /* Get the queried post object. */
        $post = get_queried_object();
        /* Checks for custom template. */
        $template = str_replace(array("{$post->post_type}-template-", "{$post->post_type}-"), '', basename(get_post_meta(get_queried_object_id(), "_wp_{$post->post_type}_template", true), '.php'));
        if (!empty($template)) {
            $classes[] = "{$post->post_type}-template-{$template}";
        }
        /* Post format. */
        if (current_theme_supports('post-formats') && post_type_supports($post->post_type, 'post-formats')) {
            $post_format = get_post_format(get_queried_object_id());
            $classes[] = empty($post_format) || is_wp_error($post_format) ? "{$post->post_type}-format-standard" : "{$post->post_type}-format-{$post_format}";
        }
        /* Attachment mime types. */
        if (is_attachment()) {
            foreach (explode('/', get_post_mime_type()) as $type) {
                $classes[] = "attachment-{$type}";
            }
        }
    }
    /* Paged views. */
    if (is_paged()) {
        $classes[] = 'paged';
        $classes[] = 'paged-' . intval(get_query_var('paged'));
    } elseif (is_singular() && 1 < get_query_var('page')) {
        $classes[] = 'paged';
        $classes[] = 'paged-' . intval(get_query_var('page'));
    }
    /* Input class. */
    if (!empty($class)) {
        $class = is_array($class) ? $class : preg_split('#\\s+#', $class);
        $classes = array_merge($classes, $class);
    }
    return array_map('esc_attr', $classes);
}
Example #2
0
/**
 * Searches for a locale stylesheet.  This function looks for stylesheets in the `css` folder in the following 
 * order:  1) $lang-$region.css, 2) $region.css, 3) $lang.css, and 4) $text_direction.css.  It first checks 
 * the child theme for these files.  If they are not present, it will check the parent theme.  This is much 
 * more robust than the WordPress locale stylesheet, allowing for multiple variations and a more flexible 
 * hierarchy.
 *
 * @since  2.0.0
 * @access public
 * @return string
 */
function hybrid_get_locale_style()
{
    $locale = strtolower(str_replace('_', '-', get_locale()));
    $lang = strtolower(hybrid_get_language());
    $region = strtolower(hybrid_get_region());
    $styles = array();
    $styles[] = "css/{$locale}.css";
    if ($region !== $locale) {
        $styles[] = "css/{$region}.css";
    }
    if ($lang !== $locale) {
        $styles[] = "css/{$lang}.css";
    }
    $styles[] = is_rtl() ? 'css/rtl.css' : 'css/ltr.css';
    return hybrid_locate_theme_file($styles);
}