/** * Adds contextual filter hooks to the theme. This allows users to easily filter context-based content * without having to know how to use WordPress conditional tags. The theme handles the logic. * * An example of a basic hook would be 'bon_entry_meta'. The apply_atomic() function extends * that to give extra hooks such as 'bon_singular_entry_meta', 'bon_singular-post_entry_meta', * and 'bon_singular-post-ID_entry_meta'. * * @since 1.0 * @access public * @uses bon_get_prefix() Gets the theme prefix. * @uses bon_get_context() Gets the context of the current page. * @param string $tag Usually the location of the hook but defines what the base hook is. * @param mixed $value The value on which the filters hooked to $tag are applied on. * @param mixed $var,... Additional variables passed to the functions hooked to $tag. * @return mixed $value The value after it has been filtered. */ function apply_atomic($tag = '', $value = '') { if (empty($tag)) { return false; } /* Get theme prefix. */ $pre = bon_get_prefix(); /* Get the args passed into the function and remove $tag. */ $args = func_get_args(); array_splice($args, 0, 1); /* Apply filters on the basic hook. */ $value = $args[0] = apply_filters_ref_array("{$pre}{$tag}", $args); /* Loop through context array and apply filters on a contextual scale. */ foreach ((array) bon_get_context() as $context) { $value = $args[0] = apply_filters_ref_array("{$pre}{$context}_{$tag}", $args); } /* Return the final value once all filters have been applied. */ return $value; }
function bon_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 = bon_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, bon_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); }