forked from anabelle/Foundation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
executable file
·451 lines (341 loc) · 11.4 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
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<?php
/**
* Functions
*
* Core functionality and initial theme setup
*
* @package WordPress
* @subpackage Foundation, for WordPress
* @since Foundation, for WordPress 4.0
*/
/**
* Initiate Foundation, for WordPress
*/
if ( ! function_exists( 'foundation_setup' ) ) :
function foundation_setup() {
// Content Width
if ( ! isset( $content_width ) ) $content_width = 900;
// Language Translations
load_theme_textdomain( 'foundation', get_template_directory() . '/languages' );
// Custom Editor Style Support
add_editor_style();
// Support for Featured Images
add_theme_support( 'post-thumbnails' );
// Automatic Feed Links & Post Formats
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'post-formats', array( 'aside', 'image', 'link', 'quote', 'status' ) );
// Custom Background
add_theme_support( 'custom-background', array(
'default-color' => 'fff',
) );
// Custom Header
add_theme_support( 'custom-header', array(
'default-text-color' => '#000',
'header-text' => true,
'height' => '200',
'uploads' => true,
) );
}
add_action( 'after_setup_theme', 'foundation_setup' );
endif;
/**
* Enqueue Scripts and Styles for Front-End
*/
if ( ! function_exists( 'foundation_assets' ) ) :
function foundation_assets() {
if (!is_admin()) {
/**
* Deregister jQuery in favour of ZeptoJS
* jQuery will be used as a fallback if ZeptoJS is not compatible
* @see foundation_compatibility & http://foundation.zurb.com/docs/javascript.html
*/
wp_deregister_script('jquery');
// Load JavaScripts
wp_enqueue_script( 'foundation', get_template_directory_uri() . '/js/foundation.min.js', null, '4.0', true );
wp_enqueue_script( 'modernizr', get_template_directory_uri().'/js/vendor/custom.modernizr.js', null, '2.1.0');
if ( is_singular() ) wp_enqueue_script( "comment-reply" );
// Load Stylesheets
wp_enqueue_style( 'normalize', get_template_directory_uri().'/css/normalize.css' );
wp_enqueue_style( 'foundation', get_template_directory_uri().'/css/foundation.min.css' );
wp_enqueue_style( 'app', get_stylesheet_uri(), array('foundation') );
// Load Google Fonts API
wp_enqueue_style( 'google-fonts', 'http://fonts.googleapis.com/css?family=Open+Sans:400,300' );
}
}
add_action( 'wp_enqueue_scripts', 'foundation_assets' );
endif;
/**
* Initialise Foundation JS
* @see: http://foundation.zurb.com/docs/javascript.html
*/
if ( ! function_exists( 'foundation_js_init' ) ) :
function foundation_js_init () {
echo '<script>$(document).foundation();</script>';
}
add_action('wp_footer', 'foundation_js_init', 50);
endif;
/**
* ZeptoJS and jQuery Fallback
* @see: http://foundation.zurb.com/docs/javascript.html
*/
if ( ! function_exists( 'foundation_comptability' ) ) :
function foundation_comptability () {
echo "<script>";
echo "document.write('<script src=' +";
echo "('__proto__' in {} ? '" . get_template_directory_uri() . "/js/vendor/zepto" . "' : '" . get_template_directory_uri() . "/js/vendor/jquery" . "') +";
echo "'.js><\/script>')";
echo "</script>";
}
add_action('wp_footer', 'foundation_comptability', 10);
endif;
/**
* Register Navigation Menus
*/
if ( ! function_exists( 'foundation_menus' ) ) :
// Register wp_nav_menus
function foundation_menus() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu', 'foundation' )
)
);
}
add_action( 'init', 'foundation_menus' );
endif;
if ( ! function_exists( 'foundation_page_menu' ) ) :
function foundation_page_menu() {
$args = array(
'sort_column' => 'menu_order, post_title',
'menu_class' => 'large-12 columns',
'include' => '',
'exclude' => '',
'echo' => true,
'show_home' => false,
'link_before' => '',
'link_after' => ''
);
wp_page_menu($args);
}
endif;
/**
* Navigation Menu Adjustments
*/
// Add class to navigation sub-menu
class foundation_navigation extends Walker_Nav_Menu {
function start_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent<ul class=\"dropdown\">\n";
}
function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
$id_field = $this->db_fields['id'];
if ( !empty( $children_elements[ $element->$id_field ] ) ) {
$element->classes[] = 'has-dropdown';
}
Walker_Nav_Menu::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
}
}
/**
* Create pagination
*/
if ( ! function_exists( 'foundation_pagination' ) ) :
function foundation_pagination() {
global $wp_query;
$big = 999999999;
$links = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'prev_next' => true,
'prev_text' => '«',
'next_text' => '»',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'type' => 'list'
)
);
$pagination = str_replace('page-numbers','pagination',$links);
echo $pagination;
}
endif;
/**
* Register Sidebars
*/
if ( ! function_exists( 'foundation_widgets' ) ) :
function foundation_widgets() {
// Sidebar Right
register_sidebar( array(
'id' => 'foundation_sidebar_right',
'name' => __( 'Sidebar Right', 'foundation' ),
'description' => __( 'This sidebar is located on the right-hand side of each page.', 'foundation' ),
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h5>',
'after_title' => '</h5>',
) );
// Sidebar Footer Column One
register_sidebar( array(
'id' => 'foundation_sidebar_footer_one',
'name' => __( 'Sidebar Footer One', 'foundation' ),
'description' => __( 'This sidebar is located in column one of your theme footer.', 'foundation' ),
'before_widget' => '<div class="large-3 columns">',
'after_widget' => '</div>',
'before_title' => '<h5>',
'after_title' => '</h5>',
) );
// Sidebar Footer Column Two
register_sidebar( array(
'id' => 'foundation_sidebar_footer_two',
'name' => __( 'Sidebar Footer Two', 'foundation' ),
'description' => __( 'This sidebar is located in column two of your theme footer.', 'foundation' ),
'before_widget' => '<div class="large-3 columns">',
'after_widget' => '</div>',
'before_title' => '<h5>',
'after_title' => '</h5>',
) );
// Sidebar Footer Column Three
register_sidebar( array(
'id' => 'foundation_sidebar_footer_three',
'name' => __( 'Sidebar Footer Three', 'foundation' ),
'description' => __( 'This sidebar is located in column three of your theme footer.', 'foundation' ),
'before_widget' => '<div class="large-3 columns">',
'after_widget' => '</div>',
'before_title' => '<h5>',
'after_title' => '</h5>',
) );
// Sidebar Footer Column Four
register_sidebar( array(
'id' => 'foundation_sidebar_footer_four',
'name' => __( 'Sidebar Footer Four', 'foundation' ),
'description' => __( 'This sidebar is located in column four of your theme footer.', 'foundation' ),
'before_widget' => '<div class="large-3 columns">',
'after_widget' => '</div>',
'before_title' => '<h5>',
'after_title' => '</h5>',
) );
}
add_action( 'widgets_init', 'foundation_widgets' );
endif;
/**
* Custom Avatar Classes
*/
if ( ! function_exists( 'foundation_avatar_css' ) ) :
function foundation_avatar_css($class) {
$class = str_replace("class='avatar", "class='author_gravatar left ", $class) ;
return $class;
}
add_filter('get_avatar','foundation_avatar_css');
endif;
/**
* Custom Post Excerpt
*/
if ( ! function_exists( 'foundation_excerpt' ) ) :
function foundation_excerpt($text) {
global $post;
if ( '' == $text ) {
$text = get_the_content('');
$text = apply_filters('the_content', $text);
$text = str_replace('\]\]\>', ']]>', $text);
$text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
$text = strip_tags($text, '<p>');
$excerpt_length = 80;
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words)> $excerpt_length) {
array_pop($words);
array_push($words, '<br><br><a href="'.get_permalink($post->ID) .'" class="button secondary small">' . __('Continue Reading', 'foundation') . '</a>');
$text = implode(' ', $words);
}
}
return $text;
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'foundation_excerpt');
endif;
/**
* Comments Template
*/
if ( ! function_exists( 'foundation_comment' ) ) :
function foundation_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case 'pingback' :
case 'trackback' :
// Display trackbacks differently than normal comments.
?>
<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
<p><?php _e( 'Pingback:', 'foundation' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'foundation' ), '<span>', '</span>' ); ?></p>
<?php
break;
default :
global $post;
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<article id="comment-<?php comment_ID(); ?>" class="comment">
<header>
<?php
echo "<span class='th alignleft' style='margin-right:1rem;'>";
echo get_avatar( $comment, 44 );
echo "</span>";
printf( '%2$s %1$s',
get_comment_author_link(),
( $comment->user_id === $post->post_author ) ? '<span class="label">' . __( 'Post Author', 'foundation' ) . '</span>' : ''
);
printf( '<br><a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
esc_url( get_comment_link( $comment->comment_ID ) ),
get_comment_time( 'c' ),
sprintf( __( '%1$s at %2$s', 'foundation' ), get_comment_date(), get_comment_time() )
);
?>
</header>
<?php if ( '0' == $comment->comment_approved ) : ?>
<p><?php _e( 'Your comment is awaiting moderation.', 'foundation' ); ?></p>
<?php endif; ?>
<section>
<?php comment_text(); ?>
</section><!-- .comment-content -->
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'foundation' ), 'after' => ' ↓ <br><br>', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div>
</article>
<?php
break;
endswitch;
}
endif;
/**
* Remove Class from Sticky Post
*/
if ( ! function_exists( 'foundation_remove_sticky' ) ) :
function foundation_remove_sticky($classes) {
$classes = array_diff($classes, array("sticky"));
return $classes;
}
add_filter('post_class','foundation_remove_sticky');
endif;
/**
* Custom Foundation Title Tag
* @see http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_title
*/
function foundation_title( $title, $sep ) {
global $paged, $page;
if ( is_feed() )
return $title;
// Add the site name.
$title .= get_bloginfo( 'name' );
// Add the site description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
$title = "$title $sep $site_description";
// Add a page number if necessary.
if ( $paged >= 2 || $page >= 2 )
$title = "$title $sep " . sprintf( __( 'Page %s', 'foundation' ), max( $paged, $page ) );
return $title;
}
add_filter( 'wp_title', 'foundation_title', 10, 2 );
/**
* Retrieve Shortcodes
* @see: http://fwp.drewsymo.com/shortcodes/
*/
$foundation_shortcodes = trailingslashit( get_template_directory() ) . 'inc/shortcodes.php';
if (file_exists($foundation_shortcodes)) {
require( $foundation_shortcodes );
}
?>