WP_List_Table::get_views_links()protectedWP 6.1.0

Generates views links.

Method of the class: WP_List_Table{}

No Hooks.

Return

Array. An array of link markup. Keys match the $link_data input array.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_views_links( $link_data );
$link_data(array)

An array of link data.

Default: array()

  • url(string)
    The link URL.

  • label(string)
    The link label.

  • current(true|false)
    Optional. Whether this is the currently selected view.

Changelog

Since 6.1.0 Introduced.

WP_List_Table::get_views_links() code WP 6.1.1

protected function get_views_links( $link_data = array() ) {
	if ( ! is_array( $link_data ) ) {
		_doing_it_wrong(
			__METHOD__,
			sprintf(
				/* translators: %s: The $link_data argument. */
				__( 'The %s argument must be an array.' ),
				'<code>$link_data</code>'
			),
			'6.1.0'
		);

		return array( '' );
	}

	$views_links = array();

	foreach ( $link_data as $view => $link ) {
		if ( empty( $link['url'] ) || ! is_string( $link['url'] ) || '' === trim( $link['url'] ) ) {
			_doing_it_wrong(
				__METHOD__,
				sprintf(
					/* translators: %1$s: The argument name. %2$s: The view name. */
					__( 'The %1$s argument must be a non-empty string for %2$s.' ),
					'<code>url</code>',
					'<code>' . esc_html( $view ) . '</code>'
				),
				'6.1.0'
			);

			continue;
		}

		if ( empty( $link['label'] ) || ! is_string( $link['label'] ) || '' === trim( $link['label'] ) ) {
			_doing_it_wrong(
				__METHOD__,
				sprintf(
					/* translators: %1$s: The argument name. %2$s: The view name. */
					__( 'The %1$s argument must be a non-empty string for %2$s.' ),
					'<code>label</code>',
					'<code>' . esc_html( $view ) . '</code>'
				),
				'6.1.0'
			);

			continue;
		}

		$views_links[ $view ] = sprintf(
			'<a href="%s"%s>%s</a>',
			esc_url( $link['url'] ),
			isset( $link['current'] ) && true === $link['current'] ? ' class="current" aria-current="page"' : '',
			$link['label']
		);
	}

	return $views_links;
}