Notifications
Clear all

[Closed] user can view domain/wp-admin page

8 Posts
3 Users
3 Reactions
1,037 Views
ufuk
Posts: 7
 ufuk
Topic starter
(@ufuk)
Active Member
Joined: 8 years ago

hi,

 

Registered users can view domain/wp-admin page.

 

how can i disable this?

 

thank you.

 

 

7 Replies
Tutrix
Posts: 1495
(@tutrix)
Noble Member
Joined: 5 years ago

@ufuk

Dashboard > Forums > Settings > Features Tab > Show Admin Bar for Members

Features

 

 

4 Replies
ufuk
 ufuk
(@ufuk)
Joined: 8 years ago

Active Member
Posts: 7

@tutrix thanks. i dit it. bar disappered but if a user type domain/wp-admin can go and login then see the page. Ok user has not have admin privileges but it is not nice 🙁

Tutrix
(@tutrix)
Joined: 5 years ago

Noble Member
Posts: 1495

@ufuk

you can add this code to the functions.php of your WP theme

function restrict_admin()
{
	if ( ! current_user_can( 'manage_options' ) ) {
                wp_redirect( site_url() );
                exit;
	}
}
add_action( 'admin_init', 'restrict_admin', 1 );
ufuk
 ufuk
(@ufuk)
Joined: 8 years ago

Active Member
Posts: 7

@tutrix it worked. Thank you so much 😊

Tutrix
(@tutrix)
Joined: 5 years ago

Noble Member
Posts: 1495

@ufuk

use this code instead of the one above, otherwise the ajax.php will be blocked and some things will no longer work

add_action( 'init', 'wpse_182220_init' );
function wpse_182220_init() {

// Exit function if doing an AJAX request
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return;
}
}
function restrict_admin() {

if ( ! current_user_can( 'manage_options' ) && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
wp_die( __( 'You are not allowed to access this part of the site' ) );
}
}
add_action( 'admin_init', 'restrict_admin', 1 );

see also https://wordpress.stackexchange.com/questions/182220/plugin-init-hook-fires-repeatedly

ufuk
Posts: 7
 ufuk
Topic starter
(@ufuk)
Active Member
Joined: 8 years ago

by the way your forum is very nice 😉 

Robert
Posts: 10591
Admin
(@robert)
Support Team
Joined: 9 years ago

Why not just use a plugin to restrict admin access?

https://wordpress.org/plugins/remove-dashboard-access-for-non-admins/