예제 #1
0
 /**
  * Ready for conditionals, before template choice.
  */
 function template_redirect()
 {
     global $hybrid;
     if (is_page()) {
         hybrid_get_context();
         $hybrid->context[] = 'singular-page-' . get_query_var('pagename');
     }
 }
예제 #2
0
/**
 * Looks for a template based on the hybrid_get_context() function.  If the $template parameter
 * is a directory, it will look for files within that directory.  Otherwise, $template becomes the 
 * template name prefix.  The function looks for templates based on the context of the current page
 * being viewed by the user.
 *
 * @since 0.8.0
 * @param string $template The slug of the template whose context we're searching for.
 * @return string $template The full path of the located template.
 */
function get_atomic_template($template)
{
    $templates = array();
    $theme_dir = trailingslashit(THEME_DIR) . $template;
    $child_dir = trailingslashit(CHILD_THEME_DIR) . $template;
    if (is_dir($child_dir) || is_dir($theme_dir)) {
        $dir = true;
        $templates[] = "{$template}/index.php";
    } else {
        $dir = false;
        $templates[] = "{$template}.php";
    }
    foreach (hybrid_get_context() as $context) {
        $templates[] = $dir ? "{$template}/{$context}.php" : "{$template}-{$context}.php";
    }
    return locate_template(array_reverse($templates), true);
}
예제 #3
0
/**
 * Provides classes for the <body> element depending on page context.
 *
 * @since 0.1.0
 * @uses $wp_query
 * @param string|array $class Additional classes for more control.
 * @return string
 */
function hybrid_body_class( $class = '' ) {
	global $wp_query;

	/* Text direction (which direction does the text flow). */
	$classes = array( 'wordpress', get_bloginfo( 'text_direction' ), get_locale() );

	/* 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 ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() )
		$classes[] = 'admin-bar';

	/* Merge base contextual classes with $classes. */
	$classes = array_merge( $classes, hybrid_get_context() );

	/* Singular post (post_type) classes. */
	if ( is_singular() ) {

		/* Checks for custom template. */
		$template = str_replace( array ( "{$wp_query->post->post_type}-template-", "{$wp_query->post->post_type}-", '.php' ), '', get_post_meta( $wp_query->post->ID, "_wp_{$wp_query->post->post_type}_template", true ) );
		if ( !empty( $template ) )
			$classes[] = "{$wp_query->post->post_type}-template-{$template}";

		/* Post format. */
		if ( current_theme_supports( 'post-formats' ) ) {
			$post_format = get_post_format( $wp_query->post->ID );
			$classes[] = ( ( empty( $post_format ) || is_wp_error( $post_format ) ) ? "{$wp_query->post->post_type}-format-standard" : "{$wp_query->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 ( ( ( $page = $wp_query->get( 'paged' ) ) || ( $page = $wp_query->get( 'page' ) ) ) && $page > 1 ) {
		$page = intval( $page );
		$classes[] = 'paged paged-' . $page;
	}

	/* Input class. */
	if ( !empty( $class ) ) {
		if ( !is_array( $class ) )
			$class = preg_split( '#\s+#', $class );
		$classes = array_merge( $classes, $class );
	}

	/* Apply the filters for WP's 'body_class'. */
	$classes = apply_filters( 'body_class', $classes, $class );

	/* Join all the classes into one string. */
	$class = join( ' ', $classes );

	/* Print the body class. */
	echo apply_atomic( 'body_class', $class );
}
예제 #4
0
/**
 * 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 'hybrid_entry_meta'.  The apply_atomic() function extends 
 * that to give extra hooks such as 'hybrid_singular_entry_meta', 'hybrid_singular-post_entry_meta', 
 * and 'hybrid_singular-post-ID_entry_meta'.
 *
 * @since 0.7.0
 * @access public
 * @uses hybrid_get_prefix() Gets the theme prefix.
 * @uses hybrid_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 = hybrid_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) hybrid_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;
}
예제 #5
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);
}
예제 #6
0
/**
 * 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 'hybrid_entry_meta'.  The apply_atomic() function extends 
 * that to give extra hooks such as 'hybrid_singular_entry_meta', 'hybrid_singular-post_entry_meta', 
 * and 'hybrid_singular-post-ID_entry_meta'.
 *
 * @since 0.7
 * @uses hybrid_get_prefix() Gets the theme prefix.
 * @uses hybrid_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 to be filtered.
 * @return mixed $value The value after it has been filtered.
 */
function apply_atomic( $tag = '', $value = '' ) {
	if ( !$tag )
		return false;

	/* Get theme prefix. */
	$pre = hybrid_get_prefix();

	/* Apply filters on the basic hook. */
	$value = apply_filters( "{$pre}_{$tag}", $value );

	/* Loop through context array and apply filters on a contextual scale. */
	foreach ( (array)hybrid_get_context() as $context )
		$value = apply_filters( "{$pre}_{$context}_{$tag}", $value );

	/* Return the final value once all filters have been applied. */
	return $value;
}
예제 #7
0
/**
 * Provides classes for the <body> element depending on page context.
 *
 * @since 0.1.0
 * @access public
 * @uses $wp_query
 * @param string|array $class Additional classes for more control.
 * @return void
 */
function hybrid_body_class($class = '')
{
    global $wp_query;
    /* Text direction (which direction does the text flow). */
    $classes = array('wordpress', get_bloginfo('text_direction'), get_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()) {
        $classes[] = 'custom-header';
    }
    /* 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 ((($page = $wp_query->get('paged')) || ($page = $wp_query->get('page'))) && $page > 1) {
        $classes[] = 'paged paged-' . intval($page);
    }
    /* Input class. */
    if (!empty($class)) {
        if (!is_array($class)) {
            $class = preg_split('#\\s+#', $class);
        }
        $classes = array_merge($classes, $class);
    }
    /* Apply the filters for WP's 'body_class'. */
    $classes = apply_filters('body_class', $classes, $class);
    /* Join all the classes into one string. */
    $class = join(' ', $classes);
    /* Print the body class. */
    echo apply_atomic('body_class', $class);
}
예제 #8
0
/**
 * Provides classes for the <body> element depending on page context.
 *
 * @since 0.1
 * @uses $wp_query
 * @param string|array $class Additional classes for more control.
 * @return string
 */
function hybrid_body_class( $class = '' ) {
	global $wp_query, $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome;

	/* Text direction (which direction does the text flow). */
	$classes = array( 'wordpress', get_bloginfo( 'text_direction' ), get_locale() );

	/* Layout class. */
	if ( ( current_theme_supports( 'post-layouts' ) || 'hybrid' == get_stylesheet() ) && is_singular() ) {
		$layout = get_post_meta( $wp_query->post->ID, 'Layout', true );
		if ( !empty( $layout ) )
			$classes[] = 'layout-' . strip_tags( esc_attr( $layout ) );
	}

	/* 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' : 'not-logged-in';

	/* Merge base contextual classes with $classes. */
	$classes = array_merge( $classes, hybrid_get_context() );

	/* Singular post (post_type) classes. */
	if ( is_singular() ) {

		/* Checks for custom template. */
		$template = str_replace( array ( "{$wp_query->post->post_type}-", "{$wp_query->post->post_type}-template-", '.php' ), '', get_post_meta( $wp_query->post->ID, "_wp_{$wp_query->post->post_type}_template", true ) );
		if ( $template ) {
			//$template = str_replace(  ), '', $template );
			$classes[] = "{$wp_query->post->post_type}-template-{$template}";
		}

		/* Attachment mime types. */
		if ( is_attachment() ) {
			foreach ( explode( '/', get_post_mime_type() ) as $type )
				$classes[] = "attachment-{$type}";
		}

		/* Deprecated classes. */
		elseif ( is_page() )
			$classes[] = "page-{$wp_query->post->ID}"; // Use singular-page-ID
		elseif ( is_singular( 'post' ) )
			$classes[] = "single-{$wp_query->post->ID}"; // Use singular-post-ID
	}

	/* Paged views. */
	if ( ( ( $page = $wp_query->get( 'paged' ) ) || ( $page = $wp_query->get( 'page' ) ) ) && $page > 1 ) {
		$page = intval( $page );
		$classes[] = 'paged paged-' . $page;
	}

	/* Browser detection. */
	$browsers = array( 	'gecko' => $is_gecko, 'opera' => $is_opera, 'lynx' => $is_lynx, 'ns4' => $is_NS4, 'safari' => $is_safari, 'chrome' => $is_chrome, 'msie' => $is_IE );
	foreach ( $browsers as $key => $value ) {
		if ( $value ) {
			$classes[] = $key;
			break;
		}
	}

	/* Hybrid theme widgets detection. */
	foreach ( array( 'primary', 'secondary', 'subsidiary' ) as $sidebar )
		$classes[] = ( is_active_sidebar( $sidebar ) ) ? "{$sidebar}-active" : "{$sidebar}-inactive";

	if ( in_array( 'primary-inactive', $classes ) && in_array( 'secondary-inactive', $classes ) && in_array( 'subsidiary-inactive', $classes ) )
		$classes[] = 'no-widgets';

	/* Input class. */
	if ( !empty( $class ) ) {
		if ( !is_array( $class ) )
			$class = preg_split( '#\s+#', $class );
		$classes = array_merge( $classes, $class );
	}

	/* Join all the classes into one string. */
	$class = join( ' ', $classes );

	/* Print the body class. */
	echo apply_atomic( 'body_class', $class );
}