Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions plugins/bcc-login/bcc-login.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ static function activate_plugin() {
if ( ! get_role( 'bcc-login-member' ) ) {
add_role( 'bcc-login-member', __( 'Member' ), array( 'read' => true ) );
}
if ( ! get_role( 'bcc-login-youth-member' ) ) {
add_role( 'bcc-login-youth-member', __( 'Youth Member' ), array( 'read' => true ) );
}
BCC_Login_Users::create_users();

// Flush rewrite rules to make pretty URLs for endpoints work.
Expand Down
7 changes: 7 additions & 0 deletions plugins/bcc-login/includes/class-bcc-login-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ function create_new_user( $person_id, $email, $id_token_claims ) {

function get_common_login( $user_claim ) {
if ( $user_claim[$this->_settings->member_organization_claim_type] == $this->_settings->member_organization_name ) {
$birthdate = date_create($user_claim['birthdate']);
$current_date = date_create();
$diff = date_diff($birthdate, $current_date);
if ( $diff->y <= 36 ) {
return BCC_Login_Users::get_youth_member();
}

return BCC_Login_Users::get_member();
}

Expand Down
12 changes: 11 additions & 1 deletion plugins/bcc-login/includes/class-bcc-login-users.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ static function get_logins() {
'desc' => __( 'Member' ),
'role' => 'bcc-login-member',
),
array(
'login' => 'bcc-login-youth-member',
'desc' => __( 'Youth Member' ),
'role' => 'bcc-login-youth-member',
),
array(
'login' => 'bcc-login-subscriber',
'desc' => __( 'Subscriber' ),
Expand All @@ -112,11 +117,16 @@ static function get_member() {
return get_user_by( 'login', $logins[0]['login'] );
}

static function get_subscriber() {
static function get_youth_member() {
$logins = self::get_logins();
return get_user_by( 'login', $logins[1]['login'] );
}

static function get_subscriber() {
$logins = self::get_logins();
return get_user_by( 'login', $logins[2]['login'] );
}

static function create_users() {
foreach ( self::get_logins() as $info ) {
if ( ! get_user_by( 'login', $info['login'] ) ) {
Expand Down
5 changes: 4 additions & 1 deletion plugins/bcc-login/includes/class-bcc-login-visibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ class BCC_Login_Visibility {
public const VISIBILITY_PUBLIC = 1;
public const VISIBILITY_SUBSCRIBER = 2;
public const VISIBILITY_MEMBER = 3;
public const VISIBILITY_YOUTH_MEMBER = 4;

// A mapping of role -> level.
private $levels = array(
'bcc-login-member' => self::VISIBILITY_MEMBER,
'bcc-login-youth-member' => self::VISIBILITY_YOUTH_MEMBER,
'subscriber' => self::VISIBILITY_SUBSCRIBER,
'public' => self::VISIBILITY_PUBLIC
);
Expand All @@ -21,7 +23,8 @@ class BCC_Login_Visibility {
private $titles = array(
self::VISIBILITY_PUBLIC => 'Public',
self::VISIBILITY_SUBSCRIBER => 'Authenticated Users',
self::VISIBILITY_MEMBER => 'Members'
self::VISIBILITY_MEMBER => 'Members',
self::VISIBILITY_YOUTH_MEMBER => 'Youth Members'
);

private $post_types = array( 'post', 'page' );
Expand Down
4 changes: 4 additions & 0 deletions plugins/bcc-login/src/visibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const visibilityOptions = [
value: levels['bcc-login-member'],
label: sprintf(__('%s Members'), localName),
},
{
value: levels['bcc-login-youth-member'],
label: sprintf(__('%s Youth Members'), localName),
},
]

function VisibilityOptions({
Expand Down