简体   繁体   中英

Wordpress Dashboard redirect for specific User Role

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 (ie 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;
    }
} );

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;
    }
} );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM