私の問題は、非管理者が新しいウィジェットを作成できないことを除いて、すべての機能が期待通りに機能することです。 [新規追加]ボタンはありますが、クリックすると「十分な権限がありません」というメッセージが表示されます。クライアントはedit_postsのようなすべての標準機能をチェックしていません(私が現れる前に他の何らかの理由で)。だから多分それは問題ですか?関連するコードは次のとおりです。カスタム機能を追加するWordpress - ユーザーが新しいカスタム投稿タイプを作成できない
public static function manage_plugin_cap($action = 'add_cap'){
$roles = get_editable_roles();
$caps = array('edit_widget','edit_widgets','read_widgets');
$admin_caps = array('edit_other_widgets','publish_widgets','read_private_widgets','delete_widgets');
foreach ($GLOBALS['wp_roles']->role_objects as $key => $role) {
if (isset($roles[$key])) {
if ($key == 'administrator'){
foreach ($admin_cap as $c){
if ($action=='add_cap')
{$role->add_cap($c, false);}
else {$role->{$action}($c);}
}
}
foreach ($cap as $c){
if ($action=='add_cap')
{$role->add_cap($c, false);}
else {$role->{$action}($c);}
}
}
}
}
register_post_type($this->prefix.'_'.$single, $args);
$args = array(
'labels' => $labels,
'description' => __('Description.', $this->text_domain),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => 'edit.php?post_type={$single}',
'query_var' => true,
'rewrite' => array('slug' => $single,'with_front'=>true),
'capability_type' => 'widget',
'has_archive' => $plural,
'can_export' => true,
'hierarchical' => false,
'menu_position' => null
);
誰かが迷っていることは誰に見えますか?私は 'create_widgets'を成功させずに 'publish_widgets'をすべてのロールに追加しようとしました(私にはできないようにしたいと思いますが)。ありがとう!
編集:私はargsから 'capability_type'を削除しました。私は自分自身を追加することを定義するときには必要ではないと思います(既存の機能からマッピングするときにのみ必要なので、新しい名前の名前を知ることができます)。
更新:私はこれを試して正しいものに戻す機会を得ました。
'capability_type' => 'widget',
'map_meta_cap' => false,
create_widgets以外のすべてのために働くように見えるん: は、私は私のregister_post_type配列内のこれらの要素を持っています。 私は$ GLOBALS [ 'wp_post_types'] [ 'my_cpt']をダンプするとき、私はそれがedit_widgets」として 'create_posts' を示し、なぜだから私はよく分からない
public 'cap' =>
object(stdClass)[434]
public 'edit_post' => string 'edit_widget' (length=10)
public 'read_post' => string 'read_widget' (length=10)
public 'delete_post' => string 'delete_widget' (length=12)
public 'edit_posts' => string 'edit_widgets' (length=11)
public 'edit_others_posts' => string 'edit_others_widgets' (length=18)
public 'publish_posts' => string 'publish_widgets' (length=14)
public 'read_private_posts' => string 'read_private_widgets' (length=19)
public 'create_posts' => string 'edit_widgets' (length=11)
を取得しますか?
お役立ち情報私が思い出すと、私はその許可を得てしまいました。私たちはそれをすべて考え出しました。私はそれが長期的に良くなったと思うので、それを変更する可能性は低いので、私はこの答えをテストすることができます。しかし、私がテストに回ったり、誰かがこれがうまくいくと答えた場合は、答えとしてそれを受け入れることができてうれしいです。ありがとうございました! – user3080408
私はこれをもう一度見ています。あなたの回避策、#1は動作しますが、メニューを制御したいと思います。グループ内の各cptのサブメニュー項目を追加しました。私の役割はedit_widgetsを持っています。私はチェックし、役割と現在のユーザーのためにそこにあります...また、私はtrueにmap_meta_capを設定します。助けてくれてありがとう! – user3080408