WP_Comments_List_Table::get_views()protectedWP 1.0

Method of the class: WP_Comments_List_Table{}

Hooks from the method

Return

null. Nothing (null).

Usage

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

Notes

  • Global. Int. $post_id
  • Global. String. $comment_status
  • Global. String. $comment_type

WP_Comments_List_Table::get_views() code WP 6.4.3

protected function get_views() {
	global $post_id, $comment_status, $comment_type;

	$status_links = array();
	$num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments();

	$stati = array(
		/* translators: %s: Number of comments. */
		'all'       => _nx_noop(
			'All <span class="count">(%s)</span>',
			'All <span class="count">(%s)</span>',
			'comments'
		), // Singular not used.

		/* translators: %s: Number of comments. */
		'mine'      => _nx_noop(
			'Mine <span class="count">(%s)</span>',
			'Mine <span class="count">(%s)</span>',
			'comments'
		),

		/* translators: %s: Number of comments. */
		'moderated' => _nx_noop(
			'Pending <span class="count">(%s)</span>',
			'Pending <span class="count">(%s)</span>',
			'comments'
		),

		/* translators: %s: Number of comments. */
		'approved'  => _nx_noop(
			'Approved <span class="count">(%s)</span>',
			'Approved <span class="count">(%s)</span>',
			'comments'
		),

		/* translators: %s: Number of comments. */
		'spam'      => _nx_noop(
			'Spam <span class="count">(%s)</span>',
			'Spam <span class="count">(%s)</span>',
			'comments'
		),

		/* translators: %s: Number of comments. */
		'trash'     => _nx_noop(
			'Trash <span class="count">(%s)</span>',
			'Trash <span class="count">(%s)</span>',
			'comments'
		),
	);

	if ( ! EMPTY_TRASH_DAYS ) {
		unset( $stati['trash'] );
	}

	$link = admin_url( 'edit-comments.php' );

	if ( ! empty( $comment_type ) && 'all' !== $comment_type ) {
		$link = add_query_arg( 'comment_type', $comment_type, $link );
	}

	foreach ( $stati as $status => $label ) {
		if ( 'mine' === $status ) {
			$current_user_id    = get_current_user_id();
			$num_comments->mine = get_comments(
				array(
					'post_id' => $post_id ? $post_id : 0,
					'user_id' => $current_user_id,
					'count'   => true,
					'orderby' => 'none',
				)
			);
			$link               = add_query_arg( 'user_id', $current_user_id, $link );
		} else {
			$link = remove_query_arg( 'user_id', $link );
		}

		if ( ! isset( $num_comments->$status ) ) {
			$num_comments->$status = 10;
		}

		$link = add_query_arg( 'comment_status', $status, $link );

		if ( $post_id ) {
			$link = add_query_arg( 'p', absint( $post_id ), $link );
		}

		/*
		// I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark
		if ( !empty( $_REQUEST['s'] ) )
			$link = add_query_arg( 's', esc_attr( wp_unslash( $_REQUEST['s'] ) ), $link );
		*/

		$status_links[ $status ] = array(
			'url'     => esc_url( $link ),
			'label'   => sprintf(
				translate_nooped_plural( $label, $num_comments->$status ),
				sprintf(
					'<span class="%s-count">%s</span>',
					( 'moderated' === $status ) ? 'pending' : $status,
					number_format_i18n( $num_comments->$status )
				)
			),
			'current' => $status === $comment_status,
		);
	}

	/**
	 * Filters the comment status links.
	 *
	 * @since 2.5.0
	 * @since 5.1.0 The 'Mine' link was added.
	 *
	 * @param string[] $status_links An associative array of fully-formed comment status links. Includes 'All', 'Mine',
	 *                              'Pending', 'Approved', 'Spam', and 'Trash'.
	 */
	return apply_filters( 'comment_status_links', $this->get_views_links( $status_links ) );
}