Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Vladimir Garagulya

    (@shinephp)

    Hi,

    This message is shown by wp-admin/includes/menu.php:

    if ( ! user_can_access_admin_page() ) {
    
    	/**
    	 * Fires when access to an admin page is denied.
    	 *
    	 * @since 2.5.0
    	 */
    	do_action( 'admin_page_access_denied' );
    
    	wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
    }

    So you can use ‘admin_page_access_denied’ to show a custom message and stop PHP execution via wp_die() or redirect.

    Thread Starter karchung0930

    (@karchung0930)

    Brilliant! What if I don’t want to show the message instead of just redirecting them to the 404? Sorry, I’m not familiar with PHP.

    Should it be something like this?

    if ( ! user_can_access_admin_page() ) {
    
    	/**
    	 * Fires when access to an admin page is denied.
    	 *
    	 * @since 2.5.0
    	 */
    	do_action( 'admin_page_access_denied' );
    
    	wp_die( __ 404 );
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Change Error Message or Redirect’ is closed to new replies.