[ XREF Home ] [ Index ]

PHP Cross Reference of WordPress Trunk

Provided by Yoast

title

Body

[close]

/wp-admin/ -> edit-tags.php (source)

   1  <?php
   2  /**
   3   * Edit Tags Administration Screen.
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /** WordPress Administration Bootstrap */
  10  require_once ('./admin.php');
  11  $tax = get_taxonomy( $taxnow );
  12  if ( !current_user_can( $tax->cap->manage_terms ) )
  13      wp_die( __( 'Cheatin&#8217; uh?' ) );
  14  
  15  $wp_list_table = _get_list_table('WP_Terms_List_Table');
  16  $pagenum = $wp_list_table->get_pagenum();
  17  
  18  $title = $tax->labels->name;
  19  
  20  if ( 'post' != $post_type ) {
  21      $parent_file = "edit.php?post_type=$post_type";
  22      $submenu_file = "edit-tags.php?taxonomy=$taxonomy&amp;post_type=$post_type";
  23  } else if ( 'link_category' == $tax->name ) {
  24      $parent_file = 'link-manager.php';
  25      $submenu_file = 'edit-tags.php?taxonomy=link_category';
  26  } else {
  27      $parent_file = 'edit.php';
  28      $submenu_file = "edit-tags.php?taxonomy=$taxonomy";
  29  }
  30  
  31  add_screen_option( 'per_page', array('label' => $title, 'default' => 20, 'option' => 'edit_' . $tax->name . '_per_page') );
  32  
  33  switch ( $wp_list_table->current_action() ) {
  34  
  35  case 'add-tag':
  36  
  37      check_admin_referer( 'add-tag', '_wpnonce_add-tag' );
  38  
  39      if ( !current_user_can( $tax->cap->edit_terms ) )
  40          wp_die( __( 'Cheatin&#8217; uh?' ) );
  41  
  42      $ret = wp_insert_term( $_POST['tag-name'], $taxonomy, $_POST );
  43      $location = 'edit-tags.php?taxonomy=' . $taxonomy;
  44      if ( 'post' != $post_type )
  45          $location .= '&post_type=' . $post_type;
  46  
  47      if ( $referer = wp_get_original_referer() ) {
  48          if ( false !== strpos( $referer, 'edit-tags.php' ) )
  49              $location = $referer;
  50      }
  51  
  52      if ( $ret && !is_wp_error( $ret ) )
  53          $location = add_query_arg( 'message', 1, $location );
  54      else
  55          $location = add_query_arg( 'message', 4, $location );
  56      wp_redirect( $location );
  57      exit;
  58  break;
  59  
  60  case 'delete':
  61      $location = 'edit-tags.php?taxonomy=' . $taxonomy;
  62      if ( 'post' != $post_type )
  63          $location .= '&post_type=' . $post_type;
  64      if ( $referer = wp_get_referer() ) {
  65          if ( false !== strpos( $referer, 'edit-tags.php' ) )
  66              $location = $referer;
  67      }
  68  
  69      if ( !isset( $_REQUEST['tag_ID'] ) ) {
  70          wp_redirect( $location );
  71          exit;
  72      }
  73  
  74      $tag_ID = (int) $_REQUEST['tag_ID'];
  75      check_admin_referer( 'delete-tag_' .  $tag_ID );
  76  
  77      if ( !current_user_can( $tax->cap->delete_terms ) )
  78          wp_die( __( 'Cheatin&#8217; uh?' ) );
  79  
  80      wp_delete_term( $tag_ID, $taxonomy );
  81  
  82      $location = add_query_arg( 'message', 2, $location );
  83      wp_redirect( $location );
  84      exit;
  85  
  86  break;
  87  
  88  case 'bulk-delete':
  89      check_admin_referer( 'bulk-tags' );
  90  
  91      if ( !current_user_can( $tax->cap->delete_terms ) )
  92          wp_die( __( 'Cheatin&#8217; uh?' ) );
  93  
  94      $tags = (array) $_REQUEST['delete_tags'];
  95      foreach ( $tags as $tag_ID ) {
  96          wp_delete_term( $tag_ID, $taxonomy );
  97      }
  98  
  99      $location = 'edit-tags.php?taxonomy=' . $taxonomy;
 100      if ( 'post' != $post_type )
 101          $location .= '&post_type=' . $post_type;
 102      if ( $referer = wp_get_referer() ) {
 103          if ( false !== strpos( $referer, 'edit-tags.php' ) )
 104              $location = $referer;
 105      }
 106  
 107      $location = add_query_arg( 'message', 6, $location );
 108      wp_redirect( $location );
 109      exit;
 110  
 111  break;
 112  
 113  case 'edit':
 114      $title = $tax->labels->edit_item;
 115  
 116      require_once  ( 'admin-header.php' );
 117      $tag_ID = (int) $_REQUEST['tag_ID'];
 118  
 119      $tag = get_term( $tag_ID, $taxonomy, OBJECT, 'edit' );
 120      include ( './edit-tag-form.php' );
 121  
 122  break;
 123  
 124  case 'editedtag':
 125      $tag_ID = (int) $_POST['tag_ID'];
 126      check_admin_referer( 'update-tag_' . $tag_ID );
 127  
 128      if ( !current_user_can( $tax->cap->edit_terms ) )
 129          wp_die( __( 'Cheatin&#8217; uh?' ) );
 130  
 131      $ret = wp_update_term( $tag_ID, $taxonomy, $_POST );
 132  
 133      $location = 'edit-tags.php?taxonomy=' . $taxonomy;
 134      if ( 'post' != $post_type )
 135          $location .= '&post_type=' . $post_type;
 136  
 137      if ( $referer = wp_get_original_referer() ) {
 138          if ( false !== strpos( $referer, 'edit-tags.php' ) )
 139              $location = $referer;
 140      }
 141  
 142      if ( $ret && !is_wp_error( $ret ) )
 143          $location = add_query_arg( 'message', 3, $location );
 144      else
 145          $location = add_query_arg( 'message', 5, $location );
 146  
 147      wp_redirect( $location );
 148      exit;
 149  break;
 150  
 151  default:
 152  if ( ! empty($_REQUEST['_wp_http_referer']) ) {
 153      $location = remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) );
 154  
 155      if ( ! empty( $_REQUEST['paged'] ) )
 156          $location = add_query_arg( 'paged', (int) $_REQUEST['paged'] );
 157  
 158      wp_redirect( $location );
 159      exit;
 160  }
 161  
 162  $wp_list_table->prepare_items();
 163  $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
 164  
 165  if ( $pagenum > $total_pages && $total_pages > 0 ) {
 166      wp_redirect( add_query_arg( 'paged', $total_pages ) );
 167      exit;
 168  }
 169  
 170  wp_enqueue_script('admin-tags');
 171  if ( current_user_can($tax->cap->edit_terms) )
 172      wp_enqueue_script('inline-edit-tax');
 173  
 174  if ( 'category' == $taxonomy || 'link_category' == $taxonomy || 'post_tag' == $taxonomy  ) {
 175      $help ='';
 176      if ( 'category' == $taxonomy )
 177          $help = '<p>' . sprintf(__( 'You can use categories to define sections of your site and group related posts. The default category is &#8220;Uncategorized&#8221; until you change it in your <a href="%s">writing settings</a>.' ) , 'options-writing.php' ) . '</p>';
 178      elseif ( 'link_category' == $taxonomy )
 179          $help = '<p>' . __( 'You can create groups of links by using link categories. Link category names must be unique and link categories are separate from the categories you use for posts.' ) . '</p>';
 180      else
 181          $help = '<p>' . __( 'You can assign keywords to your posts using Post Tags. Unlike categories, tags have no hierarchy, meaning there&#8217;s no relationship from one tag to another.' ) . '</p>';
 182  
 183      if ( 'link_category' == $taxonomy )
 184          $help .= '<p>' . __( 'You can delete link categories in the Bulk Action pulldown, but that action does not delete the links within the category. Instead, it moves them to the default link category.' ) . '</p>';
 185      else
 186          $help .='<p>' . __( 'What&#8217;s the difference between categories and tags? Normally, tags are ad-hoc keywords that identify important information in your post (names, subjects, etc) that may or may not recur in other posts, while categories are pre-determined sections. If you think of your site like a book, the categories are like the Table of Contents and the tags are like the terms in the index.' ) . '</p>';
 187  
 188      if ( 'category' == $taxonomy )
 189          $help .= '<p>' . __( 'When adding a new category on this screen, you&#8217;ll fill in the following fields:' ) . '</p>';
 190      elseif ( 'post_tag' == $taxonomy )
 191          $help .= '<p>' . __( 'When adding a new tag on this screen, you&#8217;ll fill in the following fields:' ) . '</p>';
 192  
 193      if ( 'category' == $taxonomy || 'post_tag' == $taxonomy  )
 194  
 195          $help .= '<ul>' .
 196          '<li>' . __( '<strong>Name</strong> - The name is how it appears on your site.' ) . '</li>';
 197  
 198      if ( ! global_terms_enabled()  )
 199      if ( 'category' == $taxonomy || 'post_tag' == $taxonomy  )
 200          $help .= '<li>' . __( '<strong>Slug</strong> - The &#8220;slug&#8221; is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.' ) . '</li>';
 201  
 202      if ( 'category' == $taxonomy )
 203          $help .= '<li>' . __( '<strong>Parent</strong> - Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional. To create a subcategory, just choose another category from the Parent dropdown.' ) . '</li>';
 204  
 205      if ( 'category' == $taxonomy || 'post_tag' == $taxonomy  )
 206          $help .= '<li>' . __( '<strong>Description</strong> - The description is not prominent by default; however, some themes may display it.' ) . '</li>' .
 207          '</ul>' .
 208          '<p>' . __( 'You can change the display of this screen using the Screen Options tab to set how many items are displayed per screen and to display/hide columns in the table.' ) . '</p>' .
 209          '<p><strong>' . __( 'For more information:' ) . '</strong></p>';
 210  
 211      if ( 'category' == $taxonomy )
 212          $help .= '<p>' . __( '<a href="http://codex.wordpress.org/Posts_Categories_Screen" target="_blank">Documentation on Categories</a>' ) . '</p>';
 213      elseif ( 'link_category' == $taxonomy )
 214          $help .= '<p>' . __( '<a href="http://codex.wordpress.org/Links_Link_Categories_Screen" target="_blank">Documentation on Link Categories</a>' ) . '</p>';
 215      else
 216          $help .= '<p>' . __( '<a href="http://codex.wordpress.org/Posts_Post_Tags_Screen" target="_blank">Documentation on Post Tags</a>' ) . '</p>';
 217  
 218      $help .= '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>';
 219  
 220      add_contextual_help($current_screen, $help);
 221      unset($help);
 222  }
 223  
 224  require_once  ('admin-header.php');
 225  
 226  if ( !current_user_can($tax->cap->edit_terms) )
 227      wp_die( __('You are not allowed to edit this item.') );
 228  
 229  $messages[1] = __('Item added.');
 230  $messages[2] = __('Item deleted.');
 231  $messages[3] = __('Item updated.');
 232  $messages[4] = __('Item not added.');
 233  $messages[5] = __('Item not updated.');
 234  $messages[6] = __('Items deleted.');
 235  
 236  ?>
 237  
 238  <div class="wrap nosubsub">
 239  <?php screen_icon(); ?>
 240  <h2><?php echo esc_html( $title );
 241  if ( !empty($_REQUEST['s']) )
 242      printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( stripslashes($_REQUEST['s']) ) ); ?>
 243  </h2>
 244  
 245  <?php if ( isset($_REQUEST['message']) && ( $msg = (int) $_REQUEST['message'] ) ) : ?>
 246  <div id="message" class="updated"><p><?php echo $messages[$msg]; ?></p></div>
 247  <?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
 248  endif; ?>
 249  <div id="ajax-response"></div>
 250  
 251  <form class="search-form" action="" method="get">
 252  <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
 253  <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
 254  
 255  <?php $wp_list_table->search_box( $tax->labels->search_items, 'tag' ); ?>
 256  
 257  </form>
 258  <br class="clear" />
 259  
 260  <div id="col-container">
 261  
 262  <div id="col-right">
 263  <div class="col-wrap">
 264  <form id="posts-filter" action="" method="post">
 265  <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
 266  <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
 267  
 268  <?php $wp_list_table->display(); ?>
 269  
 270  <br class="clear" />
 271  </form>
 272  
 273  <?php if ( 'category' == $taxonomy ) : ?>
 274  <div class="form-wrap">
 275  <p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete the posts in that category. Instead, posts that were only assigned to the deleted category are set to the category <strong>%s</strong>.'), apply_filters('the_category', get_cat_name(get_option('default_category')))) ?></p>
 276  <?php if ( current_user_can( 'import' ) ) : ?>
 277  <p><?php printf(__('Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.'), 'import.php') ?></p>
 278  <?php endif; ?>
 279  </div>
 280  <?php elseif ( 'post_tag' == $taxonomy && current_user_can( 'import' ) ) : ?>
 281  <div class="form-wrap">
 282  <p><?php printf(__('Tags can be selectively converted to categories using the <a href="%s">tag to category converter</a>'), 'import.php') ;?>.</p>
 283  </div>
 284  <?php endif;
 285  do_action('after-' . $taxonomy . '-table', $taxonomy);
 286  ?>
 287  
 288  </div>
 289  </div><!-- /col-right -->
 290  
 291  <div id="col-left">
 292  <div class="col-wrap">
 293  
 294  <?php
 295  
 296  if ( !is_null( $tax->labels->popular_items ) ) {
 297      if ( current_user_can( $tax->cap->edit_terms ) )
 298          $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false, 'link' => 'edit' ) );
 299      else
 300          $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) );
 301  
 302      if ( $tag_cloud ) :
 303      ?>
 304  <div class="tagcloud">
 305  <h3><?php echo $tax->labels->popular_items; ?></h3>
 306  <?php echo $tag_cloud; unset( $tag_cloud ); ?>
 307  </div>
 308  <?php
 309  endif;
 310  }
 311  
 312  if ( current_user_can($tax->cap->edit_terms) ) {
 313      // Back compat hooks. Deprecated in preference to {$taxonomy}_pre_add_form
 314      if ( 'category' == $taxonomy )
 315          do_action('add_category_form_pre', (object)array('parent' => 0) );
 316      elseif ( 'link_category' == $taxonomy )
 317          do_action('add_link_category_form_pre', (object)array('parent' => 0) );
 318      else
 319          do_action('add_tag_form_pre', $taxonomy);
 320  
 321      do_action($taxonomy . '_pre_add_form', $taxonomy);
 322  ?>
 323  
 324  <div class="form-wrap">
 325  <h3><?php echo $tax->labels->add_new_item; ?></h3>
 326  <form id="addtag" method="post" action="edit-tags.php" class="validate">
 327  <input type="hidden" name="action" value="add-tag" />
 328  <input type="hidden" name="screen" value="<?php echo esc_attr($current_screen->id); ?>" />
 329  <input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
 330  <input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
 331  <?php wp_nonce_field('add-tag', '_wpnonce_add-tag'); ?>
 332  
 333  <div class="form-field form-required">
 334      <label for="tag-name"><?php _ex('Name', 'Taxonomy Name'); ?></label>
 335      <input name="tag-name" id="tag-name" type="text" value="" size="40" aria-required="true" />
 336      <p><?php _e('The name is how it appears on your site.'); ?></p>
 337  </div>
 338  <?php if ( ! global_terms_enabled() ) : ?>
 339  <div class="form-field">
 340      <label for="tag-slug"><?php _ex('Slug', 'Taxonomy Slug'); ?></label>
 341      <input name="slug" id="tag-slug" type="text" value="" size="40" />
 342      <p><?php _e('The &#8220;slug&#8221; is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.'); ?></p>
 343  </div>
 344  <?php endif; // global_terms_enabled() ?>
 345  <?php if ( is_taxonomy_hierarchical($taxonomy) ) : ?>
 346  <div class="form-field">
 347      <label for="parent"><?php _ex('Parent', 'Taxonomy Parent'); ?></label>
 348      <?php wp_dropdown_categories(array('hide_empty' => 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __('None'))); ?>
 349      <?php if ( 'category' == $taxonomy ) : // @todo: Generic text for hierarchical taxonomies ?>
 350          <p><?php _e('Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.'); ?></p>
 351      <?php endif; ?>
 352  </div>
 353  <?php endif; // is_taxonomy_hierarchical() ?>
 354  <div class="form-field">
 355      <label for="tag-description"><?php _ex('Description', 'Taxonomy Description'); ?></label>
 356      <textarea name="description" id="tag-description" rows="5" cols="40"></textarea>
 357      <p><?php _e('The description is not prominent by default; however, some themes may show it.'); ?></p>
 358  </div>
 359  
 360  <?php
 361  if ( ! is_taxonomy_hierarchical($taxonomy) )
 362      do_action('add_tag_form_fields', $taxonomy);
 363  do_action($taxonomy . '_add_form_fields', $taxonomy);
 364  
 365  submit_button( $tax->labels->add_new_item, 'button' );
 366  
 367  // Back compat hooks. Deprecated in preference to {$taxonomy}_add_form
 368  if ( 'category' == $taxonomy )
 369      do_action('edit_category_form', (object)array('parent' => 0) );
 370  elseif ( 'link_category' == $taxonomy )
 371      do_action('edit_link_category_form', (object)array('parent' => 0) );
 372  else
 373      do_action('add_tag_form', $taxonomy);
 374  
 375  do_action($taxonomy . '_add_form', $taxonomy);
 376  ?>
 377  </form></div>
 378  <?php } ?>
 379  
 380  </div>
 381  </div><!-- /col-left -->
 382  
 383  </div><!-- /col-container -->
 384  </div><!-- /wrap -->
 385  
 386  <?php $wp_list_table->inline_edit(); ?>
 387  
 388  <?php
 389  break;
 390  }
 391  
 392  include ('./admin-footer.php');
 393  
 394  ?>


Generated: Wed Jun 1 08:30:02 2011 Cross-referenced by PHPXref 0.7
Provided by Yoast and awesome WordPress Hosting