Allow muliple tag-like taxonomies in the post editor. see #6387

git-svn-id: https://develop.svn.wordpress.org/trunk@10222 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2008-12-18 19:12:26 +00:00
parent 3a0f778fa8
commit 3c7eca56ab
15 changed files with 265 additions and 114 deletions

View File

@ -45,6 +45,11 @@ case 'ajax-tag-search' :
$s = $_GET['q']; // is this slashed already? $s = $_GET['q']; // is this slashed already?
if ( isset($_GET['tax']) )
$taxonomy = sanitize_title($_GET['tax']);
else
die('0');
if ( false !== strpos( $s, ',' ) ) { if ( false !== strpos( $s, ',' ) ) {
$s = explode( ',', $s ); $s = explode( ',', $s );
$s = $s[count( $s ) - 1]; $s = $s[count( $s ) - 1];
@ -52,7 +57,9 @@ case 'ajax-tag-search' :
$s = trim( $s ); $s = trim( $s );
if ( strlen( $s ) < 2 ) if ( strlen( $s ) < 2 )
die; // require 2 chars for matching die; // require 2 chars for matching
$results = $wpdb->get_col( "SELECT t.name FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = 'post_tag' AND t.name LIKE ('%". $s . "%')" );
$results = $wpdb->get_col( "SELECT t.name FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = '$taxonomy' AND t.name LIKE ('%" . $s . "%')" );
echo join( $results, "\n" ); echo join( $results, "\n" );
die; die;
break; break;
@ -490,7 +497,12 @@ case 'get-tagcloud' :
if ( !current_user_can( 'manage_categories' ) ) if ( !current_user_can( 'manage_categories' ) )
die('-1'); die('-1');
$tags = get_tags( array( 'number' => 45, 'orderby' => 'count', 'order' => 'DESC' ) ); if ( isset($_POST['tax']) )
$taxonomy = sanitize_title($_POST['tax']);
else
die('0');
$tags = get_terms( $taxonomy, array( 'number' => 45, 'orderby' => 'count', 'order' => 'DESC' ) );
if ( empty( $tags ) ) if ( empty( $tags ) )
die( __('No tags found!') ); die( __('No tags found!') );
@ -776,7 +788,6 @@ case 'autosave' : // The name of this action is hardcoded in edit_post()
global $current_user; global $current_user;
$_POST['post_category'] = explode(",", $_POST['catslist']); $_POST['post_category'] = explode(",", $_POST['catslist']);
$_POST['tags_input'] = explode(",", $_POST['tags_input']);
if($_POST['post_type'] == 'page' || empty($_POST['post_category'])) if($_POST['post_type'] == 'page' || empty($_POST['post_category']))
unset($_POST['post_category']); unset($_POST['post_category']);

View File

@ -682,12 +682,12 @@ li.widget-list-control-item h4,
color: #448abd; color: #448abd;
} }
#tagchecklist span a, .tagchecklist span a,
#bulk-titles div a { #bulk-titles div a {
background: url(../images/xit.gif) no-repeat; background: url(../images/xit.gif) no-repeat;
} }
#tagchecklist span a:hover, .tagchecklist span a:hover,
#bulk-titles div a:hover { #bulk-titles div a:hover {
background: url(../images/xit.gif) no-repeat -10px 0; background: url(../images/xit.gif) no-repeat -10px 0;
} }
@ -1007,7 +1007,7 @@ abbr.required,
#timestampdiv input, #timestampdiv input,
#namediv input, #namediv input,
#tagsdiv #the-tagcloud { #poststuff .inside .the-tagcloud {
border-color: #ddd; border-color: #ddd;
} }

View File

@ -682,12 +682,12 @@ li.widget-list-control-item h4,
color: #448abd; color: #448abd;
} }
#tagchecklist span a, .tagchecklist span a,
#bulk-titles div a { #bulk-titles div a {
background: url(../images/xit.gif) no-repeat; background: url(../images/xit.gif) no-repeat;
} }
#tagchecklist span a:hover, .tagchecklist span a:hover,
#bulk-titles div a:hover { #bulk-titles div a:hover {
background: url(../images/xit.gif) no-repeat -10px 0; background: url(../images/xit.gif) no-repeat -10px 0;
} }
@ -1007,7 +1007,7 @@ abbr.required,
#timestampdiv input, #timestampdiv input,
#namediv input, #namediv input,
#tagsdiv #the-tagcloud { #poststuff .inside .the-tagcloud {
border-color: #ddd; border-color: #ddd;
} }

View File

@ -44,7 +44,7 @@ div#dashboard-widgets {
padding-right: 0; padding-right: 0;
padding-left: 1px; padding-left: 1px;
} }
#tagchecklist span a { .tagchecklist span a {
margin: 4px -9px 0 0; margin: 4px -9px 0 0;
} }
.widefat th input { .widefat th input {

View File

@ -245,7 +245,7 @@ li.widget-list-control-item,
li.widget-list-control-item h4, li.widget-list-control-item h4,
.widget-sortable, .widget-sortable,
.widget-control-actions, .widget-control-actions,
#tagchecklist, .tagchecklist,
#col-container, #col-container,
#col-left, #col-left,
#col-right { #col-right {
@ -296,12 +296,12 @@ div#dashboard-widgets {
padding-right: 1px; padding-right: 1px;
} }
#tagchecklist span, #tagchecklist span a { .tagchecklist span, .tagchecklist span a {
display: inline-block; display: inline-block;
display: block; display: block;
} }
#tagchecklist span a { .tagchecklist span a {
margin: 4px 0 0 -9px; margin: 4px 0 0 -9px;
} }

View File

@ -263,14 +263,40 @@ add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', 'post', 'side',
* *
* @param object $post * @param object $post
*/ */
function post_tags_meta_box($post) { function post_tags_meta_box($post, $box) {
$tax_name = substr($box['id'], 8);
$taxonomy = get_taxonomy($tax_name);
if ( isset($taxonomy->helps) )
$helps = attribute_escape($taxonomy->helps);
else
$helps = '';
?> ?>
<p id="jaxtag"><label class="hidden" for="newtag"><?php _e('Tags'); ?></label><input type="text" name="tags_input" class="tags-input" id="tags-input" size="40" tabindex="3" value="<?php echo get_tags_to_edit( $post->ID ); ?>" /></p> <div class="tagsdiv" id="<?php echo $tax_name; ?>">
<div id="tagchecklist"></div> <p class="jaxtag">
<p id="tagcloud-link" class="hide-if-no-js"><a href='#'><?php _e( 'Choose from the most popular tags' ); ?></a></p> <label class="hidden" for="newtag"><?php _e( $box['title'] ); ?></label>
<input type="hidden" name="<?php echo "tax_input[$tax_name]"; ?>" class="the-tags" id="tax-input[<?php echo $tax_name; ?>]" value="<?php echo get_terms_to_edit( $post->ID, $tax_name ); ?>" />
<span class="ajaxtag" style="display:none;">
<input type="text" name="newtag[<?php echo $tax_name; ?>]" class="newtag form-input-tip" size="16" autocomplete="off" value="<?php _e('Add new tag'); ?>" />
<input type="button" class="button tagadd" value="<?php _e('Add'); ?>" tabindex="3" />
</span>
<?php echo $helps ? "<div class='howto'>$helps</div>" : ''; ?>
</p>
<div class="tagchecklist"></div>
</div>
<p class="tagcloud-link hide-if-no-js"><a href="#titlediv" class="tagcloud-link" id="link-<?php echo $tax_name; ?>"><?php printf( __('Choose from the most used tags in %s'), $box['title'] ); ?></a></p>
<?php <?php
} }
add_meta_box('tagsdiv', __('Tags'), 'post_tags_meta_box', 'post', 'side', 'core');
// all tag-style post taxonomies
foreach ( get_object_taxonomies('post') as $tax_name ) {
if ( !is_taxonomy_hierarchical($tax_name) ) {
$taxonomy = get_taxonomy($tax_name);
$label = isset($taxonomy->label) ? attribute_escape($taxonomy->label) : $tax_name;
add_meta_box('tagsdiv-' . $tax_name, $label, 'post_tags_meta_box', 'post', 'side', 'core');
}
}
/** /**
* Display post categories form fields. * Display post categories form fields.

View File

@ -194,21 +194,37 @@ function wp_update_category($catarr) {
* @param unknown_type $post_id * @param unknown_type $post_id
* @return unknown * @return unknown
*/ */
function get_tags_to_edit( $post_id ) { function get_tags_to_edit( $post_id, $taxonomy = 'post_tag' ) {
return get_terms_to_edit( $post_id, $taxonomy);
}
/**
* {@internal Missing Short Description}}
*
* @since unknown
*
* @param unknown_type $post_id
* @return unknown
*/
function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {
$post_id = (int) $post_id; $post_id = (int) $post_id;
if ( !$post_id ) if ( !$post_id )
return false; return false;
$tags = wp_get_post_tags($post_id); $tags = wp_get_post_terms($post_id, $taxonomy, array());
if ( !$tags ) if ( !$tags )
return false; return false;
if ( is_wp_error($tags) )
return $tags;
foreach ( $tags as $tag ) foreach ( $tags as $tag )
$tag_names[] = $tag->name; $tag_names[] = $tag->name;
$tags_to_edit = join( ',', $tag_names ); $tags_to_edit = join( ',', $tag_names );
$tags_to_edit = attribute_escape( $tags_to_edit ); $tags_to_edit = attribute_escape( $tags_to_edit );
$tags_to_edit = apply_filters( 'tags_to_edit', $tags_to_edit ); $tags_to_edit = apply_filters( 'terms_to_edit', $tags_to_edit, $taxonomy );
return $tags_to_edit; return $tags_to_edit;
} }
@ -233,10 +249,20 @@ function tag_exists($tag_name) {
* @return unknown * @return unknown
*/ */
function wp_create_tag($tag_name) { function wp_create_tag($tag_name) {
if ( $id = tag_exists($tag_name) ) return wp_create_term( $tag_name, 'post_tag');
return $id;
return wp_insert_term($tag_name, 'post_tag');
} }
?> /**
* {@internal Missing Short Description}}
*
* @since unknown
*
* @param unknown_type $tag_name
* @return unknown
*/
function wp_create_term($tag_name, $taxonomy = 'post_tag') {
if ( $id = is_term($tag_name, $taxonomy) )
return $id;
return wp_insert_term($tag_name, $taxonomy);
}

View File

@ -2695,7 +2695,7 @@ function wp_remember_old_slug() {
* @param string $context The context within the page where the boxes should show ('normal', 'advanced'). * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
* @param string $priority The priority within the context where the boxes should show ('high', 'low'). * @param string $priority The priority within the context where the boxes should show ('high', 'low').
*/ */
function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default') { function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args=null) {
global $wp_meta_boxes; global $wp_meta_boxes;
if ( !isset($wp_meta_boxes) ) if ( !isset($wp_meta_boxes) )
@ -2729,6 +2729,7 @@ function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $pri
} elseif ( 'sorted' == $priority ) { } elseif ( 'sorted' == $priority ) {
$title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title']; $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title'];
$callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback']; $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback'];
$callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args'];
} }
// An id can be in only one priority and one context // An id can be in only one priority and one context
if ( $priority != $a_priority || $context != $a_context ) if ( $priority != $a_priority || $context != $a_context )
@ -2742,7 +2743,7 @@ function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $pri
if ( !isset($wp_meta_boxes[$page][$context][$priority]) ) if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
$wp_meta_boxes[$page][$context][$priority] = array(); $wp_meta_boxes[$page][$context][$priority] = array();
$wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback); $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
} }
/** /**

View File

@ -1,95 +1,146 @@
// this file contains all the scripts used in the post/edit page // this file contains all the scripts used in the post/edit page
// return an array with any duplicate, whitespace or values removed
function array_unique_noempty(a) {
var out = [];
jQuery.each( a, function(key, val) {
val = jQuery.trim(val);
if ( val && jQuery.inArray(val, out) == -1 )
out.push(val);
} );
return out;
}
function new_tag_remove_tag() { function new_tag_remove_tag() {
var id = jQuery( this ).attr( 'id' ); var id = jQuery( this ).attr( 'id' );
var num = id.substr( 10 ); var num = id.split('-check-num-')[1];
var current_tags = jQuery( '#tags-input' ).val().split(','); var taxbox = jQuery(this).parents('.tagsdiv');
var current_tags = taxbox.find( '.the-tags' ).val().split(',');
delete current_tags[num]; delete current_tags[num];
var new_tags = []; var new_tags = [];
jQuery.each( current_tags, function( key, val ) {
if ( val && !val.match(/^\s+$/) && '' != val ) { jQuery.each( current_tags, function(key, val) {
new_tags = new_tags.concat( val ); val = jQuery.trim(val);
if ( val ) {
new_tags.push(val);
} }
}); });
jQuery( '#tags-input' ).val( new_tags.join( ',' ).replace( /\s*,+\s*/, ',' ).replace( /,+/, ',' ).replace( /,+\s+,+/, ',' ).replace( /,+\s*$/, '' ).replace( /^\s*,+/, '' ) );
tag_update_quickclicks(); taxbox.find('.the-tags').val( new_tags.join(',').replace(/\s*,+\s*/, ',').replace(/,+/, ',').replace(/,+\s+,+/, ',').replace(/,+\s*$/, '').replace(/^\s*,+/, '') );
jQuery('#newtag').focus();
tag_update_quickclicks(taxbox);
return false; return false;
} }
function tag_update_quickclicks() { function tag_update_quickclicks(taxbox) {
if ( jQuery( '#tags-input' ).length == 0 ) if ( jQuery(taxbox).find('.the-tags').length == 0 )
return; return;
var current_tags = jQuery( '#tags-input' ).val().split(',');
jQuery( '#tagchecklist' ).empty(); var current_tags = jQuery(taxbox).find('.the-tags').val().split(',');
jQuery(taxbox).find('.tagchecklist').empty();
shown = false; shown = false;
// jQuery.merge( current_tags, current_tags ); // this doesn't work anymore, need something to array_unique
jQuery.each( current_tags, function( key, val ) { jQuery.each( current_tags, function( key, val ) {
val = val.replace( /^\s+/, '' ).replace( /\s+$/, '' ); // trim val = jQuery.trim(val);
if ( !val.match(/^\s+$/) && '' != val ) { if ( !val.match(/^\s+$/) && '' != val ) {
txt = '<span><a id="tag-check-' + key + '" class="ntdelbutton">X</a>&nbsp;' + val + '</span> '; var button_id = jQuery(taxbox).attr('id') + '-check-num-' + key;
jQuery( '#tagchecklist' ).append( txt ); txt = '<span><a id="' + button_id + '" class="ntdelbutton">X</a>&nbsp;' + val + '</span> ';
jQuery( '#tag-check-' + key ).click( new_tag_remove_tag ); jQuery(taxbox).find('.tagchecklist').append(txt);
shown = true; jQuery( '#' + button_id ).click( new_tag_remove_tag );
} }
}); });
if ( shown ) if ( shown )
jQuery( '#tagchecklist' ).prepend( '<strong>'+postL10n.tagsUsed+'</strong><br />' ); jQuery(taxbox).find('.tagchecklist').prepend('<strong>'+postL10n.tagsUsed+'</strong><br />');
} }
function tag_flush_to_text(e,a) { function tag_flush_to_text(id, a) {
a = a || false; a = a || false;
var text = a ? jQuery(a).text() : jQuery('#newtag').val(); var taxbox = jQuery('#'+id);
var newtags = jQuery('#tags-input').val(); var text = a ? jQuery(a).text() : taxbox.find('input.newtag').val();
var t = text.replace( /\s*([^,]+).*/, '$1,' ); // is the input box empty (i.e. showing the 'Add new tag' tip)?
newtags += ',' if ( taxbox.find('input.newtag').hasClass('form-input-tip') && ! a )
if ( newtags.indexOf(t) != -1 )
return false; return false;
newtags += text; var tags = taxbox.find('.the-tags').val();
var newtags = tags ? tags + ',' + text : text;
// massage // massage
newtags = newtags.replace( /\s+,+\s*/g, ',' ).replace( /,+/g, ',' ).replace( /,+\s+,+/g, ',' ).replace( /,+\s*$/g, '' ).replace( /^\s*,+/g, '' ); newtags = newtags.replace(/\s+,+\s*/g, ',').replace(/,+/g, ',').replace(/,+\s+,+/g, ',').replace(/,+\s*$/g, '').replace(/^\s*,+/g, '');
jQuery('#tags-input').val( newtags ); newtags = array_unique_noempty(newtags.split(',')).join(',');
tag_update_quickclicks(); taxbox.find('.the-tags').val(newtags);
if ( ! a ) { tag_update_quickclicks(taxbox);
jQuery('#newtag').val('');
jQuery('#newtag').focus(); if ( ! a )
} taxbox.find('input.newtag').val('').focus();
return false; return false;
} }
function tag_save_on_publish() { function tag_save_on_publish() {
if ( jQuery('#newtag').val() != postL10n.addTag ) jQuery('.tagsdiv').each( function(i) {
tag_flush_to_text(); if ( !jQuery(this).find('input.newtag').hasClass('form-input-tip') )
tag_flush_to_text(jQuery(this).parents('.tagsdiv').attr('id'));
} );
} }
function tag_press_key( e ) { function tag_press_key( e ) {
if ( 13 == e.keyCode ) { if ( 13 == e.which ) {
tag_flush_to_text(); tag_flush_to_text(jQuery(e.target).parents('.tagsdiv').attr('id'));
return false; return false;
} }
}; };
function tag_init() {
jQuery('.ajaxtag').show();
jQuery('.tagsdiv').each( function(i) {
tag_update_quickclicks(this);
} );
// add the quickadd form
jQuery('.ajaxtag input.tagadd').click(function(){tag_flush_to_text(jQuery(this).parents('.tagsdiv').attr('id'));});
jQuery('.ajaxtag input.newtag').focus(function() {
if ( this.value == postL10n.addTag ) {
jQuery(this).val( '' ).removeClass( 'form-input-tip' );
}
});
jQuery('.ajaxtag input.newtag').blur(function() {
if ( this.value == '' ) {
jQuery(this).val( postL10n.addTag ).addClass( 'form-input-tip' );
}
});
// auto-save tags on post save/publish
jQuery('#publish').click( tag_save_on_publish );
jQuery('#save-post').click( tag_save_on_publish );
// catch the enter key
jQuery('.ajaxtag input.newtag').keypress( tag_press_key );
}
(function($){ (function($){
tagCloud = { tagCloud = {
init : function() { init : function() {
$('#tagcloud-link').click(function(){tagCloud.get(); $(this).unbind().click(function(){return false;}); return false;}); $('.tagcloud-link').click(function(){tagCloud.get($(this).attr('id')); $(this).unbind().click(function(){return false;}); return false;});
}, },
get : function() { get : function(id) {
$.post('admin-ajax.php', {'action':'get-tagcloud'}, function(r, stat) { tax = id.substr(id.indexOf('-')+1);
$.post('admin-ajax.php', {'action':'get-tagcloud','tax':tax}, function(r, stat) {
if ( 0 == r || 'success' != stat ) if ( 0 == r || 'success' != stat )
r = wpAjax.broken; r = wpAjax.broken;
r = '<p id="the-tagcloud">'+r+'</p>'; r = $('<p id="tagcloud-'+tax+'" class="the-tagcloud">'+r+'</p>');
$('#tagcloud-link').after($(r)); $('a', r).click(function(){
$('#the-tagcloud a').click(function(){ var id = $(this).parents('p').attr('id');
tag_flush_to_text(0,this); tag_flush_to_text(id.substr(id.indexOf('-')+1), this);
return false; return false;
}); });
$('#'+id).after(r);
}); });
} }
} }
@ -107,29 +158,16 @@ jQuery(document).ready( function($) {
// Editable slugs // Editable slugs
make_slugedit_clickable(); make_slugedit_clickable();
jQuery('#tags-input').hide(); // prepare the tag UI
tag_update_quickclicks(); tag_init();
// add the quickadd form
jQuery('#jaxtag').prepend('<span id="ajaxtag"><input type="text" name="newtag" id="newtag" class="form-input-tip" size="16" autocomplete="off" value="'+postL10n.addTag+'" /><input type="button" class="button" id="tagadd" value="' + postL10n.add + '" tabindex="3" /><input type="hidden"/><input type="hidden"/><span class="howto">'+postL10n.separate+'</span></span>');
jQuery('#tagadd').click( tag_flush_to_text );
jQuery('#newtag').focus(function() {
if ( this.value == postL10n.addTag )
jQuery(this).val( '' ).removeClass( 'form-input-tip' );
});
jQuery('#newtag').blur(function() {
if ( this.value == '' )
jQuery(this).val( postL10n.addTag ).addClass( 'form-input-tip' );
});
// auto-save tags on post save/publish
jQuery('#publish').click( tag_save_on_publish );
jQuery('#save-post').click( tag_save_on_publish );
jQuery('#title').blur( function() { if ( (jQuery("#post_ID").val() > 0) || (jQuery("#title").val().length == 0) ) return; autosave(); } ); jQuery('#title').blur( function() { if ( (jQuery("#post_ID").val() > 0) || (jQuery("#title").val().length == 0) ) return; autosave(); } );
// auto-suggest stuff // auto-suggest stuff
jQuery('#newtag').suggest( 'admin-ajax.php?action=ajax-tag-search', { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } ); jQuery('.newtag').each(function(){
jQuery('#newtag').keypress( tag_press_key ); var tax = $(this).parents('div.tagsdiv').attr('id');
$(this).suggest( 'admin-ajax.php?action=ajax-tag-search&tax='+tax, { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
});
// category tabs // category tabs
var categoryTabs =jQuery('#category-tabs').tabs(); var categoryTabs =jQuery('#category-tabs').tabs();

View File

@ -211,7 +211,7 @@ td.available-theme {
#normal-sortables .postbox .submit { #normal-sortables .postbox .submit {
float: left; float: left;
} }
#post-body #tagsdiv #newtag { #post-body .tagsdiv #newtag {
margin-right: 0; margin-right: 0;
margin-left: 5px; margin-left: 5px;
} }
@ -221,18 +221,18 @@ td.available-theme {
#comment-status-radio input { #comment-status-radio input {
margin: 2px 0 5px 3px; margin: 2px 0 5px 3px;
} }
#tagchecklist { .tagchecklist {
margin-left: 0; margin-left: 0;
margin-right: 10px; margin-right: 10px;
} }
#tagchecklist strong { .tagchecklist strong {
margin-left: 0; margin-left: 0;
margin-right: -8px; margin-right: -8px;
} }
#tagchecklist span { .tagchecklist span {
float: right; float: right;
} }
#tagchecklist span a { .tagchecklist span a {
margin: 6px -9px 0 0; margin: 6px -9px 0 0;
float: right; float: right;
} }

View File

@ -1355,7 +1355,7 @@ table.form-table td .updated {
display: none; display: none;
} }
#post-body #tagsdiv #newtag { #post-body .tagsdiv #newtag {
margin-right: 5px; margin-right: 5px;
width: 16em; width: 16em;
} }
@ -1364,7 +1364,7 @@ table.form-table td .updated {
width: 94% width: 94%
} }
#side-info-column #tagsdiv #newtag { #side-info-column .tagsdiv #newtag {
width: 68%; width: 68%;
} }
@ -1421,18 +1421,18 @@ table.form-table td .updated {
padding: 5px 0; padding: 5px 0;
} }
#tagchecklist { .tagchecklist {
margin-left: 10px; margin-left: 10px;
font-size: 12px; font-size: 12px;
overflow: auto; overflow: auto;
} }
#tagchecklist strong { .tagchecklist strong {
margin-left: -8px; margin-left: -8px;
position: absolute; position: absolute;
} }
#tagchecklist span { .tagchecklist span {
margin-right: 25px; margin-right: 25px;
display: block; display: block;
float: left; float: left;
@ -1442,7 +1442,7 @@ table.form-table td .updated {
cursor: default; cursor: default;
} }
#tagchecklist span a { .tagchecklist span a {
margin: 6px 0pt 0pt -9px; margin: 6px 0pt 0pt -9px;
cursor: pointer; cursor: pointer;
width: 10px; width: 10px;
@ -2830,8 +2830,8 @@ form.upgrade {
margin-top: 8px; margin-top: 8px;
} }
#tagsdiv #the-tagcloud { #poststuff .inside .the-tagcloud {
margin: 5px 5px 10px; margin: 5px 0 10px;
padding: 8px; padding: 8px;
border-width: 1px; border-width: 1px;
border-style: solid; border-style: solid;

View File

@ -130,11 +130,15 @@ var autosave = function() {
post_ID: jQuery("#post_ID").val() || 0, post_ID: jQuery("#post_ID").val() || 0,
post_title: jQuery("#title").val() || "", post_title: jQuery("#title").val() || "",
autosavenonce: jQuery('#autosavenonce').val(), autosavenonce: jQuery('#autosavenonce').val(),
tags_input: jQuery("#tags-input").val() || "", //tags_input: jQuery("#tags-input").val() || "",
post_type: jQuery('#post_type').val() || "", post_type: jQuery('#post_type').val() || "",
autosave: 1 autosave: 1
}; };
jQuery('.tags-input').each( function() {
post_data[this.name] = this.value;
} );
// We always send the ajax request in order to keep the post lock fresh. // We always send the ajax request in order to keep the post lock fresh.
// This (bool) tells whether or not to write the post to the DB during the ajax request. // This (bool) tells whether or not to write the post to the DB during the ajax request.
var doAutoSave = true; var doAutoSave = true;

View File

@ -1206,12 +1206,34 @@ function wp_get_post_categories( $post_id = 0, $args = array() ) {
* @return array List of post tags. * @return array List of post tags.
*/ */
function wp_get_post_tags( $post_id = 0, $args = array() ) { function wp_get_post_tags( $post_id = 0, $args = array() ) {
return wp_get_post_terms( $post_id, 'post_tag', $args);
}
/**
* Retrieve the terms for a post.
*
* There is only one default for this function, called 'fields' and by default
* is set to 'all'. There are other defaults that can be override in
* {@link wp_get_object_terms()}.
*
* @package WordPress
* @subpackage Post
* @since 2.8.0
*
* @uses wp_get_object_terms() Gets the tags for returning. Args can be found here
*
* @param int $post_id Optional. The Post ID
* @param string $taxonomy The taxonomy for which to retrieve terms. Defaults to post_tag.
* @param array $args Optional. Overwrite the defaults
* @return array List of post tags.
*/
function wp_get_post_terms( $post_id = 0, $taxonomy = 'post_tag', $args = array() ) {
$post_id = (int) $post_id; $post_id = (int) $post_id;
$defaults = array('fields' => 'all'); $defaults = array('fields' => 'all');
$args = wp_parse_args( $args, $defaults ); $args = wp_parse_args( $args, $defaults );
$tags = wp_get_object_terms($post_id, 'post_tag', $args); $tags = wp_get_object_terms($post_id, $taxonomy, $args);
return $tags; return $tags;
} }
@ -1498,7 +1520,15 @@ function wp_insert_post($postarr = array(), $wp_error = false) {
} }
wp_set_post_categories( $post_ID, $post_category ); wp_set_post_categories( $post_ID, $post_category );
// old-style tags_input
if ( !empty($tags_input) )
wp_set_post_tags( $post_ID, $tags_input ); wp_set_post_tags( $post_ID, $tags_input );
// new-style support for all tag-like taxonomies
if ( !empty($tax_input) ) {
foreach ( $tax_input as $taxonomy => $tags ) {
wp_set_post_terms( $post_ID, $tags, $taxonomy );
}
}
$current_guid = get_post_field( 'guid', $post_ID ); $current_guid = get_post_field( 'guid', $post_ID );
@ -1685,7 +1715,21 @@ function wp_add_post_tags($post_id = 0, $tags = '') {
* @return bool|null Will return false if $post_id is not an integer or is 0. Will return null otherwise * @return bool|null Will return false if $post_id is not an integer or is 0. Will return null otherwise
*/ */
function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) { function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) {
return wp_set_post_terms( $post_id, $tags, 'post_tag', $append);
}
/**
* Set the terms for a post.
*
* @since 2.8.0
* @uses wp_set_object_terms() Sets the tags for the post.
*
* @param int $post_id Post ID.
* @param string $tags The tags to set for the post, separated by commas.
* @param bool $append If true, don't delete existing tags, just add on. If false, replace the tags with the new tags.
* @return bool|null Will return false if $post_id is not an integer or is 0. Will return null otherwise
*/
function wp_set_post_terms( $post_id = 0, $tags = '', $taxonomy = 'post_tag', $append = false ) {
$post_id = (int) $post_id; $post_id = (int) $post_id;
if ( !$post_id ) if ( !$post_id )
@ -1693,8 +1737,9 @@ function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) {
if ( empty($tags) ) if ( empty($tags) )
$tags = array(); $tags = array();
$tags = (is_array($tags)) ? $tags : explode( ',', trim($tags, " \n\t\r\0\x0B,") );
wp_set_object_terms($post_id, $tags, 'post_tag', $append); $tags = is_array($tags) ? $tags : explode( ',', trim($tags, " \n\t\r\0\x0B,") );
wp_set_object_terms($post_id, $tags, $taxonomy, $append);
} }
/** /**

View File

@ -77,7 +77,7 @@ function wp_default_scripts( &$scripts ) {
'l10n_print_after' => 'try{convertEntities(wpAjax);}catch(e){};' 'l10n_print_after' => 'try{convertEntities(wpAjax);}catch(e){};'
) ); ) );
$scripts->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20081210' ); $scripts->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20081217' );
$scripts->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('wp-ajax-response'), '20081210' ); $scripts->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('wp-ajax-response'), '20081210' );
$scripts->localize( 'wp-lists', 'wpListL10n', array( $scripts->localize( 'wp-lists', 'wpListL10n', array(
@ -179,7 +179,7 @@ function wp_default_scripts( &$scripts ) {
'cancel' => __('Cancel'), 'cancel' => __('Cancel'),
'l10n_print_after' => 'try{convertEntities(slugL10n);}catch(e){};' 'l10n_print_after' => 'try{convertEntities(slugL10n);}catch(e){};'
) ); ) );
$scripts->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20081210' ); $scripts->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20081217' );
$scripts->localize( 'post', 'postL10n', array( $scripts->localize( 'post', 'postL10n', array(
'tagsUsed' => __('Tags used on this post:'), 'tagsUsed' => __('Tags used on this post:'),
'add' => attribute_escape(__('Add')), 'add' => attribute_escape(__('Add')),

View File

@ -17,8 +17,8 @@
* @global array $wp_taxonomies * @global array $wp_taxonomies
*/ */
$wp_taxonomies = array(); $wp_taxonomies = array();
$wp_taxonomies['category'] = (object) array('name' => 'category', 'object_type' => 'post', 'hierarchical' => true, 'update_count_callback' => '_update_post_term_count'); $wp_taxonomies['category'] = (object) array('name' => 'category', 'object_type' => 'post', 'hierarchical' => true, 'update_count_callback' => '_update_post_term_count', 'label' => __('Categories'));
$wp_taxonomies['post_tag'] = (object) array('name' => 'post_tag', 'object_type' => 'post', 'hierarchical' => false, 'update_count_callback' => '_update_post_term_count'); $wp_taxonomies['post_tag'] = (object) array('name' => 'post_tag', 'object_type' => 'post', 'hierarchical' => false, 'update_count_callback' => '_update_post_term_count', 'label' => __('Post Tags'));
$wp_taxonomies['link_category'] = (object) array('name' => 'link_category', 'object_type' => 'link', 'hierarchical' => false); $wp_taxonomies['link_category'] = (object) array('name' => 'link_category', 'object_type' => 'link', 'hierarchical' => false);
/** /**