PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.1
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.1
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
automatorwp / integrations / clickup / includes / actions / add-comment-task.php

add-comment-task.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 6.0.1, at integrations/clickup/includes/actions/add-comment-task.php

247 lines 9.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Add Comment Task
4 *
5 * @package AutomatorWP\Integrations\ClickUp\Actions\Add_Comment_Task
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_ClickUp_Add_Comment_Task extends AutomatorWP_Integration_Action {
13
14 public $integration = 'clickup';
15 public $action = 'clickup_add_comment_task';
16
17 /**
18 * Register the trigger
19 *
20 * @since 1.0.0
21 */
22 public function register() {
23
24 automatorwp_register_action( $this->action, array(
25 'integration' => $this->integration,
26 'label' => __( 'Add comment to a task', 'automatorwp' ),
27 'select_option' => __( 'Add comment to a <strong>task</strong>', 'automatorwp' ),
28 /* translators: %1$s: Task. */
29 'edit_label' => sprintf( __( 'Add comment to a %1$s', 'automatorwp' ), '{task}' ),
30 /* translators: %1$s: Task. */
31 'log_label' => sprintf( __( 'Add comment to a %1$s', 'automatorwp' ), '{task}' ),
32 'options' => array(
33 'task' => array(
34 'from' => 'task',
35 'default' => __( 'task', 'automatorwp' ),
36 'fields' => array(
37 'team' => automatorwp_utilities_ajax_selector_field( array(
38 'name' => __( 'Team:', 'automatorwp' ),
39 'option_none' => false,
40 'action_cb' => 'automatorwp_clickup_get_teams',
41 'options_cb' => 'automatorwp_clickup_options_cb_team',
42 'placeholder' => 'Select a team',
43 ) ),
44 'space' => automatorwp_utilities_ajax_selector_field( array(
45 'name' => __( 'Space:', 'automatorwp' ),
46 'option_none' => false,
47 'action_cb' => 'automatorwp_clickup_get_spaces',
48 'options_cb' => 'automatorwp_clickup_options_cb_space',
49 'placeholder' => 'Select a space',
50 'default' => ''
51 ) ),
52 'folder' => automatorwp_utilities_ajax_selector_field( array(
53 'name' => __( 'Folder:', 'automatorwp' ),
54 'option_none' => false,
55 'action_cb' => 'automatorwp_clickup_get_folders',
56 'options_cb' => 'automatorwp_clickup_options_cb_folder',
57 'placeholder' => 'Select a folder',
58 'default' => ''
59 ) ),
60 'list' => automatorwp_utilities_ajax_selector_field( array(
61 'name' => __( 'List:', 'automatorwp' ),
62 'option_none' => false,
63 'action_cb' => 'automatorwp_clickup_get_lists',
64 'options_cb' => 'automatorwp_clickup_options_cb_list',
65 'placeholder' => 'Select a list',
66 'default' => ''
67 ) ),
68 'task' => automatorwp_utilities_ajax_selector_field( array(
69 'name' => __( 'Task:', 'automatorwp' ),
70 'option_none' => false,
71 'action_cb' => 'automatorwp_clickup_get_tasks',
72 'options_cb' => 'automatorwp_clickup_options_cb_task',
73 'placeholder' => 'Select a task',
74 'default' => ''
75 ) ),
76 'comment' => array(
77 'name' => __( 'Comment:', 'automatorwp' ),
78 'desc' => __( 'The comment to add to the task', 'automatorwp' ),
79 'type' => 'wysiwyg',
80 'required' => true,
81 'default' => ''
82 ),
83 ),
84 ),
85 ),
86 ) );
87
88 }
89
90
91 /**
92 * Action execution function
93 *
94 * @since 1.0.0
95 *
96 * @param stdClass $action The action object
97 * @param int $user_id The user ID
98 * @param array $action_options The action's stored options (with tags already passed)
99 * @param stdClass $automation The action's automation object
100 */
101 public function execute( $action, $user_id, $action_options, $automation ) {
102
103 // Shorthand
104 $task_id = $action_options['task'];
105 $comment_text = $action_options['comment'];
106
107 // Bail if comment is empty
108 if ( empty ( $comment_text ) ) {
109 return;
110 }
111
112 $user = get_user_by ( 'ID', $user_id );
113
114 $this->result = '';
115
116 // Bail if ClickUp not configured
117 if( ! automatorwp_clickup_get_api() ) {
118 $this->result = __( 'ClickUp integration not configured in AutomatorWP settings.', 'automatorwp-clickup' );
119 return;
120 }
121
122 $response = automatorwp_clickup_add_comment( $task_id, $comment_text );
123
124 // Create list if not exist
125 if ( $response === 200 ) {
126 $this->result = __( 'Created comment in task', 'automatorwp-clickup' );
127 } else {
128 $this->result = __( 'The comment could not be created', 'automatorwp-clickup' );
129 }
130
131 }
132
133 /**
134 * Register required hooks
135 *
136 * @since 1.0.0
137 */
138 public function hooks() {
139
140 // Configuration notice
141 add_filter( 'automatorwp_automation_ui_after_item_label', array( $this, 'configuration_notice' ), 10, 2 );
142
143 // Log meta data
144 add_filter( 'automatorwp_user_completed_action_log_meta', array( $this, 'log_meta' ), 10, 5 );
145
146 // Log fields
147 add_filter( 'automatorwp_log_fields', array( $this, 'log_fields' ), 10, 5 );
148
149 parent::hooks();
150
151 }
152
153 /**
154 * Configuration notice
155 *
156 * @since 1.0.0
157 *
158 * @param stdClass $object The trigger/action object
159 * @param string $item_type The object type (trigger|action)
160 */
161 public function configuration_notice( $object, $item_type ) {
162
163 // Bail if action type don't match this action
164 if( $item_type !== 'action' ) {
165 return;
166 }
167
168 if( $object->type !== $this->action ) {
169 return;
170 }
171
172 // Warn user if the authorization has not been setup from settings
173 if( ! automatorwp_clickup_get_api() ) : ?>
174 <div class="automatorwp-notice-warning" style="margin-top: 10px; margin-bottom: 0;">
175 <?php echo sprintf(
176 __( 'You need to configure the <a href="%s" target="_blank">ClickUp settings</a> to get this action to work.', 'automatorwp-clickup' ),
177 get_admin_url() . 'admin.php?page=automatorwp_settings&tab=opt-tab-clickup'
178 ); ?>
179 <?php echo sprintf(
180 __( '<a href="%s" target="_blank">Documentation</a>', 'automatorwp-clickup' ),
181 'https://automatorwp.com/docs/clickup/'
182 ); ?>
183 </div>
184 <?php endif;
185
186 }
187
188 /**
189 * Action custom log meta
190 *
191 * @since 1.0.0
192 *
193 * @param array $log_meta Log meta data
194 * @param stdClass $action The action object
195 * @param int $user_id The user ID
196 * @param array $action_options The action's stored options (with tags already passed)
197 * @param stdClass $automation The action's automation object
198 *
199 * @return array
200 */
201 public function log_meta( $log_meta, $action, $user_id, $action_options, $automation ) {
202
203 // Bail if action type don't match this action
204 if( $action->type !== $this->action ) {
205 return $log_meta;
206 }
207
208 // Store the action's result
209 $log_meta['result'] = $this->result;
210
211 return $log_meta;
212 }
213
214 /**
215 * Action custom log fields
216 *
217 * @since 1.0.0
218 *
219 * @param array $log_fields The log fields
220 * @param stdClass $log The log object
221 * @param stdClass $object The trigger/action/automation object attached to the log
222 *
223 * @return array
224 */
225 public function log_fields( $log_fields, $log, $object ) {
226
227 // Bail if log is not assigned to an action
228 if( $log->type !== 'action' ) {
229 return $log_fields;
230 }
231
232 // Bail if action type don't match this action
233 if( $object->type !== $this->action ) {
234 return $log_fields;
235 }
236
237 $log_fields['result'] = array(
238 'name' => __( 'Result:', 'automatorwp-clickup' ),
239 'type' => 'text',
240 );
241
242 return $log_fields;
243 }
244
245 }
246
247 new AutomatorWP_ClickUp_Add_Comment_Task();