• Resolved Nick

    (@pilotnick)


    Is there any way to make the example.com/wp-admin/ login slug throw 404 error? Currently, when you visit the /wp-admin/ page a “This has been disabled” message appears.

    I really don’t like this. I would simply rather a 404 error be thrown. Is this possible?

Viewing 9 replies - 1 through 9 (of 9 total)
  • I am seconding the author of the above post on this. Getting a “This has been disabled” message is really annoying. Please rectify this issue, Thanks.

    That’s true. Is there any way to edit the text atleast?

    The plugin already throws 403 Forbidden HTTP status code:

    wp_die( __( 'This has been disabled', 'wps-hide-login' ), 403 );

    Hi, I made an hack to the plugin on my local site in order to display 404 page when wp-admin is requested.
    I replaced the line
    wp_die( __( 'This has been disabled', 'wps-hide-login' ), 403 );
    in wp_loaded() function with

    global $wp_query;
    $wp_query->set_404();
    status_header( 404 );
    get_template_part( 404 );
    exit();

    I’m not a wordpress expert but it seems to work

    @fabino, you’ll loose your hack after the plugin update. Never edit WordPress core files or plugins developed by others not you.

    @maxoud, you’re definitely right.
    A better hack would be to hook wp_loaded action

    I made a quite satisfying attempt

    add_action( 'wp_loaded', 'wp_loaded2',1 );
    function wp_loaded2(){
     global $pagenow;
     if ( is_admin() && ! is_user_logged_in() && ! defined( 'DOING_AJAX' ) && $pagenow !== 'admin-post.php' ) {
      global $wp_query;
      $wp_query->set_404();
      status_header( 404 );
      get_template_part( 404 );
      exit();
     }
    }
    add_action( 'init', 'force_404', 1 );
    
    function force_404() {
        $requested_uri = $_SERVER["REQUEST_URI"];
        do_action('debugger_var_dump', $requested_uri, '$requested_uri', 0, 0);
        do_action('debugger_var_dump', strpos( $requested_uri, '/wp-login.php'), 'FOUND?', 0, 0);
    
        if (  strpos( $requested_uri, '/wp-login.php') !== false ) {
    
            do_action('debugger_var_dump', 'REDIRECT', 'REDIRECT', 0, 0);
            // The redirect codebase
            status_header( 404 );
            nocache_headers();
            include( get_query_template( '404' ) );
            die();
        }
    
        if (  strpos( $requested_uri, '/wp-login.php') !== false || strpos( $requested_uri, '/wp-register.php') !== false ) {
    
            do_action('debugger_var_dump', 'REDIRECT', 'REDIRECT', 0, 0);
            // The redirect codebase
            status_header( 404 );
            nocache_headers();
            include( get_query_template( '404' ) );
            die();
        }
    
        if (  strpos( $requested_uri, '/wp-admin') !== false && !is_super_admin() ) {
    
            do_action('debugger_var_dump', 'REDIRECT', 'REDIRECT', 0, 0);
            // The redirect codebase
            status_header( 404 );
            nocache_headers();
            include( get_query_template( '404' ) );
            die();
        }
    
        do_action('debugger_var_dump', 'END', 'END', 0, 0);
    }

    Just add some condition for Ajax etc if you need or get template part, as you wish…

    gore.m

    (@gorem)

    1+ for redirect to 404 as default.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Make /wp-admin/ throw a 404 page or something’ is closed to new replies.