0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【WordPress】【ワードプレス】権限の設定

Last updated at Posted at 2023-07-27

投稿者の権限を設定

function add_theme_caps(){
  // 投稿者の設定をする
  $auth_role = get_role( 'author' );
  // 非公開の投稿ページを編集
  $auth_role->add_cap( 'edit_private_posts' );
  // 非公開の投稿ページを閲覧
  $auth_role->add_cap( 'read_private_posts' );     
  // 他ユーザーの投稿ページを編集
  $auth_role->add_cap( 'edit_others_posts' );
  // 固定ページを編集
  $auth_role->add_cap( 'edit_pages' );
  // 非公開の固定ページを編集
  $auth_role->add_cap( 'edit_private_pages' );
  // 非公開の固定ページを閲覧
  $auth_role->add_cap( 'read_private_pages' );
  // 公開中の固定ページを編集
  $auth_role->add_cap( 'edit_published_pages' );
  // 他ユーザーの固定ページを編集
  $auth_role->add_cap( 'edit_others_pages' );
  // HTMLフィルタリング。※有効でないとhtmlが壊れる可能性がある
  $auth_role->add_cap( 'unfiltered_html' );
}
add_action( 'admin_init', 'add_theme_caps' );

投稿者の権限に制限をつける

function remove_theme_caps(){
    // 投稿者の設定をする
    $role = get_role( 'author' );
    // 公開中の投稿ページを削除できないようにする
    $role->remove_cap( 'publish_posts' );
    // 投稿ページを公開できないようにする
    $role->remove_cap( 'delete_published_posts' );
}

add_action

用途 コマンド
admin_init cd ..
wp_enqueue_scripts cd ../..
コマンドの履歴 history
コンソールクリア clear
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?