Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use new 'wp_terms_checklist_args' filter

  • Loading branch information...
commit d1c3c1f449e1144542efa17dde84a9f52ade1739 1 parent 0769261
@scribu authored
Showing with 11 additions and 81 deletions.
  1. +6 −79 category-checklist-tree.php
  2. +5 −2 readme.txt
View
85 category-checklist-tree.php
@@ -1,7 +1,7 @@
<?php
/*
Plugin Name: Category Checklist Tree
-Version: 1.2
+Version: 1.3-beta
Description: Preserves the category hierarchy on the post editing screen
Author: scribu
Author URI: http://scribu.net
@@ -11,25 +11,15 @@
class Category_Checklist {
function init() {
- add_action('add_meta_boxes', array(__CLASS__, 'replace_box'));
+ add_filter( 'wp_terms_checklist_args', array( __CLASS__, 'checklist_args' ) );
}
- // adapted from wp-admin/edit-form-advanced.php
- function replace_box($post_type) {
- foreach ( get_object_taxonomies($post_type) as $tax_name ) {
- $taxonomy = get_taxonomy($tax_name);
- if ( !$taxonomy->show_ui || !$taxonomy->hierarchical )
- continue;
+ function checklist_args( $args ) {
+ add_action( 'admin_footer', array( __CLASS__, 'script' ) );
- $label = isset($taxonomy->label) ? esc_attr($taxonomy->label) : $tax_name;
+ $args['checked_ontop'] = false;
- remove_meta_box($tax_name . 'div', $post_type, 'side');
-
- // don't use 'core' as priority
- add_meta_box($tax_name . 'div', $label, array(__CLASS__, 'meta_box'), $post_type, 'side', 'high', array( 'taxonomy' => $tax_name ));
- }
-
- add_action('admin_footer', array(__CLASS__, 'script'));
+ return $args;
}
// Scrolls to first checked category
@@ -53,69 +43,6 @@ function script() {
</script>
<?php
}
-
- // pasted from wp-admin/includes/meta-boxes.php -> post_categories_meta_box()
- function meta_box( $post, $box ) {
- $defaults = array('taxonomy' => 'category');
- if ( !isset($box['args']) || !is_array($box['args']) )
- $args = array();
- else
- $args = $box['args'];
- extract( wp_parse_args($args, $defaults), EXTR_SKIP );
- $tax = get_taxonomy($taxonomy);
-
- ?>
- <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv">
- <ul id="<?php echo $taxonomy; ?>-tabs" class="category-tabs">
- <li class="tabs"><a href="#<?php echo $taxonomy; ?>-all" tabindex="3"><?php echo $tax->labels->all_items; ?></a></li>
- <li class="hide-if-no-js"><a href="#<?php echo $taxonomy; ?>-pop" tabindex="3"><?php _e( 'Most Used' ); ?></a></li>
- </ul>
-
- <div id="<?php echo $taxonomy; ?>-pop" class="tabs-panel" style="display: none;">
- <ul id="<?php echo $taxonomy; ?>checklist-pop" class="categorychecklist form-no-clear" >
- <?php $popular_ids = wp_popular_terms_checklist($taxonomy); ?>
- </ul>
- </div>
-
- <div id="<?php echo $taxonomy; ?>-all" class="tabs-panel">
- <?php
- $name = ( $taxonomy == 'category' ) ? 'post_category' : 'tax_input[' . $taxonomy . ']';
- 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.
- ?>
- <ul id="<?php echo $taxonomy; ?>checklist" class="list:<?php echo $taxonomy?> categorychecklist form-no-clear">
- <?php wp_terms_checklist($post->ID, array( 'taxonomy' => $taxonomy, 'popular_cats' => $popular_ids, 'checked_ontop' => false ) ) ?>
- <?php /* ^ only change */ ?>
- </ul>
- </div>
- <?php if ( !current_user_can($tax->cap->assign_terms) ) : ?>
- <p><em><?php _e('You cannot modify this taxonomy.'); ?></em></p>
- <?php endif; ?>
- <?php if ( current_user_can($tax->cap->edit_terms) ) : ?>
- <div id="<?php echo $taxonomy; ?>-adder" class="wp-hidden-children">
- <h4>
- <a id="<?php echo $taxonomy; ?>-add-toggle" href="#<?php echo $taxonomy; ?>-add" class="hide-if-no-js" tabindex="3">
- <?php
- /* translators: %s: add new taxonomy label */
- printf( __( '+ %s' ), $tax->labels->add_new_item );
- ?>
- </a>
- </h4>
- <p id="<?php echo $taxonomy; ?>-add" class="category-add wp-hidden-child">
- <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>"><?php echo $tax->labels->add_new_item; ?></label>
- <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"/>
- <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>_parent">
- <?php echo $tax->labels->parent_item_colon; ?>
- </label>
- <?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 ) ); ?>
- <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" />
- <?php wp_nonce_field( 'add-'.$taxonomy, '_ajax_nonce-add-'.$taxonomy, false ); ?>
- <span id="<?php echo $taxonomy; ?>-ajax-response"></span>
- </p>
- </div>
- <?php endif; ?>
- </div>
- <?php
- }
}
Category_Checklist::init();
View
7 readme.txt
@@ -1,8 +1,8 @@
=== Category Checklist Tree ===
Contributors: scribu
Tags: admin, ui, categories, hierarchy
-Requires at least: 3.0
-Tested up to: 3.2
+Requires at least: 3.4
+Tested up to: 3.4
Stable tag: 1.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -21,6 +21,9 @@ Links: [Plugin News](http://scribu.net/wordpress/category-checklist-tree) | [Aut
== Changelog ==
+= 1.3 =
+* WP 3.4 compatibility
+
= 1.2 =
* scroll to first checked category. Props to Sven Kronshage for the suggestion.
Please sign in to comment.
Something went wrong with that request. Please try again.