This topic has 2 replies, 2 voices, and was last updated 9 years by carolina marques.
-
Author
-
May 14, 2015 at 01:57 #58698carolina marquesParticipant
Well, I was looking for some codes to block access to wp-admin and also hide the admin bar to subscribers. I have the codes in the child theme functions.php.
COPY CODE/** * Disables the admin bar in frontend of your site * To the subscribers. */ function themeblvd_disable_admin_bar ( ) { if ( ! current_user_can ( 'activate_plugins' ) ) add_filter ( 'show_admin_bar' , '__return_false' ) ; } add_action ( 'after_setup_theme' , 'themeblvd_disable_admin_bar' ) ;
`/**
* Redirect back to the beginning and not allow access to
* WP admin to Subscribers.
*/
function themeblvd_redirect_admin ( ) {
if ( ! current_user_can ( ‘activate_plugins’ ) ) {
wp_redirect ( site_url () ) ;
exit ;
}
}
add_action ( ‘admin_init’ , ‘themeblvd_redirect_admin’ ) ; `I took these tips in another forum, but after adding the code, the problem arose with the ajax-search that no longer works. Yes, I know that the problem is caused if you use Ajax in wordpress. (Wp-admin / admin-ajax.php.)
So if a user is restricted to entire folder wp-admin, it will also be restricted in admin-ajax.php function to ajax will not work anymore.
Is there any way to fix this?
I tried another code – below – but it did not work …
COPY CODEif ( ! current_user_can( 'edit_posts' ) ){ if (defined( 'DOING_AJAX' ) and DOING_AJAX) { // do nothing } else { wp_redirect( site_url() ); exit; } }
May 14, 2015 at 04:22 #58706sharmstrModeratorhttps://gist.github.com/Victoor/7823525
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionThis support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com
-
AuthorPosts
The forum ‘KLEO’ is closed to new topics and replies.