-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathictuwp-plugin-community-posttype.php
1915 lines (1504 loc) · 56.4 KB
/
ictuwp-plugin-community-posttype.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
/**
* @link https://github.com/ICTU/ictuwp-plugin-community-posttype
* @package ictuwp-plugin-community-posttype
*
* @wordpress-plugin
* Plugin Name: ICTU / Digitale Overheid / Community
* Plugin URI: https://github.com/ICTU/ictuwp-plugin-community-posttype
* Description: Plugin voor het aanmaken van posttype 'community' en bijbehorende taxonomieen.
* Version: 1.2.8
* Version description: Show months for all posts, and show year.
* Author: Paul van Buuren
* Author URI: https://github.com/ICTU/ictuwp-plugin-community-posttype/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: wp-rijkshuisstijl
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
//========================================================================================================
// Dutch slug for taxonomy
$slug = 'community';
$slugtype = 'community-type';
$slugtopics = 'onderwerpen-community';
$slugaudiences = 'doelgroepen-community';
$slugoverheidslaag = 'overheidslaag';
if ( get_bloginfo( 'language' ) !== 'nl-NL' ) {
// non Dutch slugs
$slug = 'community';
$slugtopics = 'topics-community';
$slugaudiences = 'audience-community';
}
define( 'DO_COMMUNITY_CPT', $slug );
define( 'DO_COMMUNITYTYPE_CT', $slugtype );
define( 'DO_COMMUNITYTOPICS_CT', $slugtopics );
define( 'DO_COMMUNITYAUDIENCE_CT', $slugaudiences );
define( 'DO_COMMUNITYBESTUURSLAAG_CT', $slugoverheidslaag );
defined( 'DO_COMMUNITY_OVERVIEW_TEMPLATE' ) or define( 'DO_COMMUNITY_OVERVIEW_TEMPLATE', 'template-overview-communities.php' );
defined( 'DO_COMMUNITY_PAGE_RSS_AGENDA' ) or define( 'DO_COMMUNITY_PAGE_RSS_AGENDA', 'template-rss-agenda.php' );
defined( 'DO_COMMUNITY_PAGE_RSS_POSTS' ) or define( 'DO_COMMUNITY_PAGE_RSS_POSTS', 'template-rss-posts.php' );
defined( 'DO_COMMUNITY_DETAIL_TEMPLATE' ) or define( 'DO_COMMUNITY_DETAIL_TEMPLATE', 'template-community-detail.php' );
//if ( ! defined( 'RHSWP_WIDGET_AREA_COMMUNITY_OVERVIEW' ) ) {
// define( 'RHSWP_WIDGET_AREA_COMMUNITY_OVERVIEW', 'sidebar-community-overview' );
//}
define( 'DO_COMMUNITYTYPE_CT_VAR', 'communitytype' );
define( 'DO_COMMUNITYTOPICS_CT_VAR', 'communitytopic' );
define( 'DO_COMMUNITYAUDIENCE_CT_VAR', 'communityaudience' );
define( 'DO_COMMUNITYBESTUURSLAAG_CT_VAR', 'communitygov' );
define( 'DO_COMMUNITY_MAX_VAR', 'communitymaxnr' );
define( 'DO_COMMUNITY_MAX_DEFAULT', 20 );
define( 'DO_COMMUNITY_MAX_OPTIONS', array( 10, 20, 50, 100 ) );
//========================================================================================================
add_action( 'plugins_loaded', array( 'DO_COMMUNITY_CPT', 'init' ), 10 );
//========================================================================================================
require_once plugin_dir_path( __FILE__ ) . 'includes/widget-filter.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/widget-last-added.php';
require_once plugin_dir_path( __FILE__ ) . 'includes/widget-communitys-with-feed.php';
//========================================================================================================
/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 0.0.1
*/
if ( ! class_exists( 'DO_COMMUNITY_CPT' ) ) :
class DO_COMMUNITY_CPT {
protected $template_overview_communities;
protected $template_calendar_view;
/** ----------------------------------------------------------------------------------------------------
* Init
*/
public static function init() {
$newtaxonomy = new self();
}
/** ----------------------------------------------------------------------------------------------------
* Constructor
*/
public function __construct() {
$this->template_overview_communities = 'template_overview_communities.php';
$this->template_calendar_view = 'template-calendar-view.php';
$this->template_page_agenda = DO_COMMUNITY_PAGE_RSS_AGENDA;
$this->template_page_posts = DO_COMMUNITY_PAGE_RSS_POSTS;
$this->fn_ictu_community_setup_actions();
}
/** ----------------------------------------------------------------------------------------------------
* Hook this plugins functions into WordPress.
* Use priority = 20, to ensure that the taxonomy is registered for post types from other plugins,
* such as the podcasts plugin (seriously-simple-podcasting)
*/
private function fn_ictu_community_setup_actions() {
add_action( 'init', array( $this, 'fn_ictu_community_register_posttypes' ), 20 );
// add page templates
// add_filter( 'template_include', array( $this, 'fn_ictu_community_append_template_locations' ) );
// filter the breadcrumbs
// add_filter( 'wpseo_breadcrumb_links', array( $this, 'fn_ictu_community_yoast_filter_breadcrumb' ) );
// add the page template to the templates list
add_filter( 'theme_page_templates', array( $this, 'fn_ictu_community_add_page_template' ) );
// provide the file location to the template
add_filter( 'template_include', array( $this, 'ictuwp_community_determine_template' ) );
// Register widgets
add_action( 'widgets_init', 'ictuwp_community_load_widget_filter' );
add_action( 'widgets_init', 'ictuwp_community_load_widget_latest_added' );
add_action( 'widgets_init', 'ictuwp_community_load_widget_valid_feeds' );
// sort alphabetically and list all communities for a single taxonomy term
add_action( 'pre_get_posts', array( $this, 'fn_ictu_community_modify_main_query' ), 999 );
// add the page template to the templates list
add_filter( 'acf/include_fields', array( $this, 'fn_ictu_community_acf_fields' ) );
}
/** ----------------------------------------------------------------------------------------------------
* Do actually register the post types we need
*
* @return void
*/
public function fn_ictu_community_register_posttypes() {
require_once plugin_dir_path( __FILE__ ) . 'includes/register-community-posttype.php';
}
/** ----------------------------------------------------------------------------------------------------
* Do actually register the post types we need
*
* @return void
*/
public function fn_ictu_community_acf_fields() {
require_once plugin_dir_path( __FILE__ ) . 'includes/acf-fields.php';
}
/** ----------------------------------------------------------------------------------------------------
* Do actually register the post types we need
*
* @return void
*/
public function fn_ictu_community_add_page_template( $post_templates ) {
$post_templates[ $this->template_overview_communities ] = _x( "[community] overzicht", "naam template", "wp-rijkshuisstijl" );
$post_templates[ $this->template_page_agenda ] = _x( "[community] toon agenda", "naam template", "wp-rijkshuisstijl" );
$post_templates[ $this->template_page_posts ] = _x( "[community] toon berichten", "naam template", "wp-rijkshuisstijl" );
$post_templates[ $this->template_calendar_view ] = _x( "[community] eventoverzicht in tabelvorm", "naam template", "wp-rijkshuisstijl" );
return $post_templates;
}
//========================================================================================================
/*
* Deze function wijzigt de main query voor archives van community's en bijbehorden taxonomieen.
* Door deze wijziging wordt op 1 pagina een overzicht getoond van ALLE community's bij een bepaalde
* taxonomie, en de lijst wordt alfabetisch gesorteerd op titel
*/
public function fn_ictu_community_modify_main_query( $query ) {
global $query_vars;
if ( ! is_admin() && $query->is_main_query() ) {
if ( is_post_type_archive( DO_COMMUNITY_CPT ) ||
( is_tax( DO_COMMUNITYTYPE_CT ) ) ||
( is_tax( DO_COMMUNITYTOPICS_CT ) ) ||
( is_tax( DO_COMMUNITYBESTUURSLAAG_CT ) ) ||
( is_tax( DO_COMMUNITYAUDIENCE_CT ) ) ) {
// geen pagination voor overzichten van:
// - community types
// - community onderwerpen
// - community doelgroepen
$query->set( 'posts_per_page', - 1 );
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
return $query;
}
}
return $query;
}
/** ----------------------------------------------------------------------------------------------------
* Do actually register the post types we need
*
* @return void
*/
public function ictuwp_community_determine_template( $archive_template ) {
global $post;
if ( is_search() ) {
// do not overwrite search template
return $archive_template;
}
$page_template = get_post_meta( get_the_id(), '_wp_page_template', true );
if ( is_singular( DO_COMMUNITY_CPT ) ) {
// // het is een single voor CPT = DO_COMMUNITY_CPT
// $archive_template = dirname( __FILE__ ) . '/templates/single-initiatief.php';
} elseif ( is_tax( DO_COMMUNITYTYPE_CT ) || is_tax( DO_COMMUNITYTOPICS_CT ) || is_tax( DO_COMMUNITYBESTUURSLAAG_CT ) || is_tax( DO_COMMUNITYAUDIENCE_CT ) ) {
$archive_template = dirname( __FILE__ ) . '/templates/archive-communities.php';
} elseif ( DO_COMMUNITY_PAGE_RSS_AGENDA == $page_template ) {
$archive_template = dirname( __FILE__ ) . '/templates/template-rss-agenda.php';
} elseif ( DO_COMMUNITY_PAGE_RSS_POSTS == $page_template ) {
$archive_template = dirname( __FILE__ ) . '/templates/template-rss-posts.php';
} elseif ( 'template_overview_communities.php' == $page_template ) {
// het is een overzicht van community's
$archive_template = dirname( __FILE__ ) . '/templates/template-overview-communities.php';
} elseif ( 'template-calendar-view.php' == $page_template ) {
// overzicht van alle events in tabelvorm
$archive_template = dirname( __FILE__ ) . '/templates/template-calendar-view.php';
}
return $archive_template;
}
/**
* Checks if the template is assigned to the page
*
* @in: $template (string)
*
* @return: $template (string)
*
*/
public function fn_ictu_community_append_template_locations( $template ) {
// Get global post
global $post;
$file = '';
$pluginpath = plugin_dir_path( __FILE__ );
if ( $post ) {
// Do we have a post of whatever kind at hand?
// Get template name; this will only work for pages, obviously
$page_template = get_post_meta( $post->ID, '_wp_page_template', true );
if ( ( DO_COMMUNITY_OVERVIEW_TEMPLATE === $page_template ) || ( DO_COMMUNITY_DETAIL_TEMPLATE === $page_template || DO_COMMUNITY_PAGE_RSS_AGENDA === $page_template ) ) {
// these names are added by this plugin, so we return
// the actual file path for this template
$file = $pluginpath . $page_template;
} else {
// exit with the already set template
return $template;
}
} else {
// Not a post, not a term, return the template
return $template;
}
// Just to be safe, check if the file actually exists
if ( $file && file_exists( $file ) ) {
return $file;
} else {
// o dear, who deleted the file?
echo $file;
}
// If all else fails, return template
return $template;
}
/**
* Filter the Yoast SEO breadcrumb
*
* @in: $links (array)
*
* @return: $links (array)
*
*/
public function fn_ictu_community_yoast_filter_breadcrumb( $links ) {
// exceptions here
return $links;
}
/**
* Retrieve a page that is the overview page. This
* page shows all available items.
*
* @in: $args (array)
*
* @return: $overview_page_id (integer)
*
*/
private function fn_ictu_community_get_thema_overview_page( $args = array() ) {
$return = 0;
// TODO: discuss if we need to make this page a site setting
// there is no technical way to limit the number of pages with
// template DO_COMMUNITY_OVERVIEW_TEMPLATE, so the page we find may not be
// the exact desired page for in the breadcrumb.
//
// Try and find 1 Page
// with the DO_COMMUNITY_OVERVIEW_TEMPLATE template...
$page_template_query_args = array(
'number' => 1,
'sort_column' => 'post_date',
'sort_order' => 'DESC',
'meta_key' => '_wp_page_template',
'meta_value' => DO_COMMUNITY_OVERVIEW_TEMPLATE
);
$overview_page = get_pages( $page_template_query_args );
if ( $overview_page && isset( $overview_page[0]->ID ) ) {
$return = $overview_page[0]->ID;
}
return $return;
}
}
endif;
//========================================================================================================
/**
* Load plugin textdomain.
* only load translations if we can safely assume the taxonomy is active
*/
add_action( 'init', 'fn_ictu_community_load_plugin_textdomain' );
function fn_ictu_community_load_plugin_textdomain() {
load_plugin_textdomain( 'wp-rijkshuisstijl', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
//========================================================================================================
/**
* Returns array of allowed page templates
*
* @return array with extra templates
*/
function fn_ictu_community_add_templates() {
$return_array = array(
DO_COMMUNITY_OVERVIEW_TEMPLATE => _x( '[Community] alle community\'s', 'label page template', 'wp-rijkshuisstijl' ),
DO_COMMUNITY_DETAIL_TEMPLATE => _x( '[Community] community-detail', 'label page template', 'wp-rijkshuisstijl' ),
DO_COMMUNITY_PAGE_RSS_AGENDA => _x( '[Community] pagina agenda', 'label page template', 'wp-rijkshuisstijl' )
);
return $return_array;
}
//========================================================================================================
/**
* Voeg een paginaselector toe aan de customizer
* zie [admin] > Weergave > Customizer > Community's
*/
function community_append_customizer_field( $wp_customize ) {
// eigen sectie voor Theme Customizer
$wp_customize->add_section( 'customizer_communities', array(
'title' => _x( 'Community\'s', 'customizer menu', 'wp-rijkshuisstijl' ),
'capability' => 'edit_theme_options',
'description' => _x( 'Instellingen voor community\'s.', 'customizer menu', 'wp-rijkshuisstijl' ),
) );
// add dropdown with pages to appoint the new slug for the CPT
$wp_customize->add_setting( 'customizer_community_pageid_overview', array(
'capability' => 'edit_theme_options',
'sanitize_callback' => 'community_sanitize_initiatief_pagina',
) );
$wp_customize->add_control( 'customizer_community_pageid_overview', array(
'type' => 'dropdown-pages',
'section' => 'customizer_communities', // Add a default or your own section
'label' => _x( 'Pagina met alle community\'s', 'customizer menu', 'wp-rijkshuisstijl' ),
'description' => _x( 'In het kruimelpad en in de URL voor een initiatief zal deze pagina terugkomen.', 'customizer menu', 'wp-rijkshuisstijl' ),
) );
}
add_action( 'customize_register', 'community_append_customizer_field' );
//========================================================================================================
// zorg dat een geldige pagina wordt teruggegeven
function community_sanitize_initiatief_pagina( $page_id, $setting ) {
$value = $setting->default;
// Alleen een geldige ID accepteren
$page_id = absint( $page_id );
if ( $page_id ) {
if ( 'publish' != get_post_status( $page_id ) ) {
// alleen geubliceerde pagina's accepteren
return $value;
} else {
// TODO zorg ervoor dat de slug van de pagina gebruikt wordt in de slug van de commmunity CPT
}
$value = $page_id;
}
return $value;
}
//========================================================================================================
function communitys_filter_breadcrumb( $crumb = '', $args = '' ) {
global $post;
if ( ! (
is_singular( DO_COMMUNITY_CPT ) ||
is_tax( DO_COMMUNITYTYPE_CT ) ||
is_tax( DO_COMMUNITYTOPICS_CT ) ||
is_tax( DO_COMMUNITYBESTUURSLAAG_CT ) ||
is_tax( DO_COMMUNITYAUDIENCE_CT ) ) ) {
// hier niks doen, omdat we niet met een initiatief bezig zijn
return $crumb;
} else {
// uit siteopties de pagina ophalen die het overzicht is van alle links
$page_initatieven = get_theme_mod( 'customizer_community_pageid_overview' );
}
$currentitem = explode( '</span>', $crumb );
$termid = null;
$parents = array();
$return = '';
if ( ! $page_initatieven ) {
return $crumb;
} else {
// haal de ancestors op voor deze pagina
$ancestors = get_post_ancestors( $page_initatieven );
if ( is_post_type_archive( DO_COMMUNITY_CPT ) ) {
$parents[] = array(
'text' => get_the_title( $page_initatieven ),
);
} else {
$parents[] = array(
'url' => get_page_link( $page_initatieven ),
'text' => get_the_title( $page_initatieven ),
);
}
if ( $ancestors ) {
// haal de hele keten aan ancestors op en zet ze in de returnstring
foreach ( $ancestors as $ancestorid ) {
// Prepend one or more elements to the beginning of an array
array_unshift( $parents, [
'url' => get_page_link( $ancestorid ),
'text' => get_the_title( $ancestorid ),
] );
}
}
}
foreach ( $parents as $link ) {
if ( isset( $link['url'] ) && isset( $link['text'] ) ) {
$return .= '<a href="' . $link['url'] . '" class="parent-link">' . $link['text'] . '</a> ';
} else {
$return .= $link['text'] . ' ';
}
}
if ( isset( $post->ID ) && $post->ID === $page_initatieven ) {
//
} elseif ( is_post_type_archive( DO_COMMUNITY_CPT ) ) {
//
} else {
$queried_object = get_queried_object();
$termid = $queried_object->term_id;
if ( $termid ) {
$term = get_term( $termid );
$return .= $term->name;
} elseif ( is_singular( CPT_PROJECT ) || is_singular( DO_COMMUNITY_CPT ) ) {
$return .= get_the_title( $post->ID );
} else {
//
}
}
return $return;
}
//========================================================================================================
/**
* Show lists with this posts's links to taxonomies DO_COMMUNITYTYPE_CT, DO_COMMUNITYTOPICS_CT, DO_COMMUNITYAUDIENCE_CT
*
* @param $doreturn
*
*
* @return string|void
*/
function rhswp_community_single_terms( $doreturn = false, $post_id = 0, $show_dossiers = true, $clickable_links = true ) {
global $post;
$return = '';
$values = '';
if ( ! $post_id ) {
if ( get_the_id() ) {
$post_id = get_the_id();
} else {
return;
}
}
$community_topics = get_the_terms( $post_id, DO_COMMUNITYTOPICS_CT );
$community_types = get_the_terms( $post_id, DO_COMMUNITYTYPE_CT );
$community_audiences = get_the_terms( $post_id, DO_COMMUNITYAUDIENCE_CT );
$community_overheidslagen = get_the_terms( $post_id, DO_COMMUNITYBESTUURSLAAG_CT );
$community_tags = get_the_terms( $post_id, 'post_tag' );
// toon aan welk onderwerp deze community is gekoppeld
if ( $community_topics && ! is_wp_error( $community_topics ) ) :
$labels = '<dd>';
foreach ( $community_topics as $term ) {
if ( $clickable_links ) {
$labels .= '<a href="' . get_term_link( $term->term_id ) . '">' . $term->name . '</a>';
} else {
$labels .= $term->name;
}
if ( next( $community_topics ) ) {
$labels .= ', ';
}
}
$labels .= '</dd>';
if ( $labels ) {
$values .= '<dt>' . _x( 'Thema', 'Titel in filter', 'wp-rijkshuisstijl' ) . ': </dt>';
$values .= $labels;
}
endif;
// toon aan welk type deze community is gekoppeld
if ( $community_types && ! is_wp_error( $community_types ) ) :
$labels = '<dd>';
foreach ( $community_types as $term ) {
if ( $clickable_links ) {
$labels .= '<a href="' . get_term_link( $term->term_id ) . '">' . $term->name . '</a>';
} else {
$labels .= $term->name;
}
if ( next( $community_types ) ) {
$labels .= ', ';
}
}
$labels .= '</dd>';
if ( $labels ) {
$values .= '<dt>' . _x( 'Type community', 'Titel in filter', 'wp-rijkshuisstijl' ) . ': </dt>';
$values .= $labels;
}
endif;
// toon aan welk doelgroep deze community is gekoppeld
if ( $community_audiences && ! is_wp_error( $community_audiences ) ) :
$labels = '<dd>';
foreach ( $community_audiences as $term ) {
if ( $clickable_links ) {
$labels .= '<a href="' . get_term_link( $term->term_id ) . '">' . $term->name . '</a>';
} else {
$labels .= $term->name;
}
if ( next( $community_audiences ) ) {
$labels .= ', ';
}
}
$labels .= '</dd>';
if ( $labels ) {
$values .= '<dt>' . _x( 'Type professional', 'Titel in filter', 'wp-rijkshuisstijl' ) . ': </dt>';
$values .= $labels;
}
endif;
// toon aan welk doelgroep deze community is gekoppeld
if ( $community_overheidslagen && ! is_wp_error( $community_overheidslagen ) ) :
$labels = '<dd>';
foreach ( $community_overheidslagen as $term ) {
if ( $clickable_links ) {
$labels .= '<a href="' . get_term_link( $term->term_id ) . '">' . $term->name . '</a>';
} else {
$labels .= $term->name;
}
if ( next( $community_overheidslagen ) ) {
$labels .= ', ';
}
}
$labels .= '</dd>';
if ( $labels ) {
$values .= '<dt>' . _x( 'Type organisatie', 'Titel in filter', 'wp-rijkshuisstijl' ) . ': </dt>';
$values .= $labels;
}
endif;
if ( $show_dossiers ) {
if ( has_term( '', RHSWP_CT_DOSSIER, $post->ID ) ) {
// get dossier terms and their links
$terms = get_the_terms( $post->ID, RHSWP_CT_DOSSIER );
if ( $terms && ! is_wp_error( $terms ) ) {
$labels = '<dd>';
foreach ( $terms as $term ) {
if ( $clickable_links ) {
$labels .= '<a href="';
if ( function_exists( 'rhswp_get_pagelink_for_dossier' ) ) {
$labels .= rhswp_get_pagelink_for_dossier( $term );
} else {
$labels .= get_term_link( $term->term_id, RHSWP_CT_DOSSIER );
}
$labels .= '">' . $term->name . '</a>';
} else {
$labels .= $term->name;
}
if ( next( $terms ) ) {
$labels .= ', ';
}
}
$labels .= '</dd>';
if ( $labels ) {
$values .= '<dt>' . _n( 'Onderwerp', 'Onderwerpen', count( $terms ), 'wp-rijkshuisstijl' ) . ': </dt>';
$values .= $labels;
}
}
}
}
if ( $values ) {
$return = '<dl class="community">';
$return .= $values;
$return .= '</dl>';
}
if ( $doreturn ) {
return $return;
} else {
echo $return;
}
}
//========================================================================================================
function rhswp_community_get_terms_list( $args ) {
global $post;
$return = '';
$defaults = array(
'ID' => 0,
'title' => '',
'type' => 'div', // 'div' or 'details'
'container_id' => 0,
'is_open' => 0,
'cssclass' => 0,
'description' => '',
'before_title' => '<h2>',
'after_title' => '</h2>',
'echo' => false
);
$args = wp_parse_args( $args, $defaults );
if ( is_singular( DO_COMMUNITY_CPT ) ) {
$make_checkboxes = 1;
} else {
$make_checkboxes = 0;
}
$args2 = array(
'echo' => false,
'exclude' => $args['ID'],
'hide_empty' => false,
'make_checkboxes' => $make_checkboxes,
);
$args2['taxonomy'] = DO_COMMUNITYTYPE_CT;
$args2['title'] = _n( 'Type community', 'Types community', 2, 'wp-rijkshuisstijl' );
$community_types = ictuwp_communityfilter_list( $args2 );
$args2['taxonomy'] = DO_COMMUNITYTOPICS_CT;
$args2['title'] = _n( 'Onderwerp community', 'Onderwerpen community', 2, 'wp-rijkshuisstijl' );
$community_topics = ictuwp_communityfilter_list( $args2 );
$args2['taxonomy'] = DO_COMMUNITYAUDIENCE_CT;
$args2['title'] = _n( 'Doelgroep', 'Doelgroepen', 2, 'wp-rijkshuisstijl' );
$community_audiences = ictuwp_communityfilter_list( $args2 );
$args2['taxonomy'] = DO_COMMUNITYBESTUURSLAAG_CT;
$args2['title'] = _n( 'Bestuurslaag', 'Overheidslagen', 2, 'wp-rijkshuisstijl' );
$community_overheidslagen = ictuwp_communityfilter_list( $args2 );
if ( $community_types || $community_topics || $community_audiences || $community_overheidslagen ) {
$return .= '<div class="fieldsets">';
$return .= $community_topics;
$return .= $community_types;
$return .= $community_audiences;
$return .= $community_overheidslagen;
$return .= '</div>';
} else {
$return .= '<p>' . _x( 'We konden geen lijst met filters maken.', 'warning', 'wp-rijkshuisstijl' ) . '</p>';
}
return $return;
}
//========================================================================================================
function rhswp_community_get_filter_form( $args ) {
$defaults = array(
'ID' => 0,
'title' => '',
'type' => 'div', // 'div' or 'details'
'container_id' => 'widget_community_filter',
'is_open' => 0,
'cssclass' => 0,
'description' => '',
'input_label' => _x( 'Zoek een community', 'label keyword veld', 'wp-rijkshuisstijl' ),
'button_label' => _x( 'Zoeken', 'label input', 'wp-rijkshuisstijl' ),
'placeholder' => _x( '[zoekterm voor community]', 'placeholder input', 'wp-rijkshuisstijl' ),
'before_title' => '<legend>',
'after_title' => '</legend>',
'echo' => false
);
$args = wp_parse_args( $args, $defaults );
$title = '';
$description = '';
$thepage = get_theme_mod( 'customizer_community_pageid_overview' );
$return = '';
$attr_id = '';
$attr_classes = '';
$container_tag_start = '';
$container_tag_end = '';
$title = '';
$description = '';
if ( $args['container_id'] ) {
$attr_id = $args['container_id'];
}
if ( $args['cssclass'] ) {
$attr_classes = ' class="' . $args['cssclass'] . '"';
}
if ( isset( $_GET['community_search_string'] ) ) {
$community_search_string = sanitize_text_field( $_GET['community_search_string'] );
} else {
$community_search_string = '';
}
if ( $args['title'] ) {
$title .= $args['before_title'] . $args['title'] . $args['after_title'];
$container_tag_start = '<fieldset>';
$container_tag_end = '</fieldset>';
}
if ( $args['description'] ) {
$description .= '<p>' . $args['description'] . '</p>';
}
$return .= '<form id="' . $attr_id . '"' . $attr_classes . ' action="' . get_permalink( $thepage ) . '" method="get">';
$return .= $container_tag_start;
$return .= $title;
$return .= $description;
$return .= '<div class="submit-buttons">';
$return .= '<label for="community_search_string">' . $args['input_label'] . '</label>';
$return .= '<input type="search" id="community_search_string" name="community_search_string" value="' . $community_search_string . '" placeholder="' . $args['placeholder'] . '">';
$return .= '<button type="submit" id="widget_community_filter-submit">' . $args['button_label'] . '</button>';
$return .= '</div>';
$return .= '</form>';
$return .= $container_tag_end;
if ( $return ) {
return $return;
} else {
return false;
}
}
//========================================================================================================
function ictuwp_community_get_latest_list( $argslist ) {
$default_args = array(
'max_items' => 10,
'max_age' => 180,
'overview_link' => '',
'css_class_ul' => 'communities communities-latest',
'date_format' => 'j F'
);
$return = '';
$args = wp_parse_args( $argslist, $default_args );
$date_after = date( 'Y-m-d', strtotime( ' - ' . $args['max_age'] . ' days' ) );
$argscount = array(
'post_type' => DO_COMMUNITY_CPT,
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC',
'date_query' => array( 'after' => $date_after ),
'posts_per_page' => $args['max_items'],
);
// Assign predefined $args to your query
$community_list = new WP_query();
$community_list->query( $argscount );
if ( $community_list->have_posts() ) {
if ( isset( $args['css_class_ul'] ) ) {
$return .= '<ul class="' . $args['css_class_ul'] . '">';
} else {
$return .= '<ul>';
}
while ( $community_list->have_posts() ) : $community_list->the_post();
$the_id = get_the_id();
$return .= '<li><a href="' . get_permalink( $the_id ) . '">' . get_the_title( $the_id ) . '</a></li>';
endwhile;
$return .= '</ul>';
$overview_link = $args['overview_link'];
if ( isset( $overview_link['url'] ) && isset( $overview_link['title'] ) ) {
$return .= '<p class="more"><a href="' . $overview_link['url'] . '">' . $overview_link['title'] . '</a></p>';
}
}
wp_reset_query();
return $return;
}
//========================================================================================================
function ictuwp_communityfilter_list( $args_in = array() ) {
$return = '';
$defaults = array(
'taxonomy' => 'category',
'title' => '',
'echo' => false,
'exclude' => false,
'hide_empty' => true,
'make_checkboxes' => true,
'header_tag' => 'h3',
'show_counter' => false,
'title_li' => '',
'css_class_ul' => '',
);
$args = wp_parse_args( $args_in, $defaults );
if ( taxonomy_exists( $args['taxonomy'] ) ) {
$args_terms = array(
'taxonomy' => $args['taxonomy'],
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => ( $args['hide_empty'] ? true : false ),
'ignore_custom_sort' => true,
'echo' => 0,
'hierarchical' => true,
);
if ( $args['exclude'] ) {
// do not include this term in the list
$args_terms['exclude'] = $args['exclude'];
$args_terms['hide_empty'] = true;
}
if ( isset( $args['show_counter'] ) ) {
$args_terms['count'] = true;
}
$terms = get_terms( $args_terms );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
if ( $args['make_checkboxes'] ) {
$return .= '<fieldset class="taxonomy ' . $args['taxonomy'] . '">';
if ( $args['title'] ) {
$return .= '<legend>' . $args['title'] . '</legend>';
}
foreach ( $terms as $term ) {
$id = $term->slug . '_' . $term->term_id;
$checked = '';
$dossierid = isset( $_GET[ $id ] ) ? (int) $_GET[ $id ] : 0; // een dossier
if ( $dossierid === $term->term_id ) {
$checked = ' checked';
}
$return .= '<label for="' . $id . '"><input id="' . $id . '" type="checkbox" name="' . $id . '" value="' . $term->term_id . '"' . $checked . '>' . $term->name . '</label>';
}
$return .= '</fieldset>';
} else {
$return .= '<div class="taxonomy ' . $args['taxonomy'] . '">';
if ( $args['title'] ) {
$return .= '<' . $args['header_tag'] . '>' . $args['title'] . '</' . $args['header_tag'] . '>';
}