Skip to content

Commit 56c49ee

Browse files
committed
Introduce my roles shortcode
1 parent fb2e0f7 commit 56c49ee

2 files changed

Lines changed: 85 additions & 2 deletions

File tree

plugins/bcc-login/includes/class-bcc-login-visibility.php

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ function __construct( BCC_Login_Settings $settings, BCC_Login_Client $client, BC
6363
add_shortcode( 'tags_for_queried_target_groups', array( $this, 'tags_for_queried_target_groups' ) );
6464
add_shortcode( 'get_bcc_group_name', array( $this, 'get_bcc_group_name_by_id' ) );
6565
add_shortcode( 'get_number_of_user_groups', array( $this, 'get_number_of_user_groups' ) );
66+
add_shortcode( 'bcc_my_roles', array( $this, 'bcc_my_roles' ) );
6667

6768
add_action( 'add_meta_boxes', array( $this, 'add_visibility_meta_box_to_attachments' ) );
6869
add_action( 'attachment_updated', array( $this, 'save_visibility_to_attachments' ), 10, 3 );
@@ -386,7 +387,6 @@ function on_block_editor_assets() {
386387
);
387388

388389
if (!empty($this->_settings->site_groups) ) {
389-
390390
wp_add_inline_script(
391391
$script_handle,
392392
'var siteGroups = ' . json_encode($this->_coreapi->get_translated_site_groups()),
@@ -401,7 +401,6 @@ function on_block_editor_assets() {
401401
}
402402

403403
if (!empty($this->_settings->site_group_tags) ) {
404-
405404
wp_add_inline_script(
406405
$script_handle,
407406
'var siteGroupTags = ' . json_encode($this->_settings->site_group_tags),
@@ -697,6 +696,52 @@ public function get_number_of_user_groups() {
697696
return count($this->get_user_bcc_filtering_groups_list());
698697
}
699698

699+
public function bcc_my_roles() {
700+
$user_groups = $this->get_current_user_groups();
701+
$central_groups = $this->_settings->filtering_groups;
702+
$site_groups = $this->_coreapi->get_translated_site_groups();
703+
$central_user_groups = array();
704+
705+
foreach ($site_groups as $site_group) {
706+
if (in_array($site_group->uid, $user_groups)
707+
&& in_array($site_group->uid, $central_groups)
708+
) {
709+
$central_user_groups[] = $site_group;
710+
}
711+
}
712+
713+
// Sort by name
714+
usort($central_user_groups, fn($a, $b) => $a->name <=> $b->name);
715+
716+
if (empty($central_user_groups)) {
717+
return '';
718+
}
719+
720+
$html = '<div id="my-roles-widget">';
721+
722+
$html .= '<section class="roles-list">';
723+
$html .= '<span>' . (count($central_user_groups) == 1
724+
? __('Min rolle:', 'bcc-login')
725+
: __('Mine roller:', 'bcc-login')
726+
) . '</span>';
727+
$html .= '<div class="my-roles-tags">';
728+
729+
foreach ($central_user_groups as $group) {
730+
$html .= '<a class="bcc-badge bcc-badge-sm bcc-badge-custom" href="?target-groups[]=' . $group->uid . '"><i class="material-symbols-rounded">info</i><span>' . $group->name . '</span></a>';
731+
}
732+
733+
$html .= '</div>';
734+
$html .= '</section>';
735+
736+
$html .= '<section class="local-church-roles">';
737+
$html .= '<a href="https://members.bcc.no/roles" target="_blank">' . __('Roller i min lokalmenighet', 'bcc-login') . '</a>';
738+
$html .= '</section>';
739+
740+
$html .= '</div>';
741+
742+
return $html;
743+
}
744+
700745
/**
701746
* Checks the `bccLoginVisibility` attribute and hides the block if
702747
* the current users shouldn't be allowed to see it.

plugins/bcc-login/src/filtering.css

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
#my-roles-widget {
2+
display: flex;
3+
flex-direction: column;
4+
gap: 0.5rem;
5+
}
6+
7+
.roles-list {
8+
display: flex;
9+
flex-wrap: wrap;
10+
gap: 1rem;
11+
}
12+
13+
.my-roles-tags {
14+
display: flex;
15+
flex-wrap: wrap;
16+
gap: 0.5rem;
17+
}
18+
19+
.my-roles-tags .bcc-badge-custom {
20+
border-color: var(--brand-50);
21+
background-color: var(--brand-50);
22+
color: var(--brand-500);
23+
padding: 0.25rem 0.35rem;
24+
}
25+
26+
.my-roles-tags .bcc-badge-custom:hover {
27+
background-color: var(--brand-500);
28+
color: #fff;
29+
}
30+
131
.bcc-filter {
232
position: relative;
333
}
@@ -39,6 +69,14 @@ body.no-scroll {
3969
}
4070

4171
@media (max-width: 767px) {
72+
#my-roles-widget {
73+
margin-bottom: 2rem;
74+
}
75+
76+
.roles-list {
77+
gap: 0.25rem;
78+
}
79+
4280
.bcc-filter #bcc-filter-groups {
4381
position: fixed;
4482
inset: 0;

0 commit comments

Comments
 (0)