WP_Terms_List_Table::handle_row_actions( WP_Term $item, string $column_name, string $primary ): string

In this article

Generates and displays row action links.

Parameters

$itemWP_Termrequired
Tag being acted upon.
$column_namestringrequired
Current column name.
$primarystringrequired
Primary column name.

Return

string Row actions output for terms, or an empty string if the current column is not the primary column.

Source

protected function handle_row_actions( $item, $column_name, $primary ) {
	if ( $primary !== $column_name ) {
		return '';
	}

	// Restores the more descriptive, specific name for use within this method.
	$tag = $item;

	$taxonomy = $this->screen->taxonomy;
	$uri      = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI'];

	$actions = array();

	if ( current_user_can( 'edit_term', $tag->term_id ) ) {
		$actions['edit'] = sprintf(
			'<a href="%s" aria-label="%s">%s</a>',
			esc_url(
				add_query_arg(
					'wp_http_referer',
					urlencode( wp_unslash( $uri ) ),
					get_edit_term_link( $tag, $taxonomy, $this->screen->post_type )
				)
			),
			/* translators: %s: Taxonomy term name. */
			esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $tag->name ) ),
			__( 'Edit' )
		);

		/**
		 * Filters whether Quick Edit should be enabled for the given taxonomy.
		 *
		 * @since 6.4.0
		 *
		 * @param bool   $enable   Whether to enable the Quick Edit functionality. Default true.
		 * @param string $taxonomy Taxonomy name.
		 */
		$quick_edit_enabled = apply_filters( 'quick_edit_enabled_for_taxonomy', true, $taxonomy );

		if ( $quick_edit_enabled ) {
			$actions['inline hide-if-no-js'] = sprintf(
				'<button type="button" class="button-link editinline" aria-label="%s" aria-expanded="false">%s</button>',
				/* translators: %s: Taxonomy term name. */
				esc_attr( sprintf( __( 'Quick edit &#8220;%s&#8221; inline' ), $tag->name ) ),
				__( 'Quick&nbsp;Edit' )
			);
		}
	}

	if ( current_user_can( 'delete_term', $tag->term_id ) ) {
		$actions['delete'] = sprintf(
			'<a href="%s" class="delete-tag aria-button-if-js" aria-label="%s">%s</a>',
			wp_nonce_url( "edit-tags.php?action=delete&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id ),
			/* translators: %s: Taxonomy term name. */
			esc_attr( sprintf( __( 'Delete &#8220;%s&#8221;' ), $tag->name ) ),
			__( 'Delete' )
		);
	}

	if ( is_term_publicly_viewable( $tag ) ) {
		$actions['view'] = sprintf(
			'<a href="%s" aria-label="%s">%s</a>',
			get_term_link( $tag ),
			/* translators: %s: Taxonomy term name. */
			esc_attr( sprintf( __( 'View &#8220;%s&#8221; archive' ), $tag->name ) ),
			__( 'View' )
		);
	}

	/**
	 * Filters the action links displayed for each term in the Tags list table.
	 *
	 * @since 2.8.0
	 * @since 3.0.0 Deprecated in favor of '{$taxonomy_row_actions'} filter.
	 * @since 5.4.2 Restored (un-deprecated).
	 *
	 * @param string[] $actions An array of action links to be displayed. Default
	 *                          'Edit', 'Quick Edit', 'Delete', and 'View'.
	 * @param WP_Term  $tag     Term object.
	 */
	$actions = apply_filters( 'tag_row_actions', $actions, $tag );

	/**
	 * Filters 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.
	 *
	 * Possible hook names include:
	 *
	 *  - `category_row_actions`
	 *  - `post_tag_row_actions`
	 *
	 * @since 3.0.0
	 *
	 * @param string[] $actions An array of action links to be displayed. Default
	 *                          'Edit', 'Quick Edit', 'Delete', and 'View'.
	 * @param WP_Term  $tag     Term object.
	 */
	$actions = apply_filters( "{$taxonomy}_row_actions", $actions, $tag );

	return $this->row_actions( $actions );
}

Hooks

apply_filters( ‘quick_edit_enabled_for_taxonomy’, bool $enable, string $taxonomy )

Filters whether Quick Edit should be enabled for the given taxonomy.

apply_filters( ‘tag_row_actions’, string[] $actions, WP_Term $tag )

Filters the action links displayed for each term in the Tags list table.

apply_filters( “{$taxonomy}_row_actions”, string[] $actions, WP_Term $tag )

Filters the action links displayed for each term in the terms list table.

Changelog

VersionDescription
5.9.0Renamed $tag to $item to match parent class for PHP 8 named parameter support.
4.3.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.