-
Author
Tagged: Login Modal, restrict wp-admin, functions code
-
March 4, 2015 at 00:21 #48649tony72Participant
Hi.
Im using the code below to restrict non admin members to view dashboard when they try to access wp-admin the will be redirected to the home page. When using the code below it works great but it brakes login modal redirect. When some one logs in the green “Login Successful. Redirecting…” Doesn’t work / trigger the spinner just keeps spinning. But after refreshing the page you would be loged in.
Can you tell me how to make the code below to not brake your login modal?
Can you tell me how to make the code below redirect to profile and not home page?/* Disable WordPress Admin for all users. */
function block_wp_admin_init() {
if (strpos(strtolower($_SERVER[‘REQUEST_URI’]),’/wp-admin/’) !== false) {
if ( !is_site_admin() ) {
wp_redirect( get_option(‘siteurl’), 302 );
}
}
}
add_action(‘init’,’block_wp_admin_init’,0);
Thanks for the help
March 4, 2015 at 01:26 #48657LauraModeratorHello, have you tried this plugin? https://wordpress.org/plugins/bp-redirect-to-profile/
It may be what you are looking forHi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionLaura Solanes - Graphic Designer and Web Designer
Please be patient as I try to answer each topic as fast as i can.
If you like the theme or the support you've received please consider leaving us a review on Themeforest!
Always happy to help you 🙂
March 4, 2015 at 01:37 #48658tony72ParticipantHi Laura,
Im using that plugin already and that plug in does not restrict users from wp-admin dashboard.
All it does is redirect users to profile after they login.If my explanation wasn’t clear what I’m doing with the code is restricting non admin users to wp-admin dashboard. But seems to cause a conflict with the them login modal on front end. The green “Login Successful. Redirecting…” Doesn’t work / trigger the spinner just keeps spinning. But after refreshing the page you would be loged in even with the green “Login Successful. Redirecting…” not working / displaying.
Do you have a solution to restrict non admin users from wp-admin dashboard?
Thanks
March 4, 2015 at 03:27 #48696LauraModeratorHello, try this code in functions.php of child theme:
COPY CODEadd_action( 'init', 'blockusers_init' ); function blockusers_init() { if ( is_admin() && ! current_user_can( 'administrator' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { wp_redirect( home_url() ); exit; } }
Let me know if it works 🙂
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionLaura Solanes - Graphic Designer and Web Designer
Please be patient as I try to answer each topic as fast as i can.
If you like the theme or the support you've received please consider leaving us a review on Themeforest!
Always happy to help you 🙂
March 4, 2015 at 03:42 #48697tony72ParticipantHey Larua.
Yes that code seems to work to restrict admin panel and the modal works well with it.
Right now it redirects the users to the home page though.
Is there a way to redirect the user back to his profile?Thanks
March 5, 2015 at 15:21 #48839LauraModeratorHello, try maybe with
COPY CODEadd_action( 'init', 'blockusers_init' ); function blockusers_init() { if ( is_admin() && ! current_user_can( 'administrator' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { wp_redirect( '/members/' . bp_core_get_username( bp_loggedin_user_id() ); exit; } }
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionLaura Solanes - Graphic Designer and Web Designer
Please be patient as I try to answer each topic as fast as i can.
If you like the theme or the support you've received please consider leaving us a review on Themeforest!
Always happy to help you 🙂
March 6, 2015 at 20:29 #49013tony72ParticipantHi Laura,
Sorry for the late response.
The last code provided doesn’t work at all only throws a white screen error.
Any other suggestions?Thanks
March 8, 2015 at 20:08 #49245LauraModeratorHello, please share ftp credentials so i can test it 🙂
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionLaura Solanes - Graphic Designer and Web Designer
Please be patient as I try to answer each topic as fast as i can.
If you like the theme or the support you've received please consider leaving us a review on Themeforest!
Always happy to help you 🙂
-
AuthorPosts
The forum ‘KLEO’ is closed to new topics and replies.