Ticket #5684: tags-patch.diff

File tags-patch.diff, 16.8 kB (added by jhodgdon, 8 months ago)

Patch to add Manage Tags to the admin menu system

  • E:/EclipseWorkWeb/WordPressDev/wp-includes/category.php

    old new  
    149149        return get_term($tag, 'post_tag', $output, $filter); 
    150150} 
    151151 
     152// Retrieves tag data given a tag ID or tag object. 
     153// Converts to appropriate form for use in tag management pages 
     154function &get_tag_for_page($tag, $output = OBJECT, $filter = 'raw') { 
     155        $tag = get_term($tag, 'post_tag', $output, $filter); 
     156        if ( is_wp_error( $tag ) ) 
     157                return $tag; 
     158 
     159        _make_tag_compat($tag); 
     160 
     161        return $tag; 
     162} 
     163 
    152164// 
    153165// Cache 
    154166// 
     
    183195        } 
    184196} 
    185197 
     198function _make_tag_compat( &$tag) { 
     199        if ( is_object($tag) ) { 
     200                $tag->tag_ID = &$tag->term_id; 
     201                $tag->tag_count = &$tag->count; 
     202                $tag->tag_name = &$tag->name; 
     203                $tag->tag_slug = &$tag->slug; 
     204        } else if ( is_array($tag) && isset($tag['term_id']) ) { 
     205                $tag['tag_ID'] = &$tag['term_id']; 
     206                $tag['tag_count'] = &$tag['count']; 
     207                $tag['tag_name'] = &$tag['name']; 
     208                $tag['tag_slug'] = &$tag['slug']; 
     209        } 
     210} 
    186211?> 
  • E:/EclipseWorkWeb/WordPressDev/wp-includes/taxonomy.php

    old new  
    525525                'hide_empty' => true, 'exclude' => '', 'include' => '', 
    526526                'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 
    527527                'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 
    528                 'pad_counts' => false); 
     528                'pad_counts' => false, 'start' => ''); 
    529529        $args = wp_parse_args( $args, $defaults ); 
    530530        $args['number'] = absint( $args['number'] ); 
     531        $args['start'] = absint( $args['start'] ); 
    531532        if ( !$single_taxonomy || !is_taxonomy_hierarchical($taxonomies[0]) || 
    532533                '' != $args['parent'] ) { 
    533534                $args['child_of'] = 0; 
     
    625626        if ( $hide_empty && !$hierarchical ) 
    626627                $where .= ' AND tt.count > 0'; 
    627628 
    628         if ( !empty($number) ) 
    629                 $number = 'LIMIT ' . $number; 
    630         else 
     629        if ( !empty($number) ) { 
     630                if( $start ) 
     631                        $number = 'LIMIT ' . $start . ',' . $number; 
     632                else  
     633                        $number = 'LIMIT ' . $number; 
     634                 
     635        } else 
    631636                $number = ''; 
    632637 
    633638        if ( 'all' == $fields ) 
  • E:/EclipseWorkWeb/WordPressDev/wp-includes/script-loader.php

    old new  
    9494                                'how' => __('Separate multiple categories with commas.') 
    9595                        ) ); 
    9696                        $this->add( 'admin-categories', '/wp-admin/js/categories.js', array('wp-lists'), '20071031' ); 
     97                        $this->add( 'admin-tags', '/wp-admin/js/tags.js', array('wp-lists'), '20071031' ); 
    9798                        $this->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('wp-lists'), '20070823' ); 
    9899                        $this->add( 'password-strength-meter', '/wp-admin/js/password-strength-meter.js', array('jquery'), '20070405' );  
    99100                        $this->localize( 'password-strength-meter', 'pwsL10n', array(  
  • E:/EclipseWorkWeb/WordPressDev/wp-admin/tags.php

    old new  
     1<?php 
     2require_once('admin.php'); 
     3 
     4$title = __('Tags'); 
     5$parent_file = 'edit.php'; 
     6 
     7wp_reset_vars(array('action', 'tag')); 
     8 
     9switch($action) { 
     10 
     11case 'addtag': 
     12 
     13        check_admin_referer('add-tag'); 
     14 
     15        if ( !current_user_can('manage_categories') ) 
     16                wp_die(__('Cheatin&#8217; uh?')); 
     17 
     18        $ret = wp_insert_tag($_POST ); 
     19        if( $ret && !is_wp_error( $ret ) ) { 
     20                wp_redirect('tags.php?message=1#addtag'); 
     21        } else { 
     22                wp_redirect('tags.php?message=4#addtag'); 
     23        } 
     24        exit; 
     25break; 
     26 
     27case 'delete': 
     28        $tag_ID = (int) $_GET['tag_ID']; 
     29        check_admin_referer('delete-tag_' .  $tag_ID); 
     30 
     31        if ( !current_user_can('manage_categories') ) 
     32                wp_die(__('Cheatin&#8217; uh?')); 
     33 
     34        wp_delete_term( $tag_ID, 'post_tag'); 
     35 
     36        wp_redirect('tags.php?message=2'); 
     37        exit; 
     38 
     39break; 
     40 
     41case 'edit': 
     42 
     43        require_once ('admin-header.php'); 
     44        $tag_ID = (int) $_GET['tag_ID']; 
     45         
     46        $tag = get_tag_for_page($tag_ID, OBJECT, 'edit'); 
     47        include('edit-tag-form.php'); 
     48 
     49break; 
     50 
     51case 'editedtag': 
     52        $tag_ID = (int) $_POST['tag_ID']; 
     53        check_admin_referer('update-tag_' . $tag_ID); 
     54 
     55        if ( !current_user_can('manage_categories') ) 
     56                wp_die(__('Cheatin&#8217; uh?')); 
     57 
     58        $ret = wp_insert_tag($_POST ); 
     59        if( $ret && !is_wp_error( $ret ) ) { 
     60                wp_redirect('tags.php?message=3'); 
     61        } else { 
     62                wp_redirect('tags.php?message=5'); 
     63        } 
     64        exit; 
     65break; 
     66 
     67default: 
     68 
     69wp_enqueue_script( 'admin-tags' ); 
     70require_once ('admin-header.php'); 
     71 
     72$messages[1] = __('Tag added.'); 
     73$messages[2] = __('Tag deleted.'); 
     74$messages[3] = __('Tag updated.'); 
     75$messages[4] = __('Tag not added.'); 
     76$messages[5] = __('Tag not updated.'); 
     77?> 
     78 
     79<?php if (isset($_GET['message'])) : ?> 
     80<div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div> 
     81<?php endif; ?> 
     82 
     83<div class="wrap"> 
     84<?php if ( current_user_can('manage_categories') ) : ?> 
     85        <h2><?php printf(__('Tags (<a href="%s">add new</a>)'), '#addtag') ?> </h2> 
     86<?php else : ?> 
     87        <h2><?php _e('Tags') ?> </h2> 
     88<?php endif; ?> 
     89<table class="widefat"> 
     90        <thead> 
     91        <tr> 
     92                <th scope="col" style="text-align: center"><?php _e('ID') ?></th> 
     93        <th scope="col"><?php _e('Name') ?></th> 
     94        <th scope="col" width="90" style="text-align: center"><?php _e('Posts') ?></th> 
     95        <th colspan="2" style="text-align: center"><?php _e('Action') ?></th> 
     96        </tr> 
     97        </thead> 
     98        <tbody id="the-list" class="list:tag"> 
     99<?php 
     100$pagenum = absint( $_GET['pagenum'] ); 
     101$perpage = 10; 
     102$count = tag_rows( $pagenum, $perpage ); 
     103?> 
     104        </tbody> 
     105</table> 
     106<?php 
     107 
     108$baseurl = get_bloginfo( 'home') . '/wp-admin/tags.php?pagenum='; 
     109if( $pagenum >= 1 ) { 
     110        echo '<a href="' . $baseurl . ($pagenum - 1 ) . '">&lt;&lt;' . __('Previous Tags') . '</a>'; 
     111        if( $count == $perpage ) { 
     112                echo ' | '; 
     113        } 
     114} 
     115 
     116 
     117if( $count == $perpage ) { 
     118        echo '<a href="' . $baseurl . ($pagenum + 1 ) . '">' . __('Next Tags') . '&gt;&gt;</a>'; 
     119} 
     120 
     121?> 
     122 
     123</div> 
     124 
     125<?php if ( current_user_can('manage_categories') ) : ?> 
     126 
     127<br /> 
     128<?php include('edit-tag-form.php'); ?> 
     129 
     130<?php endif; ?> 
     131 
     132<?php 
     133break; 
     134} 
     135 
     136include('admin-footer.php'); 
     137 
     138?> 
  • E:/EclipseWorkWeb/WordPressDev/wp-admin/admin-ajax.php

    old new  
    6262                die('1'); 
    6363        else    die('0'); 
    6464        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')) 
     71                die('1'); 
     72        else    die('0'); 
     73        break; 
    6574case 'delete-link-cat' : 
    6675        check_ajax_referer( "delete-link-category_$id" ); 
    6776        if ( !current_user_can( 'manage_categories' ) ) 
     
    302311        ) ); 
    303312        $x->send(); 
    304313        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['tag_name']) ) { 
     320                $x = new WP_Ajax_Response( array( 
     321                        'what' => 'tag', 
     322                        'id' => new WP_Error( 'tag_name', __('You did not enter a tag name.') ) 
     323                ) ); 
     324                $x->send(); 
     325        } 
     326 
     327        $tag = wp_insert_tag( $_POST, true ); 
     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_tag_for_page( $tag )) ) 
     338                die('0'); 
     339 
     340        $tag_full_name = $tag->name; 
     341        $_tag = $tag; 
     342        $tag_full_name = attribute_escape($tag_full_name); 
     343 
     344        $x = new WP_Ajax_Response( array( 
     345                'what' => 'tag', 
     346                'id' => $tag->term_id, 
     347                'data' => _tag_row( $tag ), 
     348                'supplemental' => array('name' => $tag_full_name, 'show-link' => sprintf(__( 'Tag <a href="#%s">%s</a> added' ), "tag-$tag->term_id", $tag_full_name)) 
     349        ) ); 
     350        $x->send(); 
     351        break; 
    305352case 'add-comment' : 
    306353        check_ajax_referer( $action ); 
    307354        if ( !current_user_can( 'edit_post', $id ) ) 
  • E:/EclipseWorkWeb/WordPressDev/wp-admin/includes/template.php

    old new  
    232232        } 
    233233} 
    234234 
     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_id=$tag->term_id'>$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="tags.php?action=edit&amp;tag_ID=' . $tag->term_id . '" class="edit">' . 
     251                        __( 'Edit' ) . "</a></td>" . 
     252                        '<td><a href="' . wp_nonce_url( "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', "start=$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; 
     292} 
     293 
    235294// define the columns to display, the syntax is 'internal name' => 'display name' 
    236295function wp_manage_posts_columns() { 
    237296        $posts_columns = array(); 
  • E:/EclipseWorkWeb/WordPressDev/wp-admin/includes/taxonomy.php

    old new  
    141141        return wp_insert_term($tag_name, 'post_tag'); 
    142142} 
    143143 
     144// Inserts or updates a tag 
     145// $args is an array with elements: 
     146//    'tag_name' - name of the tag - required 
     147//    'tag_slug' - slug for the tag - not required 
     148//    'tag_ID' - ID number (if updating an existing tag; omit or set to 0 if not) 
     149// Return value: WP error object or 0 if it fails, ID if successful 
     150function wp_insert_tag( $args, $wp_error = false ) { 
     151        extract($args, EXTR_SKIP); 
     152 
     153        if ( trim( $tag_name ) == '' ) 
     154                return 0; 
     155 
     156        $tag_ID = (int) $tag_ID; 
     157 
     158        // Are we updating or creating? 
     159        if ( !empty ($tag_ID) ) 
     160                $update = true; 
     161        else 
     162                $update = false; 
     163 
     164        $name = $tag_name; 
     165        $slug = $tag_slug; 
     166         
     167        $args = compact('name', 'slug'); 
     168 
     169        if ( $update ) 
     170                $tag_ID = wp_update_term($tag_ID, 'post_tag', $args); 
     171        else 
     172                $tag_ID = wp_insert_term($name, 'post_tag', $args); 
     173 
     174        if ( is_wp_error($tag_ID) ) { 
     175                if ( $wp_error ) 
     176                        return $tag_ID; 
     177                else 
     178                        return 0; 
     179        } 
     180 
     181        return $tag_ID['term_id']; 
     182} 
     183 
    144184?> 
  • E:/EclipseWorkWeb/WordPressDev/wp-admin/js/tags.js

    old new  
     1jQuery(function($) { 
     2        var options = false 
     3 
     4        var addAfter = function( r, settings ) { 
     5                var name = $("<span>" + $('name', r).text() + "</span>").html(); 
     6                var id = $('tag', r).attr('id'); 
     7                options[options.length] = new Option(name, id); 
     8        } 
     9 
     10        var delAfter = function( r, settings ) { 
     11                var id = $('tag', r).attr('id'); 
     12                for ( var o = 0; o < options.length; o++ ) 
     13                        if ( id == options[o].value ) 
     14                                options[o] = null; 
     15        } 
     16 
     17        if ( options ) 
     18                $('#the-list').wpList( { addAfter: addAfter, delAfter: delAfter } ); 
     19        else 
     20                $('#the-list').wpList(); 
     21}); 
  • E:/EclipseWorkWeb/WordPressDev/wp-admin/edit-tag-form.php

    old new  
     1<?php 
     2if ( ! empty($tag_ID) ) { 
     3        $heading = __('Edit Tag'); 
     4        $submit_text = __('Edit Tag &raquo;'); 
     5        $form = '<form name="edittag" id="edittag" method="post" action="tags.php">'; 
     6        $action = 'editedtag'; 
     7        $nonce_action = 'update-tag_' . $tag_ID; 
     8        do_action('edit_tag_form_pre', $tag); 
     9} else { 
     10        $heading = __('Add Tag'); 
     11        $submit_text = __('Add Tag &raquo;'); 
     12        $form = '<form name="addtag" id="addtag" method="post" action="tags.php" class="add:the-list:">'; 
     13        $action = 'addtag'; 
     14        $nonce_action = 'add-tag'; 
     15        do_action('add_tag_form_pre', $tag); 
     16} 
     17?> 
     18 
     19<div class="wrap"> 
     20<h2><?php echo $heading ?></h2> 
     21<div id="ajax-response"></div> 
     22<?php echo $form ?> 
     23<input type="hidden" name="action" value="<?php echo $action ?>" /> 
     24<input type="hidden" name="tag_ID" value="<?php echo $tag->term_id ?>" /> 
     25<?php wp_nonce_field($nonce_action); ?> 
     26        <table class="editform" width="100%" cellspacing="2" cellpadding="5"> 
     27                <tr class="form-field form-required"> 
     28                        <th width="33%" scope="row" valign="top"><label for="tag_name"><?php _e('Tag name:') ?></label></th> 
     29                        <td width="67%"><input name="tag_name" id="tag_name" type="text" value="<?php echo attribute_escape($tag->name); ?>" size="40" /></td> 
     30                </tr> 
     31                <tr class="form-field"> 
     32                        <th scope="row" valign="top"><label for="tag_slug"><?php _e('Tag slug:') ?></label></th> 
     33                        <td><input name="tag_slug" id="tag_slug" type="text" value="<?php echo attribute_escape($tag->slug); ?>" size="40" /></td> 
     34                </tr> 
     35        </table> 
     36<p class="submit"><input type="submit" name="submit" value="<?php echo $submit_text ?>" /></p> 
     37<?php do_action('edit_tag_form', $tag); ?> 
     38</form> 
     39</div> 
  • E:/EclipseWorkWeb/WordPressDev/wp-admin/menu.php

    old new  
    4242$submenu['edit.php'][10] = array(__('Pages'), 'edit_pages', 'edit-pages.php'); 
    4343$submenu['edit.php'][15] = array(__('Links'), 'manage_links', 'link-manager.php'); 
    4444$submenu['edit.php'][20] = array(__('Categories'), 'manage_categories', 'categories.php'); 
     45$submenu['edit.php'][21] = array(__('Tags'), 'manage_categories', 'tags.php'); 
    4546$submenu['edit.php'][25] = array(__('Media Library'), 'upload_files', 'upload.php'); 
    4647$submenu['edit.php'][30] = array(__('Import'), 'import', 'import.php'); 
    4748$submenu['edit.php'][35] = array(__('Export'), 'import', 'export.php'); 
  • E:/EclipseWorkWeb/WordPressDev/wp-admin/edit.php

    old new  
    4848        } 
    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_id']) && $_GET['tag_id'] ? ' ' . 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> 
    5556