-
-
Save tommcfarlin/8b6d790e651757f54f7d62ac027846d0 to your computer and use it in GitHub Desktop.
[WordPress] Redirect WordPress Admin to a Custom Admin Page
This file contains 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 | |
/** | |
* Redirect to the page from which we came (which should always be the | |
* admin page. If the referred isn't set, then we redirect the user to | |
* the login page). | |
* | |
* @access private | |
* @param bool $success Optional If success is false, then the information can't be saved. | |
*/ | |
private function redirect( $success = true ) { | |
// To make the Coding Standards happy, we have to initialize this. | |
if ( ! isset( $_POST['_wp_http_referer'] ) ) { // Input var okay. | |
$_POST['_wp_http_referer'] = wp_login_url(); | |
} | |
// Sanitize the value of the $_POST collection for the Coding Standards. | |
$url = sanitize_text_field( | |
wp_unslash( $_POST['_wp_http_referer'] ) // Input var okay. | |
); | |
$url = ( ! $success ) ? | |
esc_url( remove_query_arg( 'settings-saved', $url ) ) : | |
add_query_arg( 'settings-saved', 'true', $url ); | |
wp_safe_redirect( urldecode( $url ) ); | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment