ap_recent_activity( Wp_Post|integer|null $_post = null, boolean $echo = 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
  • $echo
    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, $echo = true, $query_db = null ) {
	$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( [ 'ap_a' => $activity->a_id ] );
		} elseif ( 'comment' === $activity->action['ref_type'] ) {
			$link = ap_get_short_link( [ 'ap_c' => $activity->c_id ] );
		} else {
			$link = ap_get_short_link( [ '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 {
		// Fallback to old activities.
		$html = ap_latest_post_activity_html( $post_id = false, ! 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 === $echo ) {
		return $html;
	}

	echo $html;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Add your comment