Skip to content

Commit

Permalink
minor bug fix for role sync, admin role should be be changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
kalungsy committed Jan 19, 2021
1 parent 834f92c commit cba2cb2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
21 changes: 17 additions & 4 deletions public/class-servicebot-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ function updateUserRole($user_id, $product_sb_tier){
* @var [associative array]
*/
$user = get_user_by('id', $user_id);

if(in_array('administrator', $user->roles)){
return;
}

$tier_to_role_map;
$all_roles = wp_roles()->get_names();
foreach($all_roles as $role_name){
Expand All @@ -218,10 +223,18 @@ function updateUserRole($user_id, $product_sb_tier){
if($tier_to_role_map[$product_sb_tier]){
$user->set_role(strtolower($tier_to_role_map[$product_sb_tier]));
}else{
$user->set_role("subscriber");
$user->set_role(get_option('default_role'));
}
}else if($user){
$user->set_role("subscriber");
$user->set_role(get_option('default_role'));
}
}

function removeUserRole($wp_user){
// remove user roles for cancel and out of status acccounts
// except for admin
if(!in_array('administrator', $wp_user->roles)){
$wp_user->set_role("");
}
}

Expand Down Expand Up @@ -417,7 +430,7 @@ function servicebot_webhook_listener() {
// if status is canceled, unpaid, past_due, incomplete or incomplete_expired
if(in_array($subscription_status, ['unpaid', 'past_due', 'incomplete', 'incomplete_expired'])){
//set the user's role to none
$user->set_role("");
removeUserRole($user);
wp_send_json( array(
'event' => $event->type,
'subscription_status' => $subscription_status,
Expand Down Expand Up @@ -464,7 +477,7 @@ function servicebot_webhook_listener() {
}

$wp_user = get_user_by('email', $customer['email']);
$wp_user->set_role("");
removeUserRole($wp_user);

wp_send_json( array(
'message' => 'User role updated successfully.',
Expand Down
4 changes: 2 additions & 2 deletions servicebot.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Plugin Name: Billflow
* Plugin URI: http://www.wpexplorer.com/servicebot/
* Description: Provides NO-CODE integration between WordPress and Billflow, an UI layer on top of Stripe Billing.
* Version: 2.0.5
* Version: 2.0.6
* Author: Billflow
* Author URI: https://billflow.io
* License: GPL-2.0+
Expand All @@ -35,7 +35,7 @@
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define( 'SERVICEBOT_VERSION', '2.0.5' );
define( 'SERVICEBOT_VERSION', '2.0.6' );

/**
* The code that runs during plugin activation.
Expand Down

0 comments on commit cba2cb2

Please sign in to comment.