Random WordPress Function

Learn about a new WordPress function every day!


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 specific page if they are not logged in
add_action( 'wpmu_admin_do_redirect', 'custom_redirect_function' );
function custom_redirect_function() {
    if ( ! is_user_logged_in() ) {
        wp_redirect( home_url( '/login' ) );
        exit;
    }
}
// Example 2: Redirect users to a custom page based on their user role
add_action( 'wpmu_admin_do_redirect', 'custom_role_redirect_function' );
function custom_role_redirect_function() {
    if ( current_user_can( 'editor' ) ) {
        wp_redirect( home_url( '/editor-dashboard' ) );
        exit;
    } elseif ( current_user_can( 'author' ) ) {
        wp_redirect( home_url( '/author-dashboard' ) );
        exit;
    }
}
// Example 3: Redirect users to a specific page if they access a restricted area
add_action( 'wpmu_admin_do_redirect', 'custom_restricted_area_redirect_function' );
function custom_restricted_area_redirect_function() {
    if ( is_page( 'restricted-page' ) && ! current_user_can( 'manage_options' ) ) {
        wp_redirect( home_url( '/access-denied' ) );
        exit;
    }
}