changed all role occurences by a const
This commit is contained in:
@@ -12,21 +12,32 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
function restrict_author_page_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$role_fipf = PLGNTLS_class::ROLE_FIPF;
|
||||
$role_admin = PLGNTLS_class::ROLE_ADMIN;
|
||||
|
||||
if (!is_author())
|
||||
return;
|
||||
|
||||
$can_access = false;
|
||||
if (current_user_can('administrator')) {
|
||||
$can_access = true;
|
||||
}
|
||||
else if (current_user_can('editor')) {
|
||||
$can_access = true;
|
||||
}
|
||||
$current_user = wp_get_current_user();
|
||||
|
||||
if ($can_access === true)
|
||||
/*
|
||||
* check multiple user roles
|
||||
* https://developer.wordpress.org/reference/functions/current_user_can/#div-comment-4083
|
||||
* if user->role is found in array of allowed role, no redirection needed
|
||||
*
|
||||
*/
|
||||
$allowed_roles = array($role_admin, $role_fipf);
|
||||
if (array_intersect($allowed_roles, $current_user->roles))
|
||||
return;
|
||||
|
||||
/*
|
||||
* get_queried_object_id() would work too
|
||||
* here get_the_author_meta works and is more explicit
|
||||
*
|
||||
$author_id = get_queried_object_id();
|
||||
*/
|
||||
$author_id = get_the_author_meta( 'ID' );
|
||||
|
||||
$current_user_id = get_current_user_id();
|
||||
|
||||
if ($current_user_id != $author_id) {
|
||||
|
||||
Reference in New Issue
Block a user