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

git-svn-id: https://develop.svn.wordpress.org/trunk@13535 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2010-03-01 15:48:01 +00:00
parent a9dbad77ac
commit 8ef5d73550
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'] ); $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 ) { foreach ( $reset as $field ) {
if ( isset($post_data[$field]) && ( '' == $post_data[$field] || -1 == $post_data[$field] ) ) if ( isset($post_data[$field]) && ( '' == $post_data[$field] || -1 == $post_data[$field] ) )
unset($post_data[$field]); unset($post_data[$field]);
@ -267,9 +267,19 @@ function bulk_edit_posts( $post_data = null ) {
unset($post_data['post_category']); unset($post_data['post_category']);
} }
if ( isset($post_data['tags_input']) ) { $tax_input = array();
$new_tags = preg_replace( '/\s*,\s*/', ',', rtrim( trim($post_data['tags_input']), ' ,' ) ); if ( isset($post_data['tax_input'])) {
$new_tags = explode(',', $new_tags); 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']) ) { if ( isset($post_data['post_parent']) && ($parent = (int) $post_data['post_parent']) ) {
@ -301,14 +311,22 @@ function bulk_edit_posts( $post_data = null ) {
continue; 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); $cats = (array) wp_get_post_categories($post_ID);
$post_data['post_category'] = array_unique( array_merge($cats, $new_cats) ); $post_data['post_category'] = array_unique( array_merge($cats, $new_cats) );
} }
if ( isset($new_tags) ) { foreach ( $tax_names as $tax_name ) {
$tags = wp_get_post_tags($post_ID, array('fields' => 'names')); if( isset( $tax_input[$tax_name]) ) {
$post_data['tags_input'] = array_unique( array_merge($tags, $new_tags) ); $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; $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 = get_default_post_to_edit( $screen->post_type );
$post_type_object = get_post_type_object( $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); $columns = wp_manage_posts_columns($screen);
$hidden = array_intersect( array_keys( $columns ), array_filter( get_hidden_columns($screen) ) ); $hidden = array_intersect( array_keys( $columns ), array_filter( get_hidden_columns($screen) ) );
$col_count = count($columns) - count($hidden); $col_count = count($columns) - count($hidden);
@ -1002,19 +1016,25 @@ function inline_edit_row( $screen ) {
</div></fieldset> </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"> <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="catshow"><?php _e('[more]'); ?></span>
<span class="cathide" style="display:none;"><?php _e('[less]'); ?></span> <span class="cathide" style="display:none;"><?php _e('[less]'); ?></span>
</span> </span>
<ul class="cat-checklist"> <ul class="cat-checklist <?php echo esc_attr($taxonomy->name)?>-checklist">
<?php wp_category_checklist(); ?> <?php wp_terms_checklist(null, array('taxonomy' => $taxonomy->name)) ?>
</ul> </ul>
<?php endforeach; //$hierarchical_taxonomies as $taxonomy ?>
</div></fieldset> </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"> <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 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"> <label class="inline-edit-tags">
<span class="title"><?php _e( 'Tags' ); ?></span> <span class="title"><?php echo esc_html($taxonomy->label) ?></span>
<textarea cols="22" rows="1" name="tags_input" class="tags_input"></textarea> <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> </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 ) : ?> <?php if ( $bulk ) : ?>
@ -1225,13 +1249,17 @@ function get_inline_data($post) {
if ( $post_type_object->hierarchical ) if ( $post_type_object->hierarchical )
echo '<div class="menu_order">' . $post->menu_order . '</div>'; echo '<div class="menu_order">' . $post->menu_order . '</div>';
if ( is_object_in_taxonomy($post->post_type, 'post_tag') ) $taxonomy_names = get_object_taxonomies( $post->post_type );
echo '<div class="tags_input">' . esc_html( str_replace( ',', ', ', get_tags_to_edit($post->ID) ) ) . '</div>'; foreach ( $taxonomy_names as $taxonomy_name) {
$taxonomy = get_taxonomy( $taxonomy_name );
if ( is_object_in_taxonomy($post->post_type, 'post_tag') ) if ( $taxonomy->hierarchical && $taxonomy->show_ui )
echo '<div class="post_category">' . implode( ',', wp_get_post_categories( $post->ID ) ) . '</div>'; 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 class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>';
echo '</div>'; echo '</div>';

View File

@ -36,17 +36,13 @@ inlineEditPost = {
$('#inline-edit label.inline-edit-tags').clone() $('#inline-edit label.inline-edit-tags').clone()
); );
// categories expandable? // hiearchical taxonomies expandable?
$('span.catshow').click(function() { $('span.catshow').click(function() {
$('.inline-editor ul.cat-checklist').addClass("cat-hover"); $(this).hide().next().show().parent().next().addClass("cat-hover");
$('.inline-editor span.cathide').show();
$(this).hide();
}); });
$('span.cathide').click(function() { $('span.cathide').click(function() {
$('.inline-editor ul.cat-checklist').removeClass("cat-hover"); $(this).hide().prev().show().parent().next().removeClass("cat-hover");
$('.inline-editor span.catshow').show();
$(this).hide();
}); });
$('select[name="_status"] option[value="future"]', bulkRow).remove(); $('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']; 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 == 'page' ) fields.push('post_parent', 'menu_order', 'page_template');
if ( t.type == 'post' ) fields.push('tags_input');
// add the new blank row // add the new blank row
editRow = $('#inline-edit').clone(true); editRow = $('#inline-edit').clone(true);
@ -146,9 +141,24 @@ inlineEditPost = {
if ( $('.sticky', rowData).text() == 'sticky' ) if ( $('.sticky', rowData).text() == 'sticky' )
$('input[name="sticky"]', editRow).attr("checked", "checked"); $('input[name="sticky"]', editRow).attr("checked", "checked");
// categories // hierarchical taxonomies
if ( cats = $('.post_category', rowData).text() ) $('.post_category', rowData).each(function(){
$('ul.cat-checklist :checkbox', editRow).val(cats.split(',')); 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 // handle the post status
status = $('._status', rowData).text(); status = $('._status', rowData).text();
@ -180,12 +190,6 @@ inlineEditPost = {
$(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show(); $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
$('.ptitle', editRow).focus(); $('.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; return false;
}, },

File diff suppressed because one or more lines are too long