Skip to content

Instantly share code, notes, and snippets.

@adczk
Created May 1, 2023 10:01
Show Gist options
  • Select an option

  • Save adczk/4d3d5f021b70dd16419f04e63b7137c9 to your computer and use it in GitHub Desktop.

Select an option

Save adczk/4d3d5f021b70dd16419f04e63b7137c9 to your computer and use it in GitHub Desktop.
wp_die() function override to redirect to custom error page based on error message
<?php
// WP_DIE() override - redirect to custom page on specific error
// Note: this is for standard non-Ajax, non-JSON, non-XML requests;
// for other requests you will need to adjust filters/code
// https://developer.wordpress.org/reference/functions/wp_die/#hooks
add_filter( 'wp_die_handler', 'wpmu_custom_user_wpdie_handler', 11, 1 );
function wpmu_custom_user_wpdie_handler( $message ) {
return 'wpmu_custom_user_wpdie_function';
}
function wpmu_custom_user_wpdie_function( $message, $title, $args ) {
if ( $message == 'The user is already active.' ) {
wp_redirect( 'URL_TO_CUSTOM_ERROR_PAGE' );
exit();
}
call_user_func( '_default_wp_die_handler', $message, $title, $args );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment