if( is_admin() ) {
add_filter( 'init', 'custom_restrict_pages_from_admin' );
}
function custom_restrict_pages_from_admin() {
global $pagenow;
$arr = array(
'update-core.php',
'edit.php'
);
if( custom_check_user_roles() && in_array( $arr$pagenow , $pagenow$arr ) ) {
//echo some custom messages or call the functions
} else {
echo 'This page has restricted access to specific roles';
wp_die();
}
}
function custom_check_user_roles() {
//restrict pages by user role
if( current_user_can( 'administrator' ) || current_user_can( 'editor' ) )
return true;
else {
echo 'Not allowed!';
wp_die();
}
}
The parameter order is incorrect here, and the user is no longer active to fix it. Please see https://www.php.net/manual/en/function.in-array.php or test it yourself instead of just insta-rejecting the edit.