wp/wp-admin/includes/class-wp-terms-list-table.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     9 
     9 
    10 /**
    10 /**
    11  * Core class used to implement displaying terms in a list table.
    11  * Core class used to implement displaying terms in a list table.
    12  *
    12  *
    13  * @since 3.1.0
    13  * @since 3.1.0
    14  * @access private
       
    15  *
    14  *
    16  * @see WP_List_Table
    15  * @see WP_List_Table
    17  */
    16  */
    18 class WP_Terms_List_Table extends WP_List_Table {
    17 class WP_Terms_List_Table extends WP_List_Table {
    19 
    18 
    26 	 *
    25 	 *
    27 	 * @since 3.1.0
    26 	 * @since 3.1.0
    28 	 *
    27 	 *
    29 	 * @see WP_List_Table::__construct() for more information on default arguments.
    28 	 * @see WP_List_Table::__construct() for more information on default arguments.
    30 	 *
    29 	 *
    31 	 * @global string $post_type
    30 	 * @global string $post_type Global post type.
    32 	 * @global string $taxonomy
    31 	 * @global string $taxonomy  Global taxonomy.
    33 	 * @global string $action
    32 	 * @global string $action
    34 	 * @global object $tax
    33 	 * @global object $tax
    35 	 *
    34 	 *
    36 	 * @param array $args An associative array of arguments.
    35 	 * @param array $args An associative array of arguments.
    37 	 */
    36 	 */
    62 
    61 
    63 		// @todo Still needed? Maybe just the show_ui part.
    62 		// @todo Still needed? Maybe just the show_ui part.
    64 		if ( empty( $post_type ) || ! in_array( $post_type, get_post_types( array( 'show_ui' => true ) ), true ) ) {
    63 		if ( empty( $post_type ) || ! in_array( $post_type, get_post_types( array( 'show_ui' => true ) ), true ) ) {
    65 			$post_type = 'post';
    64 			$post_type = 'post';
    66 		}
    65 		}
    67 
       
    68 	}
    66 	}
    69 
    67 
    70 	/**
    68 	/**
    71 	 * @return bool
    69 	 * @return bool
    72 	 */
    70 	 */
   184 
   182 
   185 		return parent::current_action();
   183 		return parent::current_action();
   186 	}
   184 	}
   187 
   185 
   188 	/**
   186 	/**
   189 	 * @return array
   187 	 * @return string[] Array of column titles keyed by their column name.
   190 	 */
   188 	 */
   191 	public function get_columns() {
   189 	public function get_columns() {
   192 		$columns = array(
   190 		$columns = array(
   193 			'cb'          => '<input type="checkbox" />',
   191 			'cb'          => '<input type="checkbox" />',
   194 			'name'        => _x( 'Name', 'term name' ),
   192 			'name'        => _x( 'Name', 'term name' ),
   207 
   205 
   208 	/**
   206 	/**
   209 	 * @return array
   207 	 * @return array
   210 	 */
   208 	 */
   211 	protected function get_sortable_columns() {
   209 	protected function get_sortable_columns() {
       
   210 		$taxonomy = $this->screen->taxonomy;
       
   211 
       
   212 		if ( ! isset( $_GET['orderby'] ) && is_taxonomy_hierarchical( $taxonomy ) ) {
       
   213 			$name_orderby_text = __( 'Table ordered hierarchically.' );
       
   214 		} else {
       
   215 			$name_orderby_text = __( 'Table ordered by Name.' );
       
   216 		}
       
   217 
   212 		return array(
   218 		return array(
   213 			'name'        => 'name',
   219 			'name'        => array( 'name', false, _x( 'Name', 'term name' ), $name_orderby_text, 'asc' ),
   214 			'description' => 'description',
   220 			'description' => array( 'description', false, __( 'Description' ), __( 'Table ordered by Description.' ) ),
   215 			'slug'        => 'slug',
   221 			'slug'        => array( 'slug', false, __( 'Slug' ), __( 'Table ordered by Slug.' ) ),
   216 			'posts'       => 'count',
   222 			'posts'       => array( 'count', false, _x( 'Count', 'Number/count of items' ), __( 'Table ordered by Posts Count.' ) ),
   217 			'links'       => 'count',
   223 			'links'       => array( 'count', false, __( 'Links' ), __( 'Table ordered by Links.' ) ),
   218 		);
   224 		);
   219 	}
   225 	}
   220 
   226 
   221 	/**
   227 	/**
   222 	 */
   228 	 */
   302 				$num_parents = count( $my_parents );
   308 				$num_parents = count( $my_parents );
   303 
   309 
   304 				while ( $my_parent = array_pop( $my_parents ) ) {
   310 				while ( $my_parent = array_pop( $my_parents ) ) {
   305 					echo "\t";
   311 					echo "\t";
   306 					$this->single_row( $my_parent, $level - $num_parents );
   312 					$this->single_row( $my_parent, $level - $num_parents );
   307 					$num_parents--;
   313 					--$num_parents;
   308 				}
   314 				}
   309 			}
   315 			}
   310 
   316 
   311 			if ( $count >= $start ) {
   317 			if ( $count >= $start ) {
   312 				echo "\t";
   318 				echo "\t";
   322 			}
   328 			}
   323 		}
   329 		}
   324 	}
   330 	}
   325 
   331 
   326 	/**
   332 	/**
   327 	 * @global string $taxonomy
   333 	 * @global string $taxonomy Global taxonomy.
       
   334 	 *
   328 	 * @param WP_Term $tag   Term object.
   335 	 * @param WP_Term $tag   Term object.
   329 	 * @param int     $level
   336 	 * @param int     $level
   330 	 */
   337 	 */
   331 	public function single_row( $tag, $level = 0 ) {
   338 	public function single_row( $tag, $level = 0 ) {
   332 		global $taxonomy;
   339 		global $taxonomy;
   356 		// Restores the more descriptive, specific name for use within this method.
   363 		// Restores the more descriptive, specific name for use within this method.
   357 		$tag = $item;
   364 		$tag = $item;
   358 
   365 
   359 		if ( current_user_can( 'delete_term', $tag->term_id ) ) {
   366 		if ( current_user_can( 'delete_term', $tag->term_id ) ) {
   360 			return sprintf(
   367 			return sprintf(
   361 				'<label class="screen-reader-text" for="cb-select-%1$s">%2$s</label>' .
   368 				'<input type="checkbox" name="delete_tags[]" value="%1$s" id="cb-select-%1$s" />' .
   362 				'<input type="checkbox" name="delete_tags[]" value="%1$s" id="cb-select-%1$s" />',
   369 				'<label for="cb-select-%1$s"><span class="screen-reader-text">%2$s</span></label>',
   363 				$tag->term_id,
   370 				$tag->term_id,
   364 				/* translators: %s: Taxonomy term name. */
   371 				/* translators: Hidden accessibility text. %s: Taxonomy term name. */
   365 				sprintf( __( 'Select %s' ), $tag->name )
   372 				sprintf( __( 'Select %s' ), $tag->name )
   366 			);
   373 			);
   367 		}
   374 		}
   368 
   375 
   369 		return '&nbsp;';
   376 		return '&nbsp;';
   412 				esc_attr( sprintf( __( '&#8220;%s&#8221; (Edit)' ), $tag->name ) ),
   419 				esc_attr( sprintf( __( '&#8220;%s&#8221; (Edit)' ), $tag->name ) ),
   413 				$name
   420 				$name
   414 			);
   421 			);
   415 		}
   422 		}
   416 
   423 
   417 		$out = sprintf(
   424 		$output = sprintf(
   418 			'<strong>%s</strong><br />',
   425 			'<strong>%s</strong><br />',
   419 			$name
   426 			$name
   420 		);
   427 		);
   421 
   428 
   422 		$out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
   429 		/** This filter is documented in wp-admin/includes/class-wp-terms-list-table.php */
   423 		$out .= '<div class="name">' . $qe_data->name . '</div>';
   430 		$quick_edit_enabled = apply_filters( 'quick_edit_enabled_for_taxonomy', true, $taxonomy );
   424 
   431 
   425 		/** This filter is documented in wp-admin/edit-tag-form.php */
   432 		if ( $quick_edit_enabled ) {
   426 		$out .= '<div class="slug">' . apply_filters( 'editable_slug', $qe_data->slug, $qe_data ) . '</div>';
   433 			$output .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
   427 		$out .= '<div class="parent">' . $qe_data->parent . '</div></div>';
   434 			$output .= '<div class="name">' . $qe_data->name . '</div>';
   428 
   435 
   429 		return $out;
   436 			/** This filter is documented in wp-admin/edit-tag-form.php */
       
   437 			$output .= '<div class="slug">' . apply_filters( 'editable_slug', $qe_data->slug, $qe_data ) . '</div>';
       
   438 			$output .= '<div class="parent">' . $qe_data->parent . '</div></div>';
       
   439 		}
       
   440 
       
   441 		return $output;
   430 	}
   442 	}
   431 
   443 
   432 	/**
   444 	/**
   433 	 * Gets the name of the default primary column.
   445 	 * Gets the name of the default primary column.
   434 	 *
   446 	 *
   456 		if ( $primary !== $column_name ) {
   468 		if ( $primary !== $column_name ) {
   457 			return '';
   469 			return '';
   458 		}
   470 		}
   459 
   471 
   460 		// Restores the more descriptive, specific name for use within this method.
   472 		// Restores the more descriptive, specific name for use within this method.
   461 		$tag      = $item;
   473 		$tag = $item;
       
   474 
   462 		$taxonomy = $this->screen->taxonomy;
   475 		$taxonomy = $this->screen->taxonomy;
   463 		$tax      = get_taxonomy( $taxonomy );
       
   464 		$uri      = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI'];
   476 		$uri      = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI'];
   465 
       
   466 		$edit_link = add_query_arg(
       
   467 			'wp_http_referer',
       
   468 			urlencode( wp_unslash( $uri ) ),
       
   469 			get_edit_term_link( $tag, $taxonomy, $this->screen->post_type )
       
   470 		);
       
   471 
   477 
   472 		$actions = array();
   478 		$actions = array();
   473 
   479 
   474 		if ( current_user_can( 'edit_term', $tag->term_id ) ) {
   480 		if ( current_user_can( 'edit_term', $tag->term_id ) ) {
   475 			$actions['edit'] = sprintf(
   481 			$actions['edit'] = sprintf(
   476 				'<a href="%s" aria-label="%s">%s</a>',
   482 				'<a href="%s" aria-label="%s">%s</a>',
   477 				esc_url( $edit_link ),
   483 				esc_url(
       
   484 					add_query_arg(
       
   485 						'wp_http_referer',
       
   486 						urlencode( wp_unslash( $uri ) ),
       
   487 						get_edit_term_link( $tag, $taxonomy, $this->screen->post_type )
       
   488 					)
       
   489 				),
   478 				/* translators: %s: Taxonomy term name. */
   490 				/* translators: %s: Taxonomy term name. */
   479 				esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $tag->name ) ),
   491 				esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $tag->name ) ),
   480 				__( 'Edit' )
   492 				__( 'Edit' )
   481 			);
   493 			);
   482 			$actions['inline hide-if-no-js'] = sprintf(
   494 
   483 				'<button type="button" class="button-link editinline" aria-label="%s" aria-expanded="false">%s</button>',
   495 			/**
   484 				/* translators: %s: Taxonomy term name. */
   496 			 * Filters whether Quick Edit should be enabled for the given taxonomy.
   485 				esc_attr( sprintf( __( 'Quick edit &#8220;%s&#8221; inline' ), $tag->name ) ),
   497 			 *
   486 				__( 'Quick&nbsp;Edit' )
   498 			 * @since 6.4.0
   487 			);
   499 			 *
       
   500 			 * @param bool   $enable   Whether to enable the Quick Edit functionality. Default true.
       
   501 			 * @param string $taxonomy Taxonomy name.
       
   502 			 */
       
   503 			$quick_edit_enabled = apply_filters( 'quick_edit_enabled_for_taxonomy', true, $taxonomy );
       
   504 
       
   505 			if ( $quick_edit_enabled ) {
       
   506 				$actions['inline hide-if-no-js'] = sprintf(
       
   507 					'<button type="button" class="button-link editinline" aria-label="%s" aria-expanded="false">%s</button>',
       
   508 					/* translators: %s: Taxonomy term name. */
       
   509 					esc_attr( sprintf( __( 'Quick edit &#8220;%s&#8221; inline' ), $tag->name ) ),
       
   510 					__( 'Quick&nbsp;Edit' )
       
   511 				);
       
   512 			}
   488 		}
   513 		}
   489 
   514 
   490 		if ( current_user_can( 'delete_term', $tag->term_id ) ) {
   515 		if ( current_user_can( 'delete_term', $tag->term_id ) ) {
   491 			$actions['delete'] = sprintf(
   516 			$actions['delete'] = sprintf(
   492 				'<a href="%s" class="delete-tag aria-button-if-js" aria-label="%s">%s</a>',
   517 				'<a href="%s" class="delete-tag aria-button-if-js" aria-label="%s">%s</a>',
   495 				esc_attr( sprintf( __( 'Delete &#8220;%s&#8221;' ), $tag->name ) ),
   520 				esc_attr( sprintf( __( 'Delete &#8220;%s&#8221;' ), $tag->name ) ),
   496 				__( 'Delete' )
   521 				__( 'Delete' )
   497 			);
   522 			);
   498 		}
   523 		}
   499 
   524 
   500 		if ( is_taxonomy_viewable( $tax ) ) {
   525 		if ( is_term_publicly_viewable( $tag ) ) {
   501 			$actions['view'] = sprintf(
   526 			$actions['view'] = sprintf(
   502 				'<a href="%s" aria-label="%s">%s</a>',
   527 				'<a href="%s" aria-label="%s">%s</a>',
   503 				get_term_link( $tag ),
   528 				get_term_link( $tag ),
   504 				/* translators: %s: Taxonomy term name. */
   529 				/* translators: %s: Taxonomy term name. */
   505 				esc_attr( sprintf( __( 'View &#8220;%s&#8221; archive' ), $tag->name ) ),
   530 				esc_attr( sprintf( __( 'View &#8220;%s&#8221; archive' ), $tag->name ) ),
   547 	 */
   572 	 */
   548 	public function column_description( $tag ) {
   573 	public function column_description( $tag ) {
   549 		if ( $tag->description ) {
   574 		if ( $tag->description ) {
   550 			return $tag->description;
   575 			return $tag->description;
   551 		} else {
   576 		} else {
   552 			return '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . __( 'No description' ) . '</span>';
   577 			return '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' .
       
   578 				/* translators: Hidden accessibility text. */
       
   579 				__( 'No description' ) .
       
   580 			'</span>';
   553 		}
   581 		}
   554 	}
   582 	}
   555 
   583 
   556 	/**
   584 	/**
   557 	 * @param WP_Term $tag Term object.
   585 	 * @param WP_Term $tag Term object.
   616 	 * @param WP_Term $item        Term object.
   644 	 * @param WP_Term $item        Term object.
   617 	 * @param string  $column_name Name of the column.
   645 	 * @param string  $column_name Name of the column.
   618 	 * @return string
   646 	 * @return string
   619 	 */
   647 	 */
   620 	public function column_default( $item, $column_name ) {
   648 	public function column_default( $item, $column_name ) {
       
   649 		// Restores the more descriptive, specific name for use within this method.
       
   650 		$tag = $item;
       
   651 
   621 		/**
   652 		/**
   622 		 * Filters the displayed columns in the terms list table.
   653 		 * Filters the displayed columns in the terms list table.
   623 		 *
   654 		 *
   624 		 * The dynamic portion of the hook name, `$this->screen->taxonomy`,
   655 		 * The dynamic portion of the hook name, `$this->screen->taxonomy`,
   625 		 * refers to the slug of the current taxonomy.
   656 		 * refers to the slug of the current taxonomy.
   633 		 *
   664 		 *
   634 		 * @param string $string      Custom column output. Default empty.
   665 		 * @param string $string      Custom column output. Default empty.
   635 		 * @param string $column_name Name of the column.
   666 		 * @param string $column_name Name of the column.
   636 		 * @param int    $term_id     Term ID.
   667 		 * @param int    $term_id     Term ID.
   637 		 */
   668 		 */
   638 		return apply_filters( "manage_{$this->screen->taxonomy}_custom_column", '', $column_name, $item->term_id );
   669 		return apply_filters( "manage_{$this->screen->taxonomy}_custom_column", '', $column_name, $tag->term_id );
   639 	}
   670 	}
   640 
   671 
   641 	/**
   672 	/**
   642 	 * Outputs the hidden row displayed when inline editing
   673 	 * Outputs the hidden row displayed when inline editing
   643 	 *
   674 	 *
   664 				<label>
   695 				<label>
   665 					<span class="title"><?php _ex( 'Name', 'term name' ); ?></span>
   696 					<span class="title"><?php _ex( 'Name', 'term name' ); ?></span>
   666 					<span class="input-text-wrap"><input type="text" name="name" class="ptitle" value="" /></span>
   697 					<span class="input-text-wrap"><input type="text" name="name" class="ptitle" value="" /></span>
   667 				</label>
   698 				</label>
   668 
   699 
   669 				<?php if ( ! global_terms_enabled() ) : ?>
   700 				<label>
   670 					<label>
   701 					<span class="title"><?php _e( 'Slug' ); ?></span>
   671 						<span class="title"><?php _e( 'Slug' ); ?></span>
   702 					<span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span>
   672 						<span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span>
   703 				</label>
   673 					</label>
       
   674 				<?php endif; ?>
       
   675 				</div>
   704 				</div>
   676 			</fieldset>
   705 			</fieldset>
   677 
   706 
   678 			<?php
   707 			<?php
   679 			$core_columns = array(
   708 			$core_columns = array(
   703 
   732 
   704 				<?php wp_nonce_field( 'taxinlineeditnonce', '_inline_edit', false ); ?>
   733 				<?php wp_nonce_field( 'taxinlineeditnonce', '_inline_edit', false ); ?>
   705 				<input type="hidden" name="taxonomy" value="<?php echo esc_attr( $this->screen->taxonomy ); ?>" />
   734 				<input type="hidden" name="taxonomy" value="<?php echo esc_attr( $this->screen->taxonomy ); ?>" />
   706 				<input type="hidden" name="post_type" value="<?php echo esc_attr( $this->screen->post_type ); ?>" />
   735 				<input type="hidden" name="post_type" value="<?php echo esc_attr( $this->screen->post_type ); ?>" />
   707 
   736 
   708 				<div class="notice notice-error notice-alt inline hidden">
   737 				<?php
   709 					<p class="error"></p>
   738 				wp_admin_notice(
   710 				</div>
   739 					'<p class="error"></p>',
       
   740 					array(
       
   741 						'type'               => 'error',
       
   742 						'additional_classes' => array( 'notice-alt', 'inline', 'hidden' ),
       
   743 						'paragraph_wrap'     => false,
       
   744 					)
       
   745 				);
       
   746 				?>
   711 			</div>
   747 			</div>
   712 			</div>
   748 			</div>
   713 
   749 
   714 			</td></tr>
   750 			</td></tr>
   715 
   751