Skip to content
This repository
tree: a85fa7ccac
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 305 lines (239 sloc) 13.241 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
<?php
/**
* Hybrid Core - A WordPress theme development framework.
*
* Hybrid Core is a framework for developing WordPress themes. The framework allows theme developers
* to quickly build themes without having to handle all of the "logic" behind the theme or having to code
* complex functionality for features that are often needed in themes. The framework does these things
* for developers to allow them to get back to what matters the most: developing and designing themes.
* The framework was built to make it easy for developers to include (or not include) specific, pre-coded
* features. Themes handle all the markup, style, and scripts while the framework handles the logic.
*
* Hybrid Core is a modular system, which means that developers can pick and choose the features they
* want to include within their themes. Most files are only loaded if the theme registers support for the
* feature using the add_theme_support( $feature ) function within their theme.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License version 2, as published by the Free Software Foundation. You may NOT assume
* that you can use any other version of the GPL.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU General Public License along with this program; if not, write
* to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package HybridCore
* @version 1.2.1
* @author Justin Tadlock <justin@justintadlock.com>
* @copyright Copyright (c) 2008 - 2011, Justin Tadlock
* @link http://themehybrid.com/hybrid-core
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/

/**
* The Hybrid class launches the framework. It's the organizational structure behind the entire framework.
* This class should be loaded and initialized before anything else within the theme is called to properly use
* the framework.
*
* After parent themes call the Hybrid class, they should perform a theme setup function on the
* 'after_setup_theme' hook with a priority of 10. Child themes should add their theme setup function on
* the 'after_setup_theme' hook with a priority of 11. This allows the class to load theme-supported features
* at the appropriate time, which is on the 'after_setup_theme' hook with a priority of 12.
*
* @since 0.7.0
*/
class Hybrid {

/**
* Constructor method for the Hybrid class. This method adds other methods of the class to
* specific hooks within WordPress. It controls the load order of the required files for running
* the framework.
*
* @since 1.0.0
*/
function __construct() {

/* Define framework, parent theme, and child theme constants. */
add_action( 'after_setup_theme', array( &$this, 'constants' ), 1 );

/* Load the core functions required by the rest of the framework. */
add_action( 'after_setup_theme', array( &$this, 'core' ), 2 );

/* Initialize the framework's default actions and filters. */
add_action( 'after_setup_theme', array( &$this, 'default_filters' ), 3 );

/* Language functions and translations setup. */
add_action( 'after_setup_theme', array( &$this, 'i18n' ), 4 );

/* Load the framework functions. */
add_action( 'after_setup_theme', array( &$this, 'functions' ), 12 );

/* Load the framework extensions. */
add_action( 'after_setup_theme', array( &$this, 'extensions' ), 13 );

/* Load admin files. */
add_action( 'wp_loaded', array( &$this, 'admin' ) );
}

/**
* Defines the constant paths for use within the core framework, parent theme, and child theme.
* Constants prefixed with 'HYBRID_' are for use only within the core framework and don't
* reference other areas of the parent or child theme.
*
* @since 0.7.0
*/
function constants() {

/* Sets the framework version number. */
define( 'HYBRID_VERSION', '1.2.1' );

/* Sets the path to the parent theme directory. */
define( 'THEME_DIR', get_template_directory() );

/* Sets the path to the parent theme directory URI. */
define( 'THEME_URI', get_template_directory_uri() );

/* Sets the path to the child theme directory. */
define( 'CHILD_THEME_DIR', get_stylesheet_directory() );

/* Sets the path to the child theme directory URI. */
define( 'CHILD_THEME_URI', get_stylesheet_directory_uri() );

/* Sets the path to the core framework directory. */
define( 'HYBRID_DIR', trailingslashit( THEME_DIR ) . basename( dirname( __FILE__ ) ) );

/* Sets the path to the core framework directory URI. */
define( 'HYBRID_URI', trailingslashit( THEME_URI ) . basename( dirname( __FILE__ ) ) );

/* Sets the path to the core framework admin directory. */
define( 'HYBRID_ADMIN', trailingslashit( HYBRID_DIR ) . 'admin' );

/* Sets the path to the core framework classes directory. */
define( 'HYBRID_CLASSES', trailingslashit( HYBRID_DIR ) . 'classes' );

/* Sets the path to the core framework extensions directory. */
define( 'HYBRID_EXTENSIONS', trailingslashit( HYBRID_DIR ) . 'extensions' );

/* Sets the path to the core framework functions directory. */
define( 'HYBRID_FUNCTIONS', trailingslashit( HYBRID_DIR ) . 'functions' );

/* Sets the path to the core framework images directory URI. */
define( 'HYBRID_IMAGES', trailingslashit( HYBRID_URI ) . 'images' );

/* Sets the path to the core framework CSS directory URI. */
define( 'HYBRID_CSS', trailingslashit( HYBRID_URI ) . 'css' );

/* Sets the path to the core framework JavaScript directory URI. */
define( 'HYBRID_JS', trailingslashit( HYBRID_URI ) . 'js' );
}

/**
* Loads the core framework functions. These files are needed before loading anything else in the
* framework because they have required functions for use.
*
* @since 1.0.0
*/
function core() {

/* Load the core framework functions. */
require_once( trailingslashit( HYBRID_FUNCTIONS ) . 'core.php' );

/* Load the context-based functions. */
require_once( trailingslashit( HYBRID_FUNCTIONS ) . 'context.php' );
}

/**
* Loads both the parent and child theme translation files. If a locale-based functions file exists
* in either the parent or child theme (child overrides parent), it will also be loaded. All translation
* and locale functions files are expected to be within the theme's '/languages' folder, but the
* framework will fall back on the theme root folder if necessary. Translation files are expected
* to be prefixed with the template or stylesheet path (example: 'templatename-en_US.mo').
*
* @since 1.2.0
*/
function i18n() {

/* Load theme textdomain. */
load_theme_textdomain( hybrid_get_textdomain() );

/* Load child theme textdomain. */
if ( is_child_theme() )
load_child_theme_textdomain( hybrid_get_child_textdomain() );

/* Get the user's locale. */
$locale = get_locale();

/* Locate a locale-specific functions file. */
$locale_functions = locate_template( array( "languages/{$locale}.php", "{$locale}.php" ) );

/* If the locale file exists and is readable, load it. */
if ( !empty( $locale_functions ) && is_readable( $locale_functions ) )
require_once( $locale_functions );
}

/**
* Loads the framework functions. Many of these functions are needed to properly run the
* framework. Some components are only loaded if the theme supports them.
*
* @since 0.7.0
*/
function functions() {

/* Load the comments functions. */
require_once( trailingslashit( HYBRID_FUNCTIONS ) . 'comments.php' );

/* Load media-related functions. */
require_once( trailingslashit( HYBRID_FUNCTIONS ) . 'media.php' );

/* Load the utility functions. */
require_once( trailingslashit( HYBRID_FUNCTIONS ) . 'utility.php' );

/* Load the theme settings functions if supported. */
require_if_theme_supports( 'hybrid-core-theme-settings', trailingslashit( HYBRID_FUNCTIONS ) . 'settings.php' );

/* Load the menus functions if supported. */
require_if_theme_supports( 'hybrid-core-menus', trailingslashit( HYBRID_FUNCTIONS ) . 'menus.php' );

/* Load the core SEO component. */
require_if_theme_supports( 'hybrid-core-seo', trailingslashit( HYBRID_FUNCTIONS ) . 'core-seo.php' );

/* Load the shortcodes if supported. */
require_if_theme_supports( 'hybrid-core-shortcodes', trailingslashit( HYBRID_FUNCTIONS ) . 'shortcodes.php' );

/* Load the sidebars if supported. */
require_if_theme_supports( 'hybrid-core-sidebars', trailingslashit( HYBRID_FUNCTIONS ) . 'sidebars.php' );

/* Load the widgets if supported. */
require_if_theme_supports( 'hybrid-core-widgets', trailingslashit( HYBRID_FUNCTIONS ) . 'widgets.php' );

/* Load the template hierarchy if supported. */
require_if_theme_supports( 'hybrid-core-template-hierarchy', trailingslashit( HYBRID_FUNCTIONS ) . 'template-hierarchy.php' );

/* Load the deprecated functions if supported. */
require_if_theme_supports( 'hybrid-core-deprecated', trailingslashit( HYBRID_FUNCTIONS ) . 'deprecated.php' );
}

/**
* Load extensions (external projects). Extensions are projects that are included within the
* framework but are not a part of it. They are external projects developed outside of the
* framework. Themes must use add_theme_support( $extension ) to use a specific extension
* within the theme. This should be declared on 'after_setup_theme' no later than a priority of 11.
*
* @since 0.7.0
*/
function extensions() {

/* Load the Breadcrumb Trail extension if supported and the plugin isn't active. */
if ( !function_exists( 'breadcrumb_trail' ) )
require_if_theme_supports( 'breadcrumb-trail', trailingslashit( HYBRID_EXTENSIONS ) . 'breadcrumb-trail.php' );

/* Load the Cleaner Gallery extension if supported and the plugin isn't active. */
if ( !function_exists( 'cleaner_gallery' ) )
require_if_theme_supports( 'cleaner-gallery', trailingslashit( HYBRID_EXTENSIONS ) . 'cleaner-gallery.php' );

/* Load the Get the Image extension if supported and the plugin isn't active. */
if ( !function_exists( 'get_the_image' ) )
require_if_theme_supports( 'get-the-image', trailingslashit( HYBRID_EXTENSIONS ) . 'get-the-image.php' );

/* Load the Cleaner Caption extension if supported. */
require_if_theme_supports( 'cleaner-caption', trailingslashit( HYBRID_EXTENSIONS ) . 'cleaner-caption.php' );

/* Load the Custom Field Series extension if supported. */
require_if_theme_supports( 'custom-field-series', trailingslashit( HYBRID_EXTENSIONS ) . 'custom-field-series.php' );

/* Load the Loop Pagination extension if supported. */
require_if_theme_supports( 'loop-pagination', trailingslashit( HYBRID_EXTENSIONS ) . 'loop-pagination.php' );

/* Load the Entry Views extension if supported. */
require_if_theme_supports( 'entry-views', trailingslashit( HYBRID_EXTENSIONS ) . 'entry-views.php' );

/* Load the Theme Layouts extension if supported. */
require_if_theme_supports( 'theme-layouts', trailingslashit( HYBRID_EXTENSIONS ) . 'theme-layouts.php' );

/* Load the Post Stylesheets extension if supported. */
require_if_theme_supports( 'post-stylesheets', trailingslashit( HYBRID_EXTENSIONS ) . 'post-stylesheets.php' );
}

/**
* Load admin files for the framework.
*
* @since 0.7.0
*/
function admin() {

/* Check if in the WordPress admin. */
if ( is_admin() ) {

/* Load the main admin file. */
require_once( trailingslashit( HYBRID_ADMIN ) . 'admin.php' );

/* Load the theme settings feature if supported. */
require_if_theme_supports( 'hybrid-core-theme-settings', trailingslashit( HYBRID_ADMIN ) . 'theme-settings.php' );
}
}

/**
* Adds the default framework actions and filters.
*
* @since 1.0.0
*/
function default_filters() {

/* Move the WordPress generator to a better priority. */
remove_action( 'wp_head', 'wp_generator' );
add_action( 'wp_head', 'wp_generator', 1 );

/* Add the theme info to the header (lets theme developers give better support). */
add_action( 'wp_head', 'hybrid_meta_template', 1 );

/* Filter the textdomain mofile to allow child themes to load the parent theme translation. */
add_filter( 'load_textdomain_mofile', 'hybrid_load_textdomain', 10, 2 );

/* Filter textdomain for extensions. */
add_filter( 'breadcrumb_trail_textdomain', 'hybrid_get_textdomain' );
add_filter( 'theme_layouts_textdomain', 'hybrid_get_textdomain' );
add_filter( 'custom_field_series_textdomain', 'hybrid_get_textdomain' );
add_filter( 'post_stylesheets_textdomain', 'hybrid_get_textdomain' );

/* Make text widgets and term descriptions shortcode aware. */
add_filter( 'widget_text', 'do_shortcode' );
add_filter( 'term_description', 'do_shortcode' );
}
}

?>
Something went wrong with that request. Please try again.