/
functions.php
1683 lines (1500 loc) · 51 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
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
/**
* Common functions
*
* @since 3.0.0
* @version 10.0.0
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
/**
* This function looks scarier than it actually is. :)
* Each object loop (activity/members/groups/blogs/forums) contains default
* parameters to show specific information based on the page we are currently
* looking at.
*
* The following function will take into account any cookies set in the JS and
* allow us to override the parameters sent. That way we can change the results
* returned without reloading the page.
*
* By using cookies we can also make sure that user settings are retained
* across page loads.
*
* @since 3.0.0
*
* @param string $query_string Query string for the current request.
* @param string $object Object for cookie.
*
* @return string Query string for the component loops
*/
function bp_nouveau_ajax_querystring( $query_string, $object ) {
if ( empty( $object ) ) {
return '';
}
// Default query
$post_query = array(
'filter' => '',
'scope' => 'all',
'page' => 1,
'search_terms' => '',
'extras' => '',
);
if ( ! empty( $_POST ) ) {
$post_query = bp_parse_args(
$_POST,
$post_query,
'nouveau_ajax_querystring'
);
// Make sure to transport the scope, filter etc.. in HeartBeat Requests
if ( ! empty( $post_query['data']['bp_heartbeat'] ) ) {
$bp_heartbeat = $post_query['data']['bp_heartbeat'];
// Remove heartbeat specific vars
$post_query = array_diff_key(
bp_parse_args(
$bp_heartbeat,
$post_query,
'nouveau_ajax_querystring_heartbeat'
),
array(
'data' => false,
'interval' => false,
'_nonce' => false,
'action' => false,
'screen_id' => false,
'has_focus' => false,
)
);
}
}
// Init the query string
$qs = array();
// Activity stream filtering on action.
if ( ! empty( $post_query['filter'] ) && '-1' !== $post_query['filter'] ) {
if ( 'notifications' === $object ) {
$qs[] = 'component_action=' . $post_query['filter'];
} else {
$qs[] = 'type=' . $post_query['filter'];
$qs[] = 'action=' . $post_query['filter'];
}
}
// Sort the notifications if needed
if ( ! empty( $post_query['extras'] ) && 'notifications' === $object ) {
$qs[] = 'sort_order=' . $post_query['extras'];
}
if ( 'personal' === $post_query['scope'] ) {
$user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
$qs[] = 'user_id=' . $user_id;
}
// Activity stream scope only on activity directory.
if ( 'all' !== $post_query['scope'] && ! bp_displayed_user_id() && ! bp_is_single_item() ) {
$qs[] = 'scope=' . $post_query['scope'];
}
// If page have been passed via the AJAX post request, use those.
if ( '-1' != $post_query['page'] ) {
$qs[] = 'page=' . absint( $post_query['page'] );
}
// Excludes activity just posted and avoids duplicate ids.
if ( ! empty( $post_query['exclude_just_posted'] ) ) {
$just_posted = wp_parse_id_list( $post_query['exclude_just_posted'] );
$qs[] = 'exclude=' . implode( ',', $just_posted );
}
// To get newest activities.
if ( ! empty( $post_query['offset'] ) ) {
$qs[] = 'offset=' . intval( $post_query['offset'] );
}
$object_search_text = bp_get_search_default_text( $object );
if ( ! empty( $post_query['search_terms'] ) && $object_search_text != $post_query['search_terms'] && 'false' != $post_query['search_terms'] && 'undefined' != $post_query['search_terms'] ) {
$qs[] = 'search_terms=' . urlencode( $_POST['search_terms'] );
}
// Specific to messages
if ( 'messages' === $object ) {
if ( ! empty( $post_query['box'] ) ) {
$qs[] = 'box=' . $post_query['box'];
}
}
// Single activity.
if ( bp_is_single_activity() && 'activity' === $object ) {
$qs = array(
'display_comments=threaded',
'show_hidden=true',
'include=' . bp_current_action(),
);
}
// Now pass the querystring to override default values.
$query_string = empty( $qs ) ? '' : join( '&', (array) $qs );
// List the variables for the filter
list( $filter, $scope, $page, $search_terms, $extras ) = array_values( $post_query );
/**
* Filters the AJAX query string for the component loops.
*
* @since 3.0.0
*
* @param string $query_string The query string we are working with.
* @param string $object The type of page we are on.
* @param string $filter The current object filter.
* @param string $scope The current object scope.
* @param string $page The current object page.
* @param string $search_terms The current object search terms.
* @param string $extras The current object extras.
*/
return apply_filters( 'bp_nouveau_ajax_querystring', $query_string, $object, $filter, $scope, $page, $search_terms, $extras );
}
/**
* @since 3.0.0
*
* @return string
*/
function bp_nouveau_ajax_button( $output = '', $button = null, $before = '', $after = '', $r = array() ) {
if ( empty( $button->component ) ) {
return $output;
}
// Custom data attribute.
$r['button_attr']['data-bp-btn-action'] = $button->id;
$reset_ids = array(
'member_friendship' => true,
'group_membership' => true,
);
if ( ! empty( $reset_ids[ $button->id ] ) ) {
$parse_class = array_map( 'sanitize_html_class', explode( ' ', $r['button_attr']['class'] ) );
if ( false === $parse_class ) {
return $output;
}
$find_id = array_intersect( $parse_class, array(
'pending_friend',
'is_friend',
'not_friends',
'leave-group',
'join-group',
'accept-invite',
'membership-requested',
'request-membership',
) );
if ( 1 !== count( $find_id ) ) {
return $output;
}
$data_attribute = reset( $find_id );
if ( 'pending_friend' === $data_attribute ) {
$data_attribute = str_replace( '_friend', '', $data_attribute );
} elseif ( 'group_membership' === $button->id ) {
$data_attribute = str_replace( '-', '_', $data_attribute );
}
$r['button_attr']['data-bp-btn-action'] = $data_attribute;
}
// Re-render the button with our custom data attribute.
$output = new BP_Core_HTML_Element( array(
'element' => $r['button_element'],
'attr' => $r['button_attr'],
'inner_html' => ! empty( $r['link_text'] ) ? $r['link_text'] : ''
) );
$output = $output->contents();
// Add span bp-screen-reader-text class
return $before . $output . $after;
}
/**
* Output HTML content into a wrapper.
*
* @since 3.0.0
*
* @param array $args {
* Optional arguments.
*
* @type string $container String HTML container type that should wrap
* the items as a group: 'div', 'ul', or 'p'. Required.
* @type string $container_id The group wrapping container element ID
* @type string $container_classes The group wrapping container elements class
* @type string $output The HTML to output. Required.
* }
*/
function bp_nouveau_wrapper( $args = array() ) {
/**
* Classes need to be determined & set by component to a certain degree.
*
* Check the component to find a default container_class based on the component ID to add.
* We need to to this because bp_current_component() is using the component slugs which can differ
* from the component ID.
*/
$current_component_id = bp_core_get_active_components( array( 'slug' => bp_current_component() ) );
if ( $current_component_id && 1 === count( $current_component_id ) ) {
$current_component_id = reset( $current_component_id );
} else {
$current_component_id = bp_current_component();
}
$current_component_class = $current_component_id . '-meta';
if ( bp_is_group_activity() ) {
$generic_class = ' activity-meta ';
} else {
$generic_class = '';
}
$r = bp_parse_args(
$args,
array(
'container' => 'div',
'container_id' => '',
'container_classes' => array( $generic_class, $current_component_class ),
'output' => '',
),
'nouveau_wrapper'
);
$valid_containers = array(
'div' => true,
'ul' => true,
'ol' => true,
'span' => true,
'p' => true,
);
// Actually merge some classes defaults and $args
// @todo This is temp, we need certain classes but maybe improve this approach.
$default_classes = array( 'action' );
$r['container_classes'] = array_merge( $r['container_classes'], $default_classes );
if ( empty( $r['container'] ) || ! isset( $valid_containers[ $r['container'] ] ) || empty( $r['output'] ) ) {
return;
}
$container = $r['container'];
$container_id = '';
$container_classes = '';
$output = $r['output'];
if ( ! empty( $r['container_id'] ) ) {
$container_id = ' id="' . esc_attr( $r['container_id'] ) . '"';
}
if ( ! empty( $r['container_classes'] ) && is_array( $r['container_classes'] ) ) {
$container_classes = ' class="' . join( ' ', array_map( 'sanitize_html_class', $r['container_classes'] ) ) . '"';
}
// Print the wrapper and its content.
printf( '<%1$s%2$s%3$s>%4$s</%1$s>', $container, $container_id, $container_classes, $output );
}
/**
* Register the 2 sidebars for the Group & User default front page
*
* @since 3.0.0
*/
function bp_nouveau_register_sidebars() {
$default_fronts = bp_nouveau_get_appearance_settings();
$default_user_front = 0;
$default_group_front = 0;
$is_active_groups = bp_is_active( 'groups' );
if ( isset( $default_fronts['user_front_page'] ) ) {
$default_user_front = $default_fronts['user_front_page'];
}
if ( $is_active_groups ) {
if ( isset( $default_fronts['group_front_page'] ) ) {
$default_group_front = $default_fronts['group_front_page'];
}
}
// Setting the front template happens too early, so we need this!
if ( is_customize_preview() ) {
$default_user_front = bp_nouveau_get_temporary_setting( 'user_front_page', $default_user_front );
if ( $is_active_groups ) {
$default_group_front = bp_nouveau_get_temporary_setting( 'group_front_page', $default_group_front );
}
}
$sidebars = array();
if ( $default_user_front ) {
$sidebars[] = array(
'name' => __( 'BuddyPress Member\'s Home', 'buddypress' ),
'id' => 'sidebar-buddypress-members',
'description' => __( 'Add widgets here to appear in the front page of each member of your community.', 'buddypress' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
);
}
if ( $default_group_front ) {
$sidebars[] = array(
'name' => __( 'BuddyPress Group\'s Home', 'buddypress' ),
'id' => 'sidebar-buddypress-groups',
'description' => __( 'Add widgets here to appear in the front page of each group of your community.', 'buddypress' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
);
}
if ( empty( $sidebars ) ) {
return;
}
// Register the sidebars if needed.
foreach ( $sidebars as $sidebar ) {
register_sidebar( $sidebar );
}
}
/**
* @since 3.0.0
*
* @return bool
*/
function bp_nouveau_is_object_nav_in_sidebar() {
return bp_is_widget_block_active( 'bp/primary-nav', 'bp_nouveau_sidebar_object_nav_widget' );
}
/**
* @since 3.0.0
*
* @return bool
*/
function bp_nouveau_current_user_can( $capability = '' ) {
/**
* Filters whether or not the current user can perform an action for BuddyPress Nouveau.
*
* @since 3.0.0
*
* @param bool $value Whether or not the user is logged in.
* @param string $capability Current capability being checked.
* @param int $value Current logged in user ID.
*/
return apply_filters( 'bp_nouveau_current_user_can', is_user_logged_in(), $capability, bp_loggedin_user_id() );
}
/**
* Parse an html output to a list of component's directory nav item.
*
* @since 3.0.0
*
* @param string $hook The hook to fire.
* @param string $component The component nav belongs to.
* @param int $position The position of the nav item.
*
* @return array A list of component's dir nav items
*/
function bp_nouveau_parse_hooked_dir_nav( $hook = '', $component = '', $position = 99 ) {
$extra_nav_items = array();
if ( empty( $hook ) || empty( $component ) || ! has_action( $hook ) ) {
return $extra_nav_items;
}
// Get the hook output.
ob_start();
/**
* Fires at the start of the output for `bp_nouveau_parse_hooked_dir_nav()`.
*
* This hook is variable and depends on the hook parameter passed in.
*
* @since 3.0.0
*/
do_action( $hook );
$output = ob_get_clean();
if ( empty( $output ) ) {
return $extra_nav_items;
}
preg_match_all( "/<li\sid=\"{$component}\-(.*)\"[^>]*>/siU", $output, $lis );
if ( empty( $lis[1] ) ) {
return $extra_nav_items;
}
$extra_nav_items = array_fill_keys( $lis[1], array( 'component' => $component, 'position' => $position ) );
preg_match_all( '/<a\s[^>]*>(.*)<\/a>/siU', $output, $as );
if ( ! empty( $as[0] ) ) {
foreach ( $as[0] as $ka => $a ) {
$extra_nav_items[ $lis[1][ $ka ] ]['slug'] = $lis[1][ $ka ];
$extra_nav_items[ $lis[1][ $ka ] ]['text'] = $as[1][ $ka ];
preg_match_all( '/([\w\-]+)=([^"\'> ]+|([\'"]?)(?:[^\3]|\3+)+?\3)/', $a, $attrs );
if ( ! empty( $attrs[1] ) ) {
foreach ( $attrs[1] as $katt => $att ) {
if ( 'href' === $att ) {
$extra_nav_items[ $lis[1][ $ka ] ]['link'] = trim( $attrs[2][ $katt ], '"' );
} else {
$extra_nav_items[ $lis[1][ $ka ] ][ $att ] = trim( $attrs[2][ $katt ], '"' );
}
}
}
}
}
if ( ! empty( $as[1] ) ) {
foreach ( $as[1] as $ks => $s ) {
preg_match_all( '/<span>(.*)<\/span>/siU', $s, $spans );
if ( empty( $spans[0] ) ) {
$extra_nav_items[ $lis[1][ $ks ] ]['count'] = false;
} elseif ( ! empty( $spans[1][0] ) ) {
$extra_nav_items[ $lis[1][ $ks ] ]['count'] = (int) $spans[1][0];
} else {
$extra_nav_items[ $lis[1][ $ks ] ]['count'] = '';
}
}
}
return $extra_nav_items;
}
/**
* Run specific "select filter" hooks to catch the options and build an array out of them
*
* @since 3.0.0
*
* @param string $hook
* @param array $filters
*
* @return array
*/
function bp_nouveau_parse_hooked_options( $hook = '', $filters = array() ) {
if ( empty( $hook ) ) {
return $filters;
}
ob_start();
/**
* Fires at the start of the output for `bp_nouveau_parse_hooked_options()`.
*
* This hook is variable and depends on the hook parameter passed in.
*
* @since 3.0.0
*/
do_action( $hook );
$output = ob_get_clean();
preg_match_all( '/<option value="(.*?)"\s*>(.*?)<\/option>/', $output, $matches );
if ( ! empty( $matches[1] ) && ! empty( $matches[2] ) ) {
foreach ( $matches[1] as $ik => $key_action ) {
if ( ! empty( $matches[2][ $ik ] ) && ! isset( $filters[ $key_action ] ) ) {
$filters[ $key_action ] = $matches[2][ $ik ];
}
}
}
return $filters;
}
/**
* Get Dropdawn filters for the current component of the one passed in params
*
* @since 3.0.0
*
* @param string $context 'directory', 'user' or 'group'
* @param string $component The BuddyPress component ID
*
* @return array the dropdown filters
*/
function bp_nouveau_get_component_filters( $context = '', $component = '' ) {
$filters = array();
if ( empty( $context ) ) {
if ( bp_is_user() ) {
$context = 'user';
} elseif ( bp_is_group() ) {
$context = 'group';
// Defaults to directory
} else {
$context = 'directory';
}
}
if ( empty( $component ) ) {
if ( 'user' === $context ) {
$component = bp_core_get_active_components( array( 'slug' => bp_current_component() ) );
$component = reset( $component );
if ( 'friends' === $component ) {
$context = 'friends';
$component = 'members';
}
} elseif ( 'group' === $context && bp_is_group_activity() ) {
$component = 'activity';
} elseif ( 'group' === $context && bp_is_group_members() ) {
$component = 'members';
} else {
$component = bp_current_component();
}
}
if ( ! bp_is_active( $component ) ) {
return $filters;
}
if ( 'members' === $component ) {
$filters = bp_nouveau_get_members_filters( $context );
} elseif ( 'activity' === $component ) {
$filters = bp_nouveau_get_activity_filters();
// Specific case for the activity dropdown
$filters = array_merge( array( '-1' => __( '— Everything —', 'buddypress' ) ), $filters );
} elseif ( 'groups' === $component ) {
$filters = bp_nouveau_get_groups_filters( $context );
} elseif ( 'blogs' === $component ) {
$filters = bp_nouveau_get_blogs_filters( $context );
}
return $filters;
}
/**
* When previewing make sure to get the temporary setting of the customizer.
* This is necessary when we need to get these very early.
*
* @since 3.0.0
*
* @param string $option the index of the setting to get.
* @param mixed $retval the value to use as default.
*
* @return mixed The value for the requested option.
*/
function bp_nouveau_get_temporary_setting( $option = '', $retval = false ) {
if ( empty( $option ) || ! isset( $_POST['customized'] ) ) {
return $retval;
}
$temporary_setting = wp_unslash( $_POST['customized'] );
if ( ! is_array( $temporary_setting ) ) {
$temporary_setting = json_decode( $temporary_setting, true );
}
// This is used to transport the customizer settings into Ajax requests.
if ( 'any' === $option ) {
$retval = array();
foreach ( $temporary_setting as $key => $setting ) {
if ( 0 !== strpos( $key, 'bp_nouveau_appearance' ) ) {
continue;
}
$k = str_replace( array( '[', ']' ), array( '_', '' ), $key );
$retval[ $k ] = $setting;
}
// Used when it's an early regular request
} elseif ( isset( $temporary_setting[ 'bp_nouveau_appearance[' . $option . ']' ] ) ) {
$retval = $temporary_setting[ 'bp_nouveau_appearance[' . $option . ']' ];
// Used when it's an ajax request
} elseif ( isset( $_POST['customized'][ 'bp_nouveau_appearance_' . $option ] ) ) {
$retval = $_POST['customized'][ 'bp_nouveau_appearance_' . $option ];
}
return $retval;
}
/**
* Get the BP Nouveau Appearance settings.
*
* @since 3.0.0
*
* @param string $option Leave empty to get all settings, specify a value for a specific one.
* @param mixed An array of settings, the value of the requested setting.
*
* @return array|false|mixed
*/
function bp_nouveau_get_appearance_settings( $option = '' ) {
$default_args = array(
'avatar_style' => 0,
'global_alignment' => 'alignwide',
'user_front_page' => 0,
'user_front_bio' => 0,
'user_nav_display' => 0, // O is default (horizontally). 1 is vertically.
'user_nav_tabs' => 0,
'user_subnav_tabs' => 0,
'user_nav_order' => array(),
'members_layout' => 1,
'members_dir_tabs' => 0,
'members_dir_layout' => 0,
);
if ( bp_is_active( 'friends' ) ) {
$default_args['members_friends_layout'] = 1;
}
if ( bp_is_active( 'activity' ) ) {
$default_args['activity_dir_layout'] = 0;
$default_args['activity_dir_tabs'] = 0; // default = no tabs
}
if ( bp_is_active( 'groups' ) ) {
$default_args = array_merge( $default_args, array(
'group_front_page' => 0,
'group_front_boxes' => 0,
'group_front_description' => 0,
'group_nav_display' => 0, // O is default (horizontally). 1 is vertically.
'group_nav_order' => array(),
'group_nav_tabs' => 0,
'group_subnav_tabs' => 0,
'groups_create_tabs' => 1,
'groups_layout' => 1,
'members_group_layout' => 1,
'groups_dir_layout' => 0,
'groups_dir_tabs' => 0,
) );
}
if ( is_multisite() && bp_is_active( 'blogs' ) ) {
$default_args = array_merge( $default_args, array(
'sites_dir_layout' => 0,
'sites_dir_tabs' => 0,
) );
}
$settings = bp_parse_args(
bp_get_option( 'bp_nouveau_appearance', array() ),
$default_args,
'nouveau_appearance_settings'
);
if ( ! empty( $option ) ) {
if ( isset( $settings[ $option ] ) ) {
return $settings[ $option ];
} else {
return false;
}
}
return $settings;
}
/**
* Returns the choices for the Layout option of the customizer
* or the list of corresponding css classes.
*
* @since 3.0.0
*
* @param string $type 'option' to get the labels, 'classes' to get the classes
*
* @return array The list of labels or classes preserving keys.
*/
function bp_nouveau_customizer_grid_choices( $type = 'option' ) {
$columns = array(
array( 'key' => '1', 'label' => __( 'One column', 'buddypress' ), 'class' => '' ),
array( 'key' => '2', 'label' => __( 'Two columns', 'buddypress' ), 'class' => 'two' ),
array( 'key' => '3', 'label' => __( 'Three columns', 'buddypress' ), 'class' => 'three' ),
array( 'key' => '4', 'label' => __( 'Four columns', 'buddypress' ), 'class' => 'four' ),
);
if ( 'option' === $type ) {
return wp_list_pluck( $columns, 'label', 'key' );
}
return wp_list_pluck( $columns, 'class', 'key' );
}
/**
* Sanitize a list of slugs to save it as an array
*
* @since 3.0.0
*
* @param string $option A comma separated list of nav items slugs.
*
* @return array An array of nav items slugs.
*/
function bp_nouveau_sanitize_nav_order( $option = '' ) {
$option = explode( ',', $option );
return array_map( 'sanitize_key', $option );
}
/**
* BP Nouveau's callback for the cover image feature.
*
* @since 3.0.0
*
* @param array $params Optional. The current component's feature parameters.
*
* @return string
*/
function bp_nouveau_theme_cover_image( $params = array() ) {
if ( empty( $params ) ) {
return '';
}
// Avatar height - padding - 1/2 avatar height.
$avatar_offset = $params['height'] - 5 - round( (int) bp_core_avatar_full_height() / 2 );
// Header content offset + spacing.
$top_offset = bp_core_avatar_full_height() - 10;
$left_offset = bp_core_avatar_full_width() + 20;
$cover_image = isset( $params['cover_image'] ) ? 'background-image: url( ' . $params['cover_image'] . ' );' : '';
$hide_avatar_style = '';
// Adjust the cover image header, in case avatars are completely disabled.
if ( ! buddypress()->avatar->show_avatars ) {
$hide_avatar_style = '
#buddypress #item-header-cover-image #item-header-avatar {
display: none;
}
';
if ( bp_is_user() ) {
$hide_avatar_style = '
#buddypress #item-header-cover-image #item-header-avatar a {
display: block;
height: ' . $top_offset . 'px;
margin: 0 15px 19px 0;
}
#buddypress div#item-header #item-header-cover-image #item-header-content {
margin-left:auto;
}
';
}
}
return '
/* Cover image */
#buddypress #item-header-cover-image {
min-height: ' . $params['height'] . 'px;
margin-bottom: 1em;
}
#buddypress #item-header-cover-image:after {
clear: both;
content: "";
display: table;
}
#buddypress #header-cover-image {
height: ' . $params['height'] . 'px;
' . $cover_image . '
}
#buddypress #create-group-form #header-cover-image {
position: relative;
margin: 1em 0;
}
.bp-user #buddypress #item-header {
padding-top: 0;
}
#buddypress #item-header-cover-image #item-header-avatar {
margin-top: ' . $avatar_offset . 'px;
float: left;
overflow: visible;
width:auto;
}
#buddypress div#item-header #item-header-cover-image #item-header-content {
clear: both;
float: left;
margin-left: ' . $left_offset . 'px;
margin-top: -' . $top_offset . 'px;
width:auto;
}
body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content,
body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
margin-top: ' . $params['height'] . 'px;
margin-left: 0;
clear: none;
max-width: 50%;
}
body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
padding-top: 20px;
max-width: 20%;
}
' . $hide_avatar_style . '
#buddypress div#item-header-cover-image h2 a,
#buddypress div#item-header-cover-image h2 {
color: #FFF;
text-rendering: optimizelegibility;
text-shadow: 0px 0px 3px rgba( 0, 0, 0, 0.8 );
margin: 0 0 .6em;
font-size:200%;
}
#buddypress #item-header-cover-image #item-header-avatar img.avatar {
border: solid 2px #FFF;
background: rgba( 255, 255, 255, 0.8 );
}
#buddypress #item-header-cover-image #item-header-avatar a {
border: none;
text-decoration: none;
}
#buddypress #item-header-cover-image #item-buttons {
margin: 0 0 10px;
padding: 0 0 5px;
}
#buddypress #item-header-cover-image #item-buttons:after {
clear: both;
content: "";
display: table;
}
@media screen and (max-width: 782px) {
#buddypress #item-header-cover-image #item-header-avatar,
.bp-user #buddypress #item-header #item-header-cover-image #item-header-avatar,
#buddypress div#item-header #item-header-cover-image #item-header-content {
width:100%;
text-align:center;
}
#buddypress #item-header-cover-image #item-header-avatar a {
display:inline-block;
}
#buddypress #item-header-cover-image #item-header-avatar img {
margin:0;
}
#buddypress div#item-header #item-header-cover-image #item-header-content,
body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content,
body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
margin:0;
}
body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content,
body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
max-width: 100%;
}
#buddypress div#item-header-cover-image h2 a,
#buddypress div#item-header-cover-image h2 {
color: inherit;
text-shadow: none;
margin:25px 0 0;
font-size:200%;
}
#buddypress #item-header-cover-image #item-buttons div {
float:none;
display:inline-block;
}
#buddypress #item-header-cover-image #item-buttons:before {
content:"";
}
#buddypress #item-header-cover-image #item-buttons {
margin: 5px 0;
}
}
';
}
/**
* All user feedback messages are available here
*
* @since 3.0.0
* @since 8.0.0 Adds the 'member-invites-none' feedback.
*
* @param string $feedback_id The ID of the message.
*
* @return string|false The list of parameters for the message
*/
function bp_nouveau_get_user_feedback( $feedback_id = '' ) {
/**
* Filters the BuddyPress Nouveau feedback messages.
*
* Use this filter to add your custom feedback messages.
*
* @since 3.0.0
* @since 8.0.0 Adds the 'member-invites-none' feedback.
*
* @param array $value The list of feedback messages.
*/
$feedback_messages = apply_filters(
'bp_nouveau_feedback_messages',
array(
'registration-disabled' => array(
'type' => 'info',
'message' => __( 'Member registration is currently not allowed.', 'buddypress' ),
'before' => 'bp_before_registration_disabled',
'after' => 'bp_after_registration_disabled'
),
'request-details' => array(
'type' => 'info',
'message' => __( 'Registering for this site is easy. Just fill in the fields below, and we\'ll get a new account set up for you in no time.', 'buddypress' ),
'before' => false,
'after' => false,
),
'completed-confirmation' => array(
'type' => 'info',
'message' => __( 'You have successfully created your account! Please log in using the username and password you have just created.', 'buddypress' ),
'before' => 'bp_before_registration_confirmed',
'after' => 'bp_after_registration_confirmed',
),
'directory-activity-loading' => array(
'type' => 'loading',
'message' => __( 'Loading the community updates. Please wait.', 'buddypress' ),
),
'single-activity-loading' => array(
'type' => 'loading',
'message' => __( 'Loading the update. Please wait.', 'buddypress' ),
),
'activity-loop-none' => array(
'type' => 'info',
'message' => __( 'Sorry, there was no activity found. Please try a different filter.', 'buddypress' ),
),
'blogs-loop-none' => array(
'type' => 'info',
'message' => __( 'Sorry, there were no sites found.', 'buddypress' ),
),
'blogs-no-signup' => array(
'type' => 'info',
'message' => __( 'Site registration is currently disabled.', 'buddypress' ),
),
'directory-blogs-loading' => array(
'type' => 'loading',
'message' => __( 'Loading the sites of the network. Please wait.', 'buddypress' ),
),
'directory-groups-loading' => array(
'type' => 'loading',
'message' => __( 'Loading the groups of the community. Please wait.', 'buddypress' ),
),
'groups-loop-none' => array(
'type' => 'info',
'message' => __( 'Sorry, there were no groups found.', 'buddypress' ),
),
'group-activity-loading' => array(