Advertisement
IlyaOlchikov

cusom cat check list

Mar 4th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.37 KB | None | 0 0
  1. // add the new box
  2. function add_custom_categories_box() {
  3.     add_meta_box('customcategorydiv', 'Категории', 'custom_post_categories_meta_box', 'post', 'side', 'low', array( 'taxonomy' => 'category' ));
  4. }
  5. add_action('admin_menu', 'add_custom_categories_box');
  6.  
  7. function custom_post_categories_meta_box( $post, $box ) {
  8.     $defaults = array('taxonomy' => 'category');
  9.     if ( !isset($box['args']) || !is_array($box['args']) )
  10.         $args = array();
  11.     else
  12.         $args = $box['args'];
  13.     extract( wp_parse_args($args, $defaults), EXTR_SKIP );
  14.     $tax = get_taxonomy($taxonomy);
  15.  
  16.     ?>
  17.     <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv">
  18.         <ul id="<?php echo $taxonomy; ?>-tabs" class="category-tabs">
  19.             <li class="tabs"><a href="#<?php echo $taxonomy; ?>-all" tabindex="3"><?php echo $tax->labels->all_items; ?></a></li>
  20.             <li class="hide-if-no-js"><a href="#<?php echo $taxonomy; ?>-pop" tabindex="3">Часто используемые</a></li>
  21.         </ul>
  22.  
  23.         <div id="<?php echo $taxonomy; ?>-pop" class="tabs-panel" style="display: none;">
  24.             <ul id="<?php echo $taxonomy; ?>checklist-pop" class="categorychecklist form-no-clear" >
  25.                 <?php $popular_ids = wp_popular_terms_checklist($taxonomy); ?>
  26.             </ul>
  27.         </div>
  28.  
  29.         <div id="<?php echo $taxonomy; ?>-all" class="tabs-panel">
  30.             <?php
  31.             $name = ( $taxonomy == 'category' ) ? 'post_category' : 'tax_input[' . $taxonomy . ']';
  32.             echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
  33.             ?>
  34.             <ul id="<?php echo $taxonomy; ?>checklist" class="list:<?php echo $taxonomy?> categorychecklist form-no-clear">
  35.                 <?php
  36.                 /**
  37.                  * This is the one line we had to change in the original function
  38.                  * Notice that "checked_ontop" is now set to FALSE
  39.                  */
  40.                 wp_terms_checklist($post->ID, array( 'taxonomy' => $taxonomy, 'popular_cats' => $popular_ids, 'checked_ontop' => FALSE ) ) ?>
  41.             </ul>
  42.         </div>
  43.     <?php if ( !current_user_can($tax->cap->assign_terms) ) : ?>
  44.     <p><em><?php _e('You cannot modify this taxonomy.'); ?></em></p>
  45.     <?php endif; ?>
  46.     <?php if ( current_user_can($tax->cap->edit_terms) ) : ?>
  47.             <div id="<?php echo $taxonomy; ?>-adder" class="wp-hidden-children">
  48.                 <h4>
  49.                     <a id="<?php echo $taxonomy; ?>-add-toggle" href="#<?php echo $taxonomy; ?>-add" class="hide-if-no-js" tabindex="3">
  50.                         <?php
  51.                             /* translators: %s: add new taxonomy label */
  52.                             printf( __( '+ %s' ), $tax->labels->add_new_item );
  53.                         ?>
  54.                     </a>
  55.                 </h4>
  56.                 <p id="<?php echo $taxonomy; ?>-add" class="category-add wp-hidden-child">
  57.                     <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>"><?php echo $tax->labels->add_new_item; ?></label>
  58.                     <input type="text" name="new<?php echo $taxonomy; ?>" id="new<?php echo $taxonomy; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $tax->labels->new_item_name ); ?>" tabindex="3" aria-required="true"/>
  59.                     <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>_parent">
  60.                         <?php echo $tax->labels->parent_item_colon; ?>
  61.                     </label>
  62.                     <?php wp_dropdown_categories( array( 'taxonomy' => $taxonomy, 'hide_empty' => 0, 'name' => 'new'.$taxonomy.'_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '&mdash; ' . $tax->labels->parent_item . ' &mdash;', 'tab_index' => 3 ) ); ?>
  63.                     <input type="button" id="<?php echo $taxonomy; ?>-add-submit" class="add:<?php echo $taxonomy ?>checklist:<?php echo $taxonomy ?>-add button category-add-sumbit" value="<?php echo esc_attr( $tax->labels->add_new_item ); ?>" tabindex="3" />
  64.                     <?php wp_nonce_field( 'add-'.$taxonomy, '_ajax_nonce-add-'.$taxonomy, false ); ?>
  65.                     <span id="<?php echo $taxonomy; ?>-ajax-response"></span>
  66.                 </p>
  67.             </div>
  68.         <?php endif; ?>
  69.     </div>
  70.     <?php
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement