• Resolved qzha017

    (@qzha017)


    Hi everyone
    currently users of my website will be taken to a page displaying:

    Access Denied. Your site administrator has blocked your access to the WordPress back-office.

    if they try to access the dashboard, I was wondering can I change the above page to my 404 page?

    Thanks everyone

Viewing 6 replies - 1 through 6 (of 6 total)
  • That message is not coming from WordPress. Are you using a plugin to add it?

    Thread Starter qzha017

    (@qzha017)

    Hi Esmi thanks for pointing that out, I found out its the WP-User-frontend plugin thats showing the message, and the code is:

    * Block user access to admin panel for specific roles
         *
         * @global string $pagenow
         */
        function block_admin_access() {
            global $pagenow;
    
            $access_level = wpuf_get_option( 'admin_access' );
            $valid_pages = array('admin-ajax.php', 'async-upload.php', 'media-upload.php');
    
            if ( !current_user_can( $access_level ) && !in_array( $pagenow, $valid_pages ) ) {
                wp_die( __( 'Access Denied. Your site administrator has blocked your access to the WordPress back-office.', 'wpuf' ) );
            }
        }

    Do you know how to change it so it is redirected to my 404 page?
    if not I will ask the plugin author

    Thank you so much for your help

    Your best bet is to ask the plugin developer about this.

    @qzha017

    Hi, this might not be the best answer here but might be useful temporarily. Beside, as I can see on the statement above. Maybe you can replace the line:

    if ( !current_user_can( $access_level ) && !in_array( $pagenow, $valid_pages ) ) {
                wp_die( __( 'Access Denied. Your site administrator has blocked your access to the WordPress back-office.', 'wpuf' ) );
            }

    into something like:

    if ( !current_user_can( $access_level ) && !in_array( $pagenow, $valid_pages ) ) {
          header( 'Location: https://www.yoursite.com/404_page/' ) ;
            }

    I did this on some of my php sites. Please check if it may come in handy at your wordpress.

    This may seem awkward but works right. You can do a custom page for 404 handling or make the Location into something that your site will never have. hahaha…

    I am sorry if I am so dumb and lazy to do some novel code in equivalent of this short code.

    Thread Starter qzha017

    (@qzha017)

    hey criscaducoy
    That worked like magic thank you so much!
    Alex

    Your welcome ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Redirect Access Denied page to my 404 page?’ is closed to new replies.