PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.4
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.4
6.0.4 6.0.3 6.0.2 6.0.1 6.0.0 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 5.7.9.2 5.7.9.1 5.7.8 5.7.9 5.7.6 5.7.7 5.7.5 5.7.4 5.7.3 5.7.2 5.7.1 trunk 5.6.0 All 35 releases
← All changes | integrations/automatorwp/triggers/user-created.php +156 -0 5.7.1 → 6.0.4 View file →
@@ -1,0 +1,156 @@
1 +<?php
2 +/**
3 + * User Created
4 + *
5 + * @package AutomatorWP\Integrations\AutomatorWP\Triggers\User_Created
6 + * @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]>
7 + * @since 1.0.0
8 + */
9 +// Exit if accessed directly
10 +if( !defined( 'ABSPATH' ) ) exit;
11 +
12 +class AutomatorWP_AutomatorWP_User_Created 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 . '_user_created';
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 gets created through an automation', 'automatorwp' ),
38 + 'select_option' => __( 'User gets created through <strong>an automation</strong>', 'automatorwp' ),
39 + /* translators: %1$s: Automation title. %2$s: Number of times. */
40 + 'edit_label' => sprintf( __( 'User gets created through %1$s %2$s time(s)', 'automatorwp' ), '{automation}', '{times}' ),
41 + /* translators: %1$s: Automation title. */
42 + 'log_label' => sprintf( __( 'User gets created through %1$s', 'automatorwp' ), '{automation}' ),
43 + 'action' => 'automatorwp_wordpress_create_user_executed',
44 + 'function' => array( $this, 'listener' ),
45 + 'priority' => 10,
46 + 'accepted_args' => 5,
47 + 'options' => array(
48 + 'automation' => automatorwp_utilities_automation_option(),
49 + 'times' => automatorwp_utilities_times_option(),
50 + ),
51 + 'tags' => array_merge(
52 + automatorwp_utilities_times_tag()
53 + )
54 + ) );
55 +
56 + }
57 +
58 + /**
59 + * Register the trigger listener hook
60 + *
61 + * @since 1.0.0
62 + */
63 + public function register_listener_hook() {
64 +
65 + parent::register_listener_hook();
66 +
67 + if( automatorwp_is_trigger_in_use( $this->trigger ) ) {
68 + // Support for anonymous users
69 + add_action( 'automatorwp_anonymous_user_created', array( $this, 'anonymous_listener' ), 10, 4 );
70 + }
71 +
72 + }
73 + /**
74 + * Trigger listener
75 + *
76 + * @since 1.0.0
77 + *
78 + * @param int $new_user_id The new user ID
79 + * @param stdClass $action The action object
80 + * @param array $action_options The action's stored options (with tags already passed, included on meta keys and values)
81 + * @param stdClass $automation The action's automation object
82 + */
83 + public function anonymous_listener( $new_user_id, $action, $action_options, $automation ) {
84 +
85 + automatorwp_trigger_event( array(
86 + 'trigger' => $this->trigger,
87 + 'user_id' => $new_user_id,
88 + 'automation_id' => $automation->id,
89 + ) );
90 +
91 + }
92 +
93 + /**
94 + * Trigger listener
95 + *
96 + * @since 1.0.0
97 + *
98 + * @param int $new_user_id The new user ID
99 + * @param stdClass $action The action object
100 + * @param int $user_id The user ID (user who triggered the automation)
101 + * @param array $action_options The action's stored options (with tags already passed, included on meta keys and values)
102 + * @param stdClass $automation The action's automation object
103 + */
104 + public function listener( $new_user_id, $action, $user_id, $action_options, $automation ) {
105 +
106 + automatorwp_trigger_event( array(
107 + 'trigger' => $this->trigger,
108 + 'user_id' => $new_user_id,
109 + 'automation_id' => $automation->id,
110 + ) );
111 +
112 + }
113 +
114 + /**
115 + * User deserves check
116 + *
117 + * @since 1.0.0
118 + *
119 + * @param bool $deserves_trigger True if user deserves trigger, false otherwise
120 + * @param stdClass $trigger The trigger object
121 + * @param int $user_id The user ID
122 + * @param array $event Event information
123 + * @param array $trigger_options The trigger's stored options
124 + * @param stdClass $automation The trigger's automation object
125 + *
126 + * @return bool True if user deserves trigger, false otherwise
127 + */
128 + public function user_deserves_trigger( $deserves_trigger, $trigger, $user_id, $event, $trigger_options, $automation ) {
129 +
130 + // Don't deserve if automation is not received
131 + if( ! isset( $event['automation_id'] ) ) {
132 + return false;
133 + }
134 +
135 + $automation = automatorwp_get_automation_object( absint( $event['automation_id'] ) );
136 +
137 + // Don't deserve if automation doesn't exists
138 + if( ! $automation ) {
139 + return false;
140 + }
141 +
142 + $automation_id = absint( $trigger_options['automation'] );
143 +
144 + // Don't deserve if automation doesn't match with the trigger option
145 + if( $automation_id !== 0 && absint( $automation->id ) !== $automation_id ) {
146 + return false;
147 + }
148 +
149 + return $deserves_trigger;
150 +
151 + }
152 +
153 +}
154 +
155 +new AutomatorWP_AutomatorWP_User_Created( 'automatorwp' );
156 +new AutomatorWP_AutomatorWP_User_Created( 'users' );