Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlimaza committed Nov 24, 2020
2 parents 8b64ac8 + d36234f commit 13a1b28
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
40 changes: 30 additions & 10 deletions pmpro-roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Plugin URI: https://www.paidmembershipspro.com/add-ons/pmpro-roles/
* Author: Paid Memberships Pro
* Author URI: https://www.paidmembershipspro.com
* Version: 1.3.1
* Version: 1.3.2
* License: GPL2
* Text Domain: pmpro-roles
* Domain Path: /languages
Expand Down Expand Up @@ -145,8 +145,10 @@ function delete_level( $delete_id ) {
function update_role_name( $role, $name ){
if( strpos( $role, PMPRO_Roles::$role_key ) !== FALSE ) {
$roles_array = get_option( 'wp_user_roles', true );
$roles_array[$role]['name'] = sanitize_text_field( $name );
$updated = update_option( 'wp_user_roles', $roles_array );
if( !empty( $roles_array[$role] ) ){
$roles_array[$role]['name'] = sanitize_text_field( $name );
$updated = update_option( 'wp_user_roles', $roles_array );
}
}
}

Expand Down Expand Up @@ -188,8 +190,8 @@ function user_change_level($level_id, $user_id){
$wp_user_object->set_role( PMPRO_Roles::$role_key . $co_level->id );
}
}
} else if( isset( $_REQUEST['level'] ) ){
$roles = get_option( 'pmpro_roles_'.intval( $_REQUEST['level'] ) );
} else if( $level_id > 0 ){
$roles = get_option( 'pmpro_roles_'.intval( $level_id ) );
if( is_array( $roles ) && ! empty( $roles ) ){
$count = 1;
foreach( $roles as $role_key => $role_name ){
Expand All @@ -201,7 +203,7 @@ function user_change_level($level_id, $user_id){
$count++;
}
} else {
$wp_user_object->set_role( PMPRO_Roles::$role_key.intval( $_REQUEST['level'] ) );
$wp_user_object->set_role( PMPRO_Roles::$role_key.intval( $level_id ) );
}
}
}
Expand Down Expand Up @@ -282,6 +284,9 @@ public static function level_settings() {
<hr/>
<?php
}

$exclude_other_pmpro_roles = apply_filters( 'pmpro_roles_exclude_other_pmpro_roles', true, $level_id );

foreach( $editable_roles as $key => $role ){
$checked = '';
//Backwards compat here, if $saved_roles is empty, set the default level's role as checked
Expand All @@ -295,7 +300,20 @@ public static function level_settings() {
$checked = 'checked=true';
}

if ( $key != 'pmpro_role_' . $level_id ) { //Show this one first

if( $exclude_other_pmpro_roles ){
//excluding the pmpro_role_ roles here
if ( $key != 'pmpro_role_' . $level_id ) { //Show this one first
?>
<li>
<input type='checkbox' name='pmpro_roles_level[<?php echo esc_attr( $key ); ?>]' value='<?php echo stripslashes( $role["name"] ); ?>' id='<?php echo esc_attr( $key ); ?>' <?php echo esc_attr( $checked ); ?> /> <label for='<?php echo esc_attr( $key ); ?>'><?php echo stripslashes( $role['name'] ); ?>
<?php echo "<code>". esc_html( $key ). "</code>"; ?>
</label>
</li>
<?php
}
} else {
//include all roles. No checks needed
?>
<li>
<input type='checkbox' name='pmpro_roles_level[<?php echo esc_attr( $key ); ?>]' value='<?php echo stripslashes( $role["name"] ); ?>' id='<?php echo esc_attr( $key ); ?>' <?php echo esc_attr( $checked ); ?> /> <label for='<?php echo esc_attr( $key ); ?>'><?php echo stripslashes( $role['name'] ); ?>
Expand All @@ -304,7 +322,7 @@ public static function level_settings() {
</li>
<?php
}

}
?>
<?php
Expand Down Expand Up @@ -334,8 +352,10 @@ public static function remove_list_roles( $roles ){

$all_levels = pmpro_getAllLevels( true, false );

//Take admins out of the array first
unset( $roles['administrator'] );
if( apply_filters( 'pmpro_roles_hide_admin_role', true, $edit_level ) ){
//Take admins out of the array first
unset( $roles['administrator'] );
}

foreach( $all_levels as $level_key => $level ){
if( $level_key !== $edit_level ){
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: strangerstudios, joshlevinson
Tags: pmpro, paid memberships pro, membership, roles
Requires at least: 4.5
Tested up to: 5.5
Stable tag: 1.3.1
Stable tag: 1.3.2

Adds a WordPress Role for each Membership Level.

Expand Down Expand Up @@ -45,6 +45,9 @@ Please post it in the issues section of GitHub and we'll fix it as soon as we ca
Please visit our premium support site at https://www.paidmembershipspro.com for more documentation and our support forums.

== Changelog ==
= 1.3.2 - 2020-11-24 =
* ENHANCEMENT: Improved logic around changing level and assigning roles.

= 1.3.1 - 2020-10-28 =
* BUG FIX: Fixed issue where accidentaly removed administrator role from edit user profile page while plugin is active.

Expand Down

0 comments on commit 13a1b28

Please sign in to comment.