Hello,
I am currently building Hivepress website (hosted on LocalWP for now) where all listings submited by users will have to be reviewed before being published. For that, I wanted to create a Reviewer role that would have access only to review and publish the listings created by users (from the WP dashboard, just like the administrator currently does it) using this code:
function add_reviewer_role() {
add_role('reviewer', 'Reviewer', [
'read' => true,
'edit_posts' => false, // Cannot edit WordPress blog posts
'delete_posts' => false,
'publish_posts' => false,
'upload_files' => false, //
'edit_hp_listings' => true, // Can edit listings
'edit_others_hp_listings' => true, // Can edit others' listings
'publish_hp_listings' => true, // Can publish listings
'delete_hp_listings' => false, // Cannot delete listings
'manage_hp_categories' => false, // Cannot edit listing categories
]);
}
add_action('init', 'add_reviewer_role');
The addition of the new role went fine, however when I assign it to a user and then log into Wordpress as that user, I automatically get redirected to the site frontend, and I am not able to access the backend (tried accessing the wp-admin by modifying the URL, but this also redirects on frontend). I tried forcing/allowing admin view using following code:
function allow_reviewer_admin_access() {
if (current_user_can('reviewer') && !defined('DOING_AJAX')) {
show_admin_bar(true); // Show admin bar
}
}
add_action('after_setup_theme', 'allow_reviewer_admin_access');
function bypass_hivepress_redirect($redirect, $user) {
if (isset($user->roles) && in_array('reviewer', $user->roles)) {
return admin_url(); // Force redirect to WP Admin
}
return $redirect;
}
add_filter('login_redirect', 'bypass_hivepress_redirect', 10, 2);
, but it still didn’t work.
Any ideas what I could do to achieve this?