-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsermons.php
1061 lines (933 loc) · 38.6 KB
/
sermons.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
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Plugin Name: Sermon Manager for WordPress
Plugin URI: http://www.wpforchurch.com/products/sermon-manager-for-wordpress/
Description: Add audio and video sermons, manage speakers, series, and more. Visit <a href="http://wpforchurch.com" target="_blank">Wordpress for Church</a> for tutorials and support.
Version: 1.5.6
Author: Jack Lamb
Author URI: http://www.wpforchurch.com/
License: GPL2
*/
// Security check to see if someone is accessing this file directly
if(preg_match("#^sermons.php#", basename($_SERVER['PHP_SELF']))) exit();
// Translations
function wpfc_sermon_translations() {
load_plugin_textdomain( 'sermon-manager', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
add_action( 'init', 'wpfc_sermon_translations' );
// Add Images for Custom Taxonomies
require_once plugin_dir_path( __FILE__ ) . 'includes/taxonomy-images/taxonomy-images.php';
// Add Options Page
require_once plugin_dir_path( __FILE__ ) . '/includes/options.php';
// Add Entry Views Tracking
require_once plugin_dir_path( __FILE__ ) . '/includes/entry-views.php';
// Define the plugin URL
define('WPFC_SERMONS', plugins_url() . '/sermon-manager-for-wordpress');
// Create sermon Custom Post Type
add_action('init', 'create_wpfc_sermon_types');
function create_wpfc_sermon_types()
{
$plugin = WPFC_SERMONS;
$labels = array(
'name' => __( 'Sermons', 'sermon-manager'),
'singular_name' => __( 'Sermon', 'sermon-manager'),
'add_new' => __( 'Add New', 'sermon-manager'),
'add_new_item' => __('Add New Sermon', 'sermon-manager'),
'edit_item' => __('Edit Sermon', 'sermon-manager'),
'new_item' => __('New Sermon', 'sermon-manager'),
'view_item' => __('View Sermon', 'sermon-manager'),
'search_items' => __('Search Sermons', 'sermon-manager'),
'not_found' => __('No sermons found', 'sermon-manager'),
'not_found_in_trash' => __('No sermons found in Trash', 'sermon-manager'),
'parent_item_colon' => '',
'menu_name' => __( 'Sermons', 'sermon-manager'),
);
$sermon_settings = get_option('wpfc_options');
$archive_slug = $sermon_settings['archive_slug'];
if(empty($archive_slug)):
$archive_slug = 'sermons';
endif;
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'menu_icon' => plugins_url('/img/book-open-bookmark.png', __FILE__),
'capability_type' => 'post',
'has_archive' => true,
'rewrite' => array( 'slug' => $archive_slug ),
'hierarchical' => false,
'supports' => array( 'title', 'comments', 'thumbnail', 'entry-views' )
);
register_post_type('wpfc_sermon',$args);
}
//create new taxonomies: preachers, sermon series & topics
add_action( 'init', 'create_wpfc_sermon_taxonomies', 0 );
function create_wpfc_sermon_taxonomies()
{
//Preachers
$labels = array(
'name' => __( 'Preachers', 'sermon-manager'),
'singular_name' => __( 'Preacher', 'sermon-manager' ),
'menu_name' => __( 'Preachers', 'sermon-manager' ),
'search_items' => __( 'Search preachers', 'sermon-manager' ),
'popular_items' => __( 'Most frequent preachers', 'sermon-manager' ),
'all_items' => __( 'All preachers', 'sermon-manager' ),
'edit_item' => __( 'Edit preachers', 'sermon-manager' ),
'update_item' => __( 'Update preachers', 'sermon-manager' ),
'add_new_item' => __( 'Add new preacher', 'sermon-manager' ),
'new_item_name' => __( 'New preacher name', 'sermon-manager' ),
'separate_items_with_commas' => __( 'Separate multiple preachers with commas', 'sermon-manager' ),
'add_or_remove_items' => __( 'Add or remove preachers', 'sermon-manager' ),
'choose_from_most_used' => __( 'Choose from most frequent preachers', 'sermon-manager' ),
'parent_item' => null,
'parent_item_colon' => null,
);
register_taxonomy('wpfc_preacher','wpfc_sermon', array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array ( 'slug' => 'preacher' ),
));
//Sermon Series
$labels = array(
'name' => __( 'Sermon Series', 'sermon-manager'),
'graphic' => '',
'singular_name' => __( 'Sermon Series', 'sermon-manager'),
'menu_name' => __( 'Sermon Series', 'sermon-manager' ),
'search_items' => __( 'Search sermon series', 'sermon-manager' ),
'popular_items' => __( 'Most frequent sermon series', 'sermon-manager' ),
'all_items' => __( 'All sermon series', 'sermon-manager' ),
'edit_item' => __( 'Edit sermon series', 'sermon-manager' ),
'update_item' => __( 'Update sermon series', 'sermon-manager' ),
'add_new_item' => __( 'Add new sermon series', 'sermon-manager' ),
'new_item_name' => __( 'New sermon series name', 'sermon-manager' ),
'separate_items_with_commas' => __( 'Separate sermon series with commas', 'sermon-manager' ),
'add_or_remove_items' => __( 'Add or remove sermon series', 'sermon-manager' ),
'choose_from_most_used' => __( 'Choose from most used sermon series', 'sermon-manager' ),
'parent_item' => null,
'parent_item_colon' => null,
);
register_taxonomy('wpfc_sermon_series','wpfc_sermon', array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array ( 'slug' => 'sermon-series' ),
));
//Sermon Topics
$labels = array(
'name' => __( 'Sermon Topics', 'sermon-manager'),
'singular_name' => __( 'Sermon Topics', 'sermon-manager'),
'menu_name' => __( 'Sermon Topics', 'sermon-manager' ),
'search_items' => __( 'Search sermon topics', 'sermon-manager' ),
'popular_items' => __( 'Most popular sermon topics', 'sermon-manager' ),
'all_items' => __( 'All sermon topics', 'sermon-manager' ),
'edit_item' => __( 'Edit sermon topic', 'sermon-manager' ),
'update_item' => __( 'Update sermon topic', 'sermon-manager' ),
'add_new_item' => __( 'Add new sermon topic', 'sermon-manager' ),
'new_item_name' => __( 'New sermon topic', 'sermon-manager' ),
'separate_items_with_commas' => __( 'Separate sermon topics with commas', 'sermon-manager' ),
'add_or_remove_items' => __( 'Add or remove sermon topics', 'sermon-manager' ),
'choose_from_most_used' => __( 'Choose from most used sermon topics', 'sermon-manager' ),
'parent_item' => null,
'parent_item_colon' => null,
);
register_taxonomy('wpfc_sermon_topics','wpfc_sermon', array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array ( 'slug' => 'topics' ),
));
//Books of the Bible
$labels = array(
'name' => __( 'Book of the Bible', 'sermon-manager'),
'singular_name' => __( 'Book of the Bible', 'sermon-manager'),
'menu_name' => __( 'Book of the Bible', 'sermon-manager' ),
'search_items' => __( 'Search books of the Bible', 'sermon-manager' ),
'popular_items' => __( 'Most popular books of the Bible', 'sermon-manager' ),
'all_items' => __( 'All books of the Bible', 'sermon-manager' ),
'edit_item' => __( 'Edit book of the Bible', 'sermon-manager' ),
'update_item' => __( 'Update book of the Bible', 'sermon-manager' ),
'add_new_item' => __( 'Add new books of the Bible', 'sermon-manager' ),
'new_item_name' => __( 'New book of the Bible', 'sermon-manager' ),
'separate_items_with_commas' => __( 'Separate books of the Bible with commas', 'sermon-manager' ),
'add_or_remove_items' => __( 'Add or remove books of the Bible', 'sermon-manager' ),
'choose_from_most_used' => __( 'Choose from most used books of the Bible', 'sermon-manager' ),
'parent_item' => null,
'parent_item_colon' => null,
);
register_taxonomy('wpfc_bible_book','wpfc_sermon', array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array ( 'slug' => 'book' ),
));
}
//add filter to insure the text Sermon, or sermon, is displayed when user updates a sermon
add_filter('post_updated_messages', 'wpfc_sermon_updated_messages');
function wpfc_sermon_updated_messages( $messages ) {
global $post, $post_ID;
$messages['wpfc_sermon'] = array(
0 => '', // Unused. Messages start at index 1.
1 => sprintf( __('Sermon updated. <a href="%s">View sermon</a>', 'sermon-manager'), esc_url( get_permalink($post_ID) ) ),
2 => __('Custom field updated.', 'sermon-manager'),
3 => __('Custom field deleted.', 'sermon-manager'),
4 => __('Sermon updated.', 'sermon-manager'),
/* translators: %s: date and time of the revision */
5 => isset($_GET['revision']) ? sprintf( __('Sermon restored to revision from %s', 'sermon-manager'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => sprintf( __('Sermon published. <a href="%s">View sermon</a>', 'sermon-manager'), esc_url( get_permalink($post_ID) ) ),
7 => __('Sermon saved.', 'sermon-manager'),
8 => sprintf( __('Sermon submitted. <a target="_blank" href="%s">Preview sermon</a>', 'sermon-manager'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
9 => sprintf( __('Sermon scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview sermon</a>', 'sermon-manager'),
// translators: Publish box date format, see http://php.net/date
date_i18n( __( 'M j, Y @ G:i', 'sermon-manager' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
10 => sprintf( __('Sermon draft updated. <a target="_blank" href="%s">Preview sermon</a>', 'sermon-manager'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
);
return $messages;
}
// TO DO: Add more help information
//display contextual help for Sermons
add_action( 'contextual_help', 'add_wpfc_sermon_help_text', 10, 3 );
function add_wpfc_sermon_help_text($contextual_help, $screen_id, $screen) {
//$contextual_help .= var_dump($screen); // use this to help determine $screen->id
if ('wpfc_sermon' == $screen->id ) {
$contextual_help =
'<p>' . __('Things to remember when adding or editing a sermon:', 'sermon-manager') . '</p>' .
'<ul>' .
'<li>' . __('Specify a sermon series if appropriate. This will help your site visitors while browsing sermons.', 'sermon-manager') . '</li>' .
'<li>' . __('Specify the correct preacher of the sermon.', 'sermon-manager') . '</li>' .
'</ul>' .
'<p>' . __('If you want to schedule the sermon to be published in the future:', 'sermon-manager') . '</p>' .
'<ul>' .
'<li>' . __('Under the Publish meta box, click on the Edit link next to Publish.', 'sermon-manager') . '</li>' .
'<li>' . __('Change the date to the date to actual publish this article, then click on Ok.', 'sermon-manager') . '</li>' .
'</ul>' .
'<p><strong>' . __('For more help:', 'sermon-manager') . '</strong></p>' .
'<p>' . __('<a href="http://wpforchurch.com/" target="_blank">Wordpress for Church</a>', 'sermon-manager') . '</p>' ;
} elseif ( 'edit-sermon' == $screen->id ) {
$contextual_help =
'<p>' . __('This is the help screen displaying on the sermons page.', 'sermon-manager') . '</p>' ;
}
return $contextual_help;
}
// Add filter for custom search: includes bible_passage, sermon_description in WordPress search
function wpfc_sermon_search_query( $query ) {
if ( !is_admin() && $query->is_search ) {
$query->set('meta_query', array(
array(
'key' => 'bible_passage',
'value' => $query->query_vars['s'],
'compare' => 'LIKE'
),
array(
'key' => 'sermon_description',
'value' => $query->query_vars['s'],
'compare' => 'LIKE'
)
));
//$query->set('post_type', 'wpfc_sermon');
};
}
//add_filter( 'pre_get_posts', 'wpfc_sermon_search_query');
// Initialize the metabox class.
add_action( 'init', 'initialize_wpfc_sermon_meta_boxes', 9999 );
function initialize_wpfc_sermon_meta_boxes() {
require_once plugin_dir_path( __FILE__ ) . '/includes/meta-box/init.php';
}
// Meta Box
add_filter( 'wpfc_meta_boxes', 'wpfc_sermon_metaboxes' );
// Define the metabox and field configurations.
function wpfc_sermon_metaboxes( array $meta_boxes ) {
// Service Types
$service_types = array(
array( 'name' => 'Adult Bible Class', 'value' => 'Adult Bible Class', ),
array( 'name' => 'Sunday AM', 'value' => 'Sunday AM', ),
array( 'name' => 'Sunday PM', 'value' => 'Sunday PM', ),
array( 'name' => 'Midweek Service', 'value' => 'Midweek Service', ),
array( 'name' => 'Special Service', 'value' => 'Special Service', ),
array( 'name' => 'Radio Broadcast', 'value' => 'Radio Broadcast', ),);
$service_types = apply_filters('service_types', $service_types);
$meta_boxes[] = array(
'id' => 'wpfc_sermon_details',
'title' => __('Sermon Details', 'sermon-manager'),
'pages' => array( 'wpfc_sermon', ), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
'fields' => array(
array(
'name' => __('Date', 'sermon-manager'),
'desc' => __('Enter the date the sermon was given. <strong>NOTE: Each sermon must have a date!</strong>', 'sermon-manager'),
'id' => 'sermon_date',
'type' => 'text_date_timestamp',
),
array(
'name' => __('Service Type', 'sermon-manager'),
'desc' => __('Select the type of service.', 'sermon-manager'),
'id' => 'service_type',
'type' => 'select',
'options' => $service_types
),
array(
'name' => __('Main Bible Passage', 'sermon-manager'),
'desc' => __('Enter the Bible passage with the full book names,e.g. "John 3:16-18".', 'sermon-manager'),
'id' => 'bible_passage',
'type' => 'text',
),
array(
'name' => __('Description', 'sermon-manager'),
'desc' => __('Type a brief description about this sermon, an outline, or a full manuscript', 'sermon-manager'),
'id' => 'sermon_description',
'type' => 'wysiwyg',
'options' => array( 'textarea_rows' => 7, 'media_buttons' => false,),
),
),
);
$meta_boxes[] = array(
'id' => 'wpfc_sermon_files',
'title' => __('Sermon Files', 'sermon-manager'),
'pages' => array( 'wpfc_sermon', ), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
'fields' => array(
array(
'name' => __('Location of MP3', 'sermon-manager'),
'desc' => __('Upload an audio file or enter an URL.', 'sermon-manager'),
'id' => 'sermon_audio',
'type' => 'file',
),
array(
'name' => __('Video Embed Code', 'sermon-manager'),
'desc' => __('Paste your embed code for Vimeo, Youtube, or other service here', 'sermon-manager'),
'id' => 'sermon_video',
'type' => 'textarea',
),
array(
'name' => __('Sermon Notes', 'sermon-manager'),
'desc' => __('Upload a pdf file or enter an URL.', 'sermon-manager'),
'id' => 'sermon_notes',
'type' => 'file',
),
),
);
return $meta_boxes;
}
// Plugin Meta Links.
function wpfc_sermon_manager_plugin_row_meta( $links, $file ) {
static $plugin_name = '';
if ( empty( $plugin_name ) ) {
$plugin_name = plugin_basename( __FILE__ );
}
if ( $plugin_name != $file ) {
return $links;
}
$link = wpfc_sermon_manager_settings_page_link( __( 'Settings', 'sermon-manager' ) );
if ( ! empty( $link ) ) {
$links[] = $link;
}
$links[] = '<a href="http://www.wpforchurch.com/support/" target="_blank">' . __( 'Support', 'sermon-manager' ) . '</a>';
return $links;
}
add_filter( 'plugin_row_meta', 'wpfc_sermon_manager_plugin_row_meta', 10, 2 );
// Settings Page Link.
function wpfc_sermon_manager_settings_page_link( $link_text = '' ) {
if ( empty( $link_text ) ) {
$link_text = __( 'Manage Settings', 'sermon-manager' );
}
$link = '';
if ( current_user_can( 'manage_options' ) ) {
$link = '<a href="' . admin_url( 'edit.php?post_type=wpfc_sermon&page=sermon-manager-for-wordpress/includes/options.php' ) . '">' . esc_html( $link_text ) . '</a>';
}
return $link;
}
//create custom columns when listing sermon details in the Admin
add_action("manage_posts_custom_column", "wpfc_sermon_columns");
add_filter("manage_edit-wpfc_sermon_columns", "wpfc_sermon_edit_columns");
function wpfc_sermon_edit_columns($columns) {
$columns = array(
"cb" => "<input type=\"checkbox\" />",
"title" => __('Sermon Title', 'sermon-manager'),
"preacher" => __('Preacher', 'sermon-manager'),
"series" => __('Sermon Series', 'sermon-manager'),
"topics" => __('Topics', 'sermon-manager'),
"views" => __('Views', 'sermon-manager'),
);
return $columns;
}
function wpfc_sermon_columns($column){
global $post;
switch ($column){
case "preacher":
echo get_the_term_list($post->ID, 'wpfc_preacher', '', ', ','');
break;
case "series":
echo get_the_term_list($post->ID, 'wpfc_sermon_series', '', ', ','');
break;
case "topics":
echo get_the_term_list($post->ID, 'wpfc_sermon_topics', '', ', ','');
break;
case "views":
echo wpfc_entry_views_get( array( 'post_id' => $post->ID ) );
break;
}
}
/*
* Shortcodes
*/
require_once plugin_dir_path( __FILE__ ) . '/includes/shortcodes.php';
/*
* Template selection
*/
// Check plugin options to decide what to do
$sermonoptions = get_option('wpfc_options');
if ( isset($sermonoptions['template']) == '1' ) {
add_filter('template_include', 'sermon_template_include');
add_filter('template_include', 'preacher_template_include');
add_filter('template_include', 'series_template_include');
}
// Include template for displaying sermons by Preacher
function sermon_template_include($template) {
if(get_query_var('post_type') == 'wpfc_sermon') {
if ( is_archive() || is_search() ) :
if(file_exists(get_stylesheet_directory() . '/archive-wpfc_sermon.php'))
return get_stylesheet_directory() . '/archive-wpfc_sermon.php';
return plugin_dir_path( __FILE__ ) . '/views/archive-wpfc_sermon.php';
else :
if(file_exists(get_stylesheet_directory() . '/single-wpfc_sermon.php'))
return get_stylesheet_directory() . '/single-wpfc_sermon.php';
return plugin_dir_path( __FILE__ ) . '/views/single-wpfc_sermon.php';
endif;
}
return $template;
}
// Include template for displaying sermons by Preacher
function preacher_template_include($template) {
if(get_query_var('taxonomy') == 'wpfc_preacher') {
if(file_exists(get_stylesheet_directory() . '/taxonomy-wpfc_preacher.php'))
return get_stylesheet_directory() . '/taxonomy-wpfc_preacher.php';
return plugin_dir_path(__FILE__) . '/views/taxonomy-wpfc_preacher.php';
}
return $template;
}
// Include template for displaying sermon series
function series_template_include($template) {
if(get_query_var('taxonomy') == 'wpfc_sermon_series') {
if(file_exists(get_stylesheet_directory() . '/taxonomy-wpfc_sermon_series.php'))
return get_stylesheet_directory() . '/taxonomy-wpfc_sermon_series.php';
return plugin_dir_path(__FILE__) . '/views/taxonomy-wpfc_sermon_series.php';
}
return $template;
}
// Add scripts only to single sermon pages
add_action('wp_enqueue_scripts', 'add_wpfc_js');
function add_wpfc_js() {
// Register them all!
wp_register_script( 'sermon-ajax', plugins_url('/js/ajax.js', __FILE__), array('jquery'), '1.5', false );
wp_register_script('mediaelementjs-scripts', plugins_url('/js/mediaelement/mediaelement-and-player.min.js', __FILE__), array('jquery'), '2.7.0', false);
wp_register_style('mediaelementjs-styles', plugins_url('/js/mediaelement/mediaelementplayer.css', __FILE__));
wp_register_style('sermon-styles', plugins_url('/css/sermon.css', __FILE__));
wp_register_script('bibly-script', 'http://code.bib.ly/bibly.min.js', false, null );
wp_register_style('bibly-style', 'http://code.bib.ly/bibly.min.css', false, null );
// Load them as needed
if ('wpfc_sermon' == get_post_type() ) {
wp_enqueue_script('mediaelementjs-scripts');
wp_enqueue_style('mediaelementjs-styles');
}
$sermonoptions = get_option('wpfc_options');
if (is_single() && 'wpfc_sermon' == get_post_type() && !isset($sermonoptions['bibly']) == '1') {
wp_enqueue_script('bibly-script');
wp_enqueue_style('bibly-style');
// get options for JS
$Bibleversion = $sermonoptions['bibly_version'];
wp_localize_script( 'bibly-script', 'bibly', array( // pass WP data into JS from this point on
'linkVersion' => $Bibleversion,
'enablePopups' => true,
'popupVersion' => $Bibleversion,
));
}
if ( !isset($sermonoptions['css']) == '1') {
wp_enqueue_style('sermon-styles');
}
// Add ajax for pagination if shortcode is present in the content
global $wp_query;
global $post;
if($post) {
if ( false !== strpos($post->post_content, '[sermons') ) {
wp_enqueue_script('sermon-ajax');
}
}
}
// Add the number of sermons to the Right Now on the Dashboard
add_action('right_now_content_table_end', 'wpfc_right_now');
function wpfc_right_now() {
$num_posts = wp_count_posts('wpfc_sermon');
$num = number_format_i18n($num_posts->publish);
$text = _n('Sermon', 'Sermons', intval($num_posts->publish));
if ( current_user_can('edit_posts') ) {
$num = "<a href='edit.php?post_type=wpfc_sermon'>$num</a>";
$text = "<a href='edit.php?post_type=wpfc_sermon'>$text</a>";
}
echo '<td class="first b b-sermon">' . $num . '</td>';
echo '<td class="t sermons">' . $text . '</td>';
echo '</tr>';
}
/**
* Images for Series and Speakers
*/
function wpfc_sermon_images() {
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'sermon_small', 75, 75, true );
add_image_size( 'sermon_medium', 300, 200, true );
add_image_size( 'sermon_wide', 940, 350, true );
}
}
add_action("admin_init", "wpfc_sermon_images");
/**
* Recent Sermons Widget
*/
class WP4C_Recent_Sermons extends WP_Widget {
function WP4C_Recent_Sermons() {
$widget_ops = array('classname' => 'widget_recent_sermons', 'description' => __( 'The most recent sermons on your site', 'sermon-manager') );
parent::__construct('recent-sermons', __('Recent Sermons', 'sermon-manager'), $widget_ops);
$this->alt_option_name = 'widget_recent_entries';
add_action( 'save_post', array(&$this, 'flush_widget_cache') );
add_action( 'deleted_post', array(&$this, 'flush_widget_cache') );
add_action( 'switch_theme', array(&$this, 'flush_widget_cache') );
}
function widget($args, $instance) {
$cache = wp_cache_get('widget_recent_sermons', 'widget');
if ( !is_array($cache) )
$cache = array();
if ( isset($cache[$args['widget_id']]) ) {
echo $cache[$args['widget_id']];
return;
}
ob_start();
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Sermons', 'sermon-manager') : $instance['title'], $instance, $this->id_base);
if ( ! $number = absint( $instance['number'] ) )
$number = 10;
$r = new WP_Query(array(
'post_type' => 'wpfc_sermon',
'meta_key' => 'sermon_date',
'meta_value' => date("m/d/Y"),
'meta_compare' => '>=',
'orderby' => 'meta_value',
'order' => 'DESC',
'posts_per_page' => $number,
'no_found_rows' => true,
'post_status' => 'publish',
'ignore_sticky_posts' => true));
if ($r->have_posts()) :
?>
<?php echo $before_widget; ?>
<?php if ( $title ) echo $before_title . $title . $after_title; ?>
<ul>
<?php while ($r->have_posts()) : $r->the_post(); ?>
<?php global $post; ?>
<li>
<a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a><br/>
<span class="meta">
<?php
$terms = get_the_terms( $post->ID, 'wpfc_preacher' );
if ( $terms && ! is_wp_error( $terms ) ) :
$preacher_links = array();
foreach ( $terms as $term ) {
$preacher_links[] = $term->name;
}
$preacher = join( ", ", $preacher_links );
?>
<?php echo $preacher; ?>,
<?php endif;
wpfc_sermon_date('l, F j, Y');
?>
</span>
</li>
<?php endwhile; ?>
</ul>
<?php echo $after_widget; ?>
<?php
// Reset the global $the_post as this query will have stomped on it
wp_reset_postdata();
endif;
$cache[$args['widget_id']] = ob_get_flush();
wp_cache_set('widget_recent_sermons', $cache, 'widget');
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['number'] = (int) $new_instance['number'];
$this->flush_widget_cache();
$alloptions = wp_cache_get( 'alloptions', 'options' );
if ( isset($alloptions['widget_recent_entries']) )
delete_option('widget_recent_entries');
return $instance;
}
function flush_widget_cache() {
wp_cache_delete('widget_recent_sermons', 'widget');
}
function form( $instance ) {
$title = isset($instance['title']) ? esc_attr($instance['title']) : '';
$number = isset($instance['number']) ? absint($instance['number']) : 5;
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of sermons to show:'); ?></label>
<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>
<?php
}
}
add_action( 'widgets_init', create_function('', 'return register_widget("WP4C_Recent_Sermons");') );
// Custom taxonomy terms dropdown function
function wpfc_get_term_dropdown($taxonomy) {
$terms = get_terms($taxonomy);
foreach ($terms as $term) {
$term_slug = $term->slug;
$current_preacher = get_query_var('wpfc_preacher');
$current_series = get_query_var('wpfc_sermon_series');
$current_topic = get_query_var('wpfc_sermon_topics');
$current_book = get_query_var('wpfc_bible_book');
if($term_slug == $current_preacher || $term_slug == $current_series || $term_slug == $current_topic || $term_slug == $current_book) {
echo '<option value="'.$term->slug.'" selected>'.$term->name.'</option>';
} else {
echo '<option value="'.$term->slug.'">'.$term->name.'</option>';
}
}
}
// Make all queries for sermons order by the sermon date
function wpfc_sermon_order_query( $query ) {
if ( isset($query->query_vars['post_type']) != 'nav_menu_item' ) :
if( is_post_type_archive('wpfc_sermon') || is_tax( 'wpfc_preacher' ) || is_tax( 'wpfc_sermon_topics' ) || is_tax( 'wpfc_sermon_series' ) || is_tax( 'wpfc_bible_book' ) ) {
$query->set('meta_key', 'sermon_date');
$query->set('meta_value', date("m/d/Y"));
$query->set('meta_compare', '>=');
$query->set('orderby', 'meta_value');
$query->set('order', 'DESC');
}
endif;
}
add_action('pre_get_posts', 'wpfc_sermon_order_query', 9999);
// render archive entry
function render_wpfc_sermon_archive() {
global $post; ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2 class="sermon-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'sermon-manager' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<div class="wpfc_sermon_image">
<?php render_sermon_image('thumbnail'); ?>
</div>
<div class="wpfc_sermon_meta cf">
<p>
<?php
wpfc_sermon_date('l, F j, Y', '<span class="sermon_date">', '</span> '); wpfc_sermon_meta('service_type', ' <span class="service_type">(', ')</span> ');
?></p><p><?php
wpfc_sermon_meta('bible_passage', '<span class="bible_passage">Bible Text: ', '</span> | ');
echo the_terms( $post->ID, 'wpfc_preacher', '<span class="preacher_name">', ' ', '</span>');
echo the_terms( $post->ID, 'wpfc_sermon_series', '<p><span class="sermon_series">Series: ', ' ', '</span></p>' );
?>
</p>
</div>
</div> <?php
}
// render sermon sorting
function render_wpfc_sorting() { ?>
<div id="wpfc_sermon_sorting">
<span class="sortPreacher">
<form action="<?php bloginfo('url'); ?>" method="get">
<select name="wpfc_preacher" id="wpfc_preacher" onchange="return this.form.submit()">
<option value=""><?php _e('Sort by Preacher', 'sermon-manager'); ?></option>
<?php wpfc_get_term_dropdown('wpfc_preacher'); ?>
</select>
<noscript><div><input type="submit" value="Submit" /></div></noscript>
</form>
</span>
<span class="sortSeries">
<form action="<?php bloginfo('url'); ?>" method="get">
<select name="wpfc_sermon_series" id="wpfc_sermon_series" onchange="return this.form.submit()">
<option value=""><?php _e('Sort by Series', 'sermon-manager'); ?></option>
<?php wpfc_get_term_dropdown('wpfc_sermon_series'); ?>
</select>
<noscript><div><input type="submit" value="Submit" /></div></noscript>
</form>
</span>
<span class="sortTopics">
<form action="<?php bloginfo('url'); ?>" method="get">
<select name="wpfc_sermon_topics" id="wpfc_sermon_topics" onchange="return this.form.submit()">
<option value=""><?php _e('Sort by Topic', 'sermon-manager'); ?></option>
<?php wpfc_get_term_dropdown('wpfc_sermon_topics'); ?>
</select>
<noscript><div><input type="submit" value="Submit" /></div></noscript>
</form>
</span>
<span class="sortBooks">
<form action="<?php bloginfo('url'); ?>" method="get">
<select name="wpfc_bible_book" id="wpfc_bible_book" onchange="return this.form.submit()">
<option value=""><?php _e('Sort by Book', 'sermon-manager'); ?></option>
<?php wpfc_get_term_dropdown('wpfc_bible_book'); ?>
</select>
<noscript><div><input type="submit" value="Submit" /></div></noscript>
</form>
</span>
</div>
<?php
}
// echo any sermon meta
function wpfc_sermon_meta( $args, $before = '', $after = '' ) {
global $post;
$data = get_post_meta($post->ID, $args, 'true');
if ($data != '')
echo $before .$data. $after;
}
// return any sermon meta
function get_wpfc_sermon_meta( $args ) {
global $post;
$data = get_post_meta($post->ID, $args, 'true');
if ($data != '')
return $data;
return null;
}
// render sermon description
function wpfc_sermon_description( $before = '', $after = '' ) {
global $post;
$data = get_post_meta($post->ID, 'sermon_description', 'true');
if ($data != '')
echo $before .wpautop($data). $after;
}
// render any sermon date
function wpfc_sermon_date( $args, $before = '', $after = '' ) {
global $post;
$ugly_date = get_post_meta($post->ID, 'sermon_date', 'true');
$date = date($args, $ugly_date);
echo $before .$date. $after;
}
// Change published date to sermon date on frontend display
function wpfc_sermon_date_filter() {
global $post;
$ugly_date = get_post_meta($post->ID, 'sermon_date', 'true');
$date = date(get_option('date_format'), $ugly_date);
return $date;
}
if ( 'wpfc_sermon' == get_post_type() ) {
add_filter('get_the_date', 'wpfc_sermon_date_filter');
}
// Change the_author to the preacher on frontend display
function wpfc_sermon_author_filter() {
global $post;
$preacher = the_terms( $post->ID, 'wpfc_preacher', '', ', ', ' ' );
return $preacher;
}
//add_filter('the_author', 'wpfc_sermon_author_filter');
// render sermon image - loops through featured image, series image, speaker image, none
function render_sermon_image($size) {
//$size = any defined image size in WordPress
if( has_post_thumbnail() ) :
the_post_thumbnail($size);
elseif ( apply_filters( 'sermon-images-list-the-terms', '', array( 'taxonomy' => 'wpfc_sermon_series', ) )) :
// get series image
print apply_filters( 'sermon-images-list-the-terms', '', array(
'image_size' => $size,
'taxonomy' => 'wpfc_sermon_series',
'after' => '',
'after_image' => '',
'before' => '',
'before_image' => ''
) );
elseif ( !has_post_thumbnail() && !apply_filters( 'sermon-images-list-the-terms', '', array( 'taxonomy' => 'wpfc_sermon_series', ) ) ) :
// get speaker image
print apply_filters( 'sermon-images-list-the-terms', '', array(
'image_size' => $size,
'taxonomy' => 'wpfc_preacher',
'after' => '',
'after_image' => '',
'before' => '',
'before_image' => ''
) );
endif;
}
// render files section
function wpfc_sermon_files() {
if ( get_wpfc_sermon_meta('sermon_video') ) {
echo '<div id="wpfc_sermon-video" class="cf">';
echo do_shortcode( get_wpfc_sermon_meta('sermon_video'));
echo '</div>';
} elseif ( !get_wpfc_sermon_meta('sermon_video') && get_wpfc_sermon_meta('sermon_audio') ) {
echo '<div id="wpfc_sermon-audio" class="cf">';?>
<script>
jQuery.noConflict();
jQuery(document).ready(function(){
jQuery('audio').mediaelementplayer();
});
</script> <?php
echo '<audio controls="controls">';
echo '<source src="' . get_wpfc_sermon_meta('sermon_audio') . '" type="audio/mp3" />';
echo '</audio>';
echo '</div>';
}
if ( get_wpfc_sermon_meta('sermon_notes') ) {
echo '<div id="wpfc_sermon-notes" class="cf">';
echo '<a href="' . get_wpfc_sermon_meta('sermon_notes') . '" class="sermon-notes">Notes</a>';
echo '</div>';
}
}
// render additional files
function wpfc_sermon_attachments() {
global $post;
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID,
'exclude' => get_post_thumbnail_id()
);
$attachments = get_posts($args);
if ($attachments) {
echo '<div id="wpfc-attachments" class="cf">';
echo '<p><strong>Download Files:</strong>';
foreach ($attachments as $attachment) {
echo '<br/><a target="_blank" href="'.wp_get_attachment_url($attachment->ID).'">';
echo $attachment->post_title;
}
echo '</a>';
echo '</p>';
echo '</div>';
}
}
// render single sermon entry
function render_wpfc_sermon_single() {
global $post; ?>
<div id="wpfc_sermon_wrap" class="cf">
<div id="wpfc_sermon_image">
<?php render_sermon_image('sermon_small'); ?>
</div>
<div class="wpfc_sermon_meta cf">
<p>
<?php
wpfc_sermon_date('l, F j, Y', '<span class="sermon_date">', '</span> '); wpfc_sermon_meta('service_type', ' <span class="service_type">(', ')</span> ');
?></p><p><?php
wpfc_sermon_meta('bible_passage', '<span class="bible_passage">Bible Text: ', '</span> | ');
echo the_terms( $post->ID, 'wpfc_preacher', '<span class="preacher_name">', ', ', '</span>');
echo the_terms( $post->ID, 'wpfc_sermon_series', '<p><span class="sermon_series">Series: ', ', ', '</span></p>' );
?>
</p>
</div>
</div>
<div id="wpfc_sermon" class="cf">
<?php wpfc_sermon_files(); ?>
<?php wpfc_sermon_description(); ?>
<?php wpfc_sermon_attachments(); ?>
<?php echo the_terms( $post->ID, 'wpfc_sermon_topics', '<p class="sermon_topics">Topics: ', ', ', '</p>' ); ?>
</div>
<?php
}
// render single sermon entry
function render_wpfc_sermon_excerpt() {
global $post;?>
<div id="wpfc_sermon_wrap" class="cf">
<div id="wpfc_sermon_image">
<?php render_sermon_image('sermon_small'); ?>
</div>
<div class="wpfc_sermon_meta cf">
<p>
<?php
wpfc_sermon_date('l, F j, Y', '<span class="sermon_date">', '</span> '); wpfc_sermon_meta('service_type', ' <span class="service_type">(', ')</span> ');
?></p><p><?php
wpfc_sermon_meta('bible_passage', '<span class="bible_passage">Bible Text: ', '</span> | ');
echo the_terms( $post->ID, 'wpfc_preacher', '<span class="preacher_name">', ', ', '</span>');
echo the_terms( $post->ID, 'wpfc_sermon_series', '<p><span class="sermon_series">Series: ', ', ', '</span></p>' );
?>
</p>
</div>
<?php $sermonoptions = get_option('wpfc_options'); if ( isset($sermonoptions['archive_player']) == '1') { ?>
<div id="wpfc_sermon" class="cf">
<?php wpfc_sermon_files(); ?>
</div>
<?php } ?>
</div>
<?php
}
// Add sermon content
add_filter('the_content', 'add_wpfc_sermon_content');
function add_wpfc_sermon_content($content) {
if ( 'wpfc_sermon' == get_post_type() ){
if ( is_archive() ) {
$new_content = render_wpfc_sermon_excerpt();
} elseif ( is_singular() && is_main_query() ) {
$new_content = render_wpfc_sermon_single();
}
$content = $new_content;
}
return $content;
}
/**
* Podcast Settings
*/
// Create custom RSS feed for sermon podcasting
function wpfc_sermon_podcast_feed() {
load_template(plugin_dir_path( __FILE__ ) . 'includes/podcast-feed.php');
}
add_action('do_feed_podcast', 'wpfc_sermon_podcast_feed', 10, 1);
// Custom rewrite for podcast feed
function wpfc_sermon_podcast_feed_rewrite($wp_rewrite) {
$feed_rules = array(
'feed/(.+)' => 'index.php?feed=' . $wp_rewrite->preg_index(1),
'(.+).xml' => 'index.php?feed='. $wp_rewrite->preg_index(1)
);
$wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
}
add_filter('generate_rewrite_rules', 'wpfc_sermon_podcast_feed_rewrite');
// Get the filesize of a remote file, used for Podcast data
function wpfc_get_filesize( $url, $timeout = 10 ) {
// Create a curl connection
$getsize = curl_init();