Permalink
Newer
Older
100644 261 lines (202 sloc) 8.41 KB
1
<?php
2
/**
3
* The Hybrid class launches the framework. It's the organizational structure behind the
4
* entire theme. This class should be initialized before anything else in the theme is called.
5
*
6
* @package HybridCore
7
* @subpackage Classes
8
*/
9
10
class Hybrid {
11
12
/**
13
* Theme prefix (mostly used for hooks).
14
*
15
* @since 0.7
16
* @var string
17
*/
18
var $prefix;
19
20
/**
21
* PHP4 constructor method.
22
*
23
* @since 0.9
24
*/
25
function Hybrid() {
26
$this->__construct();
30
* Constructor method for the Hybrid class. Initializes the theme framework, loads the
31
* required files, and calls the functions needed to run the framework.
33
* @since 0.9.1
35
function __construct() {
36
37
/* Define theme constants. */
38
$this->constants();
39
40
/* Load the core theme functions. */
41
$this->core();
42
43
/* Load admin files. */
44
$this->admin();
45
46
/* Theme prefix for creating things such as filter hooks (i.e., "$prefix_hook_name"). */
47
$this->prefix = hybrid_get_prefix();
48
49
/* Initialize the theme's default actions. */
50
$this->actions();
51
52
/* Initialize the theme's default filters. */
53
$this->filters();
54
55
/* Load theme framework functions. */
56
add_action( 'after_setup_theme', array( &$this, 'functions' ), 12 );
57
58
/* Load theme extensions later since we need to check if they're supported. */
59
add_action( 'after_setup_theme', array( &$this, 'extensions' ), 12 );
60
61
/* Load theme textdomain. */
62
$domain = hybrid_get_textdomain();
63
$locale = get_locale();
64
load_theme_textdomain( $domain );
65
66
/* Load locale-specific functions file. */
67
$locale_functions = locate_template( array( "languages/{$locale}.php", "{$locale}.php" ) );
68
if ( !empty( $locale_functions ) && is_readable( $locale_functions ) )
69
require_once( $locale_functions );
70
71
/* Theme init hook. */
72
do_action( "{$this->prefix}_init" );
73
}
74
75
/**
76
* Defines the constant paths for use within the core framework, parent theme, and
77
* child theme. Constants prefixed with 'HYBRID_' are for use only within the core
78
* framework and don't reference other areas of the theme.
79
*
80
* @since 0.7
81
*/
82
function constants() {
83
/* Sets the path to the parent theme directory. */
84
define( 'THEME_DIR', get_template_directory() );
85
86
/* Sets the path to the parent theme directory URI. */
87
define( 'THEME_URI', get_template_directory_uri() );
88
89
/* Sets the path to the child theme directory. */
90
define( 'CHILD_THEME_DIR', get_stylesheet_directory() );
91
92
/* Sets the path to the child theme directory URI. */
93
define( 'CHILD_THEME_URI', get_stylesheet_directory_uri() );
94
95
/* Sets the path to the core framework directory. */
96
define( 'HYBRID_DIR', trailingslashit( THEME_DIR ) . basename( dirname( __FILE__ ) ) );
97
98
/* Sets the path to the core framework directory URI. */
99
define( 'HYBRID_URI', trailingslashit( THEME_URI ) . basename( dirname( __FILE__ ) ) );
100
101
/* Sets the path to the core framework admin directory. */
102
define( 'HYBRID_ADMIN', trailingslashit( HYBRID_DIR ) . 'admin' );
103
104
/* Sets the path to the core framework classes directory. */
105
define( 'HYBRID_CLASSES', trailingslashit( HYBRID_DIR ) . 'classes' );
106
107
/* Sets the path to the core framework extensions directory. */
108
define( 'HYBRID_EXTENSIONS', trailingslashit( HYBRID_DIR ) . 'extensions' );
109
110
/* Sets the path to the core framework functions directory. */
111
define( 'HYBRID_FUNCTIONS', trailingslashit( HYBRID_DIR ) . 'functions' );
112
113
/* Sets the path to the core framework legacy directory. */
114
define( 'HYBRID_LEGACY', trailingslashit( HYBRID_DIR ) . 'legacy' );
115
116
/* Sets the path to the core framework images directory URI. */
117
define( 'HYBRID_IMAGES', trailingslashit( HYBRID_URI ) . 'images' );
118
119
/* Sets the path to the core framework CSS directory URI. */
120
define( 'HYBRID_CSS', trailingslashit( HYBRID_URI ) . 'css' );
121
122
/* Sets the path to the core framework JavaScript directory URI. */
123
define( 'HYBRID_JS', trailingslashit( HYBRID_URI ) . 'js' );
124
}
125
126
/**
127
* Loads the core theme functions.
128
*
129
* @since 0.9.1
130
*/
131
function core() {
132
require_once( HYBRID_FUNCTIONS . '/core.php' );
133
require_once( HYBRID_FUNCTIONS . '/context.php' );
134
}
135
136
/**
137
* Loads the theme functions.
138
*
139
* @since 0.7
140
*/
141
function functions() {
142
143
/* Load the comments functions. */
144
require_once( HYBRID_FUNCTIONS . '/comments.php' );
145
146
/* Load media-related functions. */
147
require_once( HYBRID_FUNCTIONS . '/media.php' );
148
149
/* Load the template functions. */
150
require_once( HYBRID_FUNCTIONS . '/template.php' );
151
152
/* Load the widget functions. */
153
require_once( HYBRID_FUNCTIONS . '/widgets.php' );
154
155
/* Load the menus functions if supported. */
156
require_if_theme_supports( 'hybrid-core-menus', HYBRID_FUNCTIONS . '/menus.php' );
157
158
/* Load the temporary core SEO component. */
159
require_if_theme_supports( 'hybrid-core-seo', HYBRID_FUNCTIONS . '/core-seo.php' );
160
161
/* Load the shortcodes if supported. */
162
require_if_theme_supports( 'hybrid-core-shortcodes', HYBRID_FUNCTIONS . '/shortcodes.php' );
163
164
/* Load the template hierarchy if supported. */
165
require_if_theme_supports( 'hybrid-core-template-hierarchy', HYBRID_FUNCTIONS . '/template-hierarchy.php' );
166
167
/* Load the deprecated functions if supported. */
168
require_if_theme_supports( 'hybrid-core-deprecated', HYBRID_LEGACY . '/deprecated.php' );
169
}
170
171
/**
172
* Load extensions (external projects). Themes must use add_theme_support( $extension ) to
173
* use a specific extension within the theme. This should be declared on 'after_setup_theme' no
174
* later than the default priority of 10.
175
*
176
* @since 0.7
177
*/
178
function extensions() {
179
180
/* Load the Breadcrumb Trail extension if supported. */
181
require_if_theme_supports( 'breadcrumb-trail', HYBRID_EXTENSIONS . '/breadcrumb-trail.php' );
182
183
/* Load the Custom Field Series extension if supported. */
184
require_if_theme_supports( 'custom-field-series', HYBRID_EXTENSIONS . '/custom-field-series.php' );
185
186
/* Load the Get the Image extension if supported. */
187
require_if_theme_supports( 'get-the-image', HYBRID_EXTENSIONS . '/get-the-image.php' );
188
189
/* Load the Get the Object extension if supported. */
190
require_if_theme_supports( 'get-the-object', HYBRID_EXTENSIONS . '/get-the-object.php' );
191
192
/* Load the Pagination extension if supported. */
193
require_if_theme_supports( 'loop-pagination', HYBRID_EXTENSIONS . '/loop-pagination.php' );
194
195
/* Load the Entry Views extension if supported. */
196
require_if_theme_supports( 'entry-views', HYBRID_EXTENSIONS . '/entry-views.php' );
197
198
/* Load the Post Layouts extension if supported. */
199
require_if_theme_supports( 'post-layouts', HYBRID_EXTENSIONS . '/post-layouts.php' );
201
/* Load the Post Stylesheets extension if supported. */
202
require_if_theme_supports( 'post-stylesheets', HYBRID_EXTENSIONS . '/post-stylesheets.php' );
203
}
204
205
/**
206
* Load admin files.
207
*
208
* @since 0.7
209
*/
210
function admin() {
211
if ( is_admin() ) {
212
require_once( HYBRID_ADMIN . '/admin.php' );
213
require_once( HYBRID_ADMIN . '/meta-box.php' );
214
require_once( HYBRID_ADMIN . '/settings-page.php' );
215
}
216
}
217
218
/**
219
* Adds the default theme actions.
220
*
221
* @since 0.7
222
*/
223
function actions() {
224
225
/* Remove WP and plugin functions. */
226
remove_action( 'wp_head', 'wp_generator' );
227
228
/* Head actions. */
229
add_action( 'wp_head', 'wp_generator', 1 );
230
add_action( 'wp_head', 'hybrid_meta_template', 1 );
231
add_action( 'wp_head', 'hybrid_head_pingback' );
232
233
/* WP print scripts and styles. */
234
add_action( 'template_redirect', 'hybrid_enqueue_style' );
235
add_action( 'template_redirect', 'hybrid_enqueue_script' );
236
}
237
238
/**
239
* Adds the default theme filters.
240
*
241
* @since 0.7
242
*/
243
function filters() {
244
/* Filter the textdomain mofile to allow child themes to load the parent theme translation. */
245
add_filter( 'load_textdomain_mofile', 'hybrid_load_textdomain', 10, 2 );
246
247
/* Add same filters to user description as term descriptions. */
248
add_filter( 'get_the_author_description', 'wptexturize' );
249
add_filter( 'get_the_author_description', 'convert_chars' );
250
add_filter( 'get_the_author_description', 'wpautop' );
251
252
/* Make text widgets and term descriptions shortcode aware. */
253
add_filter( 'widget_text', 'do_shortcode' );
254
add_filter( 'term_description', 'do_shortcode' );
255
256
/* Stylesheet filters. */
257
add_filter( 'stylesheet_uri', 'hybrid_debug_stylesheet', 10, 2 );
258
}
259
}
260
261
?>