- updated states to work for user_id and post_id
- added states for partner page state publish-draft
This commit is contained in:
95
plugins/cipf_plugin/php/admin_hide_bar.php
Normal file
95
plugins/cipf_plugin/php/admin_hide_bar.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* it means someone outside wp is accessing the file, in this case kill it.
|
||||
*/
|
||||
if (!defined('ABSPATH')) {
|
||||
die('You can not access this file!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* hide admin bar if access a front page and is not an admin
|
||||
*/
|
||||
function hide_admin_bar_CIPF() {
|
||||
Plgntls::debug_infos(2);
|
||||
$role_admin = Plgntls::ROLE_ADMIN;
|
||||
$role_fipf = Plgntls::ROLE_FIPF;
|
||||
|
||||
|
||||
/*
|
||||
* on admin page, don't hide bar of course
|
||||
*
|
||||
*/
|
||||
if (is_admin()) {
|
||||
return;
|
||||
}
|
||||
Plgntls::debug_infos();
|
||||
|
||||
|
||||
/*
|
||||
* check multiple user roles
|
||||
* https://developer.wordpress.org/reference/functions/current_user_can/#div-comment-4083
|
||||
*
|
||||
*/
|
||||
$current_user = wp_get_current_user();
|
||||
$allowed_roles = array($role_admin, $role_fipf);
|
||||
if (array_intersect($allowed_roles, $current_user->roles)) {
|
||||
return;
|
||||
}
|
||||
show_admin_bar(false);
|
||||
}
|
||||
add_action('after_setup_theme', 'hide_admin_bar_CIPF');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* prevent users to access admin page
|
||||
*
|
||||
*/
|
||||
function restrict_admin_access_CIPF() {
|
||||
Plgntls::debug_infos(2);
|
||||
$role_admin = Plgntls::ROLE_ADMIN;
|
||||
$role_fipf = Plgntls::ROLE_FIPF;
|
||||
|
||||
/*
|
||||
* this concerns logged_in users, for admin page
|
||||
*
|
||||
*/
|
||||
if (!is_user_logged_in()) {
|
||||
return;
|
||||
}
|
||||
if (!is_admin()) {
|
||||
return;
|
||||
}
|
||||
Plgntls::debug_infos();
|
||||
|
||||
/*
|
||||
* some roles are allowed to access the admin panel
|
||||
*
|
||||
*/
|
||||
$current_user = wp_get_current_user();
|
||||
$allowed_roles = array($role_admin, $role_fipf);
|
||||
if (array_intersect($allowed_roles, $current_user->roles))
|
||||
return;
|
||||
|
||||
/*
|
||||
* every other roles are redirected
|
||||
*
|
||||
*/
|
||||
redirection_profil_CIPF();
|
||||
}
|
||||
//add_action('init', 'restrict_admin_access_CIPF', 100);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user