0

こんにちは、ワードプレス サイトのカスタム セクションを作成しようとしています。サブスクライバーにアクセス権を与える必要があります。

カスタム投稿タイプ (ボート) を作成しました。私がする必要があるのは:

1 - カスタム投稿タイプへのサブクライバーへのアクセスを許可します。

2 - サブスクライバーに、自分の投稿でのみファイルを公開/編集/削除/アップロードする許可を付与します (+ 私が作成した既に作成された分類の 1 つに投稿を割り当てる許可)

3 - 他の購読者の投稿の表示/編集を制限する

4 - 購読者に自分のプロフィールとカスタム投稿タイプのセクション以外は見せたくない

role scoper、wp-Members、および Capability Manager を使用しようとしましたが、どれも私が望んでいることを正確に実行していないようです。あなたがそれを行う方法を知っていれば、私は本当に感謝します

助けてくれてありがとう。

4

1 に答える 1

3

Here is what I did, instead of granting subscriber all these permission, I upgraded all my subscribers to contributor.

I changed the capability of my custom post type to:

$args = array(
        'labels'             => $labels,
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'rewrite'            => array( 'slug' => 'boat' ),
        'capability_type'    => 'post',
        'capabilities'       => array(
                                'publish_posts'       => 'edit_posts',//contributor can edit
                                'edit_others_posts'   => 'update_core',//administrator can see other
                                'delete_posts'        => 'update_core',//administrator can see other
                                'delete_others_posts' => 'update_core',//administrator can see other
                                'read_private_posts'  => 'update_core',//administrator can see other
                                'edit_post'           => 'edit_posts',//contributor can edit
                                'delete_post'         => 'update_core',//administrator can see other
                                'read_post'           => 'edit_posts',//contributor can edit
                                ),
        'has_archive'        => true,
        'hierarchical'       => false,
        'menu_position'      => null,
        'supports'           => array( 'title','revision' )
);

register_post_type("boat", $args);

Then I added some custom function I found at different webpage :

This one hide the menu I dont want the contributor to see

source : source 1 and : source 2

function remove_menus(){

  $author = wp_get_current_user();
  if(isset($author->roles[0])){ 
     $current_role = $author->roles[0];
  }else{
     $current_role = 'no_role';
  }

  if($current_role == 'contributor'){  
     remove_menu_page( 'index.php' );                  //Dashboard
     remove_menu_page( 'edit.php' );                   //Posts
     remove_menu_page( 'upload.php' );                 //Media
     remove_menu_page( 'tools.php' );                  //Tools
     remove_menu_page( 'edit-comments.php' );               //Comments
     remove_menu_page( 'edit.php?post_type=my_other_custom_post_type_I_want_to_hide' );
  }

}
add_action( 'admin_menu', 'remove_menus' );

Then I restricted contributor from seings other post with : from : source 3

add_action( 'load-edit.php', 'posts_for_current_contributor' );
function posts_for_current_contributor() {
    global $user_ID;

    if ( current_user_can( 'contributor' ) ) {
        if ( ! isset( $_GET['author'] ) ) {
            wp_redirect( add_query_arg( 'author', $user_ID ) );
            exit;
        }
    }
}

And finally I allowed contributor to upload file with : from source 4

add_action('admin_init', 'allow_contributor_uploads');

function allow_contributor_uploads() {
    $contributor = get_role('contributor');
    $contributor->add_cap('upload_files');
}

Since I got a bunch of custom field in my custom post type I made with ACF (Advance custom field) I restricted the media upload to only local post so my contributor cant use media from other people.

I hope this will help someone! :)

于 2014-09-12T18:10:52.200 に答える