Files
ultimatemember/includes/core/um-actions-wpadmin.php
T

52 lines
1.1 KiB
PHP
Raw Normal View History

<?php if ( ! defined( 'ABSPATH' ) ) {
exit;
}
2017-12-18 15:36:04 +02:00
2018-02-12 00:56:01 +02:00
/**
* Checks if user can access the backend
*/
function um_block_wpadmin_by_user_role() {
2019-12-02 13:20:51 +08:00
global $pagenow;
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
$action = empty( $_REQUEST['action'] ) ? '' : $_REQUEST['action'];
// filter that it's not admin_post or admin_post_nopriv request
2019-12-02 13:20:51 +08:00
if ( is_user_logged_in() && ! empty( $action ) && 'admin-post.php' == $pagenow ) {
return;
}
if ( um_user( 'ID' ) && ! um_user( 'can_access_wpadmin' ) && ! is_super_admin( um_user( 'ID' ) ) ) {
um_redirect_home();
}
2014-12-15 22:38:07 +02:00
}
2018-02-12 00:56:01 +02:00
}
add_action( 'init', 'um_block_wpadmin_by_user_role', 99 );
2016-02-26 22:19:18 +08:00
2015-02-01 01:30:04 +02:00
2018-02-12 00:56:01 +02:00
/**
* Hide admin bar appropriately
*
* @param bool $show
2018-02-12 00:56:01 +02:00
*
* @return bool
*/
function um_control_admin_bar( $show ) {
2020-05-04 13:37:24 +03:00
if ( is_user_logged_in() && UM()->roles()->um_user_can( 'can_not_see_adminbar' ) ) {
$show = false;
2015-01-27 01:52:11 +02:00
}
2018-02-12 00:56:01 +02:00
return apply_filters( 'um_show_admin_bar_callback', $show );
2018-02-12 00:56:01 +02:00
}
add_filter( 'show_admin_bar', 'um_control_admin_bar', 9999, 1 );
2018-02-12 00:56:01 +02:00
/**
* Fix permission for admin bar
*/
function um_force_admin_bar() {
um_reset_user();
}
add_action( 'wp_footer', 'um_force_admin_bar' );