01 May Redirect Non-Admin Users from the Backend of WP
Here’s a little piece of code that keeps users away from the backend of WordPress. Let’s say you have built a profile system from the frontend and you only want users to manage these settings through your interface.
1 2 3 4 5 6 7 8 | function jx_redirect_users() { if ( ! current_user_can( 'manage_options' ) && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF'] ) { wp_redirect( home_url('/account') ); exit; } } //Redirect non Admin add_action( 'admin_init', 'jx_redirect_users' ); |
You can customize this even further by changing the permission(current_user_can) parameter, if you only want admin and editors to access the backend.
No Comments