Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
047bb62
Register selected site groups for translation
cs1m0n Nov 28, 2025
8f27457
Remove post groups from quick edit
cs1m0n Nov 28, 2025
565907f
Remove unused code
cs1m0n Nov 28, 2025
8f07a9f
Introduce tag input component
cs1m0n Nov 28, 2025
18d6177
Improve other bcc login settings
cs1m0n Nov 28, 2025
076c417
Introduce post visibility groups & update group selector component
cs1m0n Nov 28, 2025
a0bcf00
Add logic for groups visibility
cs1m0n Nov 28, 2025
cdcebd6
Add visibility groups to Admin Dashboard
cs1m0n Nov 28, 2025
98f8e46
WPML config to copy values of new created fields to translations
cs1m0n Nov 28, 2025
f250d88
Fix secondary value on group selector
cs1m0n Dec 1, 2025
a3f8610
Refactoring target groups & visibility groups
cs1m0n Dec 2, 2025
57f9ac7
Update site groups list when removing a group tag
cs1m0n Dec 2, 2025
8649864
Add post visibility groups to public visibility logic
cs1m0n Dec 3, 2025
72c32b6
Add emailing condition to notification groups logic
cs1m0n Dec 3, 2025
635f901
Groups variable renaming
cs1m0n Dec 3, 2025
8921105
Show both target groups and visibility groups only for Post Groups
cs1m0n Dec 3, 2025
15bd3d6
Adjust logic for emailing check to string
cs1m0n Dec 3, 2025
7427361
Remove unused GroupsOptions function
cs1m0n Dec 3, 2025
08f95ad
Fix variable names for send email
cs1m0n Dec 3, 2025
7f39314
Fix return type for emailing post meta
cs1m0n Dec 3, 2025
e607d90
Improve spacing for groups settings
cs1m0n Dec 3, 2025
f1ec123
Updated titles for post groups
cs1m0n Dec 3, 2025
344c23d
Remove filtering groups settings & adjust logic
cs1m0n Dec 3, 2025
af3953c
Remove notification groups settings & adjust logic
cs1m0n Dec 3, 2025
8410e01
Send notifications on demand
cs1m0n Dec 4, 2025
f50affd
Replace notification groups logic with target groups & visibility gro…
cs1m0n Dec 5, 2025
7495eff
Send notifications dialog
cs1m0n Dec 9, 2025
a72ee38
Small code improvements
cs1m0n Dec 9, 2025
327e79c
Code review changes + improvements
cs1m0n Dec 9, 2025
a647452
Improve translations tags
cs1m0n Dec 9, 2025
6de1bab
Boolean values for send email variables
cs1m0n Dec 10, 2025
5fde83a
BCC Login localization
cs1m0n Dec 10, 2025
d9862f8
Simplify and generalize groups selector
cs1m0n Dec 10, 2025
0dea032
Fix js errors when editing a page template
cs1m0n Dec 10, 2025
cec6f5b
Update test mode tag
cs1m0n Dec 10, 2025
7d864a1
Don't show Send notifications button for post types not selected for …
cs1m0n Dec 11, 2025
6b3d965
Extra check on rest endpoint for not allowed post types for notificat…
cs1m0n Dec 11, 2025
36fce47
Dispatch tagsChanged event only on group tags changes
cs1m0n Dec 11, 2025
bfc6c6e
Translation for Yes/No buttons on group selector
cs1m0n Dec 11, 2025
8a8cf31
Disable Send button also on auto saving post
cs1m0n Dec 11, 2025
13fa45d
Feedback changes + improvements
cs1m0n Dec 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions plugins/bcc-login/bcc-login.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@
define( 'BCC_LOGIN_PATH', plugin_dir_path( __FILE__ ) );
define( 'BCC_LOGIN_URL', plugin_dir_url( __FILE__ ) );

require_once( 'includes/class-bcc-login-token-utility.php');
require_once( 'includes/class-bcc-login-token-utility.php' );
require_once( 'includes/class-bcc-login-settings.php' );
require_once( 'includes/class-bcc-login-client.php' );
require_once( 'includes/class-bcc-login-endpoints.php' );
require_once( 'includes/class-bcc-login-visibility.php' );
require_once( 'includes/class-bcc-login-users.php' );
require_once( 'includes/class-bcc-login-widgets.php' );
require_once( 'includes/class-bcc-login-feed.php' );
require_once( 'includes/class-bcc-login-updater.php');
require_once( 'includes/class-bcc-coreapi-client.php');
require_once( 'includes/class-bcc-storage.php');
require_once( 'includes/class-bcc-notifications.php');
require_once( 'includes/class-exclusive-lock.php');
require_once( 'includes/class-bcc-login-updater.php' );
require_once( 'includes/class-bcc-coreapi-client.php' );
require_once( 'includes/class-bcc-storage.php' );
require_once( 'includes/class-bcc-notifications.php' );
require_once( 'includes/class-exclusive-lock.php' );

class BCC_Login {

/**
* The plugin instance.
*/
Expand All @@ -49,8 +48,6 @@ class BCC_Login {
private BCC_Notifications $_notifications;
private BCC_Storage $_storage;



/**
* Initialize the plugin.
*/
Expand Down Expand Up @@ -101,8 +98,6 @@ function plugin_settings_link( $links ) {
return $links;
}



function redirect_login() {
global $pagenow;

Expand All @@ -123,14 +118,12 @@ function redirect_login() {
}
}


function hide_admin_bar() {
if (!is_user_logged_in()) {
echo '<style>#wpadminbar { display: none !important; }</style>';
}
}


function add_auto_login_script() {
if ( is_front_page() && !is_user_logged_in() ) {

Expand Down Expand Up @@ -163,9 +156,7 @@ function add_auto_login_script() {
}
}


function should_auto_login() {

// Don't log in user if they are already logged in
if (is_user_logged_in() && $this->_client->is_session_valid()) {
return false;
Expand Down Expand Up @@ -196,7 +187,6 @@ function should_auto_login() {
return false;
}


/**
* End PHP session (e.g. after logout)
*/
Expand All @@ -216,27 +206,42 @@ function get_logout_url() {
return home_url();
}


/**
* Action hook for bcc_site_groups option update.
*/
function on_site_groups_option_update($old_value, $value, $option) {
delete_transient('coreapi_groups');
delete_transient('coreapi_all_groups');

$this->register_selected_site_groups($value);
}

/**
* Register selected site groups for WPML String translation.
*/
function register_selected_site_groups($selected_groups) {
$all_groups = $this->_coreapi->get_all_groups();

foreach ($all_groups as $group) {
if ( !in_array($group->uid, explode(',', $selected_groups)) ) {
continue;
}

do_action( 'wpml_register_single_string', 'bcc-login', '', $group->name );
}
}

/**
* Action hook for bcc_disable_pubsub option update.
*/
function on_disable_pubsub_option_update($old_value, $value, $option) {
if($value == true) {
if ( $value == true ) {
$this->_coreapi->unsubscribe_to_person_updates();
} else {
$this->_coreapi->subscribe_to_person_updates();
}
}


/**
* Activate plugin hook
* Called when plugin is activated
Expand Down
38 changes: 10 additions & 28 deletions plugins/bcc-login/includes/class-bcc-coreapi-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,9 @@ public function get_all_groups() {
foreach ($result as $group) {
$groups[$group->uid] = $group;
}

// $group_uids = $this->_settings->filtering_groups;
// $result = $this->fetch_groups($group_uids);
// foreach ($result as $group) {
// $groups[$group->uid] = $group;
// }

// $group_uids = $this->_settings->notification_groups;
// $result = $this->fetch_groups($group_uids);
// foreach ($result as $group) {
// $groups[$group->uid] = $group;
// }

$this->_all_groups = array_values($groups);

$expiration_duration = 60 * 60 * 24; // 1 day
set_transient($cache_key, $this->_all_groups, $expiration_duration);

Expand Down Expand Up @@ -98,8 +86,7 @@ function get_translated_site_groups() {
return $site_groups;
}

function fetch_groups($group_uids)
{
function fetch_groups($group_uids) {
$token = $this->get_coreapi_token();

$qry = array(
Expand Down Expand Up @@ -138,11 +125,11 @@ function fetch_groups_by_tags($tags) {
$all_groups[$group->uid] = $group;
}
}

return array_values($all_groups);
}

function fetch_groups_by_tag($tag)
{
function fetch_groups_by_tag($tag) {
$token = $this->get_coreapi_token();

$qry = array(
Expand All @@ -167,7 +154,6 @@ function fetch_groups_by_tag($tag)

return $body->data;
}


function get_groups_for_user($user_uid) {
$cache_key = 'coreapi_user_groups_'.$user_uid;
Expand All @@ -186,7 +172,9 @@ function get_groups_for_user($user_uid) {
}

function fetch_groups_for_user($user_uid) {
if (empty($this->_settings->site_groups)) return array();
if (empty($this->_settings->site_groups)) {
return array();
}

$token = $this->get_coreapi_token();

Expand All @@ -196,7 +184,6 @@ function fetch_groups_for_user($user_uid) {
$user_groups = [];

for ($i = 0; $i < $total_groups; $i += $batch_size) {

$batch = array_slice($this->_settings->site_groups, $i, $batch_size);
$request_body = array(
"groupUids" => $batch
Expand Down Expand Up @@ -226,11 +213,10 @@ function fetch_groups_for_user($user_uid) {

$user_groups = array_merge($user_groups, $body->data->groupUids);
}

return $user_groups;
}



public function ensure_subscription_to_person_updates() {
if ($this->_settings->disable_pubsub) {
return;
Expand All @@ -241,9 +227,9 @@ public function ensure_subscription_to_person_updates() {
return;
}

$lock = new ExclusiveLock( "subscribe_person_updates" );
$lock = new ExclusiveLock("subscribe_person_updates");

if( $lock->lock( ) == FALSE ){
if ($lock->lock() == FALSE) {
return;
}

Expand Down Expand Up @@ -331,14 +317,10 @@ public function subscribe_to_person_updates() {
// ]
// }




// Type = email, sms, inapp
public function send_notification($group_uids, $type, $workflow, $payload) {
$token = $this->get_coreapi_token();


//$request_url = $this->_settings->coreapi_base_url . "/notifications/notification?createSubscribers=false&pushNotifications=true";
$request_url = str_replace("https://", "https://notifications.", $this->_settings->coreapi_base_url) . "/notifications/notification/". $type ."?createSubscribers=true&pushNotifications=" . ($this->_settings->notification_dry_run ? "false" : "true");
$request_body = array(
Expand Down
99 changes: 37 additions & 62 deletions plugins/bcc-login/includes/class-bcc-login-feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,111 +108,86 @@ function add_internal_category_to_member_items($the_list, $type) {
return $result;
}

function add_custom_elements_to_items($the_list){
function add_custom_elements_to_items($the_list) {
$this->add_visibility_and_groups_to_items($the_list);
$this->add_post_type_to_items($the_list);
$this->add_original_language_to_items($the_list);
}



function array_union($x, $y)
{
if (empty($x) && empty($y)){
return [];
}
if (empty($x)){
return $y;
}
if (empty($y)){
return $x;
}
// Use array_merge to combine three arrays:
// 1. Intersection of $x and $y
// 2. Elements in $x that are not in $y
// 3. Elements in $y that are not in $x
$aunion = array_merge(
array_intersect($x, $y), // Intersection of $x and $y
array_diff($x, $y), // Elements in $x but not in $y
array_diff($y, $x) // Elements in $y but not in $x
);

// Return the resulting array representing the union
return $aunion;
}

function add_visibility_and_groups_to_items($the_list){
function add_visibility_and_groups_to_items($the_list) {
global $post;
$visibility = $this->_settings->default_visibility;

if ( $bcc_login_visibility = (int) get_post_meta( $post->ID, 'bcc_login_visibility', true ) ) {
$visibility = $bcc_login_visibility;
}

if ( !empty($this->_settings->site_groups)) {
// Get groups that are checked on post
$post_groups = get_post_meta($post->ID, 'bcc_groups', false);
$post_target_groups = get_post_meta($post->ID, 'bcc_groups', false);
$post_visibility_groups = get_post_meta($post->ID, 'bcc_visibility_groups', false);

// Make sure posts with a group set don't have public visiblity
if (!empty($post_groups))
// Make sure posts with a group set don't have public visibility
if ( !empty($post_target_groups) || !empty($post_visibility_groups) )
{
if ($visibility == BCC_Login_Visibility::VISIBILITY_PUBLIC) {
$visibility = BCC_Login_Visibility::VISIBILITY_SUBSCRIBER;
}
}

}
$this->add_visibility_to_items($the_list,$visibility);
$this->add_groups_to_items($the_list, $visibility);

$this->add_visibility_to_items($the_list, $visibility);
$this->add_groups_to_items($the_list, $visibility);
}

// Include basic visibility settings in feed:
// - public (no authentication required)
// - user (requires authentication)
// - internal:{district name} (requires affiliation with organization in specified district)
function add_visibility_to_items ($the_list, $visibility) {

if ($visibility == BCC_Login_Visibility::VISIBILITY_PUBLIC){
function add_visibility_to_items($the_list, $visibility) {
if ($visibility == BCC_Login_Visibility::VISIBILITY_PUBLIC) {
echo "<bcc:visibility>public</bcc:visibility>\n";

} else if ($visibility == BCC_Login_Visibility::VISIBILITY_SUBSCRIBER){
} else if ($visibility == BCC_Login_Visibility::VISIBILITY_SUBSCRIBER) {
echo "<bcc:visibility>user</bcc:visibility>\n";
} else if ($visibility == BCC_Login_Visibility::VISIBILITY_MEMBER){
} else if ($visibility == BCC_Login_Visibility::VISIBILITY_MEMBER) {
echo "<bcc:visibility>internal:" . $this->_settings->member_organization_name . "</bcc:visibility>\n";
}
}


// Include group uid for each group that the post is visible for or targetted at (notification group)
// E.g.
// <bcc:visiblityGroup>d4c434a7-504a-4246-9a10-def7dbfa982c</bcc:visiblityGroup>
// <bcc:visiblityGroup>25f5bc4d-48e0-4a6e-bf05-6b2a15d70861</bcc:visiblityGroup>
// <bcc:notificationGroup>d4c434a7-504a-4246-9a10-def7dbfa982c</bcc:notificationGroup>
// Include group uid for each group that the post is targeted at or visible for
// E.g.:
// <bcc:targetGroup>d4c434a7-504a-4246-9a10-def7dbfa982c</bcc:targetGroup>
// <bcc:visibilityGroup>d4c434a7-504a-4246-9a10-def7dbfa982c</bcc:visibilityGroup>
// <bcc:visibilityGroup>25f5bc4d-48e0-4a6e-bf05-6b2a15d70861</bcc:visibilityGroup>
function add_groups_to_items($the_list, $visibility) {
global $post;
$result = '';

if ( !empty($this->_settings->site_groups) || !empty($this->_settings->full_content_access_groups) ) {
// Get groups that are checked on post
$post_groups = get_post_meta($post->ID, 'bcc_groups', false);
$post_target_groups = get_post_meta($post->ID, 'bcc_groups', false);
Comment thread
cs1m0n marked this conversation as resolved.
$post_visibility_groups = get_post_meta($post->ID, 'bcc_visibility_groups', false);

// Visiblity Groups: Groups that are checked on post
// + groups with access to all posts (only if there are groups checked on post)
if ($visibility != BCC_Login_Visibility::VISIBILITY_PUBLIC && is_array($post_groups) && count($post_groups))
{
$visibility_post_groups = $this->array_union($post_groups, $this->_settings->full_content_access_groups);
foreach ($visibility_post_groups as $group){
$result = $result . "\t\t<bcc:visibilityGroup>" . $group . "</bcc:visibilityGroup>\n";
}
if ($visibility == BCC_Login_Visibility::VISIBILITY_PUBLIC) {
return; // No groups for public posts
}

if (in_array($post->post_type, $this->_settings->notification_post_types)){
// Notification Groups: Groups that are checked on posts + are eligable for notification
$notification_groups = array_intersect($post_groups, $this->_settings->notification_groups);
foreach ($notification_groups as $group){
$result = $result . "\t\t<bcc:notificationGroup>" . $group . "</bcc:notificationGroup>\n";
// Target Groups: the primary groups that the KPIs are measured for
if (is_array($post_target_groups)) {
foreach ($post_target_groups as $group) {
$result .= "\t\t<bcc:targetGroup>" . $group . "</bcc:targetGroup>\n";
}
}

// Visibility Groups: the secondary groups which can view the post
if (is_array($post_visibility_groups) && count($post_visibility_groups)) {
$visibility_groups = $this->_settings->array_union($post_visibility_groups, $this->_settings->full_content_access_groups);

foreach ($visibility_groups as $group) {
$result .= "\t\t<bcc:visibilityGroup>" . $group . "</bcc:visibilityGroup>\n";
}
}
}

echo $result;
}

Expand Down
Loading
Loading