| 1 |
<?php |
| 2 |
/** |
| 3 |
* Login |
| 4 |
* |
| 5 |
* @package AutomatorWP\Integrations\WordPress\Triggers\Login |
| 6 |
* @author AutomatorWP <contact@automatorwp.com>, Ruben Garcia <rubengcdev@gmail.com> |
| 7 |
* @since 1.0.0 |
| 8 |
*/ |
| 9 |
// Exit if accessed directly |
| 10 |
if( !defined( 'ABSPATH' ) ) exit; |
| 11 |
|
| 12 |
class AutomatorWP_WordPress_Login extends AutomatorWP_Integration_Trigger { |
| 13 |
|
| 14 |
/** |
| 15 |
* Initialize the trigger |
| 16 |
* |
| 17 |
* @since 1.0.0 |
| 18 |
*/ |
| 19 |
public function __construct( $integration ) { |
| 20 |
|
| 21 |
$this->integration = $integration; |
| 22 |
$this->trigger = $integration . '_login'; |
| 23 |
|
| 24 |
parent::__construct(); |
| 25 |
|
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Register the trigger |
| 30 |
* |
| 31 |
* @since 1.0.0 |
| 32 |
*/ |
| 33 |
public function register() { |
| 34 |
|
| 35 |
automatorwp_register_trigger( $this->trigger, array( |
| 36 |
'integration' => $this->integration, |
| 37 |
'label' => __( 'User logs in to the site', 'automatorwp' ), |
| 38 |
'select_option' => __( 'User <strong>logs in</strong> to the site', 'automatorwp' ), |
| 39 |
/* translators: %1$s: Number of times. */ |
| 40 |
'edit_label' => sprintf( __( 'User logs in %1$s time(s)', 'automatorwp' ), '{times}' ), |
| 41 |
'log_label' => __( 'User logs in', 'automatorwp' ), |
| 42 |
'action' => 'wp_login', |
| 43 |
'function' => array( $this, 'listener' ), |
| 44 |
'priority' => 10, |
| 45 |
'accepted_args' => 2, |
| 46 |
'options' => array( |
| 47 |
'times' => automatorwp_utilities_times_option() |
| 48 |
), |
| 49 |
'tags' => array( |
| 50 |
'times' => automatorwp_utilities_times_tag( true ) |
| 51 |
) |
| 52 |
) ); |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Trigger listener |
| 58 |
* |
| 59 |
* @since 1.0.0 |
| 60 |
* |
| 61 |
* @param string $user_login |
| 62 |
* @param WP_User $user |
| 63 |
*/ |
| 64 |
public function listener( $user_login, $user ) { |
| 65 |
|
| 66 |
$user_id = $user->ID; |
| 67 |
|
| 68 |
automatorwp_trigger_event( array( |
| 69 |
'trigger' => $this->trigger, |
| 70 |
'user_id' => $user_id, |
| 71 |
) ); |
| 72 |
|
| 73 |
} |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
new AutomatorWP_WordPress_Login( 'wordpress' ); |
| 78 |
new AutomatorWP_WordPress_Login( 'users' ); |