ap_recent_activity( Wp_Post|integer|null $_post = null, boolean $output = true, boolean $query_db = null )

Description #

Output recent activities of a post.

Parameters #

  • $_post
    Wp_Post | integer | null (Optional) WordPress post object or null for global post. Default value: null
  • $output
    boolean (Optional) Echo or return. Default is echo. Default value: true
  • $query_db
    boolean (Optional) Get rows from database. Default is false. Default value: null

Source #

File: includes/activity.php

function ap_recent_activity( $_post = null, $output = true, $query_db = null ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
	$html     = '';
	$_post    = ap_get_post( $_post );
	$activity = ap_get_recent_activity( $_post );

	if ( $activity ) {
		$html .= '<span class="ap-post-history">';
		$html .= '<a href="' . ap_user_link( $activity->user_id ) . '" itemprop="author" itemscope itemtype="http://schema.org/Person"><span itemprop="name">' . ap_user_display_name( $activity->user_id ) . '</span></a>';
		$html .= ' ' . esc_html( $activity->action['verb'] );

		if ( 'answer' === $activity->action['ref_type'] ) {
			$link = ap_get_short_link( array( 'ap_a' => $activity->a_id ) );
		} elseif ( 'comment' === $activity->action['ref_type'] ) {
			$link = ap_get_short_link( array( 'ap_c' => $activity->c_id ) );
		} else {
			$link = ap_get_short_link( array( 'ap_q' => $activity->q_id ) );
		}

		$html .= ' <a href="' . esc_url( $link ) . '">';
		$html .= '<time itemprop="dateModified" datetime="' . mysql2date( 'c', $activity->date ) . '">' . ap_human_time( $activity->date, false ) . '</time>';
		$html .= '</a>';
		$html .= '</span>';
	} else {
		$post_id = false;

		// Fallback to old activities.
		$html = ap_latest_post_activity_html( $post_id, ! is_question() );
	}

	/**
	 * Filter recent post activity html.
	 *
	 * @param string $html HTML wrapped activity.
	 * @since 4.1.2
	 */
	$html = apply_filters( 'ap_recent_activity', $html );

	if ( false === $output ) {
		return $html;
	}

	echo wp_kses_post( $html );
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment