0 ) ? (int) $state['expires_on'] : null; $has_access = array_key_exists( 'has_access', $state ) ? $state['has_access'] : null; $result = $this->unknown( __( 'Not enough information to verify this event safely.', 'accesstrace-for-learndash' ) ); if ( EVLFL_Event::ACTION_ENROLLED === $event['action'] ) { if ( null !== $expires_on && $expires_on <= $now ) { $result = $this->result( 'invalid', __( 'Enrolled, but the recorded course access expiration is already in the past.', 'accesstrace-for-learndash' ), 'detected' ); } elseif ( null !== $expires_on || true === $has_access ) { $result = $this->result( 'valid', __( 'Enrolled with course access that has not expired; no conflicting indicators were found.', 'accesstrace-for-learndash' ), 'detected' ); } else { $result = $this->unknown( __( 'The resulting access state could not be confirmed at event time.', 'accesstrace-for-learndash' ) ); } } elseif ( EVLFL_Event::ACTION_UNENROLLED === $event['action'] ) { $by_admin = 'admin' === $event['actor_type'] && 'manual' === $event['event_trigger']; $expired_trig = 'course_access_expired' === $event['event_trigger']; $future_expiry = null !== $expires_on && $expires_on > $now; if ( $future_expiry && ! $by_admin ) { $result = $this->result( 'invalid', __( 'Unenrolled although the course access expiration is still in the future, and no administrator action was detected.', 'accesstrace-for-learndash' ), 'inferred' ); } elseif ( 'access_reset' === $event['event_trigger'] ) { $result = $this->result( 'valid', __( 'Access was removed and granted again within the same WooCommerce order request. This matches how LearnDash restarts expired access on a repeat purchase; the user ends up enrolled.', 'accesstrace-for-learndash' ), 'inferred' ); } elseif ( $expired_trig ) { $result = $this->result( 'valid', __( 'LearnDash reported the course access as expired for this user and course.', 'accesstrace-for-learndash' ), 'confirmed' ); } elseif ( null !== $expires_on ) { $result = $this->result( 'valid', __( 'Course access expiration had passed, which is consistent with the unenrollment.', 'accesstrace-for-learndash' ), 'inferred' ); } elseif ( $by_admin ) { $result = $this->result( 'valid', __( 'Unenrolled by a deliberate administrator action; no conflicting access indicators were found.', 'accesstrace-for-learndash' ), 'detected' ); } else { $result = $this->unknown( __( 'Unenrolled, but the cause could not be determined with the information available.', 'accesstrace-for-learndash' ) ); } } $filtered = apply_filters( 'evlfl_verify_event', $result, $event, $context, $state ); if ( is_array( $filtered ) && isset( $filtered['status'] ) && isset( EVLFL_Event::get_statuses()[ $filtered['status'] ] ) ) { $result = array( 'status' => $filtered['status'], 'verification_reason' => isset( $filtered['verification_reason'] ) ? (string) $filtered['verification_reason'] : $result['verification_reason'], 'confidence' => isset( $filtered['confidence'] ) ? (string) $filtered['confidence'] : 'unknown', ); } return $result; } /** * Build a result. * * @param string $status Status. * @param string $reason Reason. * @param string $confidence Confidence. * @return array */ private function result( $status, $reason, $confidence ) { return array( 'status' => $status, 'verification_reason' => $reason, 'confidence' => $confidence, ); } /** * Unknown result. * * @param string $reason Reason. * @return array */ private function unknown( $reason ) { return $this->result( 'unknown', $reason, 'unknown' ); } }