LoginSignup
0
0

More than 5 years have passed since last update.

カスタム権限を持ったユーザを投稿者で選べるようにする

Posted at

'author'をサポートしたカスタム投稿の編集画面には、セレクトボックスで投稿者を選択できるウィジェットが表示される。

このセレクトボックスに表示するユーザの一覧、どうもauthor相当のuser_levelを持っているかで抽出されているらしく、いろいろ独自に権限をカスタムしたユーザ(例えばカスタム投稿用に作ったロールのみを持ったユーザとか)だと、ドロップボックスに出ない。

検索条件を変えるfilterも見つからなかったので、ユーザ情報の編集画面のactionで、特定の権限の時に、author相当のuser_levelを設定するようにした。

if( current_user_can('edit_user', $user_id) ) {
  if( $_POST['role'] == "author相当のカスタム権限" ) {
    update_user_meta($user_id, $wpdb->prefix . 'user_level', 1);
  }
}

上のコードを、edit_user_profile_updateのアクションフックに設定。

悪影響がありそうな気もするが、とりあえずは動く。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0