-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
temp commit for Hai's check: add support for multiple roles #374
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -633,19 +633,33 @@ public function network_update( $id, $val ) { | |
* @since 1.6 | ||
* @access public | ||
* @param string $role The user role | ||
* @return int The set value if already set | ||
* @return boolean | ||
*/ | ||
public function in_optm_exc_roles( $role = null ) { | ||
// Get user role | ||
if ( $role === null ) { | ||
$role = Router::get_role(); | ||
} | ||
|
||
if ( ! $role ) { | ||
return false; | ||
} | ||
return in_array( $role, $this->conf( self::O_OPTM_EXC_ROLES ) ) ? true : false; | ||
} | ||
|
||
return in_array( $role, $this->conf( self::O_OPTM_EXC_ROLES ) ) ? $role : false; | ||
/** | ||
* Check if the user has role(s) that should be excluded from optm | ||
* | ||
* @since 4.2 to support single user multiple roles scenarios | ||
* @access public | ||
* @param array $roles The roles of the current user | ||
* @return boolean | ||
*/ | ||
public function has_optm_exc_role( $roles = null ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't reuse or rename |
||
//Get user roles | ||
if ( $roles == null ) { | ||
$roles = Router::get_roles(); | ||
} | ||
|
||
if ( ! $roles ) { | ||
return false; | ||
} | ||
return array_intersect( $roles, $this->conf( self::O_OPTM_EXC_ROLES ) ) ? true : false; | ||
} | ||
|
||
/** | ||
|
@@ -720,4 +734,4 @@ public function handler() { | |
|
||
Admin::redirect(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,8 +276,9 @@ public static function get_hash() { | |
* Get user role | ||
* | ||
* @since 1.6.2 | ||
* @since 4.2 update to support single user multiple roles scenarios | ||
*/ | ||
public static function get_role( $uid = null ) { | ||
public static function get_roles( $uid = null ) { | ||
if ( defined( 'LITESPEED_WP_ROLE' ) ) { | ||
return LITESPEED_WP_ROLE; | ||
} | ||
|
@@ -286,18 +287,17 @@ public static function get_role( $uid = null ) { | |
$uid = get_current_user_id(); | ||
} | ||
|
||
$role = false; | ||
$roles = array(); | ||
if ( $uid ) { | ||
$user = get_userdata( $uid ); | ||
if ( isset( $user->roles ) && is_array( $user->roles ) ) { | ||
$tmp = array_values( $user->roles ); | ||
$role = array_shift( $tmp ); | ||
$roles = array_values( $user->roles ); | ||
} | ||
} | ||
Debug2::debug( '[Router] get_role: ' . $role ); | ||
Debug2::debug( '[Router] get_roles: ' . var_export( $roles, true ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. debug function supports 2nd param which can be an array. |
||
|
||
if ( ! $role ) { | ||
return $role; | ||
if ( ! $roles ) { | ||
return $roles; | ||
// Guest user | ||
Debug2::debug( '[Router] role: guest' ); | ||
|
||
|
@@ -308,11 +308,11 @@ public static function get_role( $uid = null ) { | |
* @since 2.9.8 Won't assign const if in login process | ||
*/ | ||
if ( substr_compare( wp_login_url(), $GLOBALS[ 'pagenow' ], -strlen( $GLOBALS[ 'pagenow' ] ) ) === 0 ) { | ||
return $role; | ||
return $roles; | ||
} | ||
} | ||
|
||
define( 'LITESPEED_WP_ROLE', $role ); | ||
define( 'LITESPEED_WP_ROLE', $roles ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you test this on PHP5.3? |
||
|
||
return LITESPEED_WP_ROLE; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If dropped $role assignment in
in_optm_exc_roles
, will this break the existing code?