Create metaboxes for hierarchical taxonomies. Props prettyboymp. fixes #10122

git-svn-id: http://svn.automattic.com/wordpress/trunk@12798 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-01-22 19:30:05 +00:00
parent a731cbed8e
commit b1b44019ff
17 changed files with 268 additions and 194 deletions

View File

@ -200,6 +200,81 @@ function _wp_ajax_delete_comment_response( $comment_id ) {
$x->send();
}
function _wp_ajax_add_hierarchical_term() {
$action = $_POST['action'];
$taxonomy = get_taxonomy(substr($action, 4));
check_ajax_referer( $action );
if ( !current_user_can( 'manage_categories' ) )
die('-1');
$names = explode(',', $_POST['new'.$taxonomy->name]);
$parent = isset($_POST['new'.$taxonomy->name.'_parent']) ? (int) $_POST['new'.$taxonomy->name.'_parent'] : 0;
if ( 0 > $parent )
$parent = 0;
if ( $taxonomy->name == 'category' )
$post_category = isset($_POST['post_category']) ? (array) $_POST['post_category'] : array();
else
$post_category = ( isset($_POST['tax_input']) && isset($_POST['tax_input'][$taxonomy->name]) ) ? (array) $_POST['tax_input'][$taxonomy->name] : array();
$checked_categories = array_map( 'absint', (array) $post_category );
$popular_ids = wp_popular_terms_checklist($taxonomy->name, 0, 10, false);
foreach ( $names as $cat_name ) {
$cat_name = trim($cat_name);
$category_nicename = sanitize_title($cat_name);
if ( '' === $category_nicename )
continue;
if ( !($cat_id = is_term($cat_name, $taxonomy->name, $parent)) ) {
$new_term = wp_insert_term($cat_name, $taxonomy->name, array('parent' => $parent));
$cat_id = $new_term['term_id'];
}
$checked_categories[] = $cat_id;
if ( $parent ) // Do these all at once in a second
continue;
$category = get_term( $cat_id, $taxonomy->name );
ob_start();
wp_terms_checklist( 0, array( 'taxonomy' => $taxonomy->name, 'descendants_and_self' => $cat_id, 'selected_cats' => $checked_categories, 'popular_cats' => $popular_ids ));
$data = ob_get_contents();
ob_end_clean();
$add = array(
'what' => $taxonomy->name,
'id' => $cat_id,
'data' => str_replace( array("\n", "\t"), '', $data),
'position' => -1
);
}
if ( $parent ) { // Foncy - replace the parent and all its children
$parent = get_term( $parent, $taxonomy->name );
$term_id = $parent->term_id;
while ( $parent->parent ) { // get the top parent
$parent = &get_term( $parent->parent, $taxonomy->name );
if ( is_wp_error( $parent ) )
break;
$term_id = $parent->term_id;
}
ob_start();
wp_terms_checklist( 0, array('taxonomy' => $taxonomy->name, 'descendants_and_self' => $term_id, 'selected_cats' => $checked_categories, 'popular_cats' => $popular_ids));
$data = ob_get_contents();
ob_end_clean();
$add = array(
'what' => $taxonomy->name,
'id' => $term_id,
'data' => str_replace( array("\n", "\t"), '', $data),
'position' => -1
);
}
ob_start();
wp_dropdown_categories( array( 'taxonomy' => $taxonomy->name, 'hide_empty' => 0, 'name' => 'new'.$taxonomy->name.'_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('Parent category') ) );
$sup = ob_get_contents();
ob_end_clean();
$add['supplemental'] = array( 'newcat_parent' => $sup );
$x = new WP_Ajax_Response( $add );
$x->send();
}
$id = isset($_POST['id'])? (int) $_POST['id'] : 0;
switch ( $action = $_POST['action'] ) :
case 'delete-comment' : // On success, die with time() instead of 1
@ -409,70 +484,6 @@ case 'dim-comment' : // On success, die with time() instead of 1
_wp_ajax_delete_comment_response( $comment->comment_ID );
die( '0' );
break;
case 'add-category' : // On the Fly
check_ajax_referer( $action );
if ( !current_user_can( 'manage_categories' ) )
die('-1');
$names = explode(',', $_POST['newcat']);
if ( 0 > $parent = (int) $_POST['newcat_parent'] )
$parent = 0;
$post_category = isset($_POST['post_category'])? (array) $_POST['post_category'] : array();
$checked_categories = array_map( 'absint', (array) $post_category );
$popular_ids = wp_popular_terms_checklist('category', 0, 10, false);
foreach ( $names as $cat_name ) {
$cat_name = trim($cat_name);
$category_nicename = sanitize_title($cat_name);
if ( '' === $category_nicename )
continue;
$cat_id = wp_create_category( $cat_name, $parent );
$checked_categories[] = $cat_id;
if ( $parent ) // Do these all at once in a second
continue;
$category = get_category( $cat_id );
ob_start();
wp_category_checklist( 0, $cat_id, $checked_categories, $popular_ids );
$data = ob_get_contents();
ob_end_clean();
$add = array(
'what' => 'category',
'id' => $cat_id,
'data' => str_replace( array("\n", "\t"), '', $data),
'position' => -1
);
}
if ( $parent ) { // Foncy - replace the parent and all its children
$parent = get_category( $parent );
$term_id = $parent->term_id;
while ( $parent->parent ) { // get the top parent
$parent = &get_category( $parent->parent );
if ( is_wp_error( $parent ) )
break;
$term_id = $parent->term_id;
}
ob_start();
wp_category_checklist( 0, $term_id, $checked_categories, $popular_ids, null, false );
$data = ob_get_contents();
ob_end_clean();
$add = array(
'what' => 'category',
'id' => $term_id,
'data' => str_replace( array("\n", "\t"), '', $data),
'position' => -1
);
}
ob_start();
wp_dropdown_categories( array( 'hide_empty' => 0, 'name' => 'newcat_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('Parent category') ) );
$sup = ob_get_contents();
ob_end_clean();
$add['supplemental'] = array( 'newcat_parent' => $sup );
$x = new WP_Ajax_Response( $add );
$x->send();
break;
case 'add-link-category' : // On the Fly
check_ajax_referer( $action );
if ( !current_user_can( 'manage_categories' ) )
@ -511,7 +522,7 @@ case 'add-cat' : // From Manage->Categories
$x->send();
}
if ( category_exists( trim( $_POST['cat_name'] ), $_POST['category_parent'] ) ) {
if ( is_term( trim( $_POST['cat_name'] ), $_POST['taxonomy'], $_POST['category_parent'] ) ) {
$x = new WP_Ajax_Response( array(
'what' => 'cat',
'id' => new WP_Error( 'cat_exists', __('The category you are trying to create already exists.'), array( 'form-field' => 'cat_name' ) ),
@ -529,7 +540,7 @@ case 'add-cat' : // From Manage->Categories
$x->send();
}
if ( !$cat || (!$cat = get_category( $cat )) )
if ( !$cat || (!$cat = get_term( $cat, $_POST['taxonomy'] ) ) )
die('0');
$level = 0;

File diff suppressed because one or more lines are too long

View File

@ -110,11 +110,11 @@ div.dashboard-widget-submit {
}
div.tabs-panel,
ul#category-tabs li.tabs {
ul.category-tabs li.tabs {
border-color: #dfdfdf;
}
ul#category-tabs li.tabs {
ul.category-tabs li.tabs {
background-color: #f1f1f1;
}
@ -384,7 +384,7 @@ div.dashboard-widget-submit input:hover,
background: #faf9f7 !important;
}
#side-sortables #category-tabs .tabs a {
#side-sortables .category-tabs .tabs a {
color: #333;
}
@ -1463,7 +1463,7 @@ fieldset.inline-edit-col-right .inline-edit-col {
background-color: #f5f5f5;
}
#post-body ul#category-tabs li.tabs a {
#post-body ul.category-tabs li.tabs a {
color: #333;
}

File diff suppressed because one or more lines are too long

View File

@ -110,11 +110,11 @@ div.dashboard-widget-submit {
}
div.tabs-panel,
ul#category-tabs li.tabs {
ul.category-tabs li.tabs {
border-color: #dfdfdf;
}
ul#category-tabs li.tabs {
ul.category-tabs li.tabs {
background-color: #f1f1f1;
}
@ -380,7 +380,7 @@ div.dashboard-widget-submit input:hover,
border-color: #dfdfdf;
}
#side-sortables #category-tabs .tabs a {
#side-sortables .category-tabs .tabs a {
color: #333;
}
@ -1458,7 +1458,7 @@ fieldset.inline-edit-col-right .inline-edit-col {
background-color: #f5f5f5;
}
#post-body ul#category-tabs li.tabs a {
#post-body ul.category-tabs li.tabs a {
color: #333;
}

File diff suppressed because one or more lines are too long

View File

@ -115,7 +115,7 @@ div.zerosize {
}
#tagsdiv-post_tag h3,
#categorydiv h3 {
.categorydiv h3 {
cursor: pointer;
}
@ -308,15 +308,15 @@ h3.tb {
display: none;
}
#category-adder {
.category-adder {
padding: 4px 0;
}
#category-adder h4 {
.category-adder h4 {
margin: 0 0 8px;
}
#category-add input {
.category-add input {
width: 94%;
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size: 13px;
@ -324,7 +324,7 @@ h3.tb {
padding: 3px;
}
#category-add select {
.category-add select {
width: 70%;
-x-system-font: none;
border-style: solid;
@ -338,24 +338,24 @@ h3.tb {
vertical-align: top;
}
#category-add input,
#category-add-sumbit {
.category-add input,
.category-add-sumbit {
width: auto;
}
/* Categories */
#categorydiv ul,
.categorydiv ul,
#linkcategorydiv ul {
list-style: none;
padding: 0;
margin: 0;
}
#categorydiv ul.categorychecklist ul {
.categorydiv ul.categorychecklist ul {
margin-left: 18px;
}
#categorydiv div.tabs-panel {
.categorydiv div.tabs-panel {
height: 140px;
overflow: auto;
}

View File

@ -294,11 +294,11 @@ td.available-theme {
margin-left: 4px;
}
/* Categories */
#category-adder {
.category-adder {
margin-left: 0;
margin-right: 120px;
}
#post-body ul#category-tabs li.tabs {
#post-body ul.category-tabs li.tabs {
-moz-border-radius: 0 3px 3px 0;
-webkit-border-top-left-radius: 0;
-webkit-border-top-right-radius: 3px;
@ -309,22 +309,22 @@ td.available-theme {
border-bottom-left-radius: 0;
border-bottom-right-radius: 3px;
}
#post-body ul#category-tabs {
#post-body ul.category-tabs {
float: right;
text-align: left;
margin: 0 0 0 -120px;
}
#post-body #categorydiv div.tabs-panel,
#post-body .categorydiv div.tabs-panel,
#post-body #linkcategorydiv div.tabs-panel {
margin: 0 120px 0 5px;
}
/* 1800 - 2000
=================================== */
#side-sortables #category-tabs li {
#side-sortables .category-tabs li {
padding-right: 0;
padding-left: 8px;
}
#categorydiv ul.categorychecklist ul,
.categorydiv ul.categorychecklist ul,
#linkcategorydiv ul.categorychecklist ul {
margin-left: 0;
margin-right: 18px;

File diff suppressed because one or more lines are too long

View File

@ -1928,36 +1928,36 @@ input#link_url {
/* Categories */
#category-adder {
.category-adder {
margin-left: 120px;
padding: 4px 0;
}
#category-adder h4 {
.category-adder h4 {
margin: 0 0 8px;
}
#side-sortables #category-adder {
#side-sortables .category-adder {
margin: 0;
}
#post-body #category-add input, #category-add select {
#post-body .category-add input, .category-add select {
width: 30%;
}
#side-sortables #category-add input {
#side-sortables .category-add input {
width: 94%;
}
#side-sortables #category-add select {
#side-sortables .category-add select {
width: 100%;
}
#category-add input#category-add-sumbit {
#side-sortables .category-add input.category-add-sumbit, #post-body .category-add input.category-add input.category-add-sumbit {
width: auto;
}
#post-body ul#category-tabs {
#post-body ul.category-tabs {
float: left;
width: 120px;
text-align: right;
@ -1966,11 +1966,11 @@ input#link_url {
padding: 0;
}
#post-body ul#category-tabs li {
#post-body ul.category-tabs li {
padding: 8px;
}
#post-body ul#category-tabs li.tabs {
#post-body ul.category-tabs li.tabs {
-moz-border-radius: 3px 0 0 3px;
-webkit-border-top-left-radius: 3px;
-webkit-border-bottom-left-radius: 3px;
@ -1980,12 +1980,12 @@ input#link_url {
border-bottom-left-radius: 3px;
}
#post-body ul#category-tabs li.tabs a {
#post-body ul.category-tabs li.tabs a {
font-weight: bold;
text-decoration: none;
}
#categorydiv div.tabs-panel,
.categorydiv div.tabs-panel,
#linkcategorydiv div.tabs-panel {
height: 200px;
overflow: auto;
@ -1994,32 +1994,32 @@ input#link_url {
border-width: 1px;
}
#post-body #categorydiv div.tabs-panel,
#post-body .categorydiv div.tabs-panel,
#post-body #linkcategorydiv div.tabs-panel {
margin: 0 5px 0 125px;
}
#side-sortables #category-tabs li {
#side-sortables .category-tabs li {
display: inline;
padding-right: 8px;
}
#side-sortables #category-tabs a {
#side-sortables .category-tabs a {
text-decoration: none;
}
#side-sortables #category-tabs {
#side-sortables .category-tabs {
margin-bottom: 3px;
}
#categorydiv ul,
.categorydiv ul,
#linkcategorydiv ul {
list-style: none;
padding: 0;
margin: 0;
}
#categorydiv ul.categorychecklist ul,
.categorydiv ul.categorychecklist ul,
#linkcategorydiv ul.categorychecklist ul {
margin-left: 18px;
}
@ -2030,32 +2030,32 @@ ul.categorychecklist li {
line-height: 19px;
}
#category-adder h4 {
.category-adder h4 {
margin-top: 4px;
margin-bottom: 0px;
}
#categorydiv .tabs-panel {
.categorydiv .tabs-panel {
border-width: 3px;
border-style: solid;
}
ul#category-tabs {
ul.category-tabs {
margin-top: 12px;
}
ul#category-tabs li.tabs {
ul.category-tabs li.tabs {
border-style: solid solid none;
border-width: 1px 1px 0;
}
#post-body #category-tabs li.tabs {
#post-body .category-tabs li.tabs {
border-style: solid none solid solid;
border-width: 1px 0 1px 1px;
margin-right: -1px;
}
ul#category-tabs li {
ul.category-tabs li {
padding: 5px 8px;
-moz-border-radius: 3px 3px 0 0;
-webkit-border-top-left-radius: 3px;

View File

@ -94,17 +94,15 @@ add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', $post_type, 'si
// all tag-style taxonomies
foreach ( get_object_taxonomies($post_type) as $tax_name ) {
if ( !is_taxonomy_hierarchical($tax_name) ) {
$taxonomy = get_taxonomy($tax_name);
$label = isset($taxonomy->label) ? esc_attr($taxonomy->label) : $tax_name;
$taxonomy = get_taxonomy($tax_name);
$label = isset($taxonomy->label) ? esc_attr($taxonomy->label) : $tax_name;
if ( !is_taxonomy_hierarchical($tax_name) )
add_meta_box('tagsdiv-' . $tax_name, $label, 'post_tags_meta_box', $post_type, 'side', 'core');
}
else
add_meta_box($tax_name.'div', $label, 'post_categories_meta_box', 'post', 'side', 'core', array( 'taxonomy' => $tax_name ));
}
if ( is_object_in_taxonomy($post_type, 'category') )
add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', $post_type, 'side', 'core');
if ( post_type_supports($post_type, 'page-attributes') )
add_meta_box('pageparentdiv', __('Attributes'), 'page_attributes_meta_box', $post_type, 'side', 'core');

View File

@ -268,38 +268,46 @@ function post_tags_meta_box($post, $box) {
*
* @param object $post
*/
function post_categories_meta_box($post) {
?>
<ul id="category-tabs">
<li class="tabs"><a href="#categories-all" tabindex="3"><?php _e( 'All Categories' ); ?></a></li>
<li class="hide-if-no-js"><a href="#categories-pop" tabindex="3"><?php _e( 'Most Used' ); ?></a></li>
</ul>
function post_categories_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 );
?>
<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 _e( 'All Categories' ); ?></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="categories-pop" class="tabs-panel" style="display: none;">
<ul id="categorychecklist-pop" class="categorychecklist form-no-clear" >
<?php $popular_ids = wp_popular_terms_checklist('category'); ?>
</ul>
</div>
<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="categories-all" class="tabs-panel">
<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
<?php wp_category_checklist($post->ID, false, false, $popular_ids) ?>
</ul>
</div>
<?php if ( current_user_can('manage_categories') ) : ?>
<div id="category-adder" class="wp-hidden-children">
<h4><a id="category-add-toggle" href="#category-add" class="hide-if-no-js" tabindex="3"><?php _e( '+ Add New Category' ); ?></a></h4>
<p id="category-add" class="wp-hidden-child">
<label class="screen-reader-text" for="newcat"><?php _e( 'Add New Category' ); ?></label><input type="text" name="newcat" id="newcat" class="form-required form-input-tip" value="<?php esc_attr_e( 'New category name' ); ?>" tabindex="3" aria-required="true"/>
<label class="screen-reader-text" for="newcat_parent"><?php _e('Parent category'); ?>:</label><?php wp_dropdown_categories( array( 'hide_empty' => 0, 'name' => 'newcat_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('Parent category') ) ); ?>
<input type="button" id="category-add-sumbit" class="add:categorychecklist:category-add button" value="<?php esc_attr_e( 'Add' ); ?>" tabindex="3" />
<?php wp_nonce_field( 'add-category', '_ajax_nonce', false ); ?>
<span id="category-ajax-response"></span></p>
</div>
<?php
endif;
<div id="<?php echo $taxonomy; ?>-all" class="tabs-panel">
<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)) ?>
</ul>
</div>
<?php if ( current_user_can('manage_categories') ) : ?>
<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 _e( '+ Add New Category' ); ?></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 _e( 'Add New Category' ); ?></label><input type="text" name="new<?php echo $taxonomy; ?>" id="new<?php echo $taxonomy; ?>" class="form-required form-input-tip" value="<?php esc_attr_e( 'New category name' ); ?>" tabindex="3" aria-required="true"/>
<label class="screen-reader-text" for="new<?php echo $taxonomy; ?>_parent"><?php _e('Parent category'); ?>:</label><?php wp_dropdown_categories( array( 'taxonomy' => $taxonomy, 'hide_empty' => 0, 'name' => 'new'.$taxonomy.'_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('Parent category'), '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 esc_attr_e( 'Add' ); ?>" tabindex="3" />
<?php wp_nonce_field( 'add-'.$taxonomy, '_ajax_nonce', false ); ?>
<span id="<?php echo $taxonomy; ?>-ajax-response"></span>
</p>
</div>
<?php endif; ?>
</div>
<?php
}

View File

@ -465,9 +465,16 @@ class Walker_Category_Checklist extends Walker {
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<li id='category-$category->term_id'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="post_category[]" id="in-category-' . $category->term_id . '"' . (in_array( $category->term_id, $selected_cats ) ? ' checked="checked"' : "" ) . '/> ' . esc_html( apply_filters('the_category', $category->name )) . '</label>';
$output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' . (in_array( $category->term_id, $selected_cats ) ? ' checked="checked"' : "" ) . '/> ' . esc_html( apply_filters('the_category', $category->name )) . '</label>';
}
function end_el(&$output, $category, $depth, $args) {
@ -486,31 +493,59 @@ class Walker_Category_Checklist extends Walker {
* @param unknown_type $popular_cats
*/
function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) {
wp_terms_checklist($post_id,
array(
'taxonomy' => 'category',
'descendants_and_self' => $descendants_and_self,
'selected_cats' => $selected_cats,
'popular_cats' => $popular_cats,
'walker' => $walker,
'checked_ontop' => $checked_ontop
));
}
/**
* Taxonomy independent version of wp_category_checklist
*
* @param int $post_id
* @param array $args
*/
function wp_terms_checklist($post_id = 0, $args = array()) {
$defaults = array(
'descendants_and_self' => 0,
'selected_cats' => false,
'popular_cats' => false,
'walker' => null,
'taxonomy' => 'category',
'checked_ontop' => true
);
extract( wp_parse_args($args, $defaults), EXTR_SKIP );
if ( empty($walker) || !is_a($walker, 'Walker') )
$walker = new Walker_Category_Checklist;
$descendants_and_self = (int) $descendants_and_self;
$args = array();
$args = array('taxonomy' => $taxonomy);
if ( is_array( $selected_cats ) )
$args['selected_cats'] = $selected_cats;
elseif ( $post_id )
$args['selected_cats'] = wp_get_post_categories($post_id);
$args['selected_cats'] = wp_get_object_terms($post_id, $taxonomy, array_merge($args, array('fields' => 'ids')));
else
$args['selected_cats'] = array();
if ( is_array( $popular_cats ) )
$args['popular_cats'] = $popular_cats;
else
$args['popular_cats'] = get_terms( 'category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
$args['popular_cats'] = get_terms( $taxonomy, array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
if ( $descendants_and_self ) {
$categories = get_categories(array('child_of' => $descendants_and_self, 'hierarchical' => 0, 'hide_empty' => 0));
$self = get_category( $descendants_and_self );
$categories = (array) get_terms($taxonomy, array( 'child_of' => $descendants_and_self, 'hierarchical' => 0, 'hide_empty' => 0 ) );
$self = get_term( $descendants_and_self, $taxonomy );
array_unshift( $categories, $self );
} else {
$categories = get_categories(array('get' => 'all'));
$categories = (array) get_terms($taxonomy, array('get' => 'all'));
}
if ( $checked_ontop ) {
@ -547,7 +582,7 @@ function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $ech
global $post_ID;
if ( $post_ID )
$checked_categories = wp_get_post_categories($post_ID);
$checked_categories = wp_get_object_terms($post_ID, 'category', array('fields'=>'ids'));
else
$checked_categories = array();
@ -558,7 +593,7 @@ function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $ech
$popular_ids[] = $category->term_id;
if ( !$echo ) // hack for AJAX use
continue;
$id = "popular-category-$category->term_id";
$id = "popular-$taxonomy-$category->term_id";
$checked = in_array( $category->term_id, $checked_categories ) ? 'checked="checked"' : '';
?>
@ -3834,7 +3869,7 @@ function compression_test() {
* @since 3.0
*
* @uses $current_screen
*
*
* @param string $id Screen id, optional.
*/
function set_current_screen( $id = '' ) {
@ -3851,9 +3886,9 @@ function set_current_screen( $id = '' ) {
list( $id, $typenow ) = explode('-', $id, 2);
$current_screen = array('id' => $id, 'base' => $id);
}
$current_screen = (object) $current_screen;
if ( 'edit' == $current_screen->id ) {
if ( empty($typenow) )
$typenow = 'post';
@ -3867,7 +3902,7 @@ function set_current_screen( $id = '' ) {
} else {
$typenow = '';
}
$current_screen = apply_filters('current_screen', $current_screen);
}

View File

@ -228,7 +228,7 @@ WPRemoveThumbnail = function(){
})(jQuery);
jQuery(document).ready( function($) {
var catAddAfter, stamp, visibility, sticky = '', post = 'post' == pagenow || 'post-new' == pagenow, page = 'page' == pagenow || 'page-new' == pagenow;
var stamp, visibility, sticky = '', post = 'post' == pagenow || 'post-new' == pagenow, page = 'page' == pagenow || 'page-new' == pagenow;
// postboxes
if ( post ) {
@ -253,35 +253,55 @@ jQuery(document).ready( function($) {
}
// categories
if ( $('#categorydiv').length ) {
$('.categorydiv').each(function(){
var this_id = $(this).attr('id'), noSyncChecks = false, syncChecks, catAddAfter, popularCats;
var taxonomy_parts = this_id.split('-');
taxonomy_parts.shift();
var taxonomy = taxonomy_parts.join('-');
var settingName = taxonomy+'_tab';
if(taxonomy == 'category')
settingName = 'cats';
// TODO: move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.dev.js
$('a', '#category-tabs').click(function(){
$('a', '#'+taxonomy+'-tabs').click(function(){
var t = $(this).attr('href');
$(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
$('#category-tabs').siblings('.tabs-panel').hide();
$('#'+taxonomy+'-tabs').siblings('.tabs-panel').hide();
$(t).show();
if ( '#categories-all' == t )
deleteUserSetting('cats');
if ( '#'+taxonomy+'-all' == t )
deleteUserSetting(settingName);
else
setUserSetting('cats','pop');
setUserSetting(settingName,'pop');
return false;
});
if ( getUserSetting('cats') )
$('a[href="#categories-pop"]', '#category-tabs').click();
if ( getUserSetting(settingName) )
$('a[href="#'+taxonomy+'-pop"]', '#'+taxonomy+'-tabs').click();
// Ajax Cat
$('#newcat').one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ) } );
$('#category-add-sumbit').click( function(){ $('#newcat').focus(); } );
$('#new'+taxonomy).one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ) } );
$('#'+taxonomy+'-add-submit').click(function(){$('#new'+taxonomy).focus();});
syncChecks = function() {
if ( noSyncChecks )
return;
noSyncChecks = true;
var th = jQuery(this), c = th.is(':checked'), id = th.val().toString();
$('#in-'+taxonomy+'-' + id + ', #in-'+taxonomy+'-category-' + id).attr( 'checked', c );
noSyncChecks = false;
};
catAddBefore = function( s ) {
if ( !$('#newcat').val() )
if ( !$('#new'+taxonomy).val() )
return false;
s.data += '&' + $( ':checked', '#categorychecklist' ).serialize();
s.data += '&' + $( ':checked', '#'+taxonomy+'checklist' ).serialize();
return s;
};
catAddAfter = function( r, s ) {
var sup, drop = $('#newcat_parent');
var sup, drop = $('#new'+taxonomy+'_parent');
if ( 'undefined' != s.parsed.responses[0] && (sup = s.parsed.responses[0].supplemental.newcat_parent) ) {
drop.before(sup);
@ -289,25 +309,24 @@ jQuery(document).ready( function($) {
}
};
$('#categorychecklist').wpList({
$('#'+taxonomy+'checklist').wpList({
alt: '',
response: 'category-ajax-response',
response: taxonomy+'-ajax-response',
addBefore: catAddBefore,
addAfter: catAddAfter
});
$('#category-add-toggle').click( function() {
$('#category-adder').toggleClass( 'wp-hidden-children' );
$('a[href="#categories-all"]', '#category-tabs').click();
$('#'+taxonomy+'-add-toggle').click( function() {
$('#'+taxonomy+'-adder').toggleClass( 'wp-hidden-children' );
$('a[href="#'+taxonomy+'-all"]', '#'+taxonomy+'-tabs').click();
return false;
});
$('#categorychecklist').children('li.popular-category').add( $('#categorychecklist-pop').children() ).find(':checkbox').live( 'click', function(){
$('#'+taxonomy+'checklist').children('li.popular-category').add( $('#'+taxonomy+'checklist-pop').children() ).find(':checkbox').live( 'click', function(){
var t = $(this), c = t.is(':checked'), id = t.val();
$('#in-category-' + id + ', #in-popular-category-' + id).attr( 'checked', c );
$('#in-'+taxonomy+'-' + id + ', #in-popular-'+taxonomy+'-' + id).attr( 'checked', c );
});
} // end cats
}); // end cats
// Custom Fields
if ( $('#postcustom').length ) {

File diff suppressed because one or more lines are too long

View File

@ -356,7 +356,7 @@ function wp_dropdown_categories( $args = '' ) {
if ( (int) $tab_index > 0 )
$tab_index_attribute = " tabindex=\"$tab_index\"";
$categories = get_categories( $r );
$categories = get_terms( $taxonomy, $r );
$name = esc_attr($name);
$class = esc_attr($class);

View File

@ -194,6 +194,9 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
$args['name'] = $taxonomy;
$args['object_type'] = (array) $object_type;
$wp_taxonomies[$taxonomy] = (object) $args;
// register callback handling for metabox
add_filter('wp_ajax_add-'.$taxonomy, '_wp_ajax_add_hierarchical_term');
}
/**
@ -1573,7 +1576,7 @@ function wp_set_object_terms($object_id, $terms, $taxonomy, $append = false) {
* slug has to be globally unique for every taxonomy.
*
* The way this works is that if the taxonomy that the term belongs to is
* heirarchical and has a parent, it will append that parent to the $slug.
* hierarchical and has a parent, it will append that parent to the $slug.
*
* If that still doesn't return an unique slug, then it try to append a number
* until it finds a number that is truely unique.