1
votes

I added this to my functions.php file to disable wp-admin access for subscribers. Right now it redirects subscribers to the front page and I'd like to redirect users to the browser's stock 404. I can change the redirection to a page that doesn't exist...

wp_redirect(home_url('/fakepage'));

...which will take the user to the browser's stock 404 but that non-existent page will show in the URL.

/**
 * Disable wp-admin access for subscribers
 */
function disable_dashboard() {
    if (!is_user_logged_in()) {
        return null;
    }
    if (!current_user_can('administrator') && is_admin()) {
        wp_redirect(home_url());
        exit;
    }
}
add_action('admin_init', 'disable_dashboard');
1

1 Answers

0
votes

So, to be clear, you want the user to be sent to your homepage address, but instead of seeing your homepage they'll see a 404 message?

Wow, that sounds pretty wonky, and I'm pretty sure you don't really want to do that unless there's some very compelling reason. This would be super confusing to the user.

Why not just make your 404 page's address / slug be something descriptive like /404 or /not-found, and call it a day? Trying to redirect to the homepage and show different content would probably take some goofy POST variables which you'd need to detect on the homepage and alter your template display based on that.