0

how to hide wordpress error message "You do not have sufficient permissions to access this page" and show 404 error page for all non administrator's request like e.g mydomain.com/wp-admin/plugin.php and all such requests. And they should be redirected to 404 error page.

2

Depends on what you mean by "redirect".

If you want to 404 them, this will do the job:

add_filter('wp_die_handler','custom_404_die_handler');
function custom_404_die_handler() {
    global $wp;
    $wp->handle_404();
    load_template(get_404_template());
    die();
}

If you actually want to redirect them somewhere, then you could do something like this, but that's not exactly a "404", as such.

add_filter('wp_die_handler','custom_404_die_handler');
function custom_404_die_handler() {
    wp_safe_redirect( get_home_url() );
    die();
}
|improve this answer|||||
  • Thanks for your help can you please tell me where to put that code because I am a newbie. – user3187719 Jan 29 '14 at 19:05
  • Great it worked I put that in the theme's function.php and it worked. Thanks a lot. – user3187719 Jan 29 '14 at 19:17
  • how to redirect them to the current page or post. – user3187719 Jan 30 '14 at 17:27
  • If they're going to an admin page, then there really isn't any "current page or post" to redirect them to. – Otto Jan 30 '14 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.