-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfunctions.php
249 lines (210 loc) · 6 KB
/
functions.php
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
<?php
/**
* The theme's functions file that loads on EVERY page, used for uniform functionality.
*
* @since 0.1.0
* @package WordCrash
*/
// Don't load directly
if ( ! defined( 'ABSPATH' ) ) {
die;
}
// Make sure PHP version is correct
if ( ! version_compare( PHP_VERSION, '5.3.0', '>=' ) ) {
wp_die( 'ERROR in WordCrash theme: PHP version 5.3 or greater is required.' );
}
// Make sure no theme constants are already defined (realistically, there should be no conflicts)
if ( defined( 'THEME_VERSION' ) || defined( 'THEME_ID' ) || isset( $wordcrash_fonts ) ) {
wp_die( 'ERROR in WordCrash theme: There is a conflicting constant. Please either find the conflict or rename the constant.' );
}
/**
* The theme's current version (make sure to keep this up to date!)
*/
define( 'THEME_VERSION', '1.0.1' );
/**
* The theme's ID (used in handlers).
*/
define( 'THEME_ID', 'wordcrash' );
// Base actions
add_action( 'after_setup_theme', '_wordcrash_setup_theme' );
add_action( 'init', '_wordcrash_register_scripts' );
add_action( 'wp_enqueue_scripts', '_wordcrash_load_scripts' );
add_action( 'after_setup_theme', '_wordcrash_load_nav_menus' );
add_action( 'widgets_init', '_wordcrash_load_sidebars' );
add_action( 'wp_head', '_wordcrash_load_favicon' );
/**
* Setup theme properties and stuff.
*
* @since 0.1.0
*/
function _wordcrash_setup_theme() {
// Add theme support
require_once __DIR__ . '/includes/theme-support.php';
// Allow shortcodes in text widget
add_filter( 'widget_text', 'do_shortcode' );
}
/**
* Register theme files.
*
* @since 0.1.0
*/
function _wordcrash_register_scripts() {
// Theme styles
wp_register_style(
THEME_ID,
get_template_directory_uri() . '/style.css',
array( 'foundation' ),
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : THEME_VERSION
);
// Theme script
wp_register_script(
THEME_ID,
get_template_directory_uri() . '/script.js',
array( 'jquery', 'foundation' ),
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : THEME_VERSION,
true
);
// Shuffle
wp_register_script(
'shuffle',
get_template_directory_uri() . '/assets/vendor/js/jquery.shuffle.min.js',
array(),
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : '3.0.0'
);
// FOUNDATION
wp_register_style(
'foundation',
get_template_directory_uri() . '/assets/vendor/css/foundation.min.css',
array( 'normalize' ),
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : '5.5.2'
);
wp_register_style(
'normalize',
get_template_directory_uri() . '/assets/vendor/css/normalize.css',
array(),
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : '3.0.3'
);
wp_register_script(
'foundation',
get_template_directory_uri() . '/assets/vendor/js/foundation.min.js',
array( 'jquery', 'fastclick', 'jquery-cookie', 'modernizr', 'placeholder' ),
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : '5.5.2'
);
wp_register_script(
'fastclick',
get_template_directory_uri() . '/assets/vendor/js/fastclick.js',
array(),
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : THEME_VERSION
);
wp_register_script(
'jquery-cookie',
get_template_directory_uri() . '/assets/vendor/js/jquery.cookie.js',
array( 'jquery' ),
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : '1.4.1'
);
wp_register_script(
'modernizr',
get_template_directory_uri() . '/assets/vendor/js/modernizr.js',
array(),
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : '2.8.3'
);
wp_register_script(
'placeholder',
get_template_directory_uri() . '/assets/vendor/js/placeholder.js',
array(),
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : '2.0.9'
);
/**
* Fonts for the theme. Must be hosted font (Google fonts for example).
*
* @since 0.1.0
*/
$wordcrash_fonts = apply_filters( 'wordcrash_fonts', array(
'font-awesome' => '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css',
'open-sans' => 'https://fonts.googleapis.com/css?family=Open+Sans:400,400italic,700,700italic',
'sigmar' => '//fonts.googleapis.com/css?family=Sigmar+One',
) );
if ( ! empty( $wordcrash_fonts ) ) {
foreach ( $wordcrash_fonts as $ID => $link ) {
wp_register_style(
THEME_ID . "-font-$ID",
$link
);
}
}
}
/**
* Enqueue theme files.
*
* @since 0.1.0
*/
function _wordcrash_load_scripts() {
// Theme styles
wp_enqueue_style( THEME_ID );
// Theme script
wp_enqueue_script( THEME_ID );
// Shuffle
wp_enqueue_script( 'shuffle' );
// FOUNDATION
wp_enqueue_script( 'foundation' );
wp_enqueue_script( 'fastclick' );
wp_enqueue_script( 'jquery.cookie.js' );
wp_enqueue_script( 'modernizr.js' );
wp_enqueue_script( 'placeholder.js' );
/** Explained above */
$wordcrash_fonts = apply_filters( 'wordcrash_fonts', array(
'font-awesome' => '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css',
'open-sans' => 'https://fonts.googleapis.com/css?family=Open+Sans:400,400italic,700,700italic',
'sigmar' => '//fonts.googleapis.com/css?family=Sigmar+One',
) );
if ( ! empty( $wordcrash_fonts ) ) {
foreach ( $wordcrash_fonts as $ID => $link ) {
wp_enqueue_style( THEME_ID . "-font-$ID" );
}
}
}
/**
* Register nav menus.
*
* @since 0.1.0
*/
function _wordcrash_load_nav_menus() {
// Primary
register_nav_menu( 'primary', 'Primary Menu' );
// Error 404
register_nav_menu( 'error-404', 'Error 404' );
}
/**
* Register sidebars.
*
* @since 0.1.0
*/
function _wordcrash_load_sidebars() {
// Page
// register_sidebar( array(
// 'name' => 'Page',
// 'id' => 'page',
// 'description' => 'Displays on all pages.',
// 'before_title' => '<h3 class="widget-title">',
// 'after_title' => '</h3>',
// ));
}
/**
* Adds a favicon.
*
* @since 0.1.0
*/
function _wordcrash_load_favicon() {
if ( ! file_exists( get_stylesheet_directory() . '/assets/images/favicon.ico' ) ) {
return;
}
?>
<link rel="shortcut icon" href="<?php echo get_stylesheet_directory_uri() . '/assets/images/favicon.ico'; ?>"/>
<?php
}
// Include shortcodes
require_once __DIR__ . '/includes/shortcodes/button.php';
// Include theme specific functions
require_once __DIR__ . '/includes/theme-functions.php';
// Admin
require_once __DIR__ . '/admin/admin.php';