'parent', 'id' => 'term_id'); //TODO: decouple this function start_lvl(&$output, $depth, $args) { $indent = str_repeat("\t", $depth); $output .= "$indent\n"; } function start_el(&$output, $category, $depth, $args) { extract($args); if ( empty($taxonomy) ) $taxonomy = 'category'; if ( $taxonomy == 'category' ) $name = 'post_category'; else $name = 'tax_input['.$taxonomy.']'; $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : ''; $output .= "\n
  • " . ''; } function end_el(&$output, $category, $depth, $args) { $output .= "
  • \n"; } } class AttachmentTaxSupp_Admin { /** * Configure Admin */ function AttachmentTaxSupp_Admin() { global $AttachmentTaxSupp; add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), null, 2 ); add_filter( 'attachment_fields_to_save', array( $this, 'attachment_fields_to_save' ), null, 2 ); wp_enqueue_script( 'media_taxonomies', plugins_url( dirname( $AttachmentTaxSupp->plugin_basename ) . '/admin/js/admin.js' ), array( 'jquery', 'suggest', 'post' ) ); } /** * Edit Image Form */ function attachment_fields_to_edit( $form_fields, $post ) { foreach ( $form_fields as $key => $val ) { if ( isset( $val['hierarchical'] ) && taxonomy_exists( $val['name'] ) ) { $tax_name = esc_attr( $val['name'] ); $taxonomy = get_taxonomy( $val['name'] ); if ( $val['hierarchical'] == true) { //$popular_ids = wp_popular_terms_checklist( $tax_name ); ob_start(); //wp_terms_checklist( $post->ID, array( 'taxonomy' => $tax_name, 'popular_cats' => $popular_ids, 'walker' => new AttachmentTaxSupp_Walker_Category_Checklist ) ); $wp_terms_checklist_walker = new AttachmentTaxSupp_Walker_Category_Checklist; $wp_terms_checklist_walker->attachment_id = $post->ID; wp_terms_checklist( $post->ID, array( 'taxonomy' => $tax_name, 'walker' => $wp_terms_checklist_walker ) ); $checklist = ob_get_contents(); ob_end_clean(); $html = '
      ' . $checklist . '
    '; /* if ( current_user_can( $taxonomy->cap->edit_terms ) ) : $html .= '

    + Add New Category

    '; endif; */ $html .= '

    Manage ' . $taxonomy->labels->name . '

    '; $html .= wp_nonce_field( 'update_attachment', '_wpnonce_attachmenttaxsupp', true, false ); $form_fields[$key]['input'] = 'html'; $form_fields[$key]['html'] = $html; } else { $disabled = !current_user_can( $taxonomy->cap->assign_terms ) ? ' disabled="disabled"' : ''; $html = '

    ' . $taxonomy->labels->add_or_remove_items . '

    '; if ( current_user_can( $taxonomy->cap->assign_terms ) ) : $html .= '
    ' . $taxonomy->labels->add_new_item . '

    ' . esc_attr( $taxonomy->labels->separate_items_with_commas ) . '

    '; endif; $html .= '
    '; if ( current_user_can( $taxonomy->cap->assign_terms ) ) : $html .= '

    ' . $taxonomy->labels->choose_from_most_used . '

    '; endif; $html .= '
    '; $html .= '

    Manage ' . $taxonomy->labels->name . '

    '; $html .= wp_nonce_field( 'update_attachment', '_wpnonce_attachmenttaxsupp', true, false ); $form_fields[$key]['input'] = 'html'; $form_fields[$key]['html'] = $html; } } } return $form_fields; } /** * Save Image Form * @todo If some checkboxes are checked and you uncheck all on a media page, it doesn't save */ function attachment_fields_to_save( $post, $attachment ) { if ( empty( $_POST ) || !wp_verify_nonce( $_POST['_wpnonce_attachmenttaxsupp'], 'update_attachment' ) ) return $post; if ( isset( $_POST['tax_input'] ) && is_array( $_POST['tax_input'] ) ) { foreach ( $_POST['tax_input'] as $tax => $arr ) { if ( taxonomy_exists( $tax ) ) { $val = null; if ( isset( $arr[$post['ID']] ) ) $val = array_map( 'absint', $arr[$post['ID']] ); wp_set_object_terms( $post['ID'], $val, $tax ); } } } else { $taxes = get_taxonomies( array( 'show_ui' => true, '_builtin' => false ) ); foreach ( $taxes as $tax ) { wp_set_object_terms( $post['ID'], array(), $tax ); } } return $post; } } ?>