0

我创建了一个新用户,并给了他“作者”角色。我希望他只能在 wordpress 中写帖子。但是当他登录时,他输入了用户个人资料,但没有输入我想要的 wordpress 仪表板。我怎样才能解决这个问题?我想让他去 wordpress 仪表板,这样他就只能写帖子了。

4

2 回答 2

0

尝试这个,

<?php
  // check if current user is the post author
  global $current_user;
  get_currentuserinfo();
  if (is_user_logged_in() && $current_user->ID == $post->post_author)  {
     wp_redirect( admin_url( 'the url you need to redirect' ) );
     exit;
  }
?>
于 2019-12-18T04:59:42.693 回答
0

添加此代码

function check_custom_authentication () {

    $user_id = get_current_user_id(); 
    $user_meta = get_userdata($user_id);
    $user_roles = $user_meta->roles;

    if ( in_array('author', $user_roles, true ) ) {
        wp_redirect(admin_url());
        exit;
    }

}
add_action( 'wp_login' , 'check_custom_authentication' );
于 2020-03-02T14:21:26.810 回答