Close

Account

Documentation

Forum

Menu

The problem with fake 404

  • Post count: 25
    Ray_Kun
    February 10, 2019 at 1:53 am #43045

    Hellp.
    I use the code below in functions.php
    This works well for other sites. But in jnews, when switching to wp-admin, the page with the answer 404 is incorrectly displayed.

    add_action(‘init’, ‘remove_default_redirect’);
    add_filter(‘auth_redirect_scheme’, ‘stop_redirect’, 9999);

    function stop_redirect($scheme)
    {
    if ( $user_id = wp_validate_auth_cookie( ”, $scheme) ) {
    return $scheme;
    }
    global $wp_query;
    $wp_query->set_404();
    get_template_part( 404 );
    exit();
    }
    function remove_default_redirect()
    {
    remove_action(‘template_redirect’, ‘wp_redirect_admin_locations’, 1000);
    }

    //ошибка 404 при попытке доступа к wp-admin
    function true_wp_admin_block() {
    if (!current_user_can(‘administrator’) && $_SERVER[‘DOING_AJAX’] !== ‘/wp-admin/admin-ajax.php’) { // если не администратор
    add_action(‘wp_head’, ‘noRobots’);
    function noRobots() {
    echo “\t<meta name=’robots’ content=’noindex, nofollow’ />\r\n”;
    }
    $GLOBALS[‘wp_query’]->set_404();
    status_header( 404 );
    nocache_headers();
    include( get_query_template( ‘404’ ) );
    die();
    }
    }
    add_action(‘admin_menu’, ‘true_wp_admin_block’);

    Post count: 25
    Ray_Kun
    February 10, 2019 at 2:09 am #43046
    This reply has been marked as private.
    Post count: 2818
    Ferdy
    February 11, 2019 at 1:03 pm #43072

    Hi Ray_Kun,

    Regarding your issue, it because our theme detect the admin page has been load and make some ajax request disable the request. Actually, this is not our support scope. I hope you understand our Support Policy, hope you don’t mind. But, we will always try to help our customer as long as we can. Let us know if you have further question.

    Thank you

    Post count: 25
    Ray_Kun
    February 12, 2019 at 4:35 am #43112
    This reply has been marked as private.
    Post count: 2818
    Ferdy
    February 12, 2019 at 4:56 pm #43155
    This reply has been marked as private.

You must be logged in to reply to this topic.