diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index eb30df1fe1..3fe3c63317 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -62,6 +62,15 @@ case 'delete-cat' : die('1'); else die('0'); break; +case 'delete-tag' : + check_ajax_referer( "delete-tag_$id" ); + if ( !current_user_can( 'manage_categories' ) ) + die('-1'); + + if ( wp_delete_term($id, 'post_tag')) + die('1'); + else die('0'); + break; case 'delete-link-cat' : check_ajax_referer( "delete-link-category_$id" ); if ( !current_user_can( 'manage_categories' ) ) @@ -302,6 +311,43 @@ case 'add-link-cat' : // From Blogroll -> Categories ) ); $x->send(); break; +case 'add-tag' : // From Manage->Tags + check_ajax_referer( 'add-tag' ); + if ( !current_user_can( 'manage_categories' ) ) + die('-1'); + + if ( '' === trim($_POST['name']) ) { + $x = new WP_Ajax_Response( array( + 'what' => 'tag', + 'id' => new WP_Error( 'name', __('You did not enter a tag name.') ) + ) ); + $x->send(); + } + + $tag = wp_insert_term($_POST['name'], 'post_tag', $_POST ); + + if ( is_wp_error($tag) ) { + $x = new WP_Ajax_Response( array( + 'what' => 'tag', + 'id' => $tag + ) ); + $x->send(); + } + + if ( !$tag || (!$tag = get_term( $tag['term_id'], 'post_tag' )) ) + die('0'); + + $tag_full_name = $tag->name; + $tag_full_name = attribute_escape($tag_full_name); + + $x = new WP_Ajax_Response( array( + 'what' => 'tag', + 'id' => $tag->term_id, + 'data' => _tag_row( $tag ), + 'supplemental' => array('name' => $tag_full_name, 'show-link' => sprintf(__( 'Tag %s added' ), "tag-$tag->term_id", $tag_full_name)) + ) ); + $x->send(); + break; case 'add-comment' : check_ajax_referer( $action ); if ( !current_user_can( 'edit_post', $id ) ) diff --git a/wp-admin/edit-tag-form.php b/wp-admin/edit-tag-form.php new file mode 100644 index 0000000000..1045cc8be9 --- /dev/null +++ b/wp-admin/edit-tag-form.php @@ -0,0 +1,39 @@ +'; + $action = 'editedtag'; + $nonce_action = 'update-tag_' . $tag_ID; + do_action('edit_tag_form_pre', $tag); +} else { + $heading = __('Add Tag'); + $submit_text = __('Add Tag »'); + $form = '
'; + $action = 'addtag'; + $nonce_action = 'add-tag'; + do_action('add_tag_form_pre', $tag); +} +?> + +
+

+
+ + + + + + + + + + + + + +
+

+ + +
diff --git a/wp-admin/edit-tags.php b/wp-admin/edit-tags.php new file mode 100644 index 0000000000..7794ad09c0 --- /dev/null +++ b/wp-admin/edit-tags.php @@ -0,0 +1,140 @@ + + + +

+ + +
+ +

add new)'), '#addtag') ?>

+ +

+ + + + + + + + + + + + + +
+= 1 ) { + echo '<<' . __('Previous Tags') . ''; + if( $count == $tagsperpage ) { + echo ' | '; + } +} + + +if( $count == $tagsperpage ) { + echo '' . __('Next Tags') . '>>'; +} + +?> + +
+ + + +
+ + + + + diff --git a/wp-admin/edit.php b/wp-admin/edit.php index 92da6a6a05..c28773c7b0 100644 --- a/wp-admin/edit.php +++ b/wp-admin/edit.php @@ -48,8 +48,9 @@ if ( is_single() ) { } $h2_search = isset($_GET['s']) && $_GET['s'] ? ' ' . sprintf(__('matching “%s”'), wp_specialchars( get_search_query() ) ) : ''; $h2_cat = isset($_GET['cat']) && $_GET['cat'] ? ' ' . sprintf( __('in “%s”'), single_cat_title('', false) ) : ''; + $h2_tag = isset($_GET['tag']) && $_GET['tag'] ? ' ' . sprintf( __('tagged with “%s”'), single_tag_title('', false) ) : ''; $h2_month = isset($_GET['m']) && $_GET['m'] ? ' ' . sprintf( __('during %s'), single_month_title(' ', false) ) : ''; - printf( _c( '%1$s%2$s%3$s%4$s%5$s|You can reorder these: 1: Posts, 2: by {s}, 3: matching {s}, 4: in {s}, 5: during {s}' ), $h2_noun, $h2_author, $h2_search, $h2_cat, $h2_month ); + printf( _c( '%1$s%2$s%3$s%4$s%5$s%6$s|You can reorder these: 1: Posts, 2: by {s}, 3: matching {s}, 4: in {s}, 5: tagged with {s}, 6: during {s}' ), $h2_noun, $h2_author, $h2_search, $h2_cat, $h2_tag, $h2_month ); } ?> diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 1e87fdd5ed..74df9dc77c 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -232,6 +232,65 @@ function dropdown_link_categories( $default = 0 ) { } } +// Tag stuff + +// Returns a single tag row (see tag_rows below) +// Note: this is also used in admin-ajax.php! +function _tag_row( $tag, $class = '' ) { + $count = number_format_i18n( $tag->count ); + $count = ( $count > 0 ) ? "$count" : $count; + + $out = ''; + $out .= ''; + $out .= '' . $tag->term_id . ''; + + $out .= '' . apply_filters( 'term_name', $tag->name ) . ''; + + $out .= "$count"; + $out .= '' . + __( 'Edit' ) . "" . + 'term_id", + 'delete-tag_' . $tag->term_id ) . + '" class="delete:the-list:tag-' . $tag->term_id . ' delete">' . + __( 'Delete' ) . ""; + $out .= ''; + + return $out; +} + +// Outputs appropriate rows for the Nth page of the Tag Management screen, +// assuming M tags displayed at a time on the page +// Returns the number of tags displayed +function tag_rows( $page = 0, $pagesize = 20 ) { + + // Get a page worth of tags + $start = $page * $pagesize; + $tags = get_terms( 'post_tag', "offset=$start&number=$pagesize&hide_empty=0" ); + + // convert it to table rows + $out = ''; + $class = ''; + $i = 0; + $count = 0; + foreach( $tags as $tag ) { + if( $i ) { + $i = 0; + $class = ' class="alternate"'; + } else { + $i = 1; + $class = ''; + } + + $out .= _tag_row( $tag, $class ); + $count++; + } + + // filter and send to screen + $out = apply_filters('tag_rows', $out); + echo $out; + return $count; +} + // define the columns to display, the syntax is 'internal name' => 'display name' function wp_manage_posts_columns() { $posts_columns = array(); diff --git a/wp-admin/js/tags.js b/wp-admin/js/tags.js new file mode 100644 index 0000000000..37182dfca4 --- /dev/null +++ b/wp-admin/js/tags.js @@ -0,0 +1,21 @@ +jQuery(function($) { + var options = false + + var addAfter = function( r, settings ) { + var name = $("" + $('name', r).text() + "").html(); + var id = $('tag', r).attr('id'); + options[options.length] = new Option(name, id); + } + + var delAfter = function( r, settings ) { + var id = $('tag', r).attr('id'); + for ( var o = 0; o < options.length; o++ ) + if ( id == options[o].value ) + options[o] = null; + } + + if ( options ) + $('#the-list').wpList( { addAfter: addAfter, delAfter: delAfter } ); + else + $('#the-list').wpList(); +}); diff --git a/wp-admin/menu.php b/wp-admin/menu.php index 29cabd0ebf..30d57d1af0 100644 --- a/wp-admin/menu.php +++ b/wp-admin/menu.php @@ -40,6 +40,7 @@ $submenu['edit.php'][5] = array(__('Posts'), 'edit_posts', 'edit.php'); $submenu['edit.php'][10] = array(__('Pages'), 'edit_pages', 'edit-pages.php'); $submenu['edit.php'][15] = array(__('Links'), 'manage_links', 'link-manager.php'); $submenu['edit.php'][20] = array(__('Categories'), 'manage_categories', 'categories.php'); +$submenu['edit.php'][21] = array(__('Tags'), 'manage_categories', 'edit-tags.php'); $submenu['edit.php'][25] = array(__('Media Library'), 'upload_files', 'upload.php'); $submenu['edit.php'][30] = array(__('Import'), 'import', 'import.php'); $submenu['edit.php'][35] = array(__('Export'), 'import', 'export.php'); diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index c88c4cf41d..74bba1f672 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -116,6 +116,7 @@ class WP_Scripts { 'how' => __('Separate multiple categories with commas.') ) ); $this->add( 'admin-categories', '/wp-admin/js/categories.js', array('wp-lists'), '20071031' ); + $this->add( 'admin-tags', '/wp-admin/js/tags.js', array('wp-lists'), '20071031' ); $this->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('wp-lists'), '20070823' ); $this->add( 'password-strength-meter', '/wp-admin/js/password-strength-meter.js', array('jquery'), '20070405' ); $this->localize( 'password-strength-meter', 'pwsL10n', array( diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 8100912c73..3edb9551bb 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -525,9 +525,10 @@ function &get_terms($taxonomies, $args = '') { 'hide_empty' => true, 'exclude' => '', 'include' => '', 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', - 'pad_counts' => false); + 'pad_counts' => false, 'offset' => ''); $args = wp_parse_args( $args, $defaults ); $args['number'] = absint( $args['number'] ); + $args['offset'] = absint( $args['offset'] ); if ( !$single_taxonomy || !is_taxonomy_hierarchical($taxonomies[0]) || '' != $args['parent'] ) { $args['child_of'] = 0; @@ -625,9 +626,13 @@ function &get_terms($taxonomies, $args = '') { if ( $hide_empty && !$hierarchical ) $where .= ' AND tt.count > 0'; - if ( !empty($number) ) - $number = 'LIMIT ' . $number; - else + if ( !empty($number) ) { + if( $offset ) + $number = 'LIMIT ' . $offset . ',' . $number; + else + $number = 'LIMIT ' . $number; + + } else $number = ''; if ( 'all' == $fields )