Function Signature:
wpmu_admin_do_redirect
Function Description:
Redirect a user based on $_GET or $_POST arguments.
Function Examples:
⚠️ Examples below are generated with GPT-3 once every hour. Do not take them too seriously.
Consider them as some extra input in your learning process - reason about them. Will it work? What could fail?
// Example 1: Redirect users to a custom login page if they try to access the default WordPress login page
add_action( 'wpmu_admin_do_redirect', 'custom_login_redirect' );
function custom_login_redirect() {
if ( strpos( $_SERVER['REQUEST_URI'], 'wp-login.php' ) !== false ) {
wp_redirect( home_url( '/custom-login' ) );
exit();
}
}
// Example 2: Redirect users to a specific page if they try to access a restricted area of the website
add_action( 'wpmu_admin_do_redirect', 'restricted_area_redirect' );
function restricted_area_redirect() {
if ( ! current_user_can( 'manage_options' ) && strpos( $_SERVER['REQUEST_URI'], 'restricted-page' ) !== false ) {
wp_redirect( home_url( '/redirected-page' ) );
exit();
}
}
// Example 3: Redirect users to a maintenance page during scheduled maintenance hours
add_action( 'wpmu_admin_do_redirect', 'maintenance_redirect' );
function maintenance_redirect() {
$current_time = current_time( 'timestamp' );
$start_time = strtotime( '2023-01-01 00:00:00' );
$end_time = strtotime( '2023-01-01 06:00:00' );
if ( $current_time >= $start_time && $current_time <= $end_time ) {
wp_redirect( home_url( '/maintenance-page' ) );
exit();
}
}