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/actions/add-log.php +234 -0 5.7.7 → 6.0.4 View file →
@@ -1,0 +1,234 @@
1 +<?php
2 +/**
3 + * Add Log
4 + *
5 + * @package AutomatorWP\Integrations\AutomatorWP\Actions\Add_Log
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_Add_Log extends AutomatorWP_Integration_Action {
13 +
14 +
15 + /**
16 + * Log title
17 + *
18 + * @since 1.0.0
19 + *
20 + * @var string $log_title
21 + */
22 + public $log_title = '';
23 +
24 + /**
25 + * Initialize the action
26 + *
27 + * @since 1.0.0
28 + */
29 + public function __construct( $integration ) {
30 +
31 + $this->integration = $integration;
32 + $this->action = $integration . '_add_log';
33 +
34 + parent::__construct();
35 +
36 + }
37 +
38 + /**
39 + * Register the trigger
40 + *
41 + * @since 1.0.0
42 + */
43 + public function register() {
44 +
45 + automatorwp_register_action( $this->action, array(
46 + 'integration' => $this->integration,
47 + 'label' => __( 'Add log entry', 'automatorwp' ),
48 + 'select_option' => __( 'Add <strong>log</strong> entry', 'automatorwp' ),
49 + /* translators: %1$s: URL. */
50 + 'edit_label' => sprintf( __( 'Add %1$s entry', 'automatorwp' ), '{log}' ),
51 + /* translators: %1$s: URL. */
52 + 'log_label' => sprintf( __( 'Add %1$s entry', 'automatorwp' ), '{log}' ),
53 + 'options' => array(
54 + 'log' => array(
55 + //'from' => 'log',
56 + 'default' => __( 'log', 'automatorwp' ),
57 + 'fields' => array(
58 + 'log_title' => array(
59 + 'name' => __( 'Log Title:', 'automatorwp' ),
60 + 'desc' => __( 'The log title.', 'automatorwp' ),
61 + 'type' => 'text',
62 + 'default' => ''
63 + ),
64 + 'log_fields' => array(
65 + 'name' => __( 'Log Custom Fields:', 'automatorwp' ),
66 + 'desc' => __( 'Add the extra fields of your choice to display them on the log entry.', 'automatorwp' ),
67 + 'type' => 'group',
68 + 'classes' => 'automatorwp-fields-table',
69 + 'options' => array(
70 + 'add_button' => __( 'Add field', 'automatorwp' ),
71 + 'remove_button' => '<span class="dashicons dashicons-no-alt"></span>',
72 + ),
73 + 'fields' => array(
74 + 'field' => array(
75 + 'name' => __( 'Field:', 'automatorwp' ),
76 + 'type' => 'text',
77 + 'default' => ''
78 + ),
79 + 'value' => array(
80 + 'name' => __( 'Value:', 'automatorwp' ),
81 + 'type' => 'text',
82 + 'default' => ''
83 + ),
84 + ),
85 + ),
86 + )
87 + )
88 + ),
89 + ) );
90 +
91 + }
92 +
93 + /**
94 + * Action execution function
95 + *
96 + * @since 1.0.0
97 + *
98 + * @param stdClass $action The action object
99 + * @param int $user_id The user ID
100 + * @param array $action_options The action's stored options (with tags already passed)
101 + * @param stdClass $automation The action's automation object
102 + */
103 + public function execute( $action, $user_id, $action_options, $automation ) {
104 +
105 + $this->log_title = $action_options['log_title'];
106 +
107 + $this->result = __( 'Log entry added successfully.', 'automatorwp' );
108 +
109 + }
110 +
111 + /**
112 + * Register required hooks
113 + *
114 + * @since 1.0.0
115 + */
116 + public function hooks() {
117 +
118 + // Log data
119 + add_filter( 'automatorwp_parse_automation_item_log_label', array( $this, 'log_label' ), 10, 5 );
120 + add_filter( 'automatorwp_user_completed_action_log_meta', array( $this, 'log_meta' ), 10, 5 );
121 +
122 + // Log fields
123 + add_filter( 'automatorwp_log_fields', array( $this, 'log_fields' ), 10, 5 );
124 +
125 + parent::hooks();
126 + }
127 +
128 + /**
129 + * Action custom log label
130 + *
131 + * @since 1.0.0
132 + *
133 + * @param string $label The edit label
134 + * @param stdClass $object The trigger/action object
135 + * @param string $item_type The item type (trigger|action)
136 + * @param string $context The context this function is executed
137 + * @param array $type_args The type parameters
138 + *
139 + * @return string
140 + */
141 + public function log_label( $label, $object, $item_type, $context, $type_args ) {
142 +
143 + if( $item_type !== 'action' ) {
144 + return $label;
145 + }
146 +
147 + // Bail if action type don't match this action
148 + if( $object->type !== $this->action ) {
149 + return $label;
150 + }
151 +
152 + if( empty( $this->log_title ) ) {
153 + return $label;
154 + }
155 +
156 + return $this->log_title;
157 + }
158 +
159 + /**
160 + * Action custom log meta
161 + *
162 + * @since 1.0.0
163 + *
164 + * @param array $log_meta Log meta data
165 + * @param stdClass $action The action object
166 + * @param int $user_id The user ID
167 + * @param array $action_options The action's stored options (with tags already passed)
168 + * @param stdClass $automation The action's automation object
169 + *
170 + * @return array
171 + */
172 + public function log_meta( $log_meta, $action, $user_id, $action_options, $automation ) {
173 +
174 + // Bail if action type don't match this action
175 + if( $action->type !== $this->action ) {
176 + return $log_meta;
177 + }
178 +
179 + $log_fields = array();
180 +
181 + if( is_array( $action_options['log_fields'] ) ) {
182 + foreach( $action_options['log_fields'] as $field ) {
183 + $log_fields[$field['field']] = $field['value'];
184 + }
185 + }
186 +
187 + $log_meta['log_title'] = $action_options['log_title'];
188 + $log_meta['log_fields'] = $log_fields;
189 + $log_meta['result'] = $this->result;
190 +
191 + return $log_meta;
192 + }
193 +
194 + /**
195 + * Action custom log fields
196 + *
197 + * @since 1.0.0
198 + *
199 + * @param array $log_fields The log fields
200 + * @param stdClass $log The log object
201 + * @param stdClass $object The trigger/action/automation object attached to the log
202 + *
203 + * @return array
204 + */
205 + public function log_fields( $log_fields, $log, $object ) {
206 +
207 + // Bail if log is not assigned to an action
208 + if( $log->type !== 'action' ) {
209 + return $log_fields;
210 + }
211 +
212 + // Bail if action type don't match this action
213 + if( $object->type !== $this->action ) {
214 + return $log_fields;
215 + }
216 +
217 + $log_fields['log_fields'] = array(
218 + 'name' => __( 'Log Custom Fields:', 'automatorwp' ),
219 + 'desc' => __( 'The log custom fields.', 'automatorwp' ),
220 + 'type' => 'text',
221 + );
222 +
223 + $log_fields['result'] = array(
224 + 'name' => __( 'Result:', 'automatorwp' ),
225 + 'type' => 'text',
226 + );
227 +
228 + return $log_fields;
229 + }
230 +
231 +}
232 +
233 +new AutomatorWP_AutomatorWP_Add_Log( 'automatorwp' );
234 +new AutomatorWP_AutomatorWP_Add_Log( 'code' );