LLMS_Events_Core

LLMS_Events_Core class


Source Source

File: includes/class-llms-events-core.php

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class LLMS_Events_Core {
 
    /**
     * Constructor.
     *
     * @since 3.36.0
     *
     * @return void
     */
    public function __construct() {
 
        add_action( 'wp_login', array( $this, 'on_signon' ), 10, 2 );
        add_action( 'clear_auth_cookie', array( $this, 'on_signout' ) );
 
    }
 
    /**
     * Record account.signon event via `wp_login` hook.
     *
     * @since 3.36.0
     *
     * @param string  $username WP_Users's user_login.
     * @param WP_User $user     User object.
     * @return LLMS_Event
     */
    public function on_signon( $username, $user ) {
 
        return llms()->events()->record(
            array(
                'actor_id'     => $user->ID,
                'object_type'  => 'user',
                'object_id'    => $user->ID,
                'event_type'   => 'account',
                'event_action' => 'signon',
            )
        );
 
    }
 
    /**
     * Record an account.signout event via `wp_logout()`
     *
     * @since 3.36.0
     * @since 4.5.0 Return `false` without recording any event if no user was logged in.
     *
     * @return LLMS_Event|false The instance of the `LLMS_Event` recorded or `false` when no user was logged in.
     */
    public function on_signout() {
 
        $uid = get_current_user_id();
 
        if ( ! $uid ) {
            return false;
        }
 
        return llms()->events()->record(
            array(
                'actor_id'     => $uid,
                'object_type'  => 'user',
                'object_id'    => $uid,
                'event_type'   => 'account',
                'event_action' => 'signout',
            )
        );
 
    }
 
}

Top ↑

Methods Methods


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.