From 0b5550d8aa68589b376e4bc00a09d6b9b59e4317 Mon Sep 17 00:00:00 2001 From: Hoang Huu Date: Mon, 13 Jan 2020 11:30:24 +0700 Subject: [PATCH] Update --- inc/user/class-opalestate-user.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/inc/user/class-opalestate-user.php b/inc/user/class-opalestate-user.php index d2998f35..a448f079 100755 --- a/inc/user/class-opalestate-user.php +++ b/inc/user/class-opalestate-user.php @@ -94,8 +94,28 @@ class OpalEstate_User { add_action( 'wp_enqueue_scripts', [ $this, 'scripts_styles' ], 99 ); add_filter( 'pre_get_posts', [ $this, 'show_current_user_attachments' ] ); + add_action( 'init', [ $this, 'block_users_backend' ] ); } + /** + * Redirect contribute roles to front-end dashboard. + */ + public function block_users_backend() { + global $current_user; + + if ( ! is_a( $current_user, 'WP_User' ) ) { + return; + } + + if ( is_admin() && ! wp_doing_ajax() && ( in_array( 'opalestate_agent', $current_user->roles ) || in_array( 'opalestate_agency', $current_user->roles ) ) ) { + $redirect = opalestate_get_user_management_page_uri(); + $redirect = $redirect ? $redirect : home_url(); + wp_redirect( $redirect ); + exit; + } + } + + /** * FrontEnd Submission */