Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

LLMS_Engagements::get_engagements( string $trigger_type, int|string $related_post_id = '' )

Retrieve engagements based on the trigger type


Description Description

Joins rather than nested loops and sub queries ftw.


Top ↑

Parameters Parameters

$trigger_type

(string) (Required) Name of the trigger to look for.

$related_post_id

(int|string) (Optional) The WP_Post ID of the related post or an empty string.

Default value: ''


Top ↑

Return Return

(object[]) Array of objects from the database.

  • 'engagement_id'
    (int) WP_Post ID of the engagement post (email, certificate, achievement).
  • 'trigger_id'
    (int) WP_Post ID of the llms_engagement post.
  • 'trigger_event'
    (string) The triggering action (user_registration, course_completed, etc...).
  • 'event_type'
    (string) The engagement event action (certificate, achievement, email).
  • 'delay'
    (int) The engagement send delay (in days).


Top ↑

Source Source

File: includes/class.llms.engagements.php

	private function get_engagements( $trigger_type, $related_post_id = '' ) {

		global $wpdb;

		$related_select = '';
		$related_join   = '';
		$related_where  = '';

		if ( $related_post_id ) {

			$related_select = ', relation_meta.meta_value AS related_post_id';
			$related_join   = "LEFT JOIN $wpdb->postmeta AS relation_meta ON triggers.ID = relation_meta.post_id";
			$related_where  = $wpdb->prepare( "AND relation_meta.meta_key = '_llms_engagement_trigger_post' AND relation_meta.meta_value = %d", $related_post_id );

		}

		// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
		$results = $wpdb->get_results(
			$wpdb->prepare(
				"SELECT
				  DISTINCT triggers.ID AS trigger_id
				, triggers_meta.meta_value AS engagement_id
				, engagements_meta.meta_value AS trigger_event
				, event_meta.meta_value AS event_type
				, delay.meta_value AS delay
				$related_select

			FROM $wpdb->postmeta AS engagements_meta

			LEFT JOIN $wpdb->posts AS triggers ON triggers.ID = engagements_meta.post_id
			LEFT JOIN $wpdb->postmeta AS triggers_meta ON triggers.ID = triggers_meta.post_id
			LEFT JOIN $wpdb->posts AS engagements ON engagements.ID = triggers_meta.meta_value
			LEFT JOIN $wpdb->postmeta AS event_meta ON triggers.ID = event_meta.post_id
			LEFT JOIN $wpdb->postmeta AS delay ON triggers.ID = delay.post_id
			$related_join

			WHERE
				    triggers.post_type = 'llms_engagement'
				AND triggers.post_status = 'publish'
				AND triggers_meta.meta_key = '_llms_engagement'

				AND engagements_meta.meta_key = '_llms_trigger_type'
				AND engagements_meta.meta_value = %s
				AND engagements.post_status = 'publish'

				AND event_meta.meta_key = '_llms_engagement_type'

				AND delay.meta_key = '_llms_engagement_delay'

				$related_where
			",
				// Prepare variables.
				$trigger_type
			),
			OBJECT
		); // no-cache ok.
		// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared

		/**
		 * Filters the list of engagements to be triggered for a given trigger type and related post.
		 *
		 * @since 6.0.0
		 *
		 * @param object[] $results         Array of engagement objects.
		 * @param string   $trigger_type    Name of the engagement trigger.
		 * @param int      $related_post_id WP_Post ID of the related post.
		 */
		return apply_filters( 'lifterlms_get_engagements', $results, $trigger_type, $related_post_id );

	}


Top ↑

Changelog Changelog

Changelog
Version Description
6.0.0 Removed engagement debug logging & moved filter onto the return instead of calling in maybe_trigger_engagement().
3.13.1 Unknown.
2.3.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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