-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
625 lines (516 loc) · 18.1 KB
/
functions.php
File metadata and controls
625 lines (516 loc) · 18.1 KB
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
<?php
/**
* The theme's functions file that loads on EVERY page, used for uniform functionality.
*
* @since 0.1.0
* @package Mullins
*/
die(); // RIP
// 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 Mullins 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( $mullins_fonts ) ) {
wp_die( 'ERROR in Mullins 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', '0.1.0' );
/**
* The theme's ID (used in handlers).
*/
define( 'THEME_ID', 'mullins_theme' );
/**
* Capability required to manage MailChimp options
*/
add_action( 'after_setup_theme', 'redefine_mailchimp_capability' );
function redefine_mailchimp_capability() {
runkit_constant_remove( 'MCSF_CAP_THRESHOLD' );
define( 'MCSF_CAP_THRESHOLD', 'mailchimp_options' );
}
/**
* Fonts for the theme. Must be hosted font (Google fonts for example).
*/
$mullins_fonts = array(
'Font Awesome' => '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css',
'Lora' => '//fonts.googleapis.com/css?family=Lora:700,700italic',
);
/**
* Setup theme properties and stuff.
*
* @since 0.1.0
*/
add_action( 'after_setup_theme', function () {
// Image sizes
if ( ! empty( $mullins_image_sizes ) ) {
foreach ( $mullins_image_sizes as $ID => $size ) {
add_image_size( $ID, $size['width'], $size['height'], $size['crop'] );
}
add_filter( 'image_size_names_choose', '_meesdist_add_image_sizes' );
}
// Add Customizer Controls
add_action( 'customize_register', 'mullins_customize_register' );
// Add Customizer Preview JavaScript
add_action( 'customize_preview_init', 'mullins_customizer_live_preview' );
// Add theme support
require_once __DIR__ . '/includes/theme-support.php';
// Allow shortcodes in text widget
add_filter( 'widget_text', 'do_shortcode' );
} );
/**
* Adds support for custom image sizes.
*
* @since 0.1.0
*
* @param $sizes array The existing image sizes.
*
* @return array The new image sizes.
*/
function _meesdist_add_image_sizes( $sizes ) {
global $mullins_image_sizes;
$new_sizes = array();
foreach ( $mullins_image_sizes as $ID => $size ) {
$new_sizes[ $ID ] = $size['title'];
}
return array_merge( $sizes, $new_sizes );
}
/**
* Adds custom Customizer Controls.
*
* @since 0.1.0
*/
function mullins_customize_register( $wp_customize ) {
// General Theme Options
$wp_customize->add_section( 'mullins_customizer_section' , array(
'title' => __( 'Mullins Settings', THEME_ID ),
'priority' => 30,
)
);
$wp_customize->add_setting( 'mullins_logo_image' , array(
'default' => 'http://placehold.it/350x150',
'transport' => 'postMessage',
)
);
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'mullins_logo_image', array(
'label' => __( 'Logo', THEME_ID ),
'section' => 'mullins_customizer_section',
'settings' => 'mullins_logo_image',
) ) );
$wp_customize->add_setting( 'mullins_primary_color' , array(
'default' => '#094C8B',
'transport' => 'refresh',
)
);
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'mullins_primary_color', array(
'label' => __( 'Primary Color', THEME_ID ),
'section' => 'mullins_customizer_section',
'settings' => 'mullins_primary_color',
) ) );
$wp_customize->add_setting( 'mullins_secondary_color' , array(
'default' => '#C31A2F',
'transport' => 'refresh',
)
);
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'mullins_secondary_color', array(
'label' => __( 'Secondary Color', THEME_ID ),
'section' => 'mullins_customizer_section',
'settings' => 'mullins_secondary_color',
) ) );
$wp_customize->add_setting( 'mullins_accent_1' , array(
'default' => '#ebebeb',
'transport' => 'refresh',
)
);
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'mullins_accent_1', array(
'label' => __( 'Accent 1', THEME_ID ),
'section' => 'mullins_customizer_section',
'settings' => 'mullins_accent_1',
) ) );
$wp_customize->add_setting( 'mullins_accent_2' , array(
'default' => '#D6E0EB',
'transport' => 'refresh',
)
);
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'mullins_accent_2', array(
'label' => __( 'Accent 2', THEME_ID ),
'section' => 'mullins_customizer_section',
'settings' => 'mullins_accent_2',
) ) );
$wp_customize->add_setting( 'mullins_background' , array(
'default' => '#ffffff',
'transport' => 'refresh',
)
);
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'mullins_background', array(
'label' => __( 'Background', THEME_ID ),
'section' => 'mullins_customizer_section',
'settings' => 'mullins_background',
) ) );
$wp_customize->add_setting( 'mullins_address' , array(
'default' => '123 Some Street<br />Anytown, USA 45678',
'transport' => 'refresh',
)
);
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'mullins_address', array(
'type' => 'textarea',
'label' => __( 'Address', THEME_ID ),
'section' => 'mullins_customizer_section',
'settings' => 'mullins_address',
) ) );
$wp_customize->add_setting( 'mullins_phone_number' , array(
'default' => '(517) 867-5309',
'transport' => 'postMessage',
)
);
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'mullins_phone_number', array(
'label' => __( 'Phone Number', THEME_ID ),
'section' => 'mullins_customizer_section',
'settings' => 'mullins_phone_number',
) ) );
$wp_customize->add_setting( 'mullins_email_address' , array(
'default' => 'test@fake.com',
'transport' => 'postMessage',
)
);
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'mullins_email_address', array(
'label' => __( 'Email Address', THEME_ID ),
'section' => 'mullins_customizer_section',
'settings' => 'mullins_email_address',
) ) );
$wp_customize->add_setting( 'mullins_facebook_url' , array(
'default' => 'http://facebook.com',
'transport' => 'postMessage',
)
);
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'mullins_facebook_url', array(
'label' => __( 'Facebook URL', THEME_ID ),
'section' => 'mullins_customizer_section',
'settings' => 'mullins_facebook_url',
) ) );
$wp_customize->add_setting( 'mullins_contact_shortcode' , array(
'default' => '[contact-form-7 id="31" title="Schedule a Service Call"]',
'transport' => 'refresh',
)
);
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'mullins_contact_shortcode', array(
'label' => __( 'Contact Form Shortcode', THEME_ID ),
'section' => 'mullins_customizer_section',
'settings' => 'mullins_contact_shortcode',
) ) );
$wp_customize->add_setting( 'mullins_footer_columns' , array(
'default' => 4,
'transport' => 'refresh',
)
);
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'mullins_footer_columns', array(
'type' => 'number',
'label' => __( 'Footer Number of Columns/Widgets', THEME_ID ),
'section' => 'mullins_customizer_section',
'settings' => 'mullins_footer_columns',
) ) );
}
/**
* Adds live-refreshing capability for custom Customizer Controls.
*
* @since 0.1.0
*/
function mullins_customizer_live_preview() {
wp_enqueue_script( THEME_ID . '-customizer' );
}
/**
* Register theme files.
*
* @since 0.1.0
*/
add_action( 'init', function () {
global $mullins_fonts;
// Theme styles
wp_register_style(
THEME_ID,
get_template_directory_uri() . '/style.css',
null,
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : THEME_VERSION
);
// Theme script
wp_register_script(
THEME_ID,
get_template_directory_uri() . '/script.js',
array( 'jquery' ),
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : THEME_VERSION,
true
);
wp_localize_script( THEME_ID, THEME_ID . '_data', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ) ) );
// Admin script
wp_register_script(
THEME_ID . '-admin',
get_template_directory_uri() . '/admin.js',
array( 'jquery' ),
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : THEME_VERSION,
true
);
// Customizer Preview script
wp_register_script(
THEME_ID . '-customizer',
get_template_directory_uri() . '/customizer.js',
array( 'jquery', 'customize-preview' ),
defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : THEME_VERSION,
true
);
// Theme fonts
if ( ! empty( $mullins_fonts ) ) {
foreach ( $mullins_fonts as $ID => $link ) {
wp_register_style(
THEME_ID . "-font-$ID",
$link
);
}
}
} );
/**
* Enqueue theme files.
*
* @since 0.1.0
*/
add_action( 'wp_enqueue_scripts', function () {
global $mullins_fonts;
// Theme styles
wp_enqueue_style( THEME_ID );
// Theme script
wp_enqueue_script( THEME_ID );
// Theme fonts
if ( ! empty( $mullins_fonts ) ) {
foreach ( $mullins_fonts as $ID => $link ) {
wp_enqueue_style( THEME_ID . "-font-$ID" );
}
}
} );
/**
* Register nav menus.
*
* @since 0.1.0
*/
add_action( 'after_setup_theme', function () {
register_nav_menu( 'primary', 'Primary Menu' );
} );
/**
* Register sidebars.
*
* @since 0.1.0
*/
add_action( 'widgets_init', function () {
// Home Page
register_sidebar( array(
'name' => __( 'Home Page Sidebar', THEME_ID ),
'id' => 'home-page-sidebar',
'description' => __( 'Widgets in this area will be shown in the Home Page Sidebar.', THEME_ID ),
) );
// Sub-Page
register_sidebar( array(
'name' => 'Services Sub-Page Sidebar',
'id' => 'services-sub-page-sidebar',
'description' => 'Displays on all Services Sub-Pages.',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// Footer
$footer_columns = get_theme_mod( 'mullins_footer_columns', 4 );
for ( $index = 0; $index < $footer_columns; $index++ ) {
register_sidebar(
array(
'name' => 'Footer ' . ( $index + 1 ),
'id' => 'footer-' . ( $index + 1 ),
'description' => '',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
)
);
}
} );
/**
* Adds a favicon.
*
* @since 0.1.0
*/
add_action( 'wp_head', '_mullins_favicon' );
add_action( 'admin_head', '_mullins_favicon' );
function _mullins_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
}
/**
* Loads a partial.
*
* @since 0.1.0
*
* @param array|string $template The template to load.
*/
function mullins_template( $template ) {
$template = is_array( $template ) ? implode( '/', $template ) : $template;
if ( file_exists( __DIR__ . "/includes/partials/$template.php" ) ) {
include __DIR__ . "/includes/partials/$template.php";
}
}
/**
* Creates the Testimonials CPT
*
* @since 0.2.0
*/
add_action( 'init', 'register_cpt_mullins_testimonial' );
function register_cpt_mullins_testimonial() {
$labels = array(
'name' => _x( 'Testimonial', THEME_ID ),
'all_items' => __( 'All Testimonials', THEME_ID ),
'singular_name' => _x( 'Testimonial', THEME_ID ),
'add_new' => _x( 'Add New Testimonial', THEME_ID ),
'add_new_item' => _x( 'Add New Testimonial', THEME_ID ),
'edit_item' => _x( 'Edit Testimonial', THEME_ID ),
'new_item' => _x( 'New Testimonial', THEME_ID ),
'view_item' => _x( 'View Testimonial', THEME_ID ),
'search_items' => _x( 'Search Testimonials', THEME_ID ),
'not_found' => _x( 'No Testimonials found', THEME_ID ),
'not_found_in_trash' => _x( 'No Testimonials found in Trash', THEME_ID ),
'parent_item_colon' => _x( 'Parent Testimonial:', THEME_ID ),
'menu_name' => _x( 'Testimonials', THEME_ID ),
);
$args = array(
'labels' => $labels,
'menu_icon' => 'dashicons-awards',
'hierarchical' => false,
'description' => 'testimonial',
'supports' => array( 'title', 'editor', 'author', 'thumbnail' ),
'public' => false,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => false,
'query_var' => true,
'can_export' => true,
'rewrite' => array(
'slug' => 'testimonial',
'with_front' => false,
'feeds' => false,
'pages' => true
),
'capability_type' => 'post',
/*
'capability_type' => 'testimonial',
'capabilities' => array(
// Singular
'edit_post' => 'edit_testimonial',
'read_post' => 'read_testimonial',
'delete_post' => 'delete_testimonial',
// Plural
'edit_posts' => 'edit_testimonials',
'edit_others_posts' => 'edit_others_testimonials',
'publish_posts' => 'publish_testimonials',
'read_private_posts' => 'read_private_testimonials',
'delete_posts' => 'delete_testimonials',
'delete_private_posts' => 'delete_private_testimonials',
'delete_published_posts' => 'delete_published_testimonials',
'delete_others_posts' => 'delete_others_testimonials',
'edit_private_posts' => 'edit_private_testimonials',
'edit_published_posts' => 'edit_published_testimonials',
),
*/
);
register_post_type( 'mullins_testimonial', $args );
}
/*
* Makes Testimonial Gravity Form submit to the correct Post Type
*
* @param array $post_data The Post Data being filtered
* @param Object $form The Form being processed
* @param Object $entry The Entry being processed
*
* @since 0.2.0
*/
add_filter( 'gform_post_data', 'change_testimonials_form_post_type', 10, 3 );
function change_testimonials_form_post_type( $post_data, $form, $entry ) {
if ( $form['id'] != 1 ) {
return $post_data;
}
$post_data['post_type'] = 'mullins_testimonial';
return $post_data;
}
require_once __DIR__ . '/includes/class-angies-list-widget.php';
if ( class_exists( 'mailchimpSF_Widget' ) ) {
require_once __DIR__ . '/includes/class-mailchimp-widget.php';
}
add_action( 'widgets_init', 'mullins_register_custom_widgets' );
function mullins_register_custom_widgets() {
register_widget( 'Angies_List_Badge' );
if ( class_exists( 'mailchimpSF_Widget' ) ) {
register_widget( 'custom_mailchimpSF_widget' );
}
}
/*
* Moved Google Analytics from Google Analytics+ Network Plugin
*/
add_action( 'wp_footer', 'mullins_add_google_analytics' );
function mullins_add_google_analytics() {
?>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-96122014-1', 'auto');
ga('send', 'pageview');
</script>
<?php
}
add_action( 'admin_init', 'add_mullins_button_tinymce_filters' );
function add_mullins_button_tinymce_filters() {
if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) ) {
add_filter( 'mce_buttons', function( $buttons ) {
array_push( $buttons, 'mullins_button_shortcode' );
return $buttons;
} );
// Attach script to the button rather than enqueueing it
add_filter( 'mce_external_plugins', function( $plugin_array ) {
$plugin_array['mullins_button_shortcode_script'] = get_stylesheet_directory_uri() . '/assets/js/admin/tinymce/button-shortcode.js';
return $plugin_array;
} );
}
}
add_shortcode( 'button', 'add_mullins_button_shortcode' );
function add_mullins_button_shortcode( $atts, $content ) {
$atts = shortcode_atts(
array( // a few default values
'url' => '#',
'color' => 'primary',
'style' => 'ghost',
'new_tab' => 'false'
),
$atts,
'button'
);
ob_start();
if ( ( strpos( $atts['url'], '#' ) !== 0 ) && ( strpos( $atts['url'], 'http' ) !== 0 ) && ( strpos( $atts['url'], '/' ) !== 0 ) ) :
$atts['url'] = '//' . $atts['url'];
endif;
?>
<a href="<?php echo $atts['url']; ?>" class="button <?php echo $atts['color'] . ' ' . $atts['style']; ?>" target="<?php echo ( strtolower( $atts['new_tab'] ) == 'true' ? '_blank' : '_self' ); ?>">
<?php echo $content; ?>
</a>
<?php
$output = ob_get_contents();
ob_end_clean();
return html_entity_decode( $output );
}
require_once __DIR__ . '/includes/theme-functions.php';