-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
437 lines (373 loc) · 12.8 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
<?php
/**
* MClub LA functions and definitions
*
* @package MClub LA
*/
/**
* Set the content width based on the theme's design and stylesheet.
*/
if ( ! isset( $content_width ) )
$content_width = 900; /* pixels */
/**
* Custom function to repurpose custom-background functionality to our footer
* http://wp.tutsplus.com/articles/tips-articles/modifying-custom-background-feature-for-any-html-element-you-want/
*/
function mclub_custom_background_cb() {
$background = get_background_image();
$color = get_background_color();
if ( ! $background && ! $color )
return;
$style = $color ? "background-color: #$color;" : '';
if ( $background ) {
$image = " background-image: url('$background');";
$repeat = get_theme_mod( 'background_repeat', 'repeat' );
if ( ! in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) )
$repeat = 'repeat';
$repeat = " background-repeat: $repeat;";
$position = get_theme_mod( 'background_position_x', 'left' );
if ( ! in_array( $position, array( 'center', 'right', 'left' ) ) )
$position = 'left';
$position = " background-position: top $position;";
$attachment = get_theme_mod( 'background_attachment', 'scroll' );
if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) )
$attachment = 'scroll';
$attachment = " background-attachment: $attachment;";
$style .= $image . $repeat . $position; //. $attachment;
}
?>
<style type="text/css">
#colophon { <?php echo trim( $style ); ?> background-size: cover; }
</style>
<?php
}
if ( ! function_exists( 'mclub_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which runs
* before the init hook. The init hook is too late for some features, such as indicating
* support post thumbnails.
*/
function mclub_setup() {
/**
* Make theme available for translation
* Translations can be filed in the /languages/ directory
* If you're building a theme based on MClub LA, use a find and replace
* to change 'mclub' to the name of your theme in all the template files
*/
load_theme_textdomain( 'mclub', get_template_directory() . '/languages' );
/**
* Add default posts and comments RSS feed links to head
*/
add_theme_support( 'automatic-feed-links' );
/**
* Enable support for Post Thumbnails on posts and pages
*
* @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
add_theme_support( 'post-thumbnails' );
/* Add custom image sizes */
add_image_size( 'front-page-thumb', 400, 260, true ); // homepage thumbnail
add_image_size( 'post-leader-image', 1000, 9999, false ); // used for leader image
/**
* This theme uses wp_nav_menu() in two locations.
*/
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'mclub' ),
) );
/**
* Enable support for Post Formats
*/
//add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link' ) );
add_theme_support( 'custom-background', array(
'wp-head-callback' => 'mclub_custom_background_cb',
) );
}
endif; // mclub_setup
add_action( 'after_setup_theme', 'mclub_setup' );
/**
* Register widgetized area and update sidebar with default widgets
*/
function mclub_widgets_init() {
register_sidebar( array(
'name' => __( 'Right Sidebar', 'mclub' ),
'id' => 'sidebar-right',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Main Page Top Area', 'mclub' ),
'id' => 'homepage-top',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
) );
register_sidebar( array(
'name' => __( 'Footer Column 1', 'mclub' ),
'id' => 'footer-col-1',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<span class="footer-col-header">',
'after_title' => '</span>',
));
register_sidebar( array(
'name' => __( 'Footer Column 2', 'mclub' ),
'id' => 'footer-col-2',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<span class="footer-col-header">',
'after_title' => '</span>',
));
register_sidebar( array(
'name' => __( 'Footer Column 3', 'mclub' ),
'id' => 'footer-col-3',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<span class="footer-col-header">',
'after_title' => '</span>',
));
}
add_action( 'widgets_init', 'mclub_widgets_init' );
/**
* Enqueue scripts and styles
*/
function mclub_scripts() {
/**
* Use latest jQuery release
*/
if( !is_admin() ){
wp_deregister_script('jquery');
wp_register_script('jquery', ("//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"), false, null);
wp_enqueue_script('jquery');
}
wp_enqueue_style( 'font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css', false, null );
wp_enqueue_style( 'mclub-style', get_stylesheet_uri() );
wp_enqueue_script( 'mclub-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
wp_enqueue_script( 'mclub-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
wp_enqueue_script( 'jquery-scrolltofixed', get_template_directory_uri() . '/js/jquery-scrolltofixed-min.js', array('jquery') );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
if ( is_singular() && wp_attachment_is_image() ) {
wp_enqueue_script( 'mclub-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20120202' );
}
/**
* Enqueue social sharing scripts if singular page
*/
if ( is_singular() ) {
wp_enqueue_script( 'facebook-jssdk', '//connect.facebook.net/en_US/all.js#xfbml=1&appId=563087663768939', false, null ); // Facebook JSSDK
wp_enqueue_script( 'twitter-wjs', '//platform.twitter.com/widgets.js', false, null ); // Twitter Widget JS
wp_enqueue_script( 'gplusone', '//apis.google.com/js/plusone.js', false, null ); // Google+ JS
wp_enqueue_script( 'stumbleupon', '//platform.stumbleupon.com/1/widgets.js', false, null ); // StumbleUpon JS
}
remove_action('wp_head', 'wlwmanifest_link'); // get rid of live writer
}
add_action( 'wp_enqueue_scripts', 'mclub_scripts' );
/**
* Add IE7 support for fontawesome
* http://fontawesome.io/get-started/
*/
function mclub_fontawesome_ie7_support() {
echo '<!--[if IE 7]>';
echo '<link rel="stylesheet" href="path/to/font-awesome/css/font-awesome-ie7.min.css">';
echo '<![endif]-->';
}
//add_action('wp_head', 'mclub_fontawesome_ie7_support');
/**
* Add ie conditional html5shiv to header
* http://css-tricks.com/snippets/wordpress/html5-shim-in-functions-php/
*/
function mclub_ie_html5_shim () {
echo '<!--[if lt IE 9]>';
echo '<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>';
echo '<![endif]-->';
}
add_action('wp_head', 'mclub_ie_html5_shim');
/**
* Excerpt 'read more' customization
* http://codex.wordpress.org/Function_Reference/the_excerpt
*/
function mclub_excerpt_more( $more ) {
return ' (<a class="read-more" href="'. get_permalink( get_the_ID() ) . '">More</a>)';
}
add_filter( 'excerpt_more', 'mclub_excerpt_more' );
/**
* Breadcrumb Type Filter to fix classes
*/
function mclub_bcn_types( $bcn_content, $bcn_id ) {
return array_diff($bcn_content, array('post','post-post'));
}
add_filter( 'bcn_breadcrumb_types','mclub_bcn_types', 11, 2 );
/**
* Improves the caption shortcode with HTML5 figure & figcaption; microdata
*
* @param string $val Empty
* @param array $attr Shortcode attributes
* @param string $content Shortcode content
* @return string Shortcode output
* https://gist.github.com/JoostKiens/4477366
*/
function mclub_img_caption_shortcode_filter($val, $attr, $content = null)
{
extract(shortcode_atts(array(
'id' => '',
'align' => 'aligncenter',
'width' => '',
'caption' => ''
), $attr));
// No caption, no dice... But why width?
if ( 1 > (int) $width || empty($caption) )
return $val;
if ( $id )
$id = esc_attr( $id );
// Add itemprop="contentURL" to image - Ugly hack
$content = str_replace('<img', '<img itemprop="contentURL"', $content);
/* For the MClub Template, we want to place alignleft/alignright captions vertically
centered to the left/right of the image. Currently doing this with CSS Tables -
but the order of the caption/figure needs to be swapped depinging on which side
of the image (which "cell") the caption falls:
=Left Image=> Image First, Caption Second
=Right Image=> Caption First, Image Second
The default code works for alignleft and aligncenter, we only need to capture alignright
*/
if( $align == 'alignright' ) {
return '<figure id="' . esc_attr($id) . '" class="wp-caption ' . esc_attr($align) . '"><figcaption id="figcaption_'. esc_attr($id) . '" class="wp-caption-text" itemprop="description">' . $caption . '</figcaption>' . do_shortcode( $content ) . '</figure>';
} else {
return '<figure id="' . esc_attr($id) . '" class="wp-caption ' . esc_attr($align) . '">' . do_shortcode( $content ) . '<figcaption id="figcaption_'. esc_attr($id) . '" class="wp-caption-text" itemprop="description">' . $caption . '</figcaption></figure>';
}
}
add_filter( 'img_caption_shortcode', 'mclub_img_caption_shortcode_filter', 10, 3 );
/**
* Custom function to search for the first image in a post
* http://www.wprecipes.com/how-to-get-the-first-image-from-the-post-and-display-it
*/
function mclub_post_image_search() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
/* if(empty($first_img)){ //Defines a default image
$first_img = "/images/default.jpg";
}
*/
return $first_img;
}
/**
* Remove wooslider oembed mods
*/
/*if(function_exists("wooslider")) {
remove_filter( 'oembed_result', array($wooslider, 'oembed_video_output') );
}*/
/**
* PHP Export of ACF Fields for Theme
*/
if(function_exists("register_field_group"))
{
register_field_group(array (
'id' => 'acf_post-leader-media',
'title' => 'Post Leader Media',
'fields' => array (
array (
'key' => 'field_5215b36bdca38',
'label' => 'Post Leader: Image or Video',
'name' => 'mclub_leader_image_or_video',
'type' => 'radio',
'instructions' => 'Chose to upload an image for the leader, or insert a video',
'choices' => array (
'Image' => 'Image',
'Video' => 'Video',
'None' => 'None',
),
'other_choice' => 0,
'save_other_choice' => 0,
'default_value' => 'Image',
'layout' => 'horizontal',
),
array (
'key' => 'field_521597c945b10',
'label' => 'Post Leader Image',
'name' => 'mclub_leader_image',
'type' => 'image',
'instructions' => 'Insert a desired leader image. This will appear above the post title on the post view page.',
'conditional_logic' => array (
'status' => 1,
'rules' => array (
array (
'field' => 'field_5215b36bdca38',
'operator' => '==',
'value' => 'Image',
),
),
'allorany' => 'all',
),
'save_format' => 'object',
'preview_size' => 'medium',
'library' => 'all',
),
array (
'key' => 'field_5215b2f31961f',
'label' => 'Post Leader Video',
'name' => 'mclub_leader_external',
'type' => 'text',
'instructions' => 'Paste YouTube or Vimeo URL here. This will appear above the post title on the post view page.',
'conditional_logic' => array (
'status' => 1,
'rules' => array (
array (
'field' => 'field_5215b36bdca38',
'operator' => '==',
'value' => 'Video',
),
),
'allorany' => 'all',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'none',
'maxlength' => '',
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
'order_no' => 0,
'group_no' => 0,
),
),
),
'options' => array (
'position' => 'acf_after_title',
'layout' => 'default',
'hide_on_screen' => array (
),
),
'menu_order' => 0,
));
}
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Custom functions that act independently of the theme templates.
*/
require get_template_directory() . '/inc/extras.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Load Jetpack compatibility file.
*/
require get_template_directory() . '/inc/jetpack.php';