ap_get_recent_activity( Wp_Post|integer|false $_post = false, null $deprecated = null )

Description #

Return recent activity of question or answer.

Parameters #

  • $_post
    Wp_Post | integer | false (Optional) WordPress post object or false for global post. Default value: false
  • $deprecated
    null (Optional) Deprecated. Default value: null

Changelog #

VersionDescription
4.1.8Deprecated argument $get_cached.
4.1.2Introduced.

Source #

File: includes/activity.php

function ap_get_recent_activity( $_post = false, $deprecated = null ) {
	if ( null !== $deprecated ) {
		_deprecated_argument( __FUNCTION__, '4.1.8' );
	}

	global $wpdb;
	$_post = ap_get_post( $_post );

	// Return if not anspress posts.
	if ( ! ap_is_cpt( $_post ) ) {
		return;
	}

	$type     = $_post->post_type;
	$column   = 'answer' === $type ? 'a_id' : 'q_id';
	$activity = wp_cache_get( $_post->ID, 'ap_' . $column . '_activity' );

	if ( false === $activity ) {
		$q_where = '';

		if ( 'q_id' === $column && is_question() ) {
			$q_where = " AND (activity_a_id = 0 OR activity_action IN('new_a', 'unselected','selected') )";
		}

		$activity = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->ap_activity} WHERE activity_{$column} = %d$q_where ORDER BY activity_date DESC LIMIT 1", $_post->ID ) );

		// Parse.
		if ( $activity ) {
			$activity = ap_activity_parse( $activity );
		}

		// Set cache.
		wp_cache_set( $_post->ID, $activity, 'ap_' . $column . '_activity' );
	}

	return $activity;
}

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