web-dev-qa-db-ja.com

作者がお互いを閲覧できないようにする

著者として複数のユーザーが存在するサイトを設定します。所有者は、著者間で共有していない情報を持つメタフィールドがいくつかあるため、著者がお互いの投稿を閲覧できないようにしたい。

他の作者の投稿を表示する機能を削除する方法はありますか?

ありがとう、チャック

もう少し明確にするために、これは管理者側のためのものであり、Postsの下の一番上には、私のもの、すべてのもの、公開されたものへのリンクがあります。私は著者に「私のもの」を見てほしいだけです。

5
Chuck

概要画面で他のユーザーの投稿を表示できないように "作成者"ロールを持つユーザーを禁止したい場合は、追加のフィルタを作成者に追加できます。

add_action( 'load-edit.php', 'wpse14230_load_edit' );
function wpse14230_load_edit()
{
    add_action( 'request', 'wpse14230_request' );
}

function wpse14230_request( $query_vars )
{
    if ( ! current_user_can( $GLOBALS['post_type_object']->cap->edit_others_posts ) ) {
        $query_vars['author'] = get_current_user_id();
    }
    return $query_vars;
}

投稿テーブルの上にある小さなリンク( "Mine"、 "All"、 "Drafts")はあまり役に立ちません。それらを削除することもできます。

add_filter( 'views_edit-post', 'wpse14230_views_edit_post' );
function wpse14230_views_edit_post( $views )
{
    return array();
}
11
Jan Fabry

私は今日このようなことをしなければならなかった、そしてこれが私がこの記事を見つけた理由である。私が見つけたのは、この投稿が「 WordPress Admin で自分の投稿に投稿者を制限する方法」というwpbeginnerの投稿です。

これはあなたのfunctions.phpに貼り付けることができるコードです:

function posts_for_current_author($query) {
    global $pagenow;

    if( 'edit.php' != $pagenow || !$query->is_admin )
        return $query;

    if( !current_user_can( 'edit_others_posts' ) ) {
        global $user_ID;
        $query->set('author', $user_ID );
    }
    return $query;
}
add_filter('pre_get_posts', 'posts_for_current_author');
1
Armando Duran

それがまさにデフォルトの "作者"の役割がすることです。 http://codex.wordpress.org/Roles_and_Capabilities

1
Wyck

機能(@Wyckからのリンクを参照)と作成者IDをテンプレート内にチェックし、他の人に見られたくないものをif/elseチェック内に入れるだけです。

// Get the author of this post:
$post_author = get_query_var('author_name') ? get_user_by( 'slug', get_query_var('author_name') ) : get_userdata( get_query_var('author') );

// Get data from current user:
global $current_user;
get_currentuserinfo();
// Get the display_name from current user - maybe you have to exchange it with $current_user->user_login
$current_author = $current_user->display_name;

// Check the capability and if the currently logged in user is the the post author
if ( current_user_can('some_capability') && $post_author == $current_author )
{
    // Post Meta
    $post_meta = get_post_meta( $GLOBALS['post']->ID );
    // DO OR DISPLAY STUFF HERE
}
1
kaiser

より完全な解決策については、こちらをご覧ください(フィルタバーの投稿数も修正する): いくつかの作業コードの要約/最適化に役立ちます

0
Paul