2016-05-16 11 views
0

カスタム投稿タイプの編集ポストページの著者選択ドロップダウンリストのユーザーリストを変更したいと思います。これに使用できるフィルターフックがありますか?私が望むことをするフィルターフックに関する情報を見つけることができませんでした。WordPress編集ポストの著者リストを変更するためのフィルタ

フックは(理論上は)ユーザー配列を返さなければならず、それらは選択ボックスを一番下に配置するユーザーになります。私がこれをやりたいのは、さまざまな投稿の種類ごとにユーザーの役割を条件付きでフィルタリングできるからです。管理者(または他の管理者)として、著者になる前に特定の役割を持っているかどうかを確認する必要はありません。コードの

例:

add_filter('example_filter', 'my_custom_function'); 
function my_custom_function ($users){ 

    // Get users with role 'my_role' for post type 'my_post_type' 
    if('my_post_type' == get_post_type()){ 
     $users = get_users(['role' => 'my_role']); 
    } 

    // Get users with role 'other_role' for post type 'other_post_type' 
    if('other_post_type' == get_post_type()){ 
     $users = get_users(['role' => 'other_role']); 
    } 

    return $users; 
} 
+0

コードを確認できますか? – surajsn

+1

この質問はなぜ落とされたのか分かりません...いくつかのサンプルコードとともにいくつかの明確化と詳細で質問を更新しました。私はフックするフィルターがないので、私のテーマには今のところコードがありません。 –

答えて

0

あなたはフック 'wp_dropdown_users_args' を使用することができます。

テーマのfunctions.phpファイルに下記のコードスニペットを追加してください。

add_filter('wp_dropdown_users_args', 'change_user_dropdown', 10, 2); 

function change_user_dropdown($query_args, $r){ 
// get screen object 
$screen = get_current_screen(); 

// list users whose role is e.g. 'Editor' for 'post' post type 
if($screen->post_type == 'post'): 
    $query_args['role'] = array('Editor'); 

    // unset default role 
    unset($query_args['who']); 
endif; 

// list users whose role is e.g. 'Administrator' for 'page' post type 
if($screen->post_type == 'page'): 
    $query_args['role'] = array('Administrator'); 

    // unset default role 
    unset($query_args['who']); 
endif; 

return $query_args; 
} 

これがあなたに適しているかどうかを教えてください。

関連する問題