Fix default role to permit less restrictive

* Fix some spaces indentation
	* Create $amp_role_assigned variable

Before this change, if amp_default_role was less restrictive than the
one assigned to user, user assigned role had no effect at all. This
change permit the default role to be less restrictive than users's.
This commit is contained in:
Marcos de Oliveira 2021-04-05 11:01:33 -03:00
parent 338e0299f1
commit e584626e5e

View File

@ -270,6 +270,7 @@ function amp_have_capability( $capability ) {
$user_caps = array(); $user_caps = array();
foreach ( $amp_role_capabilities as $rolename => $rolecaps ) { foreach ( $amp_role_capabilities as $rolename => $rolecaps ) {
if ( amp_user_has_role( $user, $rolename ) ) { if ( amp_user_has_role( $user, $rolename ) ) {
$amp_role_assigned = True;
$user_caps = array_merge( $user_caps, $rolecaps ); $user_caps = array_merge( $user_caps, $rolecaps );
} }
} }
@ -287,7 +288,7 @@ function amp_have_capability( $capability ) {
break; break;
} }
} }
if( !$return ) { if( !$amp_role_assigned ) {
if ( isset( $amp_default_role ) && in_array ($amp_default_role, array_keys( $amp_role_capabilities ) ) ) { if ( isset( $amp_default_role ) && in_array ($amp_default_role, array_keys( $amp_role_capabilities ) ) ) {
$default_caps = $amp_role_capabilities [ $amp_default_role ]; $default_caps = $amp_role_capabilities [ $amp_default_role ];
$return = in_array( $capability, $default_caps ); $return = in_array( $capability, $default_caps );