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 ) ) {
//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();
}
}
1 of 2
user104130