WordPress.org

Make WordPress Core

Changeset 6660


Ignore:
Timestamp:
01/25/2008 07:29:01 PM (12 years ago)
Author:
ryan
Message:

First cut at Manage->Tags. Props jhodgdon. see #5684

Location:
trunk
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r6633 r6660  
    6060
    6161    if ( wp_delete_category( $id ) )
     62        die('1');
     63    else    die('0');
     64    break;
     65case 'delete-tag' :
     66    check_ajax_referer( "delete-tag_$id" );
     67    if ( !current_user_can( 'manage_categories' ) )
     68        die('-1');
     69
     70    if ( wp_delete_term($id, 'post_tag'))
    6271        die('1');
    6372    else    die('0');
     
    300309        'id' => $term_id,
    301310        'data' => $link_cat
     311    ) );
     312    $x->send();
     313    break;
     314case 'add-tag' : // From Manage->Tags
     315    check_ajax_referer( 'add-tag' );
     316    if ( !current_user_can( 'manage_categories' ) )
     317        die('-1');
     318
     319    if ( '' === trim($_POST['name']) ) {
     320        $x = new WP_Ajax_Response( array(
     321            'what' => 'tag',
     322            'id' => new WP_Error( 'name', __('You did not enter a tag name.') )
     323        ) );
     324        $x->send();
     325    }
     326
     327    $tag = wp_insert_term($_POST['name'], 'post_tag', $_POST );
     328
     329    if ( is_wp_error($tag) ) {
     330        $x = new WP_Ajax_Response( array(
     331            'what' => 'tag',
     332            'id' => $tag
     333        ) );
     334        $x->send();
     335    }
     336
     337    if ( !$tag || (!$tag = get_term( $tag['term_id'], 'post_tag' )) )
     338        die('0');
     339
     340    $tag_full_name = $tag->name;
     341    $tag_full_name = attribute_escape($tag_full_name);
     342
     343    $x = new WP_Ajax_Response( array(
     344        'what' => 'tag',
     345        'id' => $tag->term_id,
     346        'data' => _tag_row( $tag ),
     347        'supplemental' => array('name' => $tag_full_name, 'show-link' => sprintf(__( 'Tag <a href="#%s">%s</a> added' ), "tag-$tag->term_id", $tag_full_name))
    302348    ) );
    303349    $x->send();
  • trunk/wp-admin/edit.php

    r6581 r6660  
    4949    $h2_search = isset($_GET['s'])   && $_GET['s']   ? ' ' . sprintf(__('matching &#8220;%s&#8221;'), wp_specialchars( get_search_query() ) ) : '';
    5050    $h2_cat    = isset($_GET['cat']) && $_GET['cat'] ? ' ' . sprintf( __('in &#8220;%s&#8221;'), single_cat_title('', false) ) : '';
     51    $h2_tag    = isset($_GET['tag']) && $_GET['tag'] ? ' ' . sprintf( __('tagged with &#8220;%s&#8221;'), single_tag_title('', false) ) : '';
    5152    $h2_month  = isset($_GET['m'])   && $_GET['m']   ? ' ' . sprintf( __('during %s'), single_month_title(' ', false) ) : '';
    52     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 );
     53    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 );
    5354}
    5455?></h2>
  • trunk/wp-admin/includes/template.php

    r6659 r6660  
    231231        echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', ($checked ? ' checked="checked"' : "" ), '/> ', $name, "</label></li>";
    232232    }
     233}
     234
     235// Tag stuff
     236
     237// Returns a single tag row (see tag_rows below)
     238// Note: this is also used in admin-ajax.php!
     239function _tag_row( $tag, $class = '' ) {
     240        $count = number_format_i18n( $tag->count );
     241        $count = ( $count > 0 ) ? "<a href='edit.php?tag=$tag->slug'>$count</a>" : $count;
     242       
     243        $out = '';
     244        $out .= '<tr id="tag-' . $tag->term_id . '"' . $class . '>';
     245        $out .= '<th scope="row">' . $tag->term_id . '</th>';
     246
     247        $out .= '<td>' . apply_filters( 'term_name', $tag->name ) . '</td>';
     248
     249        $out .= "<td>$count</td>";     
     250        $out .= '<td><a href="edit-tags.php?action=edit&amp;tag_ID=' . $tag->term_id . '" class="edit">' .
     251            __( 'Edit' ) . "</a></td>" .
     252            '<td><a href="' . wp_nonce_url( "edit-tags.php?action=delete&amp;tag_ID=$tag->term_id",
     253                    'delete-tag_' . $tag->term_id ) .
     254                '" class="delete:the-list:tag-' . $tag->term_id . ' delete">' .
     255                __( 'Delete' ) . "</a></td>";
     256        $out .= '</tr>';
     257       
     258        return $out;
     259}
     260
     261// Outputs appropriate rows for the Nth page of the Tag Management screen,
     262// assuming M tags displayed at a time on the page
     263// Returns the number of tags displayed
     264function tag_rows( $page = 0, $pagesize = 20 ) {
     265   
     266    // Get a page worth of tags
     267    $start = $page * $pagesize;
     268    $tags = get_terms( 'post_tag', "offset=$start&number=$pagesize&hide_empty=0"  );
     269   
     270    // convert it to table rows
     271    $out = '';
     272    $class = '';
     273    $i = 0;
     274    $count = 0;
     275    foreach( $tags as $tag ) {
     276        if( $i ) {
     277            $i = 0;
     278            $class = ' class="alternate"';
     279        } else {
     280            $i = 1;
     281            $class = '';
     282        }
     283
     284        $out .= _tag_row( $tag, $class );
     285        $count++;
     286    }
     287   
     288    // filter and send to screen
     289    $out = apply_filters('tag_rows', $out);
     290    echo $out;
     291    return $count;
    233292}
    234293
  • trunk/wp-admin/menu.php

    r6638 r6660  
    4141$submenu['edit.php'][15] = array(__('Links'), 'manage_links', 'link-manager.php');
    4242$submenu['edit.php'][20] = array(__('Categories'), 'manage_categories', 'categories.php');
     43$submenu['edit.php'][21] = array(__('Tags'), 'manage_categories', 'edit-tags.php');
    4344$submenu['edit.php'][25] = array(__('Media Library'), 'upload_files', 'upload.php');
    4445$submenu['edit.php'][30] = array(__('Import'), 'import', 'import.php');
  • trunk/wp-includes/script-loader.php

    r6659 r6660  
    117117            ) );
    118118            $this->add( 'admin-categories', '/wp-admin/js/categories.js', array('wp-lists'), '20071031' );
     119            $this->add( 'admin-tags', '/wp-admin/js/tags.js', array('wp-lists'), '20071031' );
    119120            $this->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('wp-lists'), '20070823' );
    120121            $this->add( 'password-strength-meter', '/wp-admin/js/password-strength-meter.js', array('jquery'), '20070405' );
  • trunk/wp-includes/taxonomy.php

    r6592 r6660  
    526526        'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '',
    527527        'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '',
    528         'pad_counts' => false);
     528        'pad_counts' => false, 'offset' => '');
    529529    $args = wp_parse_args( $args, $defaults );
    530530    $args['number'] = absint( $args['number'] );
     531    $args['offset'] = absint( $args['offset'] );
    531532    if ( !$single_taxonomy || !is_taxonomy_hierarchical($taxonomies[0]) ||
    532533        '' != $args['parent'] ) {
     
    626627        $where .= ' AND tt.count > 0';
    627628
    628     if ( !empty($number) )
    629         $number = 'LIMIT ' . $number;
    630     else
     629    if ( !empty($number) ) {
     630        if( $offset )
     631            $number = 'LIMIT ' . $offset . ',' . $number;
     632        else
     633            $number = 'LIMIT ' . $number;
     634       
     635    } else
    631636        $number = '';
    632637
Note: See TracChangeset for help on using the changeset viewer.