-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
702 lines (617 loc) · 19.3 KB
/
functions.php
File metadata and controls
702 lines (617 loc) · 19.3 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
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
<?php
require_once('functions/base.php'); # Base theme functions
require_once('custom-taxonomies.php'); # Where per theme taxonomies are defined
require_once('custom-post-types.php'); # Where per theme post types are defined
require_once('functions/admin.php'); # Admin/login functions
require_once('functions/config.php'); # Where per theme settings are registered
require_once('functions/meta.php'); # Hooks for header meta
require_once('shortcodes.php'); # Per theme shortcodes
// Add theme-specific functions here.
function get_header_menu() {
ob_start();
?>
<nav class="navbar navbar-ucf-gold site-navbar" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#header-menu">
<span class="navbar-toggle-text"><span class="sr-only">Toggle Navigation</span> Menu</span>
<span class="fa fa-bars" aria-hidden="true"></span>
</button>
<?php if ( is_home() || is_front_page() ): ?>
<h1 class="margin-xs-top-0">
<?php endif; ?>
<div class="navbar-brand-wrapper">
<a class="navbar-brand ucf-online" href="<?php echo bloginfo('url'); ?>"><?php echo bloginfo('name'); ?></a>
</div>
<?php if ( is_home() || is_front_page() ): ?>
</h1>
<?php endif; ?>
</div>
<div class="collapse navbar-collapse" id="header-menu">
<?php
wp_nav_menu( array(
'theme_location' => 'header-menu',
'depth' => 2,
'container' => false,
'menu_class' => 'nav navbar-nav header-menu-nav navbar-right',
'walker' => new Bootstrap_Walker_Nav_Menu()
) );
?>
</div>
</div>
</nav>
<?php
return ob_get_clean();
}
/**
* Returns the markup for the header with media
* @author RJ Bruneel
**/
function get_header_media($header) {
ob_start();
?>
<div class="media-header">
<div class="visible-xs visible-sm"><?php echo get_header_menu(); ?></div>
<div class="media-header-content" data-header-md="<?php echo $header->url; ?>" data-header-sm="<?php echo $header->mobile; ?>">
<div class="hidden-xs hidden-sm"><?php echo get_header_menu(); ?></div>
<div class="media-header-copy-wrapper">
<div class="container-wrapper">
<div class="container">
<div class="row">
<div class="col-md-8">
<?php if ( get_theme_mod_or_default( 'header_copy' ) ) :?>
<p class="media-header-copy child"><?php echo get_theme_mod_or_default( 'header_copy' ) ?></p>
<?php endif; // End header copy if ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
return ob_get_clean();
}
/**
* Updates the people_group custom taxonomies labels
**/
function people_group_labels( $labels ) {
$labels['singular'] = 'Committee';
$labels['plural'] = 'Committees';
$labels['slug'] = 'committees';
return $labels;
}
add_filter( 'ucf_people_group_labels', 'people_group_labels', 10, 1 );
function format_meeting_metadata( $metadata ) {
if ( isset( $metadata['ucf_meeting_date'] ) ) {
$date = new DateTime( $metadata['ucf_meeting_date'] );
$metadata['ucf_meeting_date'] = $date;
}
if ( ! empty( $metadata['ucf_meeting_start_time'] ) ) {
$date = new DateTime( $metadata['ucf_meeting_start_time'] );
$metadata['ucf_meeting_start_time'] = $date->format( 'g:i a' );
} else {
$metadata['ucf_meeting_start_time'] = 'TBD';
}
if ( ! empty ( $metadata['ucf_meeting_end_time'] ) ) {
$date = new DateTime( $metadata['ucf_meeting_end_time'] );
$metadata['ucf_meeting_end_time'] = $date->format( 'g:i a' );
} else {
$metadata['ucf_meeting_end_time'] = 'TBD';
}
return $metadata;
}
add_filter( 'ucf_meeting_format_metadata', 'format_meeting_metadata', 10, 1 );
function format_people_metadata( $metadata ) {
if ( isset( $metadata['_thumbnail_id'] ) ) {
$src = wp_get_attachment_image_src( $metadata['_thumbnail_id'], 'people-portrait' );
$metadata['thumbnail_url'] = $src[0];
}
return $metadata;
}
add_filter( 'ucf_people_format_metadata', 'format_people_metadata', 10, 1 );
function get_committee_url( $term ) {
return get_site_url( null, '/committees/' . $term->slug );
}
function get_board_members() {
$args = array(
'post_type' => 'person',
'posts_per_page' => -1,
'category_name' => 'trustee'
);
return get_posts( $args );
}
function get_board_members_as_options() {
$members = get_board_members();
$retval = array();
// Add an empty value as an option
$retval[''] = '';
foreach( $members as $member ) {
$retval[$member->ID] = $member->post_title;
}
return $retval;
}
function get_people_group_data( $tax_term ) {
$tax_term->members = get_posts(
array(
'post_type' => 'person',
'posts_per_page' => -1,
'category_name' => 'trustee',
'order' => 'ASC',
'orderby' => 'post_title',
'tax_query' => array(
array(
'taxonomy' => 'people_group',
'field' => 'slug',
'terms' => $tax_term->slug
)
)
)
);
$tax_term->staff = get_posts(
array(
'post_type' => 'person',
'posts_per_page' => -1,
'category_name' => 'committee-staff',
'order' => 'ASC',
'orderby' => 'post_title',
'tax_query' => array(
array(
'taxonomy' => 'people_group',
'field' => 'slug',
'terms' => $tax_term->slug
)
)
)
);
return $tax_term;
}
function get_custom_header_extended() {
$retval = get_custom_header();
$mobile = wp_get_attachment_image_src( $retval->attachment_id, 'header-mobile' );
$retval->mobile = $mobile[0];
return $retval;
}
/**
* Displays meetings
* Note: REQUIRES meetings to be pulled using the UCF_Meeting class
* @author Jim Barnes
* @param $meetings Array<WP_Post>
**/
function display_meetings( $meetings, $show_videos = true ) {
ob_start();
?>
<table class="table table-collapse table-striped">
<thead>
<tr>
<th>Date</th>
<th>Time</th>
<th>Location</th>
<th>Agenda</th>
<th>Minutes</th>
<?php if( $show_videos ) { ?>
<th>Video</th>
<?php } ?>
</tr>
</thead>
<tbody>
<?php foreach( $meetings as $post ) : ?>
<?php
$date = isset( $post->metadata['ucf_meeting_date'] ) ? $post->metadata['ucf_meeting_date']->format( 'M j, Y' ) : 'TBD';
$start = isset( $post->metadata['ucf_meeting_start_time'] ) ? $post->metadata['ucf_meeting_start_time'] : null;
$end = isset( $post->metadata['ucf_meeting_end_time'] ) ? $post->metadata['ucf_meeting_end_time'] : null;
$location = isset( $post->metadata['ucf_meeting_location'] ) ? $post->metadata['ucf_meeting_location'] : 'TBD';
?>
<tr class="mb-3">
<td data-title="Date"><?php echo $date; ?></td>
<td data-title="Time">
<?php if ( ( $start && ! $end ) || ( $start == $end ) ) : ?>
<time><?php echo $start; ?></time>
<?php elseif ( $start && $end ) : ?>
<time><?php echo $start; ?> - <?php echo $end; ?></time>
<?php else : ?>
TBD
<?php endif; ?>
</td>
<td data-title="Location"><?php echo ! empty( $location ) ? $location : '-'; ?>
</td>
<td data-title="Agenda">
<?php if ( isset( $post->metadata['ucf_meeting_agenda'] ) && ! empty( $post->metadata['ucf_meeting_agenda'] ) ) : ?>
<a class="document" href="<?php echo wp_get_attachment_url( $post->metadata['ucf_meeting_agenda'] ); ?>" target="_blank">Download</a>
<?php else: ?>
-
<?php endif; ?>
</td>
<td data-title="Minutes">
<?php if ( isset( $post->metadata['ucf_meeting_minutes'] ) && ! empty( $post->metadata['ucf_meeting_minutes'] ) ) : ?>
<a class="document" href="<?php echo wp_get_attachment_url( $post->metadata['ucf_meeting_minutes'] ); ?>" target="_blank">Download</a>
<?php else: ?>
-
<?php endif; ?>
</td>
<?php if( $show_videos ) : ?>
<td data-title="Video">
<?php if ( isset( $post->metadata['ucf_meeting_video'] ) && ! empty( $post->metadata['ucf_meeting_video'] ) ) : ?>
<a class="document" href="<?php echo $post->metadata['ucf_meeting_video']; ?>" target="_blank">Watch</a>
<?php else : ?>
-
<?php endif; ?>
</td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
return ob_get_clean();
}
function display_meetings_by_year( $years, $show_videos = true ) {
ob_start();
if ( ! $years ) :
?>
<p>No meetings to display.</p>
<?php
return ob_get_clean();
endif;
reset( $years );
$first_year = ( is_array( $years ) ) ? (int)key( $years ) : null;
?>
<div class="row">
<div class="col-md-8">
<h2>Meetings in <span id="meeting-year"><?php echo $first_year; ?></span></h2>
</div>
<div class="col-md-4">
<div class="meeting-select">
<label class="form-label" for="year_select">Select Year</label>
<select id="year_select" class="form-control dropdown">
<?php foreach ( array_keys( $years ) as $year ) :?>
<option value="<?php echo $year; ?>"<?php echo ( $first_year === $year ) ? ' selected' : ''; ?>><?php echo $year; ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
<div class="tab-content">
<?php foreach( $years as $year=>$meetings ) : ?>
<div role="tabpanel" class="tab-pane<?php echo ($first_year === $year) ? ' active' : ''; ?>" id="panel_<?php echo $year; ?>">
<?php echo display_meetings( $meetings, $show_videos ); ?>
</div>
<?php endforeach; ?>
</div>
<?php
return ob_get_clean();
}
function get_meetings_committee( $committee, $args=array() ) {
$args['meta_query'] = array(
array(
'key' => 'ucf_meeting_committee',
'value' => $committee->term_id
)
);
return UCF_Meeting::all( $args );
}
function get_meetings_by_year_committee( $committee, $args=array() ) {
$args['meta_key'] = 'ucf_meeting_date';
$args['orderby'] = 'meta_value';
$args['order'] = 'ASC';
$args['meta_query'] = array(
array(
'key' => 'ucf_meeting_committee',
'value' => $committee->term_id,
'compare' => 'LIKE'
),
array(
'relation' => 'OR',
array(
'key' => 'ucf_meeting_special_meeting',
'compare' => 'NOT EXISTS'
),
array(
'key' => 'ucf_meeting_special_meeting',
'value' => 1,
'compare' => '!='
)
)
);
return UCF_Meeting::group_by_year( $args );
}
function get_special_meetings_by_year_committee( $committee, $args=array() ) {
$args['meta_key'] = 'ucf_meeting_date';
$args['orderby'] = 'meta_value';
$args['order'] = 'ASC';
$args['meta_query'] = array(
array(
'key' => 'ucf_meeting_committee',
'value' => $committee->term_id,
'compare' => 'LIKE'
),
array(
array(
'key' => 'ucf_meeting_special_meeting',
'value' => 1,
'compare' => '='
)
)
);
return UCF_Meeting::group_by_year( $args );
}
function get_latest_meeting_minutes( $committee='None', $args=array() ) {
$retval = null;
$today = date('Y-m-d H:i:s');
$committee = term_exists( $committee, 'people_group' );
$args = array(
'posts_per_page' => 1,
'meta_key' => 'ucf_meeting_date',
'meta_type' => 'DATETIME',
'orderby' => 'meta_value',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'ucf_meeting_date',
'value' => $today,
'compare' => '<=',
'type' => 'DATETIME'
),
array(
'key' => 'ucf_meeting_committee',
'value' => $committee['term_id'],
'compare' => 'LIKE'
),
array(
'key' => 'ucf_meeting_minutes',
'compare' => 'EXISTS'
)
)
);
$meetings = UCF_Meeting::all( $args );
$meeting = ( count( $meetings ) ) ? $meetings[0] : null;
if ( $meeting ) {
$retval = array(
'name' => $meeting->metadata['ucf_meeting_date']->format( 'F j, Y' ),
'file' => wp_get_attachment_url( $meeting->metadata['ucf_meeting_minutes'] ),
'video' => isset( $meeting->metadata['ucf_meeting_video'] ) ? $meeting->metadata['ucf_meeting_video'] : null
);
}
return $retval;
}
function get_next_meeting( $committee='None', $args=array() ) {
$today = date('Y-m-d');
$committee = term_exists( $committee, 'people_group' );
$args = array(
'posts_per_page' => 1,
'meta_key' => 'ucf_meeting_date',
'meta_type' => 'DATE',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'ucf_meeting_date',
'value' => $today,
'compare' => '>=',
'type' => 'DATE'
),
array(
'key' => 'ucf_meeting_committee',
'value' => $committee['term_id'],
'compare' => '='
),
array(
'relation' => 'OR',
array(
'key' => 'ucf_meeting_special_meeting',
'compare' => 'NOT EXISTS'
),
array(
'key' => 'ucf_meeting_special_meeting',
'value' => '1',
'compare' => '!='
)
)
)
);
$meetings = UCF_Meeting::all( $args );
return ( count( $meetings ) ) ? $meetings[0] : null;
}
function get_next_special_meeting( $committee='None', $args=array() ) {
$today = date('Y-m-d');
$committee = term_exists( $committee, 'people_group' );
$args = array(
'posts_per_page' => 1,
'meta_key' => 'ucf_meeting_date',
'meta_type' => 'DATE',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'ucf_meeting_date',
'value' => $today,
'compare' => '>=',
'type' => 'DATE'
),
array(
'key' => 'ucf_meeting_committee',
'value' => $committee['term_id'],
'compare' => '='
),
array(
'key' => 'ucf_meeting_special_meeting',
'value' => '1',
'compare' => '='
)
)
);
$meetings = UCF_Meeting::all( $args );
$meeting = ( count( $meetings ) ) ? $meetings[0] : null;
return $meeting;
}
function get_person_markup( $person, $title=null ) {
$img = isset( $person->metadata['thumbnail_url'] ) ? $person->metadata['thumbnail_url'] : get_bloginfo('stylesheet_directory') . '/static/img/no-photo.jpg';
ob_start();
?>
<figure class="figure person-figure">
<a href="<?php echo get_permalink( $person->ID ); ?>">
<img clas="img-responsive" src="<?php echo $img; ?>" alt="<?php echo $person->post_title; ?>">
<figcaption class="figure-caption">
<?php echo $person->post_title; ?>
<?php if ( $title ) : ?>
<p class="text-muted"><?php echo $title; ?></p>
<?php endif; ?>
</figcaption>
</a>
</figure>
<?php
return ob_get_clean();
}
function display_committee_members( $people_group ) {
$people_group_id = $people_group->term_id;
$chair = get_field( 'people_group_chair', 'people_group_' . $people_group_id );
$vice_chair = get_field( 'people_group_vice_chair', 'people_group_' . $people_group_id );
$ex_officio = get_field( 'people_group_ex_officio', 'people_group_' . $people_group_id );
$exclude = array();
if ( $chair ) {
$exclude[] = $chair->ID;
}
if ( $vice_chair ) {
$exclude[] = $vice_chair->ID;
}
if ( $ex_officio ) {
$exclude[] = $ex_officio->ID;
}
// Remove the committee officers from the rest of the memebers.
$args = array(
'post_type' => 'person',
'posts_per_page' => -1,
'post__not_in' => $exclude,
'meta_key' => 'person_last_name',
'order' => 'ASC',
'orderby' => 'meta_value',
'category_name' => 'trustee',
'tax_query' => array(
array(
'taxonomy' => 'people_group',
'field' => 'id',
'terms' => $people_group_id
)
)
);
$people = get_posts( $args );
if ( count( $people ) < 1 ) return;
ob_start();
?>
<h2>Committee Members</h2>
<div class="row">
<?php if ( $chair ) : $chair = UCF_People_PostType::append_metadata( $chair ); ?>
<div class="col-md-4 col-sm-6">
<?php echo get_person_markup( $chair, 'Chair' ); ?>
</div>
<?php endif; ?>
<?php if ( $vice_chair ) : $vice_chair = UCF_People_PostType::append_metadata( $vice_chair ); ?>
<div class="col-md-4 col-sm-6">
<?php echo get_person_markup( $vice_chair, 'Vice Chair' ); ?>
</div>
<?php endif; ?>
<?php if ( $ex_officio ) : $ex_officio = UCF_People_PostType::append_metadata( $ex_officio ); ?>
<div class="col-md-4 col-sm-6">
<?php echo get_person_markup( $ex_officio, 'Ex Officio' ); ?>
</div>
<?php endif; ?>
<?php foreach( $people as $i=>$person ) : $person = UCF_People_PostType::append_metadata( $person ); ?>
<div class="col-md-4 col-sm-6">
<?php echo get_person_markup( $person ); ?>
</div>
<?php endforeach; ?>
</div>
<?php
return ob_get_clean();
}
function display_committee_staff( $people_group ) {
$people_group_id = $people_group->term_id;
$args = array(
'post_type' => 'person',
'posts_per_page' => -1,
'meta_key' => 'person_last_name',
'order' => 'ASC',
'orderby' => 'meta_value',
'category_name' => 'committee-staff',
'tax_query' => array(
array(
'taxonomy' => 'people_group',
'field' => 'id',
'terms' => $people_group_id
)
)
);
$people = get_posts( $args );
if ( count( $people ) < 1 ) return;
ob_start();
?>
<h2>Committee Staff</h2>
<?php
foreach( $people as $i=>$person ) : $person = UCF_People_PostType::append_metadata( $person ); ?>
<?php if ( $i % 3 === 0 ) : ?><div class="row"><?php endif; ?>
<div class="col-md-4 col-sm-6">
<?php echo get_person_markup( $person ); ?>
</div>
<?php if ( $i % 3 === 2 || $i == count( $people ) - 1 ) : ?></div><?php endif; ?>
<?php
endforeach;
return ob_get_clean();
}
/**
* Return object with homepage Call to Action details
*/
function get_homepage_cta_object() {
$retval = array();
$retval['show'] = get_theme_mod_or_default( 'show_call_to_action' );
$retval['theme'] = get_theme_mod_or_default( 'call_to_action_theme' );
$retval['title'] = get_theme_mod_or_default( 'call_to_action_title' );
$retval['content'] = get_theme_mod_or_default( 'call_to_action_content' );
$retval['btn_text'] = get_theme_mod_or_default( 'call_to_action_button_text' );
$retval['btn_url'] = get_theme_mod_or_default( 'call_to_action_button_url' );
$retval['has_content'] = ( ! empty( $retval['title'] ) || ! empty( $retval['content'] ) ) ? true : false;
$retval['has_button'] = ( ! empty( $retval['btn_text'] ) && ! empty( $retval['btn_url'] ) ) ? true : false;
return (object)$retval;
}
/**
* Add ID attribute to registered University Header script.
**/
function add_id_to_ucfhb($url) {
if ( (false !== strpos($url, 'bar/js/university-header.js')) || (false !== strpos($url, 'bar/js/university-header-full.js')) ) {
remove_filter('clean_url', 'add_id_to_ucfhb', 10, 3);
return "$url' id='ucfhb-script";
}
return $url;
}
add_filter('clean_url', 'add_id_to_ucfhb', 10, 3);
/**
* Function that adds the `special meeting` column
*/
function add_special_meeting_checkbox() {
global $post_type;
$checked = ( isset( $_GET['meeting_special'] ) && $_GET['meeting_special'] === 'on' ) ? true : false;
if ( $post_type === 'meeting' ) :
?>
<label><input type="checkbox" name="meeting_special" id="meeting_special"<?php echo ( $checked ) ? ' checked' : '';?>> Special Meetings</label>
<?php
endif;
}
add_action( 'restrict_manage_posts', 'add_special_meeting_checkbox', 10, 0 );
/**
* If the meeting_special query var is on, only list special meetings.
*/
function special_meeting_filter( $query ) {
global $pagenow, $post_type;
if ( $post_type === 'meeting' &&
is_admin() &&
$pagenow == 'edit.php' &&
isset( $_GET['meeting_special'] ) &&
$_GET['meeting_special'] === 'on' )
{
$query->query_vars['meta_key'] = 'ucf_meeting_special_meeting';
$query->query_vars['meta_value'] = '1';
$query->query_vars['meta_compare'] = '=';
return $query;
}
}
add_action( 'parse_query', 'special_meeting_filter' , 10, 1 );
?>