WordPress PHP Cross Reference Web Logs

Source: /wp-admin/includes/class-wp-terms-list-table.php - 378 lines - 12205 bytes - Summary - Text - Print

   1  <?php
   2  /**
   3   * Terms List Table class.
   4   *
   5   * @package WordPress
   6   * @subpackage List_Table
   7   * @since 3.1.0
   8   * @access private
   9   */
  10  class WP_Terms_List_Table extends WP_List_Table {
  11  
  12      var $callback_args;
  13  
  14  	function __construct( $args = array() ) {
  15          global $post_type, $taxonomy, $action, $tax;
  16  
  17          parent::__construct( array(
  18              'plural' => 'tags',
  19              'singular' => 'tag',
  20              'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
  21          ) );
  22  
  23          $action    = $this->screen->action;
  24          $post_type = $this->screen->post_type;
  25          $taxonomy  = $this->screen->taxonomy;
  26  
  27          if ( empty( $taxonomy ) )
  28              $taxonomy = 'post_tag';
  29  
  30          if ( ! taxonomy_exists( $taxonomy ) )
  31              wp_die( __( 'Invalid taxonomy' ) );
  32  
  33          $tax = get_taxonomy( $taxonomy );
  34  
  35          // @todo Still needed? Maybe just the show_ui part.
  36          if ( empty( $post_type ) || !in_array( $post_type, get_post_types( array( 'show_ui' => true ) ) ) )
  37              $post_type = 'post';
  38  
  39      }
  40  
  41  	function ajax_user_can() {
  42          return current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->manage_terms );
  43      }
  44  
  45  	function prepare_items() {
  46          $tags_per_page = $this->get_items_per_page( 'edit_' . $this->screen->taxonomy . '_per_page' );
  47  
  48          if ( 'post_tag' == $this->screen->taxonomy ) {
  49              $tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page );
  50              $tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); // Old filter
  51          } elseif ( 'category' == $this->screen->taxonomy ) {
  52              $tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page ); // Old filter
  53          }
  54  
  55          $search = !empty( $_REQUEST['s'] ) ? trim( stripslashes( $_REQUEST['s'] ) ) : '';
  56  
  57          $args = array(
  58              'search' => $search,
  59              'page' => $this->get_pagenum(),
  60              'number' => $tags_per_page,
  61          );
  62  
  63          if ( !empty( $_REQUEST['orderby'] ) )
  64              $args['orderby'] = trim( stripslashes( $_REQUEST['orderby'] ) );
  65  
  66          if ( !empty( $_REQUEST['order'] ) )
  67              $args['order'] = trim( stripslashes( $_REQUEST['order'] ) );
  68  
  69          $this->callback_args = $args;
  70  
  71          $this->set_pagination_args( array(
  72              'total_items' => wp_count_terms( $this->screen->taxonomy, compact( 'search' ) ),
  73              'per_page' => $tags_per_page,
  74          ) );
  75      }
  76  
  77  	function has_items() {
  78          // todo: populate $this->items in prepare_items()
  79          return true;
  80      }
  81  
  82  	function get_bulk_actions() {
  83          $actions = array();
  84          $actions['delete'] = __( 'Delete' );
  85  
  86          return $actions;
  87      }
  88  
  89  	function current_action() {
  90          if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' == $_REQUEST['action'] || 'delete' == $_REQUEST['action2'] ) )
  91              return 'bulk-delete';
  92  
  93          return parent::current_action();
  94      }
  95  
  96  	function get_columns() {
  97          $columns = array(
  98              'cb'          => '<input type="checkbox" />',
  99              'name'        => _x( 'Name', 'term name' ),
 100              'description' => __( 'Description' ),
 101              'slug'        => __( 'Slug' ),
 102          );
 103  
 104          if ( 'link_category' == $this->screen->taxonomy ) {
 105              $columns['links'] = __( 'Links' );
 106          } else {
 107              $post_type_object = get_post_type_object( $this->screen->post_type );
 108              $columns['posts'] = $post_type_object ? $post_type_object->labels->name : __( 'Posts' );
 109          }
 110  
 111          return $columns;
 112      }
 113  
 114  	function get_sortable_columns() {
 115          return array(
 116              'name'        => 'name',
 117              'description' => 'description',
 118              'slug'        => 'slug',
 119              'posts'       => 'count',
 120              'links'       => 'count'
 121          );
 122      }
 123  
 124  	function display_rows_or_placeholder() {
 125          $taxonomy = $this->screen->taxonomy;
 126  
 127          $args = wp_parse_args( $this->callback_args, array(
 128              'page' => 1,
 129              'number' => 20,
 130              'search' => '',
 131              'hide_empty' => 0
 132          ) );
 133  
 134          extract( $args, EXTR_SKIP );
 135  
 136          $args['offset'] = $offset = ( $page - 1 ) * $number;
 137  
 138          // convert it to table rows
 139          $out = '';
 140          $count = 0;
 141  
 142          $terms = array();
 143  
 144          if ( is_taxonomy_hierarchical( $taxonomy ) && !isset( $orderby ) ) {
 145              // We'll need the full set of terms then.
 146              $args['number'] = $args['offset'] = 0;
 147  
 148              $terms = get_terms( $taxonomy, $args );
 149              if ( !empty( $search ) ) // Ignore children on searches.
 150                  $children = array();
 151              else
 152                  $children = _get_term_hierarchy( $taxonomy );
 153  
 154              // Some funky recursion to get the job done( Paging & parents mainly ) is contained within, Skip it for non-hierarchical taxonomies for performance sake
 155              $out .= $this->_rows( $taxonomy, $terms, $children, $offset, $number, $count );
 156          } else {
 157              $terms = get_terms( $taxonomy, $args );
 158              foreach ( $terms as $term )
 159                  $out .= $this->single_row( $term, 0, $taxonomy );
 160              $count = $number; // Only displaying a single page.
 161          }
 162  
 163          if ( empty( $terms ) ) {
 164              list( $columns, $hidden ) = $this->get_column_info();
 165              echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">';
 166              $this->no_items();
 167              echo '</td></tr>';
 168          } else {
 169              echo $out;
 170          }
 171      }
 172  
 173  	function _rows( $taxonomy, $terms, &$children, $start = 0, $per_page = 20, &$count, $parent = 0, $level = 0 ) {
 174  
 175          $end = $start + $per_page;
 176  
 177          $output = '';
 178          foreach ( $terms as $key => $term ) {
 179  
 180              if ( $count >= $end )
 181                  break;
 182  
 183              if ( $term->parent != $parent && empty( $_REQUEST['s'] ) )
 184                  continue;
 185  
 186              // If the page starts in a subtree, print the parents.
 187              if ( $count == $start && $term->parent > 0 && empty( $_REQUEST['s'] ) ) {
 188                  $my_parents = $parent_ids = array();
 189                  $p = $term->parent;
 190                  while ( $p ) {
 191                      $my_parent = get_term( $p, $taxonomy );
 192                      $my_parents[] = $my_parent;
 193                      $p = $my_parent->parent;
 194                      if ( in_array( $p, $parent_ids ) ) // Prevent parent loops.
 195                          break;
 196                      $parent_ids[] = $p;
 197                  }
 198                  unset( $parent_ids );
 199  
 200                  $num_parents = count( $my_parents );
 201                  while ( $my_parent = array_pop( $my_parents ) ) {
 202                      $output .=  "\t" . $this->single_row( $my_parent, $level - $num_parents, $taxonomy );
 203                      $num_parents--;
 204                  }
 205              }
 206  
 207              if ( $count >= $start )
 208                  $output .= "\t" . $this->single_row( $term, $level, $taxonomy );
 209  
 210              ++$count;
 211  
 212              unset( $terms[$key] );
 213  
 214              if ( isset( $children[$term->term_id] ) && empty( $_REQUEST['s'] ) )
 215                  $output .= $this->_rows( $taxonomy, $terms, $children, $start, $per_page, $count, $term->term_id, $level + 1 );
 216          }
 217  
 218          return $output;
 219      }
 220  
 221  	function single_row( $tag, $level = 0 ) {
 222          static $row_class = '';
 223          $row_class = ( $row_class == '' ? ' class="alternate"' : '' );
 224  
 225          $this->level = $level;
 226  
 227          echo '<tr id="tag-' . $tag->term_id . '"' . $row_class . '>';
 228          echo $this->single_row_columns( $tag );
 229          echo '</tr>';
 230      }
 231  
 232  	function column_cb( $tag ) {
 233          $default_term = get_option( 'default_' . $this->screen->taxonomy );
 234  
 235          if ( current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->delete_terms ) && $tag->term_id != $default_term )
 236              return '<label class="screen-reader-text" for="cb-select-' . $tag->term_id . '">' . sprintf( __( 'Select %s' ), $tag->name ) . '</label>'
 237                  . '<input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" id="cb-select-' . $tag->term_id . '" />';
 238  
 239          return '&nbsp;';
 240      }
 241  
 242  	function column_name( $tag ) {
 243          $taxonomy = $this->screen->taxonomy;
 244          $tax = get_taxonomy( $taxonomy );
 245  
 246          $default_term = get_option( 'default_' . $taxonomy );
 247  
 248          $pad = str_repeat( '&#8212; ', max( 0, $this->level ) );
 249          $name = apply_filters( 'term_name', $pad . ' ' . $tag->name, $tag );
 250          $qe_data = get_term( $tag->term_id, $taxonomy, OBJECT, 'edit' );
 251          $edit_link = esc_url( get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type ) );
 252  
 253          $out = '<strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $name ) ) . '">' . $name . '</a></strong><br />';
 254  
 255          $actions = array();
 256          if ( current_user_can( $tax->cap->edit_terms ) ) {
 257              $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
 258              $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __( 'Quick&nbsp;Edit' ) . '</a>';
 259          }
 260          if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term )
 261              $actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url( "edit-tags.php?action=delete&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id ) . "'>" . __( 'Delete' ) . "</a>";
 262          $actions['view'] = '<a href="' . get_term_link( $tag ) . '">' . __( 'View' ) . '</a>';
 263  
 264          $actions = apply_filters( 'tag_row_actions', $actions, $tag );
 265          $actions = apply_filters( "{$taxonomy}_row_actions", $actions, $tag );
 266  
 267          $out .= $this->row_actions( $actions );
 268          $out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
 269          $out .= '<div class="name">' . $qe_data->name . '</div>';
 270          $out .= '<div class="slug">' . apply_filters( 'editable_slug', $qe_data->slug ) . '</div>';
 271          $out .= '<div class="parent">' . $qe_data->parent . '</div></div>';
 272  
 273          return $out;
 274      }
 275  
 276  	function column_description( $tag ) {
 277          return $tag->description;
 278      }
 279  
 280  	function column_slug( $tag ) {
 281          return apply_filters( 'editable_slug', $tag->slug );
 282      }
 283  
 284  	function column_posts( $tag ) {
 285          $count = number_format_i18n( $tag->count );
 286  
 287          $tax = get_taxonomy( $this->screen->taxonomy );
 288  
 289          $ptype_object = get_post_type_object( $this->screen->post_type );
 290          if ( ! $ptype_object->show_ui )
 291              return $count;
 292  
 293          if ( $tax->query_var ) {
 294              $args = array( $tax->query_var => $tag->slug );
 295          } else {
 296              $args = array( 'taxonomy' => $tax->name, 'term' => $tag->slug );
 297          }
 298  
 299          if ( 'post' != $this->screen->post_type )
 300              $args['post_type'] = $this->screen->post_type;
 301  
 302          if ( 'attachment' == $this->screen->post_type )
 303              return "<a href='" . esc_url ( add_query_arg( $args, 'upload.php' ) ) . "'>$count</a>";
 304  
 305          return "<a href='" . esc_url ( add_query_arg( $args, 'edit.php' ) ) . "'>$count</a>";
 306      }
 307  
 308  	function column_links( $tag ) {
 309          $count = number_format_i18n( $tag->count );
 310          if ( $count )
 311              $count = "<a href='link-manager.php?cat_id=$tag->term_id'>$count</a>";
 312          return $count;
 313      }
 314  
 315  	function column_default( $tag, $column_name ) {
 316          return apply_filters( "manage_{$this->screen->taxonomy}_custom_column", '', $column_name, $tag->term_id );
 317      }
 318  
 319      /**
 320       * Outputs the hidden row displayed when inline editing
 321       *
 322       * @since 3.1.0
 323       */
 324  	function inline_edit() {
 325          $tax = get_taxonomy( $this->screen->taxonomy );
 326  
 327          if ( ! current_user_can( $tax->cap->edit_terms ) )
 328              return;
 329  ?>
 330  
 331      <form method="get" action=""><table style="display: none"><tbody id="inlineedit">
 332          <tr id="inline-edit" class="inline-edit-row" style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange">
 333  
 334              <fieldset><div class="inline-edit-col">
 335                  <h4><?php _e( 'Quick Edit' ); ?></h4>
 336  
 337                  <label>
 338                      <span class="title"><?php _ex( 'Name', 'term name' ); ?></span>
 339                      <span class="input-text-wrap"><input type="text" name="name" class="ptitle" value="" /></span>
 340                  </label>
 341      <?php if ( !global_terms_enabled() ) { ?>
 342                  <label>
 343                      <span class="title"><?php _e( 'Slug' ); ?></span>
 344                      <span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span>
 345                  </label>
 346      <?php } ?>
 347              </div></fieldset>
 348      <?php
 349  
 350          $core_columns = array( 'cb' => true, 'description' => true, 'name' => true, 'slug' => true, 'posts' => true );
 351  
 352          list( $columns ) = $this->get_column_info();
 353  
 354          foreach ( $columns as $column_name => $column_display_name ) {
 355              if ( isset( $core_columns[$column_name] ) )
 356                  continue;
 357  
 358              do_action( 'quick_edit_custom_box', $column_name, 'edit-tags', $this->screen->taxonomy );
 359          }
 360  
 361      ?>
 362  
 363          <p class="inline-edit-save submit">
 364              <a accesskey="c" href="#inline-edit" title="<?php esc_attr_e( 'Cancel' ); ?>" class="cancel button-secondary alignleft"><?php _e( 'Cancel' ); ?></a>
 365              <?php $update_text = $tax->labels->update_item; ?>
 366              <a accesskey="s" href="#inline-edit" title="<?php echo esc_attr( $update_text ); ?>" class="save button-primary alignright"><?php echo $update_text; ?></a>
 367              <span class="spinner"></span>
 368              <span class="error" style="display:none;"></span>
 369              <?php wp_nonce_field( 'taxinlineeditnonce', '_inline_edit', false ); ?>
 370              <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $this->screen->taxonomy ); ?>" />
 371              <input type="hidden" name="post_type" value="<?php echo esc_attr( $this->screen->post_type ); ?>" />
 372              <br class="clear" />
 373          </p>
 374          </td></tr>
 375          </tbody></table></form>
 376      <?php
 377      }
 378  }

title

Description

title

Description

title

Description

title

title

Body