PageRenderTime 47ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/public_html/wp-admin/includes/class-wp-terms-list-table.php

https://github.com/terry69/fluxflex_wordpress
PHP | 379 lines | 272 code | 89 blank | 18 comment | 53 complexity | e6aef90fa9275ae62d1227386575b2d9 MD5 | raw file
  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. var $callback_args;
  12. function WP_Terms_List_Table() {
  13. global $post_type, $taxonomy, $tax;
  14. wp_reset_vars( array( 'action', 'taxonomy', 'post_type' ) );
  15. if ( empty( $taxonomy ) )
  16. $taxonomy = 'post_tag';
  17. if ( !taxonomy_exists( $taxonomy ) )
  18. wp_die( __( 'Invalid taxonomy' ) );
  19. $tax = get_taxonomy( $taxonomy );
  20. if ( empty( $post_type ) || !in_array( $post_type, get_post_types( array( 'public' => true ) ) ) )
  21. $post_type = 'post';
  22. parent::WP_List_Table( array(
  23. 'plural' => 'tags',
  24. 'singular' => 'tag',
  25. ) );
  26. }
  27. function ajax_user_can() {
  28. global $tax;
  29. return current_user_can( $tax->cap->manage_terms );
  30. }
  31. function prepare_items() {
  32. global $taxonomy;
  33. $tags_per_page = $this->get_items_per_page( 'edit_' . $taxonomy . '_per_page' );
  34. if ( 'post_tag' == $taxonomy ) {
  35. $tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page );
  36. $tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); // Old filter
  37. } elseif ( 'category' == $taxonomy ) {
  38. $tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page ); // Old filter
  39. }
  40. $search = !empty( $_REQUEST['s'] ) ? trim( stripslashes( $_REQUEST['s'] ) ) : '';
  41. $args = array(
  42. 'search' => $search,
  43. 'page' => $this->get_pagenum(),
  44. 'number' => $tags_per_page,
  45. );
  46. if ( !empty( $_REQUEST['orderby'] ) )
  47. $args['orderby'] = trim( stripslashes( $_REQUEST['orderby'] ) );
  48. if ( !empty( $_REQUEST['order'] ) )
  49. $args['order'] = trim( stripslashes( $_REQUEST['order'] ) );
  50. $this->callback_args = $args;
  51. $this->set_pagination_args( array(
  52. 'total_items' => wp_count_terms( $taxonomy, compact( 'search' ) ),
  53. 'per_page' => $tags_per_page,
  54. ) );
  55. }
  56. function has_items() {
  57. // todo: populate $this->items in prepare_items()
  58. return true;
  59. }
  60. function get_bulk_actions() {
  61. $actions = array();
  62. $actions['delete'] = __( 'Delete' );
  63. return $actions;
  64. }
  65. function current_action() {
  66. if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' == $_REQUEST['action'] || 'delete' == $_REQUEST['action2'] ) )
  67. return 'bulk-delete';
  68. return parent::current_action();
  69. }
  70. function get_columns() {
  71. global $taxonomy, $typenow;
  72. $columns = array(
  73. 'cb' => '<input type="checkbox" />',
  74. 'name' => __( 'Name' ),
  75. 'description' => __( 'Description' ),
  76. 'slug' => __( 'Slug' ),
  77. );
  78. if ( 'link_category' == $taxonomy ) {
  79. $columns['links'] = __( 'Links' );
  80. } else {
  81. $post_type = empty( $typenow ) ? 'post' : $typenow;
  82. $post_type_object = get_post_type_object( $post_type );
  83. $columns['posts'] = $post_type_object ? $post_type_object->labels->name : __( 'Posts' );
  84. }
  85. return $columns;
  86. }
  87. function get_sortable_columns() {
  88. return array(
  89. 'name' => 'name',
  90. 'description' => 'description',
  91. 'slug' => 'slug',
  92. 'posts' => 'count',
  93. 'links' => 'count'
  94. );
  95. }
  96. function display_rows_or_placeholder() {
  97. global $taxonomy;
  98. $args = wp_parse_args( $this->callback_args, array(
  99. 'page' => 1,
  100. 'number' => 20,
  101. 'search' => '',
  102. 'hide_empty' => 0
  103. ) );
  104. extract( $args, EXTR_SKIP );
  105. $args['offset'] = $offset = ( $page - 1 ) * $number;
  106. // convert it to table rows
  107. $out = '';
  108. $count = 0;
  109. $terms = array();
  110. if ( is_taxonomy_hierarchical( $taxonomy ) && !isset( $orderby ) ) {
  111. // We'll need the full set of terms then.
  112. $args['number'] = $args['offset'] = 0;
  113. $terms = get_terms( $taxonomy, $args );
  114. if ( !empty( $search ) ) // Ignore children on searches.
  115. $children = array();
  116. else
  117. $children = _get_term_hierarchy( $taxonomy );
  118. // Some funky recursion to get the job done( Paging & parents mainly ) is contained within, Skip it for non-hierarchical taxonomies for performance sake
  119. $out .= $this->_rows( $taxonomy, $terms, $children, $offset, $number, $count );
  120. } else {
  121. $terms = get_terms( $taxonomy, $args );
  122. foreach ( $terms as $term )
  123. $out .= $this->single_row( $term, 0, $taxonomy );
  124. $count = $number; // Only displaying a single page.
  125. }
  126. if ( empty( $terms ) ) {
  127. list( $columns, $hidden ) = $this->get_column_info();
  128. echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">';
  129. $this->no_items();
  130. echo '</td></tr>';
  131. } else {
  132. echo $out;
  133. }
  134. }
  135. function _rows( $taxonomy, $terms, &$children, $start = 0, $per_page = 20, &$count, $parent = 0, $level = 0 ) {
  136. $end = $start + $per_page;
  137. $output = '';
  138. foreach ( $terms as $key => $term ) {
  139. if ( $count >= $end )
  140. break;
  141. if ( $term->parent != $parent && empty( $_REQUEST['s'] ) )
  142. continue;
  143. // If the page starts in a subtree, print the parents.
  144. if ( $count == $start && $term->parent > 0 && empty( $_REQUEST['s'] ) ) {
  145. $my_parents = $parent_ids = array();
  146. $p = $term->parent;
  147. while ( $p ) {
  148. $my_parent = get_term( $p, $taxonomy );
  149. $my_parents[] = $my_parent;
  150. $p = $my_parent->parent;
  151. if ( in_array( $p, $parent_ids ) ) // Prevent parent loops.
  152. break;
  153. $parent_ids[] = $p;
  154. }
  155. unset( $parent_ids );
  156. $num_parents = count( $my_parents );
  157. while ( $my_parent = array_pop( $my_parents ) ) {
  158. $output .= "\t" . $this->single_row( $my_parent, $level - $num_parents, $taxonomy );
  159. $num_parents--;
  160. }
  161. }
  162. if ( $count >= $start )
  163. $output .= "\t" . $this->single_row( $term, $level, $taxonomy );
  164. ++$count;
  165. unset( $terms[$key] );
  166. if ( isset( $children[$term->term_id] ) && empty( $_REQUEST['s'] ) )
  167. $output .= $this->_rows( $taxonomy, $terms, $children, $start, $per_page, $count, $term->term_id, $level + 1 );
  168. }
  169. return $output;
  170. }
  171. function single_row( $tag, $level = 0 ) {
  172. static $row_class = '';
  173. $row_class = ( $row_class == '' ? ' class="alternate"' : '' );
  174. $this->level = $level;
  175. echo '<tr id="tag-' . $tag->term_id . '"' . $row_class . '>';
  176. echo $this->single_row_columns( $tag );
  177. echo '</tr>';
  178. }
  179. function column_cb( $tag ) {
  180. global $taxonomy, $tax;
  181. $default_term = get_option( 'default_' . $taxonomy );
  182. if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term )
  183. return '<input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" />';
  184. else
  185. return '&nbsp;';
  186. }
  187. function column_name( $tag ) {
  188. global $taxonomy, $tax, $post_type;
  189. $default_term = get_option( 'default_' . $taxonomy );
  190. $pad = str_repeat( '&#8212; ', max( 0, $this->level ) );
  191. $name = apply_filters( 'term_name', $pad . ' ' . $tag->name, $tag );
  192. $qe_data = get_term( $tag->term_id, $taxonomy, OBJECT, 'edit' );
  193. $edit_link = get_edit_term_link( $tag->term_id, $taxonomy, $post_type );
  194. $out = '<strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $name ) ) . '">' . $name . '</a></strong><br />';
  195. $actions = array();
  196. if ( current_user_can( $tax->cap->edit_terms ) ) {
  197. $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
  198. $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __( 'Quick&nbsp;Edit' ) . '</a>';
  199. }
  200. if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term )
  201. $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>";
  202. $actions = apply_filters( 'tag_row_actions', $actions, $tag );
  203. $actions = apply_filters( "{$taxonomy}_row_actions", $actions, $tag );
  204. $out .= $this->row_actions( $actions );
  205. $out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
  206. $out .= '<div class="name">' . $qe_data->name . '</div>';
  207. $out .= '<div class="slug">' . apply_filters( 'editable_slug', $qe_data->slug ) . '</div>';
  208. $out .= '<div class="parent">' . $qe_data->parent . '</div></div></td>';
  209. return $out;
  210. }
  211. function column_description( $tag ) {
  212. return $tag->description;
  213. }
  214. function column_slug( $tag ) {
  215. return apply_filters( 'editable_slug', $tag->slug );
  216. }
  217. function column_posts( $tag ) {
  218. global $taxonomy, $post_type;
  219. $count = number_format_i18n( $tag->count );
  220. $tax = get_taxonomy( $taxonomy );
  221. if ( ! $tax->public )
  222. return $count;
  223. if ( $tax->query_var ) {
  224. $args = array( $tax->query_var => $tag->slug );
  225. } else {
  226. $args = array( 'taxonomy' => $tax->name, 'term' => $tag->slug );
  227. }
  228. $args['post_type'] = $post_type;
  229. return "<a href='" . add_query_arg( $args, 'edit.php' ) . "'>$count</a>";
  230. }
  231. function column_links( $tag ) {
  232. $count = number_format_i18n( $tag->count );
  233. if ( $count )
  234. $count = "<a href='link-manager.php?cat_id=$tag->term_id'>$count</a>";
  235. return $count;
  236. }
  237. function column_default( $tag, $column_name ) {
  238. $screen = get_current_screen();
  239. return apply_filters( "manage_{$screen->taxonomy}_custom_column", '', $column_name, $tag->term_id );
  240. }
  241. /**
  242. * Outputs the hidden row displayed when inline editing
  243. *
  244. * @since 3.1.0
  245. */
  246. function inline_edit() {
  247. global $tax;
  248. if ( ! current_user_can( $tax->cap->edit_terms ) )
  249. return;
  250. ?>
  251. <form method="get" action=""><table style="display: none"><tbody id="inlineedit">
  252. <tr id="inline-edit" class="inline-edit-row" style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange">
  253. <fieldset><div class="inline-edit-col">
  254. <h4><?php _e( 'Quick Edit' ); ?></h4>
  255. <label>
  256. <span class="title"><?php _e( 'Name' ); ?></span>
  257. <span class="input-text-wrap"><input type="text" name="name" class="ptitle" value="" /></span>
  258. </label>
  259. <?php if ( !global_terms_enabled() ) { ?>
  260. <label>
  261. <span class="title"><?php _e( 'Slug' ); ?></span>
  262. <span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span>
  263. </label>
  264. <?php } ?>
  265. </div></fieldset>
  266. <?php
  267. $core_columns = array( 'cb' => true, 'description' => true, 'name' => true, 'slug' => true, 'posts' => true );
  268. list( $columns ) = $this->get_column_info();
  269. foreach ( $columns as $column_name => $column_display_name ) {
  270. if ( isset( $core_columns[$column_name] ) )
  271. continue;
  272. do_action( 'quick_edit_custom_box', $column_name, 'edit-tags', $tax->name );
  273. }
  274. ?>
  275. <p class="inline-edit-save submit">
  276. <a accesskey="c" href="#inline-edit" title="<?php _e( 'Cancel' ); ?>" class="cancel button-secondary alignleft"><?php _e( 'Cancel' ); ?></a>
  277. <?php $update_text = $tax->labels->update_item; ?>
  278. <a accesskey="s" href="#inline-edit" title="<?php echo esc_attr( $update_text ); ?>" class="save button-primary alignright"><?php echo $update_text; ?></a>
  279. <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
  280. <span class="error" style="display:none;"></span>
  281. <?php wp_nonce_field( 'taxinlineeditnonce', '_inline_edit', false ); ?>
  282. <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $tax->name ); ?>" />
  283. <br class="clear" />
  284. </p>
  285. </td></tr>
  286. </tbody></table></form>
  287. <?php
  288. }
  289. }
  290. ?>