A
A
Alexander Sharomet2017-10-16 11:48:01
PHP
Alexander Sharomet, 2017-10-16 11:48:01

How to redirect a regular user to 404 in wordpress if he climbs into the admin panel?

Hello.
Please tell me how to do something like this.
If I enter the site as an admin, I can go to the admin panel in plugins, etc. site/wp-admin/plugins.php
But if a regular user enters site/wp-admin/plugins.php without admin rights, then he needs to be redirected to 404 page.
How to do this. Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Sobolev, 2017-10-16
@sharomet

read about wordpress htaccess

D
deadnice, 2017-10-20
@deadnice

Here is a crutch option:

add_action( 'auth_redirect', 'check_user_access' );
function check_user_access() {
  if ( $_SERVER['REQUEST_URI'] == '/wp-admin/plugins.php' && ! current_user_can('administrator') ) {
    wp_redirect(home_url().'/404');
    exit;
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question