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 all non-admin users to the homepage when accessing the admin dashboard
add_action( 'wpmu_admin_do_redirect', function() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_redirect( home_url() );
exit;
}
});
// Example 2: Redirect users to a custom page if they try to access a specific admin page
add_action( 'wpmu_admin_do_redirect', function() {
if ( isset( $_GET['page'] ) && $_GET['page'] === 'custom-admin-page' ) {
wp_redirect( home_url( '/custom-page' ) );
exit;
}
});
// Example 3: Redirect users to a login page if they are not logged in when trying to access the admin dashboard
add_action( 'wpmu_admin_do_redirect', function() {
if ( ! is_user_logged_in() ) {
wp_redirect( wp_login_url() );
exit;
}
});