Wordpress Dashboard redirect for specific User Role

677 views Asked by At

I'm successfully using this code to redirect /wp-admin/index.php (WP Dashboard) to another specific Admin page. I would now like to limit this action to a specific user role (i.e Author).

add_action( 'admin_init', function () {

    global $pagenow;

    # Check current admin page.
    if ( $pagenow == 'index.php' ) {

        wp_redirect( admin_url( '/admin.php?page=wuapc-page-376' ) );
        exit;
    }
} );
1

There are 1 answers

0
Pankaj Prajapati On BEST ANSWER

use wp_get_current_user

add_action( 'admin_init', function () {

    global $pagenow;
    $user = wp_get_current_user();

    # Check current admin page.
    if ( $pagenow == 'index.php' && in_array('author', $user->roles)) {

        wp_redirect( admin_url( '/admin.php?page=wuapc-page-376' ) );
        exit;
    }
} );