BP_Activity_Activity::get_id( int $user_id, string $component, string $type, int $item_id, int $secondary_item_id, string $action, string $content, string $date_recorded )

Get the first activity ID that matches a set of criteria.


Description Description


Parameters Parameters

$user_id

(Required) User ID to filter by.

$component

(Required) Component to filter by.

$type

(Required) Activity type to filter by.

$item_id

(Required) Associated item to filter by.

$secondary_item_id

(Required) Secondary associated item to filter by.

$action

(Required) Action to filter by.

$content

(Required) Content to filter by.

$date_recorded

(Required) Date to filter by.


Top ↑

Return Return

(int|false) Activity ID on success, false if none is found.


Top ↑

Source Source

File: bp-activity/classes/class-bp-activity-activity.php

	public static function get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) {
		global $wpdb;

		$bp = buddypress();

		$where_args = false;

		if ( ! empty( $user_id ) ) {
			$where_args[] = $wpdb->prepare( "user_id = %d", $user_id );
		}

		if ( ! empty( $component ) ) {
			$where_args[] = $wpdb->prepare( "component = %s", $component );
		}

		if ( ! empty( $type ) ) {
			$where_args[] = $wpdb->prepare( "type = %s", $type );
		}

		if ( ! empty( $item_id ) ) {
			$where_args[] = $wpdb->prepare( "item_id = %d", $item_id );
		}

		if ( ! empty( $secondary_item_id ) ) {
			$where_args[] = $wpdb->prepare( "secondary_item_id = %d", $secondary_item_id );
		}

		if ( ! empty( $action ) ) {
			$where_args[] = $wpdb->prepare( "action = %s", $action );
		}

		if ( ! empty( $content ) ) {
			$where_args[] = $wpdb->prepare( "content = %s", $content );
		}

		if ( ! empty( $date_recorded ) ) {
			$where_args[] = $wpdb->prepare( "date_recorded = %s", $date_recorded );
		}

		if ( ! empty( $where_args ) ) {
			$where_sql = 'WHERE ' . join( ' AND ', $where_args );
			$result = $wpdb->get_var( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" );

			return is_numeric( $result ) ? (int) $result : false;
		}

		return false;
	}

Top ↑

Changelog Changelog

Changelog
Version Description
1.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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