I am building a community based WP site at the mo and have blocked anyone bar admins from using the admin section on the site with:
add_action( 'init', 'sw_block_users' );
function sw_block_users() {
if ( is_admin() && ! current_user_can( 'administrator' ) ) {
wp_redirect( home_url() );
exit;
}
}
However, I'm also using the awesome power of admin-ajax.php to do a few ajaxy things (as outlined here : http://reallywebdesign.com/2011/09/send-dynamic-data-to-javascript-in-wordpress/), which get blocked by the above function.
Is there a different way I can prevent non-admins from getting to wp-admin directory, while maintaining the use of the admin-ajax file? Thanks!