Created
November 18, 2020 14:00
-
-
Save denisbaranov/3be17ef61a277ffa807fc2a4cc96e2b1 to your computer and use it in GitHub Desktop.
This code snippet restores capabilities 'edit_user' and 'delete_user' if they were blocked by a third-party plugin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This code snippet restores capabilities 'edit_user' and 'delete_user' if they were blocked by a third-party plugin. | |
* | |
* You can add this code to the end of the file functions.php in the active theme (child theme) directory. | |
* | |
* Ultimate Member documentation: https://docs.ultimatemember.com/ | |
* Ultimate Member support (for customers): https://ultimatemember.com/support/ticket/ | |
* | |
* @author Ultimate Member support <support@ultimatemember.com> | |
* @since 2020-11-18 | |
* @see #45381 | |
*/ | |
if ( function_exists( 'UM' ) ) { | |
function um_map_meta_cap( $caps, $cap, $user_id, $args ) { | |
static $permissions = array(); | |
$index = array_keys( $caps, 'do_not_allow' ); | |
if ( $index ) { | |
$index = current( $index ); | |
if ( empty( $permissions[$user_id] ) ) { | |
$role = UM()->roles()->get_priority_user_role( $user_id ); | |
$permissions[$user_id] = UM()->roles()->role_data( $role ); | |
} | |
$p = $permissions[$user_id]; | |
switch ( $cap ) { | |
case 'edit_user': | |
case 'edit_users': | |
if ( !empty( $p['can_edit_everyone'] ) ) { // role setting Can edit other member accounts? | |
if ( empty( $p['can_edit_roles'] ) ) { | |
unset( $caps[$index] ); | |
} elseif ( is_array( $p['can_edit_roles'] ) && isset( $args[0] ) && is_numeric( $args[0] ) ) { | |
$urole = UM()->roles()->get_priority_user_role( $args[0] ); | |
if ( in_array( $urole, $p['can_edit_roles'] ) ) { | |
unset( $caps[$index] ); | |
} | |
} | |
} | |
break; | |
case 'delete_user': | |
case 'delete_users': | |
if ( !empty( $p['can_delete_everyone'] ) ) { // role setting Can delete other member accounts? | |
if ( empty( $p['can_delete_roles'] ) ) { | |
unset( $caps[$index] ); | |
} elseif ( is_array( $p['can_delete_roles'] ) && isset( $args[0] ) && is_numeric( $args[0] ) ) { | |
$urole = UM()->roles()->get_priority_user_role( $args[0] ); | |
if ( in_array( $urole, $p['can_delete_roles'] ) ) { | |
unset( $caps[$index] ); | |
} | |
} | |
} | |
break; | |
} | |
} | |
return $caps; | |
} | |
add_filter( 'map_meta_cap', 'um_map_meta_cap', 99, 4 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment