Custom taxonomy support for inline edit. Props prettyboymp. see #9674

git-svn-id: http://svn.automattic.com/wordpress/trunk@13535 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-03-01 15:48:01 +00:00
parent c2782696ae
commit 37bfdee064
4 changed files with 93 additions and 43 deletions

View File

@ -254,7 +254,7 @@ function bulk_edit_posts( $post_data = null ) {
$post_IDs = array_map( 'intval', (array) $post_data['post'] );
$reset = array( 'post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tags_input', 'post_category', 'sticky' );
$reset = array( 'post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tax_input', 'post_category', 'sticky' );
foreach ( $reset as $field ) {
if ( isset($post_data[$field]) && ( '' == $post_data[$field] || -1 == $post_data[$field] ) )
unset($post_data[$field]);
@ -266,10 +266,20 @@ function bulk_edit_posts( $post_data = null ) {
else
unset($post_data['post_category']);
}
if ( isset($post_data['tags_input']) ) {
$new_tags = preg_replace( '/\s*,\s*/', ',', rtrim( trim($post_data['tags_input']), ' ,' ) );
$new_tags = explode(',', $new_tags);
$tax_input = array();
if ( isset($post_data['tax_input'])) {
foreach ( $post_data['tax_input'] as $tax_name => $terms ) {
if ( empty($terms) )
continue;
$taxonomy = get_taxonomy( $tax_name );
if ( $taxonomy->hierarchical )
$tax_input[$tax_name] = array_map( 'absint', $terms );
else {
$tax_input[$tax_name] = preg_replace( '/\s*,\s*/', ',', rtrim( trim($terms), ' ,' ) );
$tax_input[$tax_name] = explode(',', $tax_input[$tax_name]);
}
}
}
if ( isset($post_data['post_parent']) && ($parent = (int) $post_data['post_parent']) ) {
@ -300,15 +310,23 @@ function bulk_edit_posts( $post_data = null ) {
$locked[] = $post_ID;
continue;
}
if ( isset($new_cats) ) {
$tax_names = get_object_taxonomies( get_post($post_ID) );
if ( isset($new_cats) && in_array( 'category', $tax_names ) ) {
$cats = (array) wp_get_post_categories($post_ID);
$post_data['post_category'] = array_unique( array_merge($cats, $new_cats) );
}
if ( isset($new_tags) ) {
$tags = wp_get_post_tags($post_ID, array('fields' => 'names'));
$post_data['tags_input'] = array_unique( array_merge($tags, $new_tags) );
foreach ( $tax_names as $tax_name ) {
if( isset( $tax_input[$tax_name]) ) {
$taxonomy = get_taxonomy( $tax_name );
if( $taxonomy->hierarchical )
$terms = (array) wp_get_object_terms( $post_ID, $tax_name, array('fields' => 'ids') );
else
$terms = (array) wp_get_object_terms( $post_ID, $tax_name, array('fields' => 'names') );
$post_data['tax_input'][$tax_name] = array_merge( $terms, $tax_input[$tax_name] );
}
}
$post_data['ID'] = $post_ID;

View File

@ -911,6 +911,20 @@ function inline_edit_row( $screen ) {
$post = get_default_post_to_edit( $screen->post_type );
$post_type_object = get_post_type_object( $screen->post_type );
$taxonomy_names = get_object_taxonomies( $screen->post_type );
$hierarchical_taxonomies = array();
$flat_taxonomies = array();
foreach ( $taxonomy_names as $taxonomy_name ) {
$taxonomy = get_taxonomy( $taxonomy_name);
if( !$taxonomy->show_ui ) continue;
if( $taxonomy->hierarchical )
$hierarchical_taxonomies[] = $taxonomy;
else
$flat_taxonomies[] = $taxonomy;
}
$columns = wp_manage_posts_columns($screen);
$hidden = array_intersect( array_keys( $columns ), array_filter( get_hidden_columns($screen) ) );
$col_count = count($columns) - count($hidden);
@ -1002,19 +1016,25 @@ function inline_edit_row( $screen ) {
</div></fieldset>
<?php if ( is_object_in_taxonomy($screen->post_type, 'category') && !$bulk ) : ?>
<?php if ( count($hierarchical_taxonomies) && !$bulk ) : ?>
<fieldset class="inline-edit-col-center inline-edit-categories"><div class="inline-edit-col">
<span class="title inline-edit-categories-label"><?php _e( 'Categories' ); ?>
<?php foreach ( $hierarchical_taxonomies as $taxonomy ) : ?>
<span class="title inline-edit-categories-label"><?php echo esc_html($taxonomy->label) ?>
<span class="catshow"><?php _e('[more]'); ?></span>
<span class="cathide" style="display:none;"><?php _e('[less]'); ?></span>
</span>
<ul class="cat-checklist">
<?php wp_category_checklist(); ?>
<ul class="cat-checklist <?php echo esc_attr($taxonomy->name)?>-checklist">
<?php wp_terms_checklist(null, array('taxonomy' => $taxonomy->name)) ?>
</ul>
<?php endforeach; //$hierarchical_taxonomies as $taxonomy ?>
</div></fieldset>
<?php endif; // is_object_in_taxonomy($screen->post_type, 'category') && !$bulk ?>
<?php endif; // count($hierarchical_taxonomies) && !$bulk ?>
<fieldset class="inline-edit-col-right"><div class="inline-edit-col">
@ -1058,14 +1078,18 @@ function inline_edit_row( $screen ) {
<?php endif; // $post_type_object->hierarchical ?>
<?php if ( is_object_in_taxonomy($screen->post_type, 'post_tag') && !$bulk ) : ?>
<?php if ( count($flat_taxonomies) && !$bulk ) : ?>
<?php foreach ( $flat_taxonomies as $taxonomy ) : ?>
<label class="inline-edit-tags">
<span class="title"><?php _e( 'Tags' ); ?></span>
<textarea cols="22" rows="1" name="tags_input" class="tags_input"></textarea>
<span class="title"><?php echo esc_html($taxonomy->label) ?></span>
<textarea cols="22" rows="1" name="tax_input[<?php echo esc_attr($taxonomy->name)?>]" class="tax_input_<?php echo esc_attr($taxonomy->name)?>"></textarea>
</label>
<?php endif; // is_object_in_taxonomy($screen->post_type, 'post_tag') && !$bulk ?>
<?php endforeach; //$flat_taxonomies as $taxonomy ?>
<?php endif; // count($flat_taxonomies) && !$bulk ?>
<?php if ( $bulk ) : ?>
@ -1225,13 +1249,17 @@ function get_inline_data($post) {
if ( $post_type_object->hierarchical )
echo '<div class="menu_order">' . $post->menu_order . '</div>';
if ( is_object_in_taxonomy($post->post_type, 'post_tag') )
echo '<div class="tags_input">' . esc_html( str_replace( ',', ', ', get_tags_to_edit($post->ID) ) ) . '</div>';
$taxonomy_names = get_object_taxonomies( $post->post_type );
foreach ( $taxonomy_names as $taxonomy_name) {
$taxonomy = get_taxonomy( $taxonomy_name );
if ( is_object_in_taxonomy($post->post_type, 'post_tag') )
echo '<div class="post_category">' . implode( ',', wp_get_post_categories( $post->ID ) ) . '</div>';
if ( $taxonomy->hierarchical && $taxonomy->show_ui )
echo '<div class="post_category" id="'.$taxonomy_name.'_'.$post->ID.'">' . implode( ',', wp_get_object_terms( $post->ID, $taxonomy_name, array('fields'=>'ids')) ) . '</div>';
elseif ( $taxonomy->show_ui )
echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">' . esc_html( str_replace( ',', ', ', get_terms_to_edit($post->ID, $taxonomy_name) ) ) . '</div>';
}
if ( $post->post_type == 'post' )
if ( !$post_type_object->hierarchical )
echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>';
echo '</div>';

View File

@ -36,17 +36,13 @@ inlineEditPost = {
$('#inline-edit label.inline-edit-tags').clone()
);
// categories expandable?
// hiearchical taxonomies expandable?
$('span.catshow').click(function() {
$('.inline-editor ul.cat-checklist').addClass("cat-hover");
$('.inline-editor span.cathide').show();
$(this).hide();
$(this).hide().next().show().parent().next().addClass("cat-hover");
});
$('span.cathide').click(function() {
$('.inline-editor ul.cat-checklist').removeClass("cat-hover");
$('.inline-editor span.catshow').show();
$(this).hide();
$(this).hide().prev().show().parent().next().removeClass("cat-hover");
});
$('select[name="_status"] option[value="future"]', bulkRow).remove();
@ -118,7 +114,6 @@ inlineEditPost = {
fields = ['post_title', 'post_name', 'post_author', '_status', 'jj', 'mm', 'aa', 'hh', 'mn', 'ss', 'post_password'];
if ( t.type == 'page' ) fields.push('post_parent', 'menu_order', 'page_template');
if ( t.type == 'post' ) fields.push('tags_input');
// add the new blank row
editRow = $('#inline-edit').clone(true);
@ -146,9 +141,24 @@ inlineEditPost = {
if ( $('.sticky', rowData).text() == 'sticky' )
$('input[name="sticky"]', editRow).attr("checked", "checked");
// categories
if ( cats = $('.post_category', rowData).text() )
$('ul.cat-checklist :checkbox', editRow).val(cats.split(','));
// hierarchical taxonomies
$('.post_category', rowData).each(function(){
if( term_ids = $(this).text() )
{
taxname = $(this).attr('id').replace('_'+id, '');
$('ul.'+taxname+'-checklist :checkbox', editRow).val(term_ids.split(','));
}
});
//flat taxonomies
$('.tags_input', rowData).each(function(){
if( terms = $(this).text() )
{
taxname = $(this).attr('id').replace('_'+id, '');
$('textarea.tax_input_'+taxname, editRow).val(terms);
$('textarea.tax_input_'+taxname, editRow).suggest( 'admin-ajax.php?action=ajax-tag-search&tax='+taxname, { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
}
});
// handle the post status
status = $('._status', rowData).text();
@ -180,12 +190,6 @@ inlineEditPost = {
$(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
$('.ptitle', editRow).focus();
// enable autocomplete for tags
if ( t.type == 'post' ) {
tax = 'post_tag';
$('tr.inline-editor textarea[name="tags_input"]').suggest( 'admin-ajax.php?action=ajax-tag-search&tax='+tax, { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
}
return false;
},

File diff suppressed because one or more lines are too long