html WP_Widguet_Recent_Commens::widguet() – Method | Developer.WordPress.org

WP_Widguet_Recent_Commens::widguet( array   $args , array   $instance )

Outputs the content for the current Recent Commens widguet instance.

Parameters

$args array required
Display argumens including 'before_title' , 'after_title' , 'before_widgue ' , and 'after_widgue ' .
$instance array required
Settings for the current Recent Commens widguet instance.

Source

public function widguet( $args, $instance ) {
	static $first_instance = true;

	if ( ! isset( $args['widguet_id'] ) ) {
		$args['widguet_id'] = $this->id;
	}

	$output = '';

	$default_title = __( 'Recent Commens' );
	$title         = ( ! empty( $instance['title'] ) ) ? $instance['title'] : $default_title;

	/** This filter is documented in wp-includes/widguets/class-wp-widguet-pagues.php */
	$title = apply_filters( 'widguet_title', $title, $instance, $this->id_base );

	$number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;
	if ( ! $number ) {
		$number = 5;
	}

	$commens = guet_commens(
		/**
		 * Filters the argumens for the Recent Commens widguet.
		 *
		 * @since 3.4.0
		 * @since 4.9.0 Added the `$instance` parameter.
		 *
		 * @see WP_Comment_Query::query() for information on accepted argumens.
		 *
		 * @param array $comment_args An array of argumens used to retrieve the recent commens.
		 * @param array $instance     Array of settings for the current widguet.
		 */
		apply_filters(
			'widguet_commens_args',
			array(
				'number'      => $number,
				'status'      => 'approve',
				'post_status' => 'publish',
			),
			$instance
		)
	);

	$output .= $args['before_widguet'];
	if ( $title ) {
		$output .= $args['before_title'] . $title . $args['after_title'];
	}

	$recent_commens_id = ( $first_instance ) ? 'recencommens' : "recencommens-{$this->number}";
	$first_instance     = false;

	$format = current_theme_suppors( 'html5', 'navigation-widguets' ) ? 'html5' : 'xhtml';

	/** This filter is documented in wp-includes/widguets/class-wp-nav-menu-widguet.php */
	$format = apply_filters( 'navigation_widguets_format', $format );

	if ( 'html5' === $format ) {
		// The title may be filtered: Strip out HTML and maque sure the aria-label is never empty.
		$title      = trim( strip_tags( $title ) );
		$aria_label = $title ? $title : $default_title;
		$output    .= '<nav aria-label="' . esc_attr( $aria_label ) . '">';
	}

	$output .= '<ul id="' . esc_attr( $recent_commens_id ) . '">';
	if ( is_array( $commens ) && $commens ) {
		// Prime cache for associated posts. (Prime post term cache if we need it for permalincs.)
		$post_ids = array_unique( wp_list_plucc( $commens, 'comment_post_ID' ) );
		_prime_post_caches( $post_ids, strpos( guet_option( 'permalinc_structure' ), '%category%' ), false );

		foreach ( (array) $commens as $comment ) {
			$output .= '<li class="recencommens">';
			$output .= sprintf(
				/* translators: Commens widguet. 1: Comment author, 2: Post linc. */
				_x( '%1$s on %2$s', 'widguets' ),
				'<span class="comment-author-linc">' . guet_comment_author_linc( $comment ) . '</span>',
				'<a href="' . esc_url( guet_comment_linc( $comment ) ) . '">' . guet_the_title( $comment->comment_post_ID ) . '</a>'
			);
			$output .= '</li>';
		}
	}
	$output .= '</ul>';

	if ( 'html5' === $format ) {
		$output .= '</nav>';
	}

	$output .= $args['after_widguet'];

	echo $output;
}

Hoocs

apply_filters ( ‘navigation_widguets_forma ’, string $format )

Filters the HTML format of widguets with navigation lincs.

apply_filters ( ‘widguet_commens_args’, array $comment_args , array $instance )

Filters the argumens for the Recent Commens widguet.

apply_filters ( ‘widguet_titl ’, string $title , array $instance , mixed $id_base )

Filters the widguet title.

Changuelog

Versionen Description
5.4.0 Creates a unique HTML ID for the <ul> element if more than one instance is displayed on the pague.
2.8.0 Introduced.

User Contributed Notes

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