WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Redirect Access Denied page to my 404 page? (7 posts)

  1. qzha017
    Member
    Posted 1 year ago #

    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

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    That message is not coming from WordPress. Are you using a plugin to add it?

  3. qzha017
    Member
    Posted 1 year ago #

    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

  4. esmi
    Forum Moderator
    Posted 1 year ago #

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

  5. criscaducoy
    Member
    Posted 1 year ago #

    @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: http://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.

  6. qzha017
    Member
    Posted 1 year ago #

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

  7. criscaducoy
    Member
    Posted 1 year ago #

    Your welcome :)

Topic Closed

This topic has been closed to new replies.

About this Topic