2016-03-22 15 views
0

wp_terms_checklistを使用して、ユーザがユーザプロファイルをチェックインするオプションを表示しています。 の管理者としてログインしても問題ありませんが、のユーザとしてログインすると、チェックボックスの入力にはdisabled="disabled"が追加されます。ユーザプロファイルでwp_terms_checklistチェックボックスが無効になっています

コンテンツがサブスクライバのプロファイルページに実際に表示されているため、これは権限の問題ではないと思います。それは、この関数から来る可能性が高いと思われる理由は、https://codex.wordpress.org/Function_Reference/disabledです。

あなたが正しい
<?php 

add_action('show_user_profile', 'iw_notify_show_user_options'); 
add_action('edit_user_profile', 'iw_notify_show_user_options'); 

function iw_notify_show_user_options($user) { ?> 

<h3 id="notifications">Notification Options</h3> 

<style> 
    .iw_notify_heirarchical_list ul { padding-left:20px; } 
</style> 

<div class='iw_notify_heirarchical_list'> 
    <ul class=iw_notify_heirarchical_list> 
     <?php 
      $selected_cats = get_the_author_meta('tax_input', $user->ID); 
      $selected_cats = $selected_cats['notifications']; 

      if (!function_exists('wp_terms_checklist')) { 
        require_once ABSPATH . '/wp-admin/includes/template.php'; 
       } 
      $post_id = -1; 
      $args = array( 
       'descendants_and_self' => 0, 
       'selected_cats' => array('165','164'), 
       'popular_cats' => false, 
       'walker' => '', 
       'taxonomy' => 'notifications', 
       'checked_ontop' => false 
      ); 
      wp_terms_checklist($post_id, $args); 
     ?> 
    </ul> 
</div> 


<?php } 

add_action('personal_options_update', 'my_save_extra_profile_fields'); 
add_action('edit_user_profile_update', 'my_save_extra_profile_fields'); 

function my_save_extra_profile_fields($user_id) { 

if (!current_user_can('read', $user_id)) 
    return false; 

    update_usermeta($user_id, 'tax_input', $_POST['tax_input']); 
} 

答えて

0

wp_terms_checklistチェックボックスは機能disabledによって無効:

はここのコードです(これは私が作っていたカスタムプラグインの一部です)。

キーdisabledが設定されたtemplate.php https://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-admin/includes/template.php#L114

$tax = get_taxonomy($taxonomy); 
$args['disabled'] = ! current_user_can($tax->cap->assign_terms); 

コアが表示された場合(あなたのケースに分類が通知です)分類から割り当てる現在のユーザーroles and capabilitiesに依存します。

だから、あなたはあなたの関数にregister_taxonomy通知を確認し、パラメータcapabilitiesを設定することを確認する必要があります。あなたの条件のチェックリストを使用する完全な権限を持っている加入者が必要な場合は、次のように設定する必要があります。

'capabilities' => array(
    'manage_terms' => 'read', 
    'edit_terms' => 'read', 
    'delete_terms' => 'read', 
    'assign_terms' => 'read' 
) 

はちょうどあなたのニーズと微調整します。役割と能力についてはWP Codex https://codex.wordpress.org/Roles_and_Capabilitiesを参照してください。