Skip to content

Commit

Permalink
Fixed issue with pmpro_draft_role
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlimaza committed Oct 29, 2024
1 parent 854340a commit f7ddaaf
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions pmpro-roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ public static function get_roles_for_level( $level_id ) {
* @since 1.3
*/
function edit_level( $saveid ) {
global $wpdb;

//by being here, we know we already have the $_REQUEST we need, so no need to check.
$capabilities = self::capabilities( self::$role_key . $saveid ) ?: array( 'read' => true );

Expand All @@ -147,7 +149,11 @@ function edit_level( $saveid ) {

// We detect that the draft_role has been selected, so lets try to create it. (This can now happen whenever the role doesn't exist not just on new level creation)
if ( ! empty( $level_roles['pmpro_draft_role'] ) ) {
add_role( PMPRO_Roles::$role_key.$saveid, sanitize_text_field( $_REQUEST['name'] ), $capabilities );
unset( $level_roles['pmpro_draft_role'] ); // Remove it from the array.
$role_name = sanitize_text_field( $_REQUEST['name'] );
add_role( PMPRO_Roles::$role_key.$saveid, $role_name, $capabilities );
$level_roles[PMPRO_Roles::$role_key.$saveid] = $role_name; // Got to add the newly created role to the level_roles array.
remove_role( 'pmpro_draft_role' ); // Delete the role entirely in case it exists, we no longer need it at this point forward.
}

if ( isset( $_REQUEST['edit'] ) && $_REQUEST['edit'] < 0 ) {
Expand All @@ -158,8 +164,6 @@ function edit_level( $saveid ) {
}
}
} else {

global $wpdb;
//have to get all roles and find ours because get_role() doesn't yield the role's "pretty" name, only its index.
$roles = get_option( $wpdb->get_blog_prefix() . 'user_roles' );

Expand All @@ -180,11 +184,6 @@ function edit_level( $saveid ) {
}
}

if( !empty( $level_roles['pmpro_draft_role'] ) ){
unset( $level_roles['pmpro_draft_role'] );
$level_roles[PMPRO_Roles::$role_key.$saveid] = sanitize_text_field( $_REQUEST['name'] );
}

update_option( 'pmpro_roles_'.$saveid, $level_roles );

}
Expand Down

0 comments on commit f7ddaaf

Please sign in to comment.