mardi 22 mars 2016

wp_terms_checklist checkboxes are disabled in the subscriber profile

I am using wp_terms_checklist to display options for a user to check in the user profile. This works fine when logged in as admin, but when I log in as a subscriber the check box inputs have disabled="disabled" added to them.

I would not think this is a permissions issue, since the content is actually appearing in the subscriber's profile page. It seems likely that it comes from this function http://ift.tt/1RjPKuJ, why I don't know.

Here's the code (This is part of a custom plugin I am making):

<?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'] );
}




Aucun commentaire:

Enregistrer un commentaire