X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/9e77185fafaf4e60e2b73821e0e4b9b1a11fb85f..53f4633144ed68c8b8fb5861f992b5489894a940:/wp-admin/includes/class-wp-terms-list-table.php diff --git a/wp-admin/includes/class-wp-terms-list-table.php b/wp-admin/includes/class-wp-terms-list-table.php index 743dfde4..a4c81afb 100644 --- a/wp-admin/includes/class-wp-terms-list-table.php +++ b/wp-admin/includes/class-wp-terms-list-table.php @@ -11,6 +11,8 @@ class WP_Terms_List_Table extends WP_List_Table { public $callback_args; + private $level; + /** * Constructor. * @@ -19,6 +21,11 @@ class WP_Terms_List_Table extends WP_List_Table { * * @see WP_List_Table::__construct() for more information on default arguments. * + * @global string $post_type + * @global string $taxonomy + * @global string $action + * @global object $tax + * * @param array $args An associative array of arguments. */ public function __construct( $args = array() ) { @@ -48,10 +55,17 @@ class WP_Terms_List_Table extends WP_List_Table { } + /** + * + * @return bool + */ public function ajax_user_can() { return current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->manage_terms ); } + /** + * @access public + */ public function prepare_items() { $tags_per_page = $this->get_items_per_page( 'edit_' . $this->screen->taxonomy . '_per_page' ); @@ -107,11 +121,26 @@ class WP_Terms_List_Table extends WP_List_Table { ) ); } + /** + * + * @return bool + */ public function has_items() { // todo: populate $this->items in prepare_items() return true; } + /** + * @access public + */ + public function no_items() { + echo get_taxonomy( $this->screen->taxonomy )->labels->not_found; + } + + /** + * + * @return array + */ protected function get_bulk_actions() { $actions = array(); $actions['delete'] = __( 'Delete' ); @@ -119,6 +148,10 @@ class WP_Terms_List_Table extends WP_List_Table { return $actions; } + /** + * + * @return string + */ public function current_action() { if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' == $_REQUEST['action'] || 'delete' == $_REQUEST['action2'] ) ) return 'bulk-delete'; @@ -126,6 +159,10 @@ class WP_Terms_List_Table extends WP_List_Table { return parent::current_action(); } + /** + * + * @return array + */ public function get_columns() { $columns = array( 'cb' => '', @@ -143,6 +180,10 @@ class WP_Terms_List_Table extends WP_List_Table { return $columns; } + /** + * + * @return array + */ protected function get_sortable_columns() { return array( 'name' => 'name', @@ -153,6 +194,9 @@ class WP_Terms_List_Table extends WP_List_Table { ); } + /** + * @access public + */ public function display_rows_or_placeholder() { $taxonomy = $this->screen->taxonomy; @@ -179,7 +223,7 @@ class WP_Terms_List_Table extends WP_List_Table { } $terms = get_terms( $taxonomy, $args ); - if ( empty( $terms ) ) { + if ( empty( $terms ) || ! is_array( $terms ) ) { echo ''; $this->no_items(); echo ''; @@ -195,13 +239,22 @@ class WP_Terms_List_Table extends WP_List_Table { // Some funky recursion to get the job done( Paging & parents mainly ) is contained within, Skip it for non-hierarchical taxonomies for performance sake $this->_rows( $taxonomy, $terms, $children, $offset, $number, $count ); } else { - $terms = get_terms( $taxonomy, $args ); foreach ( $terms as $term ) { $this->single_row( $term ); } } } + /** + * @param string $taxonomy + * @param array $terms + * @param array $children + * @param int $start + * @param int $per_page + * @param int $count + * @param int $parent + * @param int $level + */ private function _rows( $taxonomy, $terms, &$children, $start, $per_page, &$count, $parent = 0, $level = 0 ) { $end = $start + $per_page; @@ -250,20 +303,26 @@ class WP_Terms_List_Table extends WP_List_Table { } } + /** + * @global string $taxonomy + * @param object $tag + * @param int $level + */ public function single_row( $tag, $level = 0 ) { global $taxonomy; $tag = sanitize_term( $tag, $taxonomy ); - static $row_class = ''; - $row_class = ( $row_class == '' ? ' class="alternate"' : '' ); - $this->level = $level; - echo ''; + echo ''; $this->single_row_columns( $tag ); echo ''; } + /** + * @param object $tag + * @return string + */ public function column_cb( $tag ) { $default_term = get_option( 'default_' . $this->screen->taxonomy ); @@ -274,11 +333,12 @@ class WP_Terms_List_Table extends WP_List_Table { return ' '; } + /** + * @param object $tag + * @return string + */ public function column_name( $tag ) { $taxonomy = $this->screen->taxonomy; - $tax = get_taxonomy( $taxonomy ); - - $default_term = get_option( 'default_' . $taxonomy ); $pad = str_repeat( '— ', max( 0, $this->level ) ); @@ -302,6 +362,50 @@ class WP_Terms_List_Table extends WP_List_Table { $out = '' . $name . '
'; + $out .= ''; + + return $out; + } + + /** + * Gets the name of the default primary column. + * + * @since 4.3.0 + * @access protected + * + * @return string Name of the default primary column, in this case, 'name'. + */ + protected function get_default_primary_column_name() { + return 'name'; + } + + /** + * Generates and displays row action links. + * + * @since 4.3.0 + * @access protected + * + * @param object $tag Tag being acted upon. + * @param string $column_name Current column name. + * @param string $primary Primary column name. + * @return string Row actions output for terms. + */ + protected function handle_row_actions( $tag, $column_name, $primary ) { + if ( $primary !== $column_name ) { + return ''; + } + + $taxonomy = $this->screen->taxonomy; + $tax = get_taxonomy( $taxonomy ); + $default_term = get_option( 'default_' . $taxonomy ); + + $edit_link = esc_url( get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type ) ); + $actions = array(); if ( current_user_can( $tax->cap->edit_terms ) ) { $actions['edit'] = '' . __( 'Edit' ) . ''; @@ -327,7 +431,7 @@ class WP_Terms_List_Table extends WP_List_Table { /** * Filter the action links displayed for each term in the terms list table. * - * The dynamic portion of the hook name, $taxonomy, refers to the taxonomy slug. + * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug. * * @since 3.0.0 * @@ -337,26 +441,30 @@ class WP_Terms_List_Table extends WP_List_Table { */ $actions = apply_filters( "{$taxonomy}_row_actions", $actions, $tag ); - $out .= $this->row_actions( $actions ); - $out .= ''; - - return $out; + return $this->row_actions( $actions ); } + /** + * @param object $tag + * @return string + */ public function column_description( $tag ) { return $tag->description; } + /** + * @param object $tag + * @return string + */ public function column_slug( $tag ) { /** This filter is documented in wp-admin/edit-tag-form.php */ return apply_filters( 'editable_slug', $tag->slug ); } + /** + * @param object $tag + * @return string + */ public function column_posts( $tag ) { $count = number_format_i18n( $tag->count ); @@ -381,6 +489,10 @@ class WP_Terms_List_Table extends WP_List_Table { return "$count"; } + /** + * @param object $tag + * @return string + */ public function column_links( $tag ) { $count = number_format_i18n( $tag->count ); if ( $count ) @@ -388,11 +500,16 @@ class WP_Terms_List_Table extends WP_List_Table { return $count; } + /** + * @param object $tag + * @param string $column_name + * @return string + */ public function column_default( $tag, $column_name ) { /** * Filter the displayed columns in the terms list table. * - * The dynamic portion of the hook name, $this->screen->taxonomy, + * The dynamic portion of the hook name, `$this->screen->taxonomy`, * refers to the slug of the current taxonomy. * * @since 2.8.0 @@ -416,7 +533,7 @@ class WP_Terms_List_Table extends WP_List_Table { return; ?> -
+