Wordpress: Hide WP backend from subscribers

<?php function hide_admin_from_subscribers () { if ( ! current_user_can( 'edit_posts' ) && ( ! defined( 'DOING_AJAX' ) || false == DOING_AJAX ) ){ wp_safe_redirect( site_url() ); exit; } } add_action( 'admin_init', 'hide_admin_from_subscribers' );
Prevents anyone without privileges to edit posts from seeing the wordpress backend. We make an exception for ajax so our `wp_ajax_*` hooks successfully fire.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.