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()
Return Return
(array)
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; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.36.0 | Introduced. |