forked from wpcampus/wpcampus-wp-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
848 lines (660 loc) · 23.1 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
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
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
<?php
$includes_path = STYLESHEETPATH . '/includes/';
// Include filters.
require_once( $includes_path . 'filters.php' );
// Include data functionality.
require_once( $includes_path . 'data.php' );
// Include university functionality.
require_once( $includes_path . 'universities.php' );
// Include shortcodes.
require_once( $includes_path . 'shortcodes.php' );
/**
* Decide which main callout to print.
*/
function wpcampus_print_main_callout() {
wpcampus_print_2017_callout();
}
/**
* Print the 2017 callout.
*/
function wpcampus_print_2017_callout() {
?>
<div class="panel" style="text-align:center;">
<h2>WPCampus 2017 Conference on July 14-15</h2>
<p><a href="https://2017.wpcampus.org/" style="color:inherit;">WPCampus 2017</a> will take place July 14-15 on the campus of Canisius College in Buffalo, New York. <strong>Ticket sales have closed</strong> but, if you can't join us in person, all sessions will be live-streamed and made available online after the event. Gather with other WordPress users on your campus and create your own WPCampus experience!</p>
<a class="button expand" href="https://2017.wpcampus.org/">Visit the WPCampus 2017 website</a>
</div>
<?php
}
/**
* Print the ed survey callout.
*/
function wpcampus_print_ed_survey_callout() {
?>
<div class="panel" style="text-align:center;">
<h2>The "WordPress in Education" Survey</h2>
<p>After an overwhelming response to our 2016 survey, WPCampus is back this year to dig a little deeper on key topics that schools and campuses care about most when it comes to WordPress and website development. We’d love to include your feedback in our results this year. The larger the data set, the more we all benefit. <strong>The survey will close on June 23rd, 2017.</strong></p>
<a class="button expand" href="https://2017.wpcampus.org/announcements/wordpress-in-education-survey/">Take the "WordPress in Education" survey</a>
</div>
<?php
}
/**
* Setup the API.
*/
function wpcampus_setup_api() {
global $wpcampus_api_data;
// Load the class.
require_once( STYLESHEETPATH . '/includes/class-api-data.php' );
// Initialize our class.
$wpcampus_api_data = new WPCampus_API_Data();
// Register our routes.
$wpcampus_api_data->register_routes();
}
add_action( 'rest_api_init', 'wpcampus_setup_api' );
/**
* Setup the theme:
*
* - Load the textdomain.
* - Register the navigation menus.
*/
function wpcampus_setup_theme() {
// Load the textdomain.
load_theme_textdomain( 'wpcampus', get_stylesheet_directory() . '/languages' );
// Register the nav menus.
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'wpcampus' ),
'footer' => __( 'Footer Menu', 'wpcampus' ),
));
// Add HTML5 support.
add_theme_support( 'html5', array(
'comment-form',
'comment-list',
'gallery',
'caption',
));
}
add_action( 'after_setup_theme', 'wpcampus_setup_theme' );
/**
* Load files depending on page,
* After WP object is set up.
*/
function wpcampus_load_files() {
// Include comments.
if ( is_singular() ) {
require_once( STYLESHEETPATH . '/includes/comments.php' );
}
}
add_action( 'wp', 'wpcampus_load_files' );
/**
* Register the category taxonomy
* to the podcast.
*/
function wpcampus_add_category_to_podcast() {
register_taxonomy_for_object_type( 'category', 'podcast' );
}
add_action( 'wp_loaded', 'wpcampus_add_category_to_podcast' );
/**
* Setup styles and scripts.
*/
function wpcampus_enqueue_styles_scripts() {
$wpcampus_version = '0.74';
// Get the directory.
$wpcampus_dir = trailingslashit( get_stylesheet_directory_uri() );
// Load fonts.
wp_enqueue_style( 'wpcampus-fonts', 'https://fonts.googleapis.com/css?family=Open+Sans:600,400,300' );
// Enqueue the base styles.
wp_enqueue_style( 'wpcampus', $wpcampus_dir . 'assets/css/styles.min.css', array( 'wpcampus-fonts' ), $wpcampus_version, 'all' );
// Enqueue modernizr - goes in header.
wp_enqueue_script( 'modernizr', 'https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js' );
// Enqueue the main script file - goes in footer.
wp_enqueue_script( 'wpcampus', $wpcampus_dir . 'assets/js/wpcampus.min.js', array( 'jquery', 'modernizr' ), $wpcampus_version, true );
// Enqueue the application styles.
if ( is_page( 'apply-to-host' ) ) {
wp_enqueue_style( 'wpcampus-host-application', $wpcampus_dir . 'assets/css/application.css', array(), $wpcampus_version, 'all' );
}
// Enqueue the data scripts.
if ( is_page( 'data' ) ) {
// Register Google Charts script.
wp_register_script( 'google-charts', 'https://www.google.com/jsapi', array( 'jquery' ) );
// Register Chartist script.
wp_register_script( 'chartist', 'https://cdn.jsdelivr.net/chartist.js/latest/chartist.min.js' );
// Enqueue Chartist styles.
wp_enqueue_style( 'chartist', $wpcampus_dir . 'assets/css/chartist.min.css', array(), $wpcampus_version, 'all' );
/*
* Enqueue our data script.
*
* Set a var so that we can automatically
* use the non-minified script on staging,
* but the minified script on prod.
*/
$min = stristr( $_SERVER['HTTP_HOST'], '.staging' ) ? '' : '.min';
wp_enqueue_script( 'wpcampus-data', $wpcampus_dir . 'assets/js/wpcampus-data' . $min . '.js', array( 'jquery', 'google-charts', 'chartist' ), $wpcampus_version, false );
}
// Enqueue the events styles.
if ( is_post_type_archive( 'tribe_events' ) || is_singular( 'tribe_events' ) ) {
wp_enqueue_style( 'wpcampus-events', $wpcampus_dir . 'assets/css/tribe-events.min.css', array( 'wpcampus' ), $wpcampus_version, 'all' );
}
}
add_action( 'wp_enqueue_scripts', 'wpcampus_enqueue_styles_scripts' );
/**
* Add the AddThis script to the footer.
*/
function wpcampus_add_addthis() {
?>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-55c7ed90ac8a8479" async="async"></script>
<?php
}
add_action( 'wp_footer', 'wpcampus_add_addthis' );
/**
* Load favicons.
*/
function wpcampus_add_favicons() {
// Set the images folder.
$favicons_folder = get_stylesheet_directory_uri() . '/assets/images/favicons/';
// Print the default icons.
?>
<link rel="shortcut icon" href="<?php echo $favicons_folder; ?>wpcampus-favicon-60.png"/>
<link rel="apple-touch-icon" href="<?php echo $favicons_folder; ?>wpcampus-favicon-60.png"/><?php
// Set the image sizes.
$image_sizes = array( 57, 72, 76, 114, 120, 144, 152 );
foreach ( $image_sizes as $size ) :
?>
<link rel="apple-touch-icon" sizes="<?php echo "{$size}x{$size}"; ?>" href="<?php echo $favicons_folder; ?>wpcampus-favicon-<?php echo $size; ?>.png"/>
<?php
endforeach;
}
add_action( 'wp_head', 'wpcampus_add_favicons' );
add_action( 'admin_head', 'wpcampus_add_favicons' );
add_action( 'login_head', 'wpcampus_add_favicons' );
/**
* Get the post type archive title.
*/
function wpcampus_get_post_type_archive_title( $post_type = '' ) {
// Make sure we have a post type.
if ( ! $post_type ) {
$post_type = get_query_var( 'post_type' );
}
// Get post type archive title.
if ( $post_type ) {
// Make sure its not an array.
if ( is_array( $post_type ) ) {
$post_type = reset( $post_type );
}
// Get the post type data.
if ( $post_type_obj = get_post_type_object( $post_type ) ) {
// Get the title.
$title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type );
// Return the title.
return apply_filters( 'wpcampus_post_type_archive_title', $title, $post_type );
}
}
return null;
}
/**
* Print the articles.
*
* @param array $args
*/
function wpcampus_print_articles( $args = array(), $query = null ) {
global $wp_query;
// Use default query if none was passed.
if ( ! $query || ! is_a( $query, 'WP_Query' ) ) {
$query = $wp_query;
}
do_action( 'wpcampus_before_articles' );
?>
<div class="wpcampus-articles">
<?php
while ( $query->have_posts() ) :
$query->the_post();
wpcampus_print_article( $args );
endwhile;
?>
</div><!--.wpcampus-articles-->
<?php
do_action( 'wpcampus_after_articles' );
}
/**
* Print the article.
*
* @param array $args
*/
function wpcampus_print_article( $args = array() ) {
// Define the defaults.
$defaults = array(
'header' => false,
'link_to_post' => true,
'print_content' => true,
);
// Merge incoming with defaults.
$args = wp_parse_args( $args, $defaults );
// Get post information.
$post_id = get_the_ID();
$post_permalink = get_permalink( $post_id );
$post_thumbnail_id = get_post_thumbnail_id( $post_id );
do_action( 'wpcampus_before_article' );
?>
<article id="post-<?php echo $post_id; ?>" <?php post_class(); ?>>
<?php
// Should we add a header?
if ( ! empty( $args['header'] ) ) :
do_action( 'wpcampus_before_article_header' );
?>
<<?php echo $args['header']; ?> class="article-title"><?php
if ( $args['link_to_post'] ) {
?><a href="<?php echo $post_permalink; ?>"><?php the_title(); ?></a><?php
} else {
the_title();
}
?></<?php echo $args['header']; ?>>
<?php
do_action( 'wpcampus_after_article_header' );
endif;
// Get the featured image.
$featured_image = $post_thumbnail_id > 0 ? wp_get_attachment_image_src( $post_thumbnail_id, 'thumbnail' ) : '';
if ( ! empty( $featured_image[0] ) ) :
do_action( 'wpcampus_before_article_thumbnail' );
?>
<img class="article-thumbnail" src="<?php echo $featured_image[0]; ?>" />
<?php
do_action( 'wpcampus_after_article_thumbnail' );
endif;
if ( $args['print_content'] ) {
do_action( 'wpcampus_before_article_content' );
the_content();
do_action( 'wpcampus_after_article_content' );
} else {
do_action( 'wpcampus_before_article_excerpt' );
the_excerpt();
do_action( 'wpcampus_after_article_excerpt' );
}
?>
</article>
<?php
do_action( 'wpcampus_after_article' );
}
/**
* Print article meta.
*/
function wpcampus_print_article_meta() {
// Get categories.
$categories = get_the_category_list( ', ' );
// Get permalink.
$comments_link = get_permalink() . '#comments';
?>
<div class="article-meta-wrapper">
<span class="article-meta article-time"><?php wpcampus_print_article_time(); ?></span>
<?php
// Print authors.
$authors = wpcampus_get_article_authors();
if ( ! empty( $authors ) ) :
?><span class="article-meta article-author"><?php echo $authors; ?></span><?php
endif;
// If comments are closed and there are comments, let's leave a little note, shall we?
if ( post_type_supports( get_post_type(), 'comments' ) ) :
// Get # of comments.
$comments_number = get_comments_number();
// Build comment classes.
$comment_classes = array( 'article-meta', 'article-comments' );
if ( $comments_number ) {
$comment_classes[] = 'has-comments';
}
?>
<span class="<?php echo implode( ' ', $comment_classes ); ?>"><a href="<?php echo $comments_link; ?>"><?php
if ( ! $comments_number ) {
echo __( 'Leave a comment', 'wpcampus' );
} else {
printf( _n( '%s comment', '%s comments', $comments_number, 'wpcampus' ), $comments_number );
}
?></a></span>
<?php
endif;
if ( $categories ) :
?>
<span class="article-meta article-categories"><?php echo $categories; ?></span>
<?php
endif;
?>
</div>
<?php
}
/**
* Get the article author(s).
*/
function wpcampus_get_article_authors( $post_id = 0 ) {
if ( function_exists( 'my_multi_author' ) && method_exists( my_multi_author(), 'get_the_authors_list' ) ) {
return my_multi_author()->get_the_authors_list( $post_id );
}
return '<a href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . get_the_author() . '</a>';
}
/**
* Print the article time.
*/
function wpcampus_print_article_time() {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
}
echo sprintf( $time_string,
get_the_date( DATE_W3C ),
get_the_date()
);
}
/**
* Print breadcrumbs.
*/
function wpcampus_print_breadcrumbs() {
echo wpcampus_get_breadcrumbs_html();
}
/**
* Get breadcrumbs list.
*/
function wpcampus_get_breadcrumbs() {
// Build array of breadcrumbs.
$breadcrumbs = array();
// Not for front page or 404.
if ( is_front_page() || is_404() ) {
return false;
}
// Get post type.
$post_type = get_query_var( 'post_type' );
// Make sure its not an array.
if ( is_array( $post_type ) ) {
$post_type = reset( $post_type );
}
// Add home.
$breadcrumbs[] = array(
'url' => get_bloginfo( 'url' ),
'label' => 'Home',
);
// Add archive(s).
if ( is_archive() ) {
// Add the archive breadcrumb.
if ( is_post_type_archive() ) {
// Get the info.
$post_type_archive_link = get_post_type_archive_link( $post_type );
$post_type_archive_title = wpcampus_get_post_type_archive_title( $post_type );
// Add the breadcrumb.
if ( $post_type_archive_link && $post_type_archive_title ) {
$breadcrumbs[] = array( 'url' => $post_type_archive_link, 'label' => $post_type_archive_title );
}
} elseif ( is_author() ) {
// Add crumb to contributors page.
$breadcrumbs[] = array(
'url' => '/contributors/',
'label' => __( 'Contributors', 'wpcampus' ),
);
// Add crumb to current contributor's page.
$author = get_queried_object();
if ( ! empty( $author->ID ) ) {
$breadcrumbs['current'] = array(
'url' => get_author_posts_url( $author->ID ),
'label' => get_the_author_meta( 'display_name', $author->ID ),
);
}
} else {
$breadcrumbs[] = array(
'url' => '/blog/',
'label' => __( 'Blog', 'wpcampus' ),
);
}
} else {
/*
* Add links to main blog
* or to post type archive.
*/
if ( is_singular( 'post' ) ) {
$breadcrumbs[] = array(
'url' => '/blog/',
'label' => __( 'Blog', 'wpcampus' ),
);
} elseif ( is_singular() ) {
// Get the information.
$post_type_archive_link = get_post_type_archive_link( $post_type );
$post_type_archive_title = wpcampus_get_post_type_archive_title( $post_type );
if ( $post_type_archive_link ) {
$breadcrumbs[] = array(
'url' => $post_type_archive_link,
'label' => $post_type_archive_title,
);
}
}
// Print info for the current post.
$post = get_queried_object();
if ( $post && is_a( $post, 'WP_Post' ) ) {
// Get ancestors.
$post_ancestors = isset( $post ) ? get_post_ancestors( $post->ID ) : array();
// Add the ancestors.
foreach ( $post_ancestors as $post_ancestor_id ) {
// Add ancestor.
$breadcrumbs[] = array(
'ID' => $post_ancestor_id,
'url' => get_permalink( $post_ancestor_id ),
'label' => get_the_title( $post_ancestor_id ),
);
}
// Add current page - if not singular post.
if ( isset( $post ) && ! is_singular( array( 'post', 'podcast', 'video' ) ) ) {
$breadcrumbs['current'] = array(
'ID' => $post->ID,
'url' => get_permalink( $post ),
'label' => get_the_title( $post->ID ),
);
}
}
}
return $breadcrumbs;
}
/**
* Get breadcrumbs markup.
*/
function wpcampus_get_breadcrumbs_html() {
// Get the breadcrumbs.
$breadcrumbs = wpcampus_get_breadcrumbs();
// Make sure we have crumbs.
if ( empty( $breadcrumbs ) ) {
return '';
}
// Build breadcrumbs HTML.
$breadcrumbs_html = null;
foreach ( $breadcrumbs as $crumb_key => $crumb ) {
// Make sure we have what we need.
if ( empty( $crumb['label'] ) ) {
continue;
}
// If no string crumb key, set as ancestor.
if ( ! $crumb_key || is_numeric( $crumb_key ) ) {
$crumb_key = 'ancestor';
}
// Setup classes.
$crumb_classes = array( $crumb_key );
// Add if current.
if ( isset( $crumb['current'] ) && $crumb['current'] ) {
$crumb_classes[] = 'current';
}
$breadcrumbs_html .= '<li role="menuitem"' . ( ! empty( $crumb_classes ) ? ' class="' . implode( ' ', $crumb_classes ) . '"' : null ) . '>';
// Add URL and label.
if ( ! empty( $crumb['url'] ) ) {
$breadcrumbs_html .= '<a href="' . $crumb['url'] . '"' . ( ! empty( $crumb['title'] ) ? ' title="' . $crumb['title'] . '"' : null ) . '>' . $crumb['label'] . '</a>';
} else {
$breadcrumbs_html .= $crumb['label'];
}
$breadcrumbs_html .= '</li>';
}
// Wrap them in nav.
if ( ! empty( $breadcrumbs_html ) ) {
$breadcrumbs_html = '<div class="breadcrumbs-wrapper">
<nav class="breadcrumbs" role="menubar" aria-label="breadcrumbs">' . $breadcrumbs_html . '</nav>
</div>';
}
return $breadcrumbs_html;
}
/**
* Prints list of social media icons.
*
* @param $color - string - color of icon, black is default.
*/
function wpcampus_print_social_media_icons( $color = 'black' ) {
// Get the theme directory.
$theme_dir = trailingslashit( get_template_directory_uri() );
$images_dir = "{$theme_dir}assets/images/";
// If color, prefix with dash.
if ( $color ) {
$color = "-{$color}";
}
?>
<ul class="social-media-icons">
<li><a class="slack" href="https://wpcampus.org/get-involved/"><img src="<?php echo $images_dir; ?>slack<?php echo $color; ?>.svg" alt="<?php printf( __( 'Join %1$s on %2$s', 'wpcampus' ), 'WPCampus', 'Slack' ); ?>" /></a></li>
<li><a class="twitter" href="https://twitter.com/wpcampusorg"><img src="<?php echo $images_dir; ?>twitter<?php echo $color; ?>.svg" alt="<?php printf( __( 'Follow %1$s on %2$s', 'wpcampus' ), 'WPCampus', 'Twitter' ); ?>" /></a></li>
<li><a class="facebook" href="https://www.facebook.com/wpcampus"><img src="<?php echo $images_dir; ?>facebook<?php echo $color; ?>.svg" alt="<?php printf( __( 'Follow %1$s on %2$s', 'wpcampus' ), 'WPCampus', 'Facebook' ); ?>" /></a></li>
<li><a class="youtube" href="https://www.youtube.com/wpcampusorg"><img src="<?php echo $images_dir; ?>youtube<?php echo $color; ?>.svg" alt="<?php printf( __( 'Follow %1$s on %2$s', 'wpcampus' ), 'WPCampus', 'YouTube' ); ?>" /></a></li>
<li><a class="github" href="https://github.com/wpcampus/"><img src="<?php echo $images_dir; ?>github<?php echo $color; ?>.svg" alt="<?php printf( __( 'Follow %1$s on %2$s', 'wpcampus' ), 'WPCampus', 'GitHub' ); ?>" /></a></li>
</ul>
<?php
}
/**
* Print the 404 page.
*/
function wpcampus_print_404() {
do_action( 'wpcampus_before_404' );
?>
<p>Uh-oh. This page seems to be missing. Please check to make sure the link you requested was entered correctly.</p>
<p>If you can't find what you're looking for in the menu, please <a href="/contact/">reach out to us</a> and let us know. We'd be happy to help.</p>
<?php
do_action( 'wpcampus_after_404' );
}
/**
* Print a specific contributor's profile.
*/
function wpcampus_print_contributor( $user_id = 0 ) {
// Make sure we have a user ID.
if ( ! $user_id ) {
$user_id = get_the_author_meta( 'ID' );
}
// Get display name
$author_name = get_the_author_meta( 'display_name', $user_id );
// Get thumbnail.
$author_thumbnail = get_avatar_url( $user_id, array(
'size' => '200',
));
// Get other fields.
$author_desc = get_the_author_meta( 'description', $user_id );
$author_website = get_the_author_meta( 'url', $user_id );
$author_twitter = get_the_author_meta( 'twitter', $user_id );
$author_company = get_the_author_meta( 'company', $user_id );
$author_company_pos = get_the_author_meta( 'company_position', $user_id );
?>
<div class="wpcampus-contributor<?php echo $author_thumbnail ? ' has-thumbnail' : ''; ?>">
<div class="inside">
<h2 class="contributor-name"><?php
if ( ! is_author() ) :
?>
<a href="<?php echo esc_url( get_author_posts_url( $user_id ) ); ?>"><?php echo $author_name; ?></a>
<?php
else :
echo $author_name;
endif;
?></h2>
<?php
// Display author thumbnail.
if ( ! empty( $author_thumbnail ) ) :
?>
<img class="author-thumbnail" src="<?php echo $author_thumbnail; ?>" />
<?php
endif;
// Build meta.
$contributor_meta = array();
// Add company.
if ( $author_company ) {
if ( $author_company_pos ) {
$contributor_meta['company'] = "{$author_company_pos}, {$author_company}";
} else {
$contributor_meta['company'] = $author_company;
}
} else if ( $author_company_pos ) {
$contributor_meta['company'] = $author_company_pos;
}
// Add Twitter.
if ( $author_twitter ) {
// Sanitize Twitter handle.
$author_twitter_handle = preg_replace( '/[^a-z0-9]/i', '', $author_twitter );
$contributor_meta['twitter'] = '<a href="' . esc_url( 'https://twitter.com/' . $author_twitter_handle ) . '">@' . $author_twitter_handle . '</a>';
}
// Add website.
if ( $author_website ) {
$contributor_meta['website'] = '<a href="' . esc_url( $author_website ) . '">' . $author_website . '</a>';
}
// Display meta
if ( ! empty( $contributor_meta ) ) :
?>
<div class="contributor-meta-wrapper">
<?php
foreach ( $contributor_meta as $meta ) :
?><span class="contributor-meta"><?php echo $meta; ?></span><?php
endforeach;
?>
</div>
<?php
endif;
// Display author bio.
if ( ! empty( $author_desc ) ) :
?>
<p class="contributor-desc"><?php echo $author_desc; ?></p>
<?php
endif;
?>
</div>
</div>
<?php
}
/**
* Print podcast promo/links.
*/
function wpcampus_print_podcast_promo() {
?>
<div class="wpcampus-podcast-promo">
<div class="panel">
<p>The WPCampus Podcast is a monthly show where members of the community come together to discuss relevant topics, unique ways that WordPress is being used in higher education, share tutorials and walkthroughs, and more. <strong><em>If you'd like to be a guest on the show, or have a topic you'd like us to discuss, please <a href="/contact/">let us know</a>.</em></strong></p>
</div>
<div class="panel dark-blue center" style="margin-bottom:20px;">New episodes of <a href="/podcast/">The WPCampus Podcast</a> are released every month.</div>
<div style="text-align: center">
<ul class="button-group">
<li><a href="https://itun.es/i6YF9HH" class="button">Listen on iTunes</a></li>
<li><a href="https://play.google.com/music/listen?u=0#/ps/Imipnlywvba5v3lqu7y646dg6z4" class="button">Listen on Google Play</a></li>
<li><a href="/feed/podcast" class="button">View RSS feed</a></li>
</ul>
</div>
</div>
<?php
}
/**
* Print user registration promo.
*/
function wpcampus_print_user_reg_promo() {
?>
<div class="panel blue center" style="margin:2em 0 3em 0;">
<p><strong><?php printf( __( 'Want to become a %s contributor?', 'wpcampus' ), 'WPCampus' ); ?></strong><br/><?php printf( __( 'Great! We\'d love to have your voice and insight. %1$sRegister as a %2$s user%3$s to get started.', 'wpcampus' ), '<a href="/user-registration/">', 'WPCampus', '</a>' ); ?></p>
</div>
<?php
}
/**
* Is used in certain places to prepend
* the post title with post type.
*
* @param $post_title - the post title we're prepending.
* @param $post_id - the post ID.
* @return string - the new post title.
*/
function wpcampus_prepend_post_title( $post_title, $post_id ) {
// Get the post type.
$post_type = get_post_type( $post_id );
switch( $post_type ) {
case 'podcast':
return '<span class="fade type">' . __( 'Podcast:', 'wpcampus' ) . '</span> ' . $post_title;
case 'post':
return '<span class="fade type">' . __( 'Blog:', 'wpcampus' ) . '</span> ' . $post_title;
case 'video':
return '<span class="fade type">' . __( 'Video:', 'wpcampus' ) . '</span> ' . $post_title;
}
return $post_title;
}