Created
May 1, 2023 10:01
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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