-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
526 lines (410 loc) · 12.3 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
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
<?php
/**
* Understrap functions and definitions
*
* @package understrap
*/
/**
* Initialize theme default settings
*/
require get_template_directory() . '/inc/theme-settings.php';
/**
* Theme setup and custom theme supports.
*/
require get_template_directory() . '/inc/setup.php';
/**
* Register widget area.
*/
require get_template_directory() . '/inc/widgets.php';
/**
* Enqueue scripts and styles.
*/
require get_template_directory() . '/inc/enqueue.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Custom pagination for this theme.
*/
require get_template_directory() . '/inc/pagination.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';
/**
* Custom Comments file.
*/
require get_template_directory() . '/inc/custom-comments.php';
/**
* Load Jetpack compatibility file.
*/
require get_template_directory() . '/inc/jetpack.php';
/**
* Load custom WordPress nav walker.
*/
require get_template_directory() . '/inc/class-wp-bootstrap-navwalker.php';
/**
* Load WooCommerce functions.
*/
require get_template_directory() . '/inc/woocommerce.php';
/**
* Load Editor functions.
*/
require get_template_directory() . '/inc/editor.php';
/**
* Minimal-ize the backend
*/
require get_template_directory() . '/inc/minimal.php';
/**
* Extra Tools text
*/
require get_template_directory() . '/inc/extras-text.php';
/**
* ACF Fields
*/
require get_template_directory() . '/inc/envs-acf.php';
//auto activate ACF PRO
if (!is_plugin_active( 'advanced-custom-fields-pro/acf.php')){
activate_plugin( 'advanced-custom-fields-pro/acf.php' );
}
//ADD FONTS and VCU Brand Bar
add_action('wp_enqueue_scripts', 'alt_lab_scripts');
function alt_lab_scripts() {
$query_args = array(
'family' => 'Roboto:300,400,700|Old+Standard+TT:400,700|Oswald:400,500,700',
'subset' => 'latin,latin-ext',
);
wp_enqueue_style ( 'google_fonts', add_query_arg( $query_args, "//fonts.googleapis.com/css" ), array(), null );
wp_enqueue_script( 'vcu_brand_bar', 'https:///branding.vcu.edu/bar/academic/latest.js', array(), '1.1.1', true );
wp_enqueue_script( 'alt_lab_js', get_template_directory_uri() . '/js/alt-lab.js', array(), '1.1.1', true );
}
//add footer widget areas
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Footer - far left',
'id' => 'footer-far-left',
'before_widget' => '<div class = "widgetizedArea">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
)
);
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Footer - medium left',
'id' => 'footer-med-left',
'before_widget' => '<div class = "widgetizedArea">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
)
);
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Footer - medium right',
'id' => 'footer-med-right',
'before_widget' => '<div class = "widgetizedArea">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
)
);
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Footer - far right',
'id' => 'footer-far-right',
'before_widget' => '<div class = "widgetizedArea">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
)
);
//set a path for IMGS
if( !defined('THEME_IMG_PATH')){
define( 'THEME_IMG_PATH', get_stylesheet_directory_uri() . '/imgs/' );
}
//ACF stuff
//Biography Page
/* Now this done on the options page
*/
//Options page
//CV Page
function acf_fetch_cv_interests(){
global $post;
$html = '';
$cv_interests = get_field('cv_interests');
if( $cv_interests) {
$html = $cv_interests;
return $html;
}
}
function acf_fetch_cv_skills(){
global $post;
$html = '';
$cv_skills = get_field('cv_skills');
if( $cv_skills) {
$html = $cv_skills;
return $html;
}
}
function acf_fetch_cv_academics(){
global $post;
$html = '';
$cv_academics = get_field('cv_academics');
if( $cv_academics) {
$html = $cv_academics;
return $html;
}
}
function acf_fetch_cv_work_history(){
global $post;
$html = '';
$rows = get_field('cv_work_history');
if($rows)
{
echo '<div class="cv-work-history col-md-12">';
foreach($rows as $row)
{
echo '<div class="work-title-stuff">' . $row['work_institution'] . ' - ' . $row['work_position_title'] . '</div> <div class="work-duites">'. $row['work_responsibilities'] . '</div> <div class="work-dates">' . $row['work_start_date'] . ' – ' . $row['work_end_date'] .'</div>';
}
echo '</div>';
}
}
function acf_fetch_cv_name(){
$html = '';
$cv_name = get_field('cv_name', 17);
if( $cv_name) {
$html = $cv_name;
return $html;
}
}
function acf_fetch_cv_skills_data(){
global $post;
$html = '';
$rows = get_field('cv_skills');
if($rows)
{
echo '<ul>';
foreach($rows as $row)
{
echo '<li>' . $row['type_of_skill'] . '</li>';
}
echo '</ul>';
}
}
function acf_fetch_cv_academic_major(){
global $post;
$html = '';
$rows = get_field('cv_academics');
if($rows)
{
echo '<div class="majors"><ul>';
foreach($rows as $row)
{
echo '<li>' . $row['majors'] . '</li>';
}
echo '</ul></div>';
}
}
function acf_fetch_cv_academic_minor(){
global $post;
$html = '';
$rows = get_field('cv_academics');
// print("<pre>".print_r($rows,true)."</pre>");
if($rows)
{
if($rows[0]['minors'])
{
echo '<div class="minors"><h4>Minor</h4><ul>';
}
foreach($rows as $row)
{
if($row['minors'])
{
echo '<li>' . $row['minors'] . '</li>';
}
}
echo '</ul></div>';
}
}
function acf_fetch_cv_coursework_data(){
global $post;
$html = '';
$rows = get_field('cv_coursework');
// print("<pre>".print_r($rows,true)."</pre>");
if($rows)
{
echo '<div class="cv-courseinfo col-md-12">';
foreach($rows as $row)
{
echo '<div class="row"><div class="course-number col-md-3">' . $row['course_number'] . '</div> <div class="course-title col-md-3">'. $row['course_title'] . '</div> <div class="course-semester col-md-3">'. $row['course_semester'] . '</div> <div class="course-year col-md-3">'. $row['course_year'] . '</div></div>';
}
echo '</div>';
}
}
function acf_fetch_cv_uploader(){
global $post;
$html = '';
$exists = get_field('cv_uploader');
// print("<pre>".print_r($exists,true)."</pre>");
if($exists) {
return '<div class="card"><a href="' . $exists . '">Download my full CV <i class="fa fa-arrow-down" aria-hidden="true"></i></a></div>';
}
}
function acf_fetch_cv_graduation(){
$html = '';
$graduation_date = get_field('expected_graduation_date');
if( $graduation_date) {
$html = $graduation_date;
return $html;
}
}
function acf_fetch_capstone_main(){
$html = '';
$cap_content = get_field('cap_content');
if( $cap_content) {
$html = $cap_content;
return $html;
}
}
function acf_fetch_capstone_notes(){
$html = '';
$cap_notes_aside = get_field('cap_notes_aside');
if( $cap_notes_aside) {
$html = $cap_notes_aside;
return $html;
}
}
function bannerMaker(){
global $post;
if ( get_the_post_thumbnail_url( $post->ID ) ) {
//$thumbnail_id = get_post_thumbnail_id( $post->ID );
$thumb_url = get_the_post_thumbnail_url($post->ID);
//$alt = get_post_meta($thumbnail_id, '_wp_attachment_image_alt', true);
return '<div class="jumbotron custom-header-img" style="background-image:url('. $thumb_url .')"></div>';
}
}
function menu_maker(){
$html = '';
$base_url = get_site_url();
if(get_field('menu_cats', 'option')){
$cats = get_field('menu_cats', 'option');
foreach ($cats as $cat) {
$html .= '<li><a href="' . $base_url . '/category/' . $cat->slug .'">' . $cat->name . '</a></li>';
}
return $html;
} else {
return popular_categories();//if not set via ACF then show three most popular
}
}
function popular_categories(){
$html = '';
$base_url = get_site_url();
$cats = get_categories( array(
'orderby' => 'count',
'order' => 'DESC',
'hide_empty' => true,
) );
foreach ($cats as $key => $cat) {
if ( $key < 3){
$html .= '<li><a href="' . $base_url . '/category/' . $cat->slug .'">' . $cat->name . '</a></li>';
}
}
return $html;
}
//MAKE SURE ACF IS ON
//CUSTOMIZER PAGE
if (is_plugin_active( 'advanced-custom-fields-pro/acf.php')) {
$args = array(
'page_title'=>'Portfolio Options',
'menu_title'=>'Portfolio Options',
'menu_slug'=>'portfolio-options',
'redirect'=>true,
'position' => '0.001',
'capability' => 'edit_posts',
'icon_url' => 'dashicons-admin-site'
);
acf_add_options_page( $args );
}
//ACF JSON SAVER
// add_filter('acf/settings/save_json', 'envs_acf_json_save_point');
// function envs_acf_json_save_point( $path ) {
// // update path
// $path = get_stylesheet_directory() . '/acf-json';
// // return
// return $path;
// }
add_filter('acf/settings/load_json', 'envs_acf_json_load_point');
function envs_acf_json_load_point( $paths ) {
// remove original path (optional)
unset($paths[0]);
// append path
$path = get_stylesheet_directory() . '/acf-json';
// return
return $paths;
}
//MAKE PAGES IF DON'T EXIST
function make_all_the_pages(){
$owner_email = get_bloginfo('admin_email');
$owner_id = get_user_by( 'email', $owner_email )->ID;
$base_pages = ['Biography','Capstone','CV', 'Posts'];
foreach ($base_pages as $page) {
if(get_page_by_path( strtolower($page) ) === NULL) {
$my_post = array(
'post_author' => $owner_id,
'post_title' => $page,
'post_content' => '',
'post_status' => 'publish',
'post_type'=> 'page',
//'post_template' => 'page-templates/fullwidthpage-'.strtolower($page).'.php',//doesn't seem to work
);
// Insert the post into the database and set the Frontpage and Posts page
$post_id = wp_insert_post( $my_post );
if($page != 'Posts'){
update_post_meta( $post_id, '_wp_page_template', 'page-templates/fullwidthpage-'.strtolower($page).'.php' );
if($page === 'Biography') {
// var_dump() //Wrap the line below inside the ()
update_option( 'page_on_front', $post_id );
update_option( 'show_on_front', 'page' );
}
} else {
update_post_meta( $post_id, '_wp_page_template', 'page-templates/fullwidthpage.php' );
update_option( 'page_for_posts', $post_id );
}
}
}
}
add_action("after_switch_theme", "make_all_the_pages");
// //JSON ADDITIONS
function envs_portfolio_json($response){
$data = $response->data;
$cv_id = get_page_by_path('cv');//get cv page ID
$academic = get_field( 'cv_academics', $cv_id);
$major = envs_json_repeater_tamer($academic, 'majors');
$minor = envs_json_repeater_tamer($academic, 'minors');
$data['envs']['student_name'] = get_field('name', 'option');
$data['envs']['graduation_date'] = get_field( 'expected_graduation_date', $cv_id);
$data['envs']['majors'] = $major;
$data['envs']['minors'] = $minor;
$data['envs']['bio_pic'] = get_field('profile_picture', 'option')['sizes'];
$data['envs']['proj_categories'] = get_field('menu_cats', 'option');
$response->set_data($data);
return $response;
}
add_filter('rest_index', 'envs_portfolio_json');
function envs_json_repeater_tamer($rows, $sub_field){
$data = [];
if($rows){
foreach($rows as $row){
if ($row[$sub_field]){
array_push($data,$row[$sub_field]);
}
}
return $data;
}
}