PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.3
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.3
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 5.6.1 All 34 releases
← All changes | integrations/fluentcommunity/includes/triggers/comment-added.php +193 -0 5.7.2 → 6.0.3 View file →
@@ -1,0 +1,193 @@
1 +<?php
2 +/**
3 + * Comment Added
4 + *
5 + * @package AutomatorWP\Integrations\FluentCommunity\Triggers\Comment_Added
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_FluentCommunity_Comment_Added extends AutomatorWP_Integration_Trigger {
13 +
14 + public $integration = 'fluentcommunity';
15 + public $trigger = 'fluentcommunity_comment_added';
16 +
17 + /**
18 + * Register the trigger
19 + *
20 + * @since 1.0.0
21 + */
22 + public function register() {
23 +
24 + automatorwp_register_trigger($this->trigger, array(
25 + 'integration' => $this->integration,
26 + 'label' => __( 'User adds a comment in a space', 'automatorwp' ),
27 + 'select_option' => __( 'User adds a <strong>comment</strong> in a space', 'automatorwp' ),
28 + /* translators: %1$s: Space title. %2$s: Number of times. */
29 + 'edit_label' => sprintf( __( 'User adds a comment in %1$s %2$s time(s)', 'automatorwp' ), '{space}', '{times}' ),
30 + /* translators: %1$s: Space title. */
31 + 'log_label' => sprintf( __( 'User adds a comment in %1$s', 'automatorwp' ), '{space}' ),
32 + 'action' => 'fluent_community/comment_added',
33 + 'function' => array($this, 'listener'),
34 + 'priority' => 10,
35 + 'accepted_args' => 2,
36 + 'options' => array(
37 + 'space' => automatorwp_utilities_ajax_selector_option( array(
38 + 'field' => 'space',
39 + 'name' => __( 'Space:', 'automatorwp' ),
40 + 'option_none_value' => 'any',
41 + 'option_none_label' => __( 'any space', 'automatorwp' ),
42 + 'action_cb' => 'automatorwp_fluentcommunity_get_spaces',
43 + 'options_cb' => 'automatorwp_fluentcommunity_options_cb_space',
44 + 'default' => 'any'
45 + ) ),
46 + 'times' => automatorwp_utilities_times_option(),
47 + ),
48 + 'tags' => array_merge(
49 + automatorwp_utilities_times_tag()
50 + )
51 + ));
52 + }
53 +
54 + /**
55 + * Trigger listener
56 + *
57 + * @since 1.0.0
58 + *
59 + * @param object $comment
60 + * @param object $feed
61 + */
62 + public function listener( $comment, $feed ) {
63 +
64 + $user_id = get_current_user_id();
65 +
66 + // Login is required
67 + if ( $user_id === 0 ) {
68 + return;
69 + }
70 +
71 + $comment_data = $comment->getOriginal();
72 + $feed_data = $feed->getOriginal();
73 +
74 + // Trigger event when user adds a comment
75 + automatorwp_trigger_event(array(
76 + 'trigger' => $this->trigger,
77 + 'user_id' => $user_id,
78 + 'comment' => $comment_data['message'],
79 + 'comment_id' => $comment_data['id'],
80 + 'space_id' => $feed_data['space_id'],
81 + ));
82 + }
83 +
84 + /**
85 + * User deserves check
86 + *
87 + * @since 1.0.0
88 + *
89 + * @param bool $deserves_trigger True if user deserves trigger, false otherwise
90 + * @param stdClass $trigger The trigger object
91 + * @param int $user_id The user ID
92 + * @param array $event Event information
93 + * @param array $trigger_options The trigger's stored options
94 + * @param stdClass $automation The trigger's automation object
95 + *
96 + * @return bool True if user deserves trigger, false otherwise
97 + */
98 +
99 +
100 + public function user_deserves_trigger( $deserves_trigger, $trigger, $user_id, $event, $trigger_options, $automation ) {
101 +
102 + // Don't deserve if post is not received
103 + if( ! isset( $event['space_id'] ) ) {
104 + return false;
105 + }
106 +
107 + // Don't deserve if post doesn't match with the trigger option
108 + if( $trigger_options['space'] !== 'any' && absint( $trigger_options['space'] ) !== absint( $event['space_id'] ) ) {
109 + return false;
110 + }
111 +
112 + return $deserves_trigger;
113 +
114 + }
115 +
116 + /**
117 + * Register the required hooks
118 + *
119 + * @since 1.0.0
120 + */
121 + public function hooks() {
122 +
123 + // Log meta data
124 + add_filter( 'automatorwp_user_completed_trigger_log_meta', array( $this, 'log_meta' ), 10, 6 );
125 +
126 + // Log fields
127 + add_filter( 'automatorwp_log_fields', array( $this, 'log_fields' ), 10, 5 );
128 +
129 + parent::hooks();
130 + }
131 +
132 + /**
133 + * Trigger custom log meta
134 + *
135 + * @since 1.0.0
136 + *
137 + * @param array $log_meta Log meta data
138 + * @param stdClass $trigger The trigger object
139 + * @param int $user_id The user ID
140 + * @param array $event Event information
141 + * @param array $trigger_options The trigger's stored options
142 + * @param stdClass $automation The trigger's automation object
143 + *
144 + * @return array
145 + */
146 + function log_meta( $log_meta, $trigger, $user_id, $event, $trigger_options, $automation ) {
147 +
148 + // Bail if action type don't match this action
149 + if( $trigger->type !== $this->trigger ) {
150 + return $log_meta;
151 + }
152 +
153 + $log_meta['comment'] = ( isset( $event['comment'] ) ? $event['comment'] : array() );
154 +
155 + return $log_meta;
156 +
157 + }
158 +
159 + /**
160 + * Action custom log fields
161 + *
162 + * @since 1.0.0
163 + *
164 + * @param array $log_fields The log fields
165 + * @param stdClass $log The log object
166 + * @param stdClass $object The trigger/action/automation object attached to the log
167 + *
168 + * @return array
169 + */
170 + public function log_fields( $log_fields, $log, $object ) {
171 +
172 + // Bail if log is not assigned to an trigger
173 + if( $log->type !== 'trigger' ) {
174 + return $log_fields;
175 + }
176 +
177 + // Bail if trigger type don't match this trigger
178 + if( $object->type !== $this->trigger ) {
179 + return $log_fields;
180 + }
181 +
182 + $log_fields['comment'] = array(
183 + 'name' => __( 'Comment', 'automatorwp' ),
184 + 'type' => 'text',
185 + );
186 +
187 + return $log_fields;
188 +
189 + }
190 +
191 +}
192 +
193 +new AutomatorWP_FluentCommunity_Comment_Added();