LLMS_Events::prepare_event( array $raw_event = array() )

Prepares partial events from client-side event data.


Parameters Parameters

$raw_event

(array) (Optional) Raw event from client-side data.

Default value: array()


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/class-llms-events.php

	public function prepare_event( $raw_event = array() ) {

		if ( ! isset( $raw_event['event'] ) ) {
			// Translators: %s = Event field key.
			return new WP_Error( 'llms_events_missing_event', sprintf( __( 'The event is missing the "%s" field.', 'lifterlms' ), 'event' ) );
		}

		$event    = explode( '.', $raw_event['event'] );
		$prepared = array(
			'actor_id'     => get_current_user_id(),
			'event_type'   => $event[0],
			'event_action' => $event[1],
			'meta'         => isset( $raw_event['meta'] ) ? $raw_event['meta'] : array(),
		);

		// Convert timestamps to MYSQL date.
		if ( isset( $raw_event['time'] ) && is_numeric( $raw_event['time'] ) ) {
			$prepared['date'] = date( 'Y-m-d H:i:s', $raw_event['time'] );
		}

		if ( isset( $raw_event['url'] ) ) {
			$id = url_to_postid( $raw_event['url'] );
			if ( ! $id ) {
				// Translators: %s = URL.
				return new WP_Error( 'llms_events_invalid_url', sprintf( __( 'The URL "%s" cannot be mapped to a valid post object.', 'lifterlms' ), esc_url( $raw_event['url'] ) ) );
			}
			$prepared['object_id']   = $id;
			$prepared['object_type'] = str_replace( 'llms_', '', get_post_type( $id ) );
		} elseif ( isset( $raw_event['object_id'] ) && isset( $raw_event['object_type'] ) ) {
			$prepared['object_id']   = $raw_event['object_id'];
			$prepared['object_type'] = $raw_event['object_type'];
		}

		return $prepared;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
3.36.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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