PageRenderTime 29ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/news/library/hybrid.php

https://bitbucket.org/lgorence/quickpress
PHP | 355 lines | 104 code | 80 blank | 171 comment | 8 complexity | 0089a1192f2ce4749f5e751ac8078f6a MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /**
  3. * Hybrid Core - A WordPress theme development framework.
  4. *
  5. * Hybrid Core is a framework for developing WordPress themes. The framework allows theme developers
  6. * to quickly build themes without having to handle all of the "logic" behind the theme or having to code
  7. * complex functionality for features that are often needed in themes. The framework does these things
  8. * for developers to allow them to get back to what matters the most: developing and designing themes.
  9. * The framework was built to make it easy for developers to include (or not include) specific, pre-coded
  10. * features. Themes handle all the markup, style, and scripts while the framework handles the logic.
  11. *
  12. * Hybrid Core is a modular system, which means that developers can pick and choose the features they
  13. * want to include within their themes. Most files are only loaded if the theme registers support for the
  14. * feature using the add_theme_support( $feature ) function within their theme.
  15. *
  16. * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
  17. * General Public License as published by the Free Software Foundation; either version 2 of the License,
  18. * or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
  21. * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22. *
  23. * You should have received a copy of the GNU General Public License along with this program; if not, write
  24. * to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  25. *
  26. * @package HybridCore
  27. * @version 1.4.2
  28. * @author Justin Tadlock <justin@justintadlock.com>
  29. * @copyright Copyright (c) 2008 - 2012, Justin Tadlock
  30. * @link http://themehybrid.com/hybrid-core
  31. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  32. */
  33. /**
  34. * The Hybrid class launches the framework. It's the organizational structure behind the entire framework.
  35. * This class should be loaded and initialized before anything else within the theme is called to properly use
  36. * the framework.
  37. *
  38. * After parent themes call the Hybrid class, they should perform a theme setup function on the
  39. * 'after_setup_theme' hook with a priority of 10. Child themes should add their theme setup function on
  40. * the 'after_setup_theme' hook with a priority of 11. This allows the class to load theme-supported features
  41. * at the appropriate time, which is on the 'after_setup_theme' hook with a priority of 12.
  42. *
  43. * @since 0.7.0
  44. */
  45. class Hybrid {
  46. /**
  47. * Constructor method for the Hybrid class. This method adds other methods of the class to
  48. * specific hooks within WordPress. It controls the load order of the required files for running
  49. * the framework.
  50. *
  51. * @since 1.0.0
  52. */
  53. function __construct() {
  54. global $hybrid;
  55. /* Set up an empty class for the global $hybrid object. */
  56. $hybrid = new stdClass;
  57. /* Define framework, parent theme, and child theme constants. */
  58. add_action( 'after_setup_theme', array( &$this, 'constants' ), 1 );
  59. /* Load the core functions required by the rest of the framework. */
  60. add_action( 'after_setup_theme', array( &$this, 'core' ), 2 );
  61. /* Initialize the framework's default actions and filters. */
  62. add_action( 'after_setup_theme', array( &$this, 'default_filters' ), 3 );
  63. /* Language functions and translations setup. */
  64. add_action( 'after_setup_theme', array( &$this, 'i18n' ), 4 );
  65. /* Handle theme supported features. */
  66. add_action( 'after_setup_theme', array( &$this, 'theme_support' ), 12 );
  67. /* Load the framework functions. */
  68. add_action( 'after_setup_theme', array( &$this, 'functions' ), 13 );
  69. /* Load the framework extensions. */
  70. add_action( 'after_setup_theme', array( &$this, 'extensions' ), 14 );
  71. /* Load admin files. */
  72. add_action( 'wp_loaded', array( &$this, 'admin' ) );
  73. }
  74. /**
  75. * Defines the constant paths for use within the core framework, parent theme, and child theme.
  76. * Constants prefixed with 'HYBRID_' are for use only within the core framework and don't
  77. * reference other areas of the parent or child theme.
  78. *
  79. * @since 0.7.0
  80. */
  81. function constants() {
  82. /* Sets the framework version number. */
  83. define( 'HYBRID_VERSION', '1.4.2' );
  84. /* Sets the path to the parent theme directory. */
  85. define( 'THEME_DIR', get_template_directory() );
  86. /* Sets the path to the parent theme directory URI. */
  87. define( 'THEME_URI', get_template_directory_uri() );
  88. /* Sets the path to the child theme directory. */
  89. define( 'CHILD_THEME_DIR', get_stylesheet_directory() );
  90. /* Sets the path to the child theme directory URI. */
  91. define( 'CHILD_THEME_URI', get_stylesheet_directory_uri() );
  92. /* Sets the path to the core framework directory. */
  93. define( 'HYBRID_DIR', trailingslashit( THEME_DIR ) . basename( dirname( __FILE__ ) ) );
  94. /* Sets the path to the core framework directory URI. */
  95. define( 'HYBRID_URI', trailingslashit( THEME_URI ) . basename( dirname( __FILE__ ) ) );
  96. /* Sets the path to the core framework admin directory. */
  97. define( 'HYBRID_ADMIN', trailingslashit( HYBRID_DIR ) . 'admin' );
  98. /* Sets the path to the core framework classes directory. */
  99. define( 'HYBRID_CLASSES', trailingslashit( HYBRID_DIR ) . 'classes' );
  100. /* Sets the path to the core framework extensions directory. */
  101. define( 'HYBRID_EXTENSIONS', trailingslashit( HYBRID_DIR ) . 'extensions' );
  102. /* Sets the path to the core framework functions directory. */
  103. define( 'HYBRID_FUNCTIONS', trailingslashit( HYBRID_DIR ) . 'functions' );
  104. /* Sets the path to the core framework languages directory. */
  105. define( 'HYBRID_LANGUAGES', trailingslashit( HYBRID_DIR ) . 'languages' );
  106. /* Sets the path to the core framework images directory URI. */
  107. define( 'HYBRID_IMAGES', trailingslashit( HYBRID_URI ) . 'images' );
  108. /* Sets the path to the core framework CSS directory URI. */
  109. define( 'HYBRID_CSS', trailingslashit( HYBRID_URI ) . 'css' );
  110. /* Sets the path to the core framework JavaScript directory URI. */
  111. define( 'HYBRID_JS', trailingslashit( HYBRID_URI ) . 'js' );
  112. }
  113. /**
  114. * Loads the core framework functions. These files are needed before loading anything else in the
  115. * framework because they have required functions for use.
  116. *
  117. * @since 1.0.0
  118. */
  119. function core() {
  120. /* Load the core framework functions. */
  121. require_once( trailingslashit( HYBRID_FUNCTIONS ) . 'core.php' );
  122. /* Load the context-based functions. */
  123. require_once( trailingslashit( HYBRID_FUNCTIONS ) . 'context.php' );
  124. /* Load the core framework internationalization functions. */
  125. require_once( trailingslashit( HYBRID_FUNCTIONS ) . 'i18n.php' );
  126. }
  127. /**
  128. * Loads both the parent and child theme translation files. If a locale-based functions file exists
  129. * in either the parent or child theme (child overrides parent), it will also be loaded. All translation
  130. * and locale functions files are expected to be within the theme's '/languages' folder, but the
  131. * framework will fall back on the theme root folder if necessary. Translation files are expected
  132. * to be prefixed with the template or stylesheet path (example: 'templatename-en_US.mo').
  133. *
  134. * @since 1.2.0
  135. */
  136. function i18n() {
  137. global $hybrid;
  138. /* Get parent and child theme textdomains. */
  139. $parent_textdomain = hybrid_get_parent_textdomain();
  140. $child_textdomain = hybrid_get_child_textdomain();
  141. /* Load the framework textdomain. */
  142. $hybrid->textdomain_loaded['hybrid-core'] = hybrid_load_framework_textdomain( 'hybrid-core' );
  143. /* Load theme textdomain. */
  144. $hybrid->textdomain_loaded[$parent_textdomain] = load_theme_textdomain( $parent_textdomain );
  145. /* Load child theme textdomain. */
  146. $hybrid->textdomain_loaded[$child_textdomain] = is_child_theme() ? load_child_theme_textdomain( $child_textdomain ) : false;
  147. /* Get the user's locale. */
  148. $locale = get_locale();
  149. /* Locate a locale-specific functions file. */
  150. $locale_functions = locate_template( array( "languages/{$locale}.php", "{$locale}.php" ) );
  151. /* If the locale file exists and is readable, load it. */
  152. if ( !empty( $locale_functions ) && is_readable( $locale_functions ) )
  153. require_once( $locale_functions );
  154. }
  155. /**
  156. * Removes theme supported features from themes in the case that a user has a plugin installed
  157. * that handles the functionality.
  158. *
  159. * @since 1.3.0
  160. */
  161. function theme_support() {
  162. /* Remove support for the core SEO component if the WP SEO plugin is installed. */
  163. if ( defined( 'WPSEO_VERSION' ) )
  164. remove_theme_support( 'hybrid-core-seo' );
  165. /* Remove support for the the Breadcrumb Trail extension if the plugin is installed. */
  166. if ( function_exists( 'breadcrumb_trail' ) )
  167. remove_theme_support( 'breadcrumb-trail' );
  168. /* Remove support for the the Cleaner Gallery extension if the plugin is installed. */
  169. if ( function_exists( 'cleaner_gallery' ) )
  170. remove_theme_support( 'cleaner-gallery' );
  171. /* Remove support for the the Get the Image extension if the plugin is installed. */
  172. if ( function_exists( 'get_the_image' ) )
  173. remove_theme_support( 'get-the-image' );
  174. }
  175. /**
  176. * Loads the framework functions. Many of these functions are needed to properly run the
  177. * framework. Some components are only loaded if the theme supports them.
  178. *
  179. * @since 0.7.0
  180. */
  181. function functions() {
  182. /* Load the comments functions. */
  183. require_once( trailingslashit( HYBRID_FUNCTIONS ) . 'comments.php' );
  184. /* Load media-related functions. */
  185. require_once( trailingslashit( HYBRID_FUNCTIONS ) . 'media.php' );
  186. /* Load the metadata functions. */
  187. require_once( trailingslashit( HYBRID_FUNCTIONS ) . 'meta.php' );
  188. /* Load the utility functions. */
  189. require_once( trailingslashit( HYBRID_FUNCTIONS ) . 'utility.php' );
  190. /* Load the theme settings functions if supported. */
  191. require_if_theme_supports( 'hybrid-core-theme-settings', trailingslashit( HYBRID_FUNCTIONS ) . 'settings.php' );
  192. /* Load the customizer functions if theme settings are supported. */
  193. require_if_theme_supports( 'hybrid-core-theme-settings', trailingslashit( HYBRID_FUNCTIONS ) . 'customize.php' );
  194. /* Load the menus functions if supported. */
  195. require_if_theme_supports( 'hybrid-core-menus', trailingslashit( HYBRID_FUNCTIONS ) . 'menus.php' );
  196. /* Load the core SEO component if supported. */
  197. require_if_theme_supports( 'hybrid-core-seo', trailingslashit( HYBRID_FUNCTIONS ) . 'core-seo.php' );
  198. /* Load the shortcodes if supported. */
  199. require_if_theme_supports( 'hybrid-core-shortcodes', trailingslashit( HYBRID_FUNCTIONS ) . 'shortcodes.php' );
  200. /* Load the sidebars if supported. */
  201. require_if_theme_supports( 'hybrid-core-sidebars', trailingslashit( HYBRID_FUNCTIONS ) . 'sidebars.php' );
  202. /* Load the widgets if supported. */
  203. require_if_theme_supports( 'hybrid-core-widgets', trailingslashit( HYBRID_FUNCTIONS ) . 'widgets.php' );
  204. /* Load the template hierarchy if supported. */
  205. require_if_theme_supports( 'hybrid-core-template-hierarchy', trailingslashit( HYBRID_FUNCTIONS ) . 'template-hierarchy.php' );
  206. /* Load the deprecated functions if supported. */
  207. require_if_theme_supports( 'hybrid-core-deprecated', trailingslashit( HYBRID_FUNCTIONS ) . 'deprecated.php' );
  208. }
  209. /**
  210. * Load extensions (external projects). Extensions are projects that are included within the
  211. * framework but are not a part of it. They are external projects developed outside of the
  212. * framework. Themes must use add_theme_support( $extension ) to use a specific extension
  213. * within the theme. This should be declared on 'after_setup_theme' no later than a priority of 11.
  214. *
  215. * @since 0.7.0
  216. */
  217. function extensions() {
  218. /* Load the Breadcrumb Trail extension if supported. */
  219. require_if_theme_supports( 'breadcrumb-trail', trailingslashit( HYBRID_EXTENSIONS ) . 'breadcrumb-trail.php' );
  220. /* Load the Cleaner Gallery extension if supported. */
  221. require_if_theme_supports( 'cleaner-gallery', trailingslashit( HYBRID_EXTENSIONS ) . 'cleaner-gallery.php' );
  222. /* Load the Get the Image extension if supported. */
  223. require_if_theme_supports( 'get-the-image', trailingslashit( HYBRID_EXTENSIONS ) . 'get-the-image.php' );
  224. /* Load the Cleaner Caption extension if supported. */
  225. require_if_theme_supports( 'cleaner-caption', trailingslashit( HYBRID_EXTENSIONS ) . 'cleaner-caption.php' );
  226. /* Load the Custom Field Series extension if supported. */
  227. require_if_theme_supports( 'custom-field-series', trailingslashit( HYBRID_EXTENSIONS ) . 'custom-field-series.php' );
  228. /* Load the Loop Pagination extension if supported. */
  229. require_if_theme_supports( 'loop-pagination', trailingslashit( HYBRID_EXTENSIONS ) . 'loop-pagination.php' );
  230. /* Load the Entry Views extension if supported. */
  231. require_if_theme_supports( 'entry-views', trailingslashit( HYBRID_EXTENSIONS ) . 'entry-views.php' );
  232. /* Load the Theme Layouts extension if supported. */
  233. require_if_theme_supports( 'theme-layouts', trailingslashit( HYBRID_EXTENSIONS ) . 'theme-layouts.php' );
  234. /* Load the Post Stylesheets extension if supported. */
  235. require_if_theme_supports( 'post-stylesheets', trailingslashit( HYBRID_EXTENSIONS ) . 'post-stylesheets.php' );
  236. }
  237. /**
  238. * Load admin files for the framework.
  239. *
  240. * @since 0.7.0
  241. */
  242. function admin() {
  243. /* Check if in the WordPress admin. */
  244. if ( is_admin() ) {
  245. /* Load the main admin file. */
  246. require_once( trailingslashit( HYBRID_ADMIN ) . 'admin.php' );
  247. /* Load the theme settings feature if supported. */
  248. require_if_theme_supports( 'hybrid-core-theme-settings', trailingslashit( HYBRID_ADMIN ) . 'theme-settings.php' );
  249. }
  250. }
  251. /**
  252. * Adds the default framework actions and filters.
  253. *
  254. * @since 1.0.0
  255. */
  256. function default_filters() {
  257. /* Remove bbPress theme compatibility if current theme supports bbPress. */
  258. if ( current_theme_supports( 'bbpress' ) )
  259. remove_action( 'bbp_init', 'bbp_setup_theme_compat', 8 );
  260. /* Move the WordPress generator to a better priority. */
  261. remove_action( 'wp_head', 'wp_generator' );
  262. add_action( 'wp_head', 'wp_generator', 1 );
  263. /* Add the theme info to the header (lets theme developers give better support). */
  264. add_action( 'wp_head', 'hybrid_meta_template', 1 );
  265. /* Filter the textdomain mofile to allow child themes to load the parent theme translation. */
  266. add_filter( 'load_textdomain_mofile', 'hybrid_load_textdomain_mofile', 10, 2 );
  267. /* Filter text strings for Hybrid Core and extensions so themes can serve up translations. */
  268. add_filter( 'gettext', 'hybrid_gettext', 1, 3 );
  269. add_filter( 'gettext', 'hybrid_extensions_gettext', 1, 3 );
  270. /* Make text widgets and term descriptions shortcode aware. */
  271. add_filter( 'widget_text', 'do_shortcode' );
  272. add_filter( 'term_description', 'do_shortcode' );
  273. }
  274. }
  275. ?>