PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 3.06.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v3.06.06
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmFormAction.php +235 -407 6.43.06.06 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -if ( ! defined( 'ABSPATH' ) ) {
3 - die( 'You are not allowed to call this page directly.' );
4 -}
5 2
6 3 class FrmFormAction {
7 4
8 5 public $id_base; // Root id for all actions of this type.
@@ -24,9 +21,8 @@
24 21 * If "false" is returned, the instance won't be saved/updated.
25 22 *
26 23 * @param array $new_instance New settings for this instance as input by the user via form()
27 24 * @param array $old_instance Old settings for this instance
28 - *
29 25 * @return array Settings to save or bool false to cancel saving
30 26 */
31 27 public function update( $new_instance, $old_instance ) {
32 28 return $new_instance;
@@ -32,15 +28,14 @@
32 28 return $new_instance;
33 29 }
34 30
35 31 /**
36 - * Echo the settings update form
32 + * Echo the settings update form
37 33 *
38 34 * @param array $instance Current settings
39 35 */
40 36 public function form( $instance, $args = array() ) {
41 37 echo '<p class="no-options-widget">' . esc_html__( 'There are no options for this action.', 'formidable' ) . '</p>';
42 -
43 38 return 'noform';
44 39 }
45 40
46 41 /**
@@ -46,20 +41,17 @@
46 41 /**
47 42 * @return array of the default options
48 43 */
49 44 public function get_defaults() {
50 - return array();
45 + return array();
51 46 }
52 47
53 - /**
54 - * @return array
55 - */
56 48 public function get_switch_fields() {
57 - return array();
49 + return array();
58 50 }
59 51
60 52 public function migrate_values( $action, $form ) {
61 - return $action;
53 + return $action;
62 54 }
63 55
64 56 // Functions you'll need to call.
65 57
@@ -80,50 +72,26 @@
80 72 if ( ! defined( 'ABSPATH' ) ) {
81 73 die( 'You are not allowed to call this page directly.' );
82 74 }
83 75
84 - $this->id_base = strtolower( $id_base );
85 - $this->name = $name;
76 + $this->id_base = strtolower( $id_base );
77 + $this->name = $name;
86 78 $this->option_name = 'frm_' . $this->id_base . '_action';
87 79
88 - $default_options = array(
89 - 'classes' => '',
90 - 'active' => true,
91 - 'event' => array( 'create' ),
92 - 'limit' => 1,
93 - 'force_event' => false,
94 - 'priority' => 20,
95 - 'ajax_load' => true,
96 - 'plugin' => $this->id_base,
97 - 'tooltip' => $name,
98 - 'group' => $id_base,
99 - 'color' => '',
100 - 'keywords' => '',
101 - );
80 + $default_options = array(
81 + 'classes' => '',
82 + 'active' => true,
83 + 'event' => array( 'create' ),
84 + 'limit' => 1,
85 + 'force_event' => false,
86 + 'priority' => 20,
87 + 'ajax_load' => true,
88 + 'plugin' => $this->id_base,
89 + 'tooltip' => $name,
90 + );
102 91
103 - $action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options );
104 - $group = $this->get_group( $action_options );
105 - $action_options['group'] = $group['id'];
106 -
107 - if ( ! isset( $action_options['color'] ) ) {
108 - $colors = array( 'green', 'orange', 'purple' );
109 - shuffle( $colors );
110 - $action_options['color'] = 'var(--' . reset( $colors ) . ')';
111 - }
112 -
113 - $upgrade_class = isset( $action_options['classes'] ) && $action_options['classes'] === 'frm_show_upgrade';
114 - if ( $action_options['group'] === $id_base ) {
115 - $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false;
116 - $action_options['classes'] = $group['icon'];
117 - } elseif ( ! isset( $action_options['classes'] ) || empty( $action_options['classes'] ) || $upgrade_class ) {
118 - $action_options['classes'] = $group['icon'];
119 - }
120 -
121 - if ( $upgrade_class ) {
122 - $action_options['classes'] .= ' frm_show_upgrade';
123 - }
124 -
125 - $this->action_options = wp_parse_args( $action_options, $default_options );
92 + $action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options );
93 + $this->action_options = wp_parse_args( $action_options, $default_options );
126 94 $this->control_options = wp_parse_args( $control_options, array( 'id_base' => $this->id_base ) );
127 95 }
128 96
129 97 /**
@@ -133,53 +101,13 @@
133 101 self::__construct( $id_base, $name, $action_options, $control_options );
134 102 }
135 103
136 104 /**
137 - * Help to switch old field id by new field id for duplicate form
138 - *
139 - * @param string $action id of the field that needs to be switched
140 - *
141 - * @return string
142 - */
143 - public function maybe_switch_field_ids( $action ) {
144 - $updated_action = apply_filters( 'frm_maybe_switch_field_ids', $action );
145 - if ( $updated_action === $action ) {
146 - $updated_action = FrmFieldsHelper::switch_field_ids( $action );
147 - }
148 - return $updated_action;
149 - }
150 -
151 - /**
152 - * @since 4.0
153 - */
154 - protected function get_group( $action_options ) {
155 - $groups = FrmFormActionsController::form_action_groups();
156 - $group = 'misc';
157 -
158 - if ( isset( $action_options['group'] ) && isset( $groups[ $action_options['group'] ] ) ) {
159 - $group = $action_options['group'];
160 - } elseif ( isset( $groups[ $this->id_base ] ) ) {
161 - $group = $this->id_base;
162 - } else {
163 - foreach ( $groups as $name => $check_group ) {
164 - if ( isset( $check_group['actions'] ) && in_array( $this->id_base, $check_group['actions'] ) ) {
165 - $group = $name;
166 - break;
167 - }
168 - }
169 - }
170 -
171 - $groups[ $group ]['id'] = $group;
172 - return $groups[ $group ];
173 - }
174 -
175 - /**
176 105 * Constructs name attributes for use in form() fields
177 106 *
178 107 * This function should be used in form() methods to create name attributes for fields to be saved by update()
179 108 *
180 109 * @param string $field_name Field name
181 - *
182 110 * @return string Name attribute for $field_name
183 111 */
184 112 public function get_field_name( $field_name, $post_field = 'post_content' ) {
185 113 $name = $this->option_name . '[' . $this->number . ']';
@@ -184,9 +112,8 @@
184 112 public function get_field_name( $field_name, $post_field = 'post_content' ) {
185 113 $name = $this->option_name . '[' . $this->number . ']';
186 114 $name .= ( empty( $post_field ) ? '' : '[' . $post_field . ']' );
187 115 $name .= '[' . $field_name . ']';
188 -
189 116 return $name;
190 117 }
191 118
192 119 /**
@@ -194,9 +121,8 @@
194 121 *
195 122 * This function should be used in form() methods to create id attributes for fields to be saved by update()
196 123 *
197 124 * @param string $field_name Field name
198 - *
199 125 * @return string ID attribute for $field_name
200 126 */
201 127 public function get_field_id( $field_name ) {
202 128 return $field_name . '_' . $this->number;
@@ -201,27 +127,22 @@
201 127 public function get_field_id( $field_name ) {
202 128 return $field_name . '_' . $this->number;
203 129 }
204 130
205 - /**
206 - * @param int|string $number
207 - * @return void
208 - */
131 + // Private Function. Don't worry about this.
132 +
209 133 public function _set( $number ) {
210 134 $this->number = $number;
211 - $this->id = $this->id_base . '-' . $number;
135 + $this->id = $this->id_base . '-' . $number;
212 136 }
213 137
214 - /**
215 - * @return object
216 - */
217 138 public function prepare_new( $form_id = false ) {
218 - if ( $form_id ) {
219 - $this->form_id = $form_id;
220 - }
139 + if ( $form_id ) {
140 + $this->form_id = $form_id;
141 + }
221 142
222 - $post_content = array();
223 - $default_values = $this->get_global_defaults();
143 + $post_content = array();
144 + $default_values = $this->get_global_defaults();
224 145
225 146 // fill default values
226 147 $post_content = wp_parse_args( $post_content, $default_values );
227 148
@@ -228,87 +149,79 @@
228 149 if ( ! isset( $post_content['event'] ) && ! $this->action_options['force_event'] ) {
229 150 $post_content['event'] = array( reset( $this->action_options['event'] ) );
230 151 }
231 152
232 - $form_action = array(
233 - 'post_title' => $this->name,
234 - 'post_content' => $post_content,
235 - 'post_excerpt' => $this->id_base,
236 - 'ID' => '',
237 - 'post_status' => 'publish',
238 - 'post_type' => FrmFormActionsController::$action_post_type,
239 - 'post_name' => $this->form_id . '_' . $this->id_base . '_' . $this->number,
240 - 'menu_order' => $this->form_id,
241 - );
153 + $form_action = array(
154 + 'post_title' => $this->name,
155 + 'post_content' => $post_content,
156 + 'post_excerpt' => $this->id_base,
157 + 'ID' => '',
158 + 'post_status' => 'publish',
159 + 'post_type' => FrmFormActionsController::$action_post_type,
160 + 'post_name' => $this->form_id . '_' . $this->id_base . '_' . $this->number,
161 + 'menu_order' => $this->form_id,
162 + );
242 163 unset( $post_content );
243 164
244 - return (object) $form_action;
245 - }
165 + return (object) $form_action;
166 + }
246 167
247 168 public function create( $form_id ) {
248 - $this->form_id = $form_id;
169 + $this->form_id = $form_id;
249 170
250 - $action = $this->prepare_new();
171 + $action = $this->prepare_new();
251 172
252 173 return $this->save_settings( $action );
253 - }
174 + }
254 175
255 - /**
256 - * @return void
257 - */
258 176 public function duplicate_form_actions( $form_id, $old_id ) {
259 - if ( $form_id == $old_id ) {
260 - // don't duplicate the actions if this is a template getting updated
261 - return;
262 - }
177 + if ( $form_id == $old_id ) {
178 + // don't duplicate the actions if this is a template getting updated
179 + return;
180 + }
263 181
264 - $this->form_id = $old_id;
265 - $actions = $this->get_all( $old_id );
182 + $this->form_id = $old_id;
183 + $actions = $this->get_all( $old_id );
266 184
267 - $this->form_id = $form_id;
268 - foreach ( $actions as $action ) {
185 + $this->form_id = $form_id;
186 + foreach ( $actions as $action ) {
269 187 $this->duplicate_one( $action, $form_id );
270 188 unset( $action );
271 - }
272 - }
189 + }
190 + }
273 191
274 - /* Check if imported action should be created or updated
275 - *
276 - * @since 2.0
277 - *
278 - * @param array $action
279 - * @return integer $post_id
280 - */
281 - public function maybe_create_action( $action, $forms ) {
192 + /* Check if imported action should be created or updated
193 + *
194 + * Since 2.0
195 + *
196 + * @param array $action
197 + * @return integer $post_id
198 + */
199 + public function maybe_create_action( $action, $forms ) {
282 200 if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] == 'updated' ) {
283 - // Update action only
284 - $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
285 - $post_id = $this->save_settings( $action );
286 - } else {
201 + // Update action only
202 + $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
203 + $post_id = $this->save_settings( $action );
204 + } else {
287 205 // Create action
288 206 $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
289 - $post_id = $this->duplicate_one( (object) $action, $action['menu_order'] );
290 - }
207 + $post_id = $this->duplicate_one( (object) $action, $action['menu_order'] );
208 + }
209 + return $post_id;
210 + }
291 211
292 - return $post_id;
293 - }
294 -
295 - /**
296 - * @param object $action
297 - */
298 212 public function duplicate_one( $action, $form_id ) {
299 - global $frm_duplicate_ids;
213 + global $frm_duplicate_ids;
300 214
301 - $action->menu_order = $form_id;
302 - $switch = $this->get_global_switch_fields();
303 -
304 - foreach ( (array) $action->post_content as $key => $val ) {
215 + $action->menu_order = $form_id;
216 + $switch = $this->get_global_switch_fields();
217 + foreach ( (array) $action->post_content as $key => $val ) {
305 218 if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) {
306 219 $action->post_content[ $key ] = $frm_duplicate_ids[ $val ];
307 - } elseif ( ! is_array( $val ) ) {
220 + } else if ( ! is_array( $val ) ) {
308 221 $action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val );
309 - } elseif ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) {
310 - // loop through each value if empty
222 + } else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) {
223 + // loop through each value if empty
311 224 if ( empty( $switch[ $key ] ) ) {
312 225 $switch[ $key ] = array_keys( $val );
313 226 }
314 227
@@ -313,10 +226,10 @@
313 226 }
314 227
315 228 foreach ( $switch[ $key ] as $subkey ) {
316 229 $action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val );
317 - }
318 - }
230 + }
231 + }
319 232
320 233 unset( $key, $val );
321 234 }
322 235 unset( $action->ID );
@@ -321,37 +234,35 @@
321 234 }
322 235 unset( $action->ID );
323 236
324 237 return $this->save_settings( $action );
325 - }
238 + }
326 239
327 240 private function duplicate_array_walk( $action, $subkey, $val ) {
328 - global $frm_duplicate_ids;
241 + global $frm_duplicate_ids;
329 242
330 243 if ( is_array( $subkey ) ) {
331 - foreach ( $subkey as $subkey2 ) {
332 - foreach ( (array) $val as $ck => $cv ) {
244 + foreach ( $subkey as $subkey2 ) {
245 + foreach ( (array) $val as $ck => $cv ) {
333 246 if ( is_array( $cv ) ) {
334 247 $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv );
335 - } elseif ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) {
248 + } else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) {
336 249 $action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ];
337 - }
338 - }
339 - }
340 - } else {
341 - foreach ( (array) $val as $ck => $cv ) {
250 + }
251 + }
252 + }
253 + } else {
254 + foreach ( (array) $val as $ck => $cv ) {
342 255 if ( is_array( $cv ) ) {
343 256 $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv );
344 - } elseif ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) {
257 + } else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) {
345 258 $action[ $ck ] = $frm_duplicate_ids[ $cv ];
346 - } elseif ( $ck == $subkey ) {
347 - $action[ $ck ] = $this->maybe_switch_field_ids( $action[ $ck ] );
348 - }
349 - }
350 - }
259 + }
260 + }
261 + }
351 262
352 - return $action;
353 - }
263 + return $action;
264 + }
354 265
355 266 /**
356 267 * Deal with changed settings.
357 268 *
@@ -356,31 +267,28 @@
356 267 * Deal with changed settings.
357 268 *
358 269 * Do NOT over-ride this function
359 270 */
360 - public function update_callback( $form_id ) {
361 - $this->form_id = $form_id;
271 + public function update_callback( $form_id ) {
272 + $this->form_id = $form_id;
362 273
363 - $all_instances = $this->get_settings();
274 + $all_instances = $this->get_settings();
364 275
365 - // We need to update the data
366 - if ( $this->updated ) {
367 - return;
368 - }
276 + // We need to update the data
277 + if ( $this->updated ) {
278 + return;
279 + }
369 280
370 - // phpcs:ignore WordPress.Security.NonceVerification.Missing
371 281 if ( isset( $_POST[ $this->option_name ] ) && is_array( $_POST[ $this->option_name ] ) ) {
372 - // Sanitizing removes scripts and <email> type of values.
373 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
374 - $settings = wp_unslash( $_POST[ $this->option_name ] );
375 - } else {
376 - return;
377 - }
282 + $settings = $_POST[ $this->option_name ];
283 + } else {
284 + return;
285 + }
378 286
379 - $action_ids = array();
287 + $action_ids = array();
380 288
381 - foreach ( $settings as $number => $new_instance ) {
382 - $this->_set( $number );
289 + foreach ( $settings as $number => $new_instance ) {
290 + $this->_set( $number );
383 291
384 292 $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array();
385 293
386 294 if ( ! isset( $new_instance['post_status'] ) ) {
@@ -387,21 +295,22 @@
387 295 $new_instance['post_status'] = 'draft';
388 296 }
389 297
390 298 // settings were never opened, so don't update
391 - if ( ! isset( $new_instance['post_title'] ) ) {
299 + if ( ! isset( $new_instance['post_title'] ) ) {
392 300 $this->maybe_update_status( $new_instance, $old_instance );
393 - $action_ids[] = $new_instance['ID'];
394 - $this->updated = true;
395 - continue;
396 - }
301 + $action_ids[] = $new_instance['ID'];
302 + $this->updated = true;
303 + continue;
304 + }
397 305
398 306 $new_instance['post_type'] = FrmFormActionsController::$action_post_type;
399 307 $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number;
400 308 $new_instance['menu_order'] = $this->form_id;
401 309 $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
402 - $instance = $this->update( $new_instance, $old_instance );
403 310
311 + $instance = $this->update( $new_instance, $old_instance );
312 +
404 313 /**
405 314 * Filter an action's settings before saving.
406 315 *
407 316 * Returning false will effectively short-circuit the widget's ability
@@ -408,17 +317,17 @@
408 317 * to update settings.
409 318 *
410 319 * @since 2.0
411 320 *
412 - * @param array $instance The current widget instance's settings.
413 - * @param array $new_instance Array of new widget settings.
414 - * @param array $old_instance Array of old widget settings.
415 - * @param WP_Widget $this The current widget instance.
321 + * @param array $instance The current widget instance's settings.
322 + * @param array $new_instance Array of new widget settings.
323 + * @param array $old_instance Array of old widget settings.
324 + * @param WP_Widget $this The current widget instance.
416 325 */
417 326 $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this );
418 327
419 328 $instance['post_content'] = apply_filters( 'frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this );
420 - $instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this );
329 + $instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this );
421 330
422 331 if ( false !== $instance ) {
423 332 $all_instances[ $number ] = $instance;
424 333 }
@@ -424,40 +333,33 @@
424 333 }
425 334
426 335 $action_ids[] = $this->save_settings( $instance );
427 336
428 - $this->updated = true;
429 - }
337 + $this->updated = true;
338 + }
430 339
431 - return $action_ids;
432 - }
340 + return $action_ids;
341 + }
433 342
434 343 /**
435 344 * If the status of the action has changed, update it
436 345 *
437 346 * @since 3.04
438 - *
439 - * @param array $new_instance
440 - * @param stdClass|array $old_instance
441 - * @return void
442 347 */
443 348 protected function maybe_update_status( $new_instance, $old_instance ) {
444 - if ( ! is_object( $old_instance ) || $new_instance['post_status'] === $old_instance->post_status ) {
445 - return;
349 + if ( $new_instance['post_status'] !== $old_instance->post_status ) {
350 + self::clear_cache();
351 + wp_update_post(
352 + array(
353 + 'ID' => $new_instance['ID'],
354 + 'post_status' => $new_instance['post_status'],
355 + )
356 + );
446 357 }
447 -
448 - self::clear_cache();
449 - wp_update_post(
450 - array(
451 - 'ID' => $new_instance['ID'],
452 - 'post_status' => $new_instance['post_status'],
453 - )
454 - );
455 358 }
456 359
457 360 public function save_settings( $settings ) {
458 361 self::clear_cache();
459 -
460 362 return FrmDb::save_settings( $settings, 'frm_actions' );
461 363 }
462 364
463 365 public function get_single_action( $id ) {
@@ -465,10 +367,9 @@
465 367 if ( $action ) {
466 368 $action = $this->prepare_action( $action );
467 369 $this->_set( $id );
468 370 }
469 -
470 - return $action;
371 + return $action;
471 372 }
472 373
473 374 public function get_one( $form_id ) {
474 375 return $this->get_all( $form_id, 1 );
@@ -473,14 +374,14 @@
473 374 public function get_one( $form_id ) {
474 375 return $this->get_all( $form_id, 1 );
475 376 }
476 377
477 - public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) {
478 - $action_controls = FrmFormActionsController::get_form_actions( $type );
378 + public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) {
379 + $action_controls = FrmFormActionsController::get_form_actions( $type );
479 380 if ( empty( $action_controls ) ) {
480 - // don't continue if there are no available actions
481 - return array();
482 - }
381 + // don't continue if there are no available actions
382 + return array();
383 + }
483 384
484 385 if ( 'all' != $type ) {
485 386 return $action_controls->get_all( $form_id, $atts );
486 387 }
@@ -488,47 +389,44 @@
488 389 self::prepare_get_action( $atts );
489 390
490 391 $limit = apply_filters( 'frm_form_action_limit', $atts['limit'], compact( 'type', 'form_id' ) );
491 392
492 - $args = self::action_args( $form_id, $limit );
393 + $args = self::action_args( $form_id, $limit );
493 394 $args['post_status'] = $atts['post_status'];
494 - $actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
395 + $actions = FrmDb::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' );
495 396
496 - if ( ! $actions ) {
497 - return array();
498 - }
397 + if ( ! $actions ) {
398 + return array();
399 + }
499 400
500 - $settings = array();
501 - foreach ( $actions as $action ) {
401 + $settings = array();
402 + foreach ( $actions as $action ) {
502 403 // some plugins/themes are formatting the post_excerpt
503 404 $action->post_excerpt = sanitize_title( $action->post_excerpt );
504 405
505 406 if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) {
506 - continue;
507 - }
407 + continue;
408 + }
508 409
509 - $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
410 + $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
510 411 $settings[ $action->ID ] = $action;
511 412
512 413 if ( count( $settings ) >= $limit ) {
513 414 break;
514 415 }
515 - }
416 + }
516 417
517 - if ( 1 === $limit ) {
418 + if ( 1 === $limit ) {
518 419 $settings = reset( $settings );
519 - }
420 + }
520 421
521 - return $settings;
522 - }
422 + return $settings;
423 + }
523 424
524 425 /**
525 426 * @since 3.04
526 - *
527 427 * @param array $args
528 428 * @param string $default_status
529 - *
530 - * @return void
531 429 */
532 430 protected static function prepare_get_action( &$args, $default_status = 'publish' ) {
533 431 if ( is_numeric( $args ) ) {
534 432 // for reverse compatibility. $limit was changed to $args
@@ -539,9 +437,9 @@
539 437 $defaults = array(
540 438 'limit' => 99,
541 439 'post_status' => $default_status,
542 440 );
543 - $args = wp_parse_args( $args, $defaults );
441 + $args = wp_parse_args( $args, $defaults );
544 442 }
545 443
546 444 /**
547 445 * @param int $action_id
@@ -550,76 +448,65 @@
550 448 if ( ! $type ) {
551 449 return false;
552 450 }
553 451 $action_control = FrmFormActionsController::get_form_actions( $type );
554 -
555 452 return $action_control->get_single_action( $action_id );
556 453 }
557 454
558 455 /**
559 456 * @param int $form_id
560 - *
561 457 * @return bool
562 458 */
563 459 public static function form_has_action_type( $form_id, $type ) {
564 460 $payment_actions = self::get_action_for_form( $form_id, $type );
565 -
566 461 return ! empty( $payment_actions );
567 462 }
568 463
569 464 public function get_all( $form_id = false, $atts = array() ) {
570 - if ( is_array( $atts ) && ! isset( $atts['limit'] ) && $this->action_options['limit'] > 99 ) {
571 - $atts['limit'] = $this->action_options['limit'];
572 - }
573 -
574 465 self::prepare_get_action( $atts, 'any' );
575 -
576 466 $limit = $atts['limit'];
577 467
578 - if ( $form_id ) {
579 - $this->form_id = $form_id;
580 - }
468 + if ( $form_id ) {
469 + $this->form_id = $form_id;
470 + }
581 471
582 - $type = $this->id_base;
472 + $type = $this->id_base;
583 473
584 - global $frm_vars;
585 - $frm_vars['action_type'] = $type;
474 + global $frm_vars;
475 + $frm_vars['action_type'] = $type;
586 476
587 477 add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
588 478 $query = self::action_args( $form_id, $limit );
589 479 $query['post_status'] = $atts['post_status'];
590 - $query['suppress_filters'] = false;
480 + $query['suppress_filters'] = false;
591 481
592 - $actions = FrmDb::check_cache( json_encode( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
482 + $actions = FrmDb::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
593 483 unset( $query );
594 484
595 485 remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
596 486
597 487 if ( empty( $actions ) ) {
598 - return array();
599 - }
488 + return array();
489 + }
600 490
601 - $settings = array();
602 - foreach ( $actions as $action ) {
491 + $settings = array();
492 + foreach ( $actions as $action ) {
603 493 if ( count( $settings ) >= $limit ) {
604 - continue;
605 - }
494 + continue;
495 + }
606 496
607 497 $action = $this->prepare_action( $action );
608 498
609 499 $settings[ $action->ID ] = $action;
610 - }
500 + }
611 501
612 - if ( 1 === $limit ) {
502 + if ( 1 === $limit ) {
613 503 $settings = reset( $settings );
614 - }
504 + }
615 505
616 - return $settings;
506 + return $settings;
617 507 }
618 508
619 - /**
620 - * @return array
621 - */
622 509 public static function action_args( $form_id = 0, $limit = 99 ) {
623 510 $args = array(
624 511 'post_type' => FrmFormActionsController::$action_post_type,
625 512 'post_status' => 'publish',
@@ -634,57 +521,51 @@
634 521
635 522 return $args;
636 523 }
637 524
638 - /**
639 - * @param WP_Post|array $action
640 - */
641 525 public function prepare_action( $action ) {
642 526 $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content );
643 527 $action->post_excerpt = sanitize_title( $action->post_excerpt );
644 528
645 - $default_values = $this->get_global_defaults();
529 + $default_values = $this->get_global_defaults();
646 530
647 - // fill default values
648 - $action->post_content += $default_values;
531 + // fill default values
532 + $action->post_content += $default_values;
649 533
650 - foreach ( $default_values as $k => $vals ) {
534 + foreach ( $default_values as $k => $vals ) {
651 535 if ( is_array( $vals ) && ! empty( $vals ) ) {
652 536 if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
653 - continue;
654 - }
537 + continue;
538 + }
655 539 $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
656 - }
657 - }
540 + }
541 + }
658 542
659 543 if ( ! is_array( $action->post_content['event'] ) ) {
660 544 $action->post_content['event'] = explode( ',', $action->post_content['event'] );
661 545 }
662 546
663 - return $action;
547 + return $action;
664 548 }
665 549
666 - /**
667 - * @return void
668 - */
669 550 public function destroy( $form_id = false, $type = 'default' ) {
670 - global $wpdb;
551 + global $wpdb;
671 552
672 - $this->form_id = $form_id;
553 + $this->form_id = $form_id;
673 554
674 - $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
675 - if ( $form_id ) {
676 - $query['menu_order'] = $form_id;
677 - }
678 - if ( 'all' != $type ) {
679 - $query['post_excerpt'] = $this->id_base;
680 - }
555 + $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
556 + if ( $form_id ) {
557 + $query['menu_order'] = $form_id;
558 + }
559 + if ( 'all' != $type ) {
560 + $query['post_excerpt'] = $this->id_base;
561 + }
681 562
682 - $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
563 + $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
683 564
684 - foreach ( $post_ids as $id ) {
565 + foreach ( $post_ids as $id ) {
685 566 wp_delete_post( $id );
686 - }
567 + }
687 568 self::clear_cache();
688 569 }
689 570
690 571 /**
@@ -690,10 +571,8 @@
690 571 /**
691 572 * Delete the action cache when a form action is created, deleted, or updated
692 573 *
693 574 * @since 2.0.5
694 - *
695 - * @return void
696 575 */
697 576 public static function clear_cache() {
698 577 FrmDb::cache_delete_group( 'frm_actions' );
699 578 }
@@ -701,35 +580,29 @@
701 580 public function get_settings() {
702 581 return self::get_action_for_form( $this->form_id, $this->id_base );
703 582 }
704 583
705 - /**
706 - * @return array
707 - */
708 584 public function get_global_defaults() {
709 - $defaults = $this->get_defaults();
585 + $defaults = $this->get_defaults();
710 586
711 587 if ( ! isset( $defaults['event'] ) ) {
712 588 $defaults['event'] = array( 'create' );
713 - }
589 + }
714 590
715 591 if ( ! isset( $defaults['conditions'] ) ) {
716 - $defaults['conditions'] = array(
717 - 'send_stop' => '',
718 - 'any_all' => '',
719 - );
720 - }
592 + $defaults['conditions'] = array(
593 + 'send_stop' => '',
594 + 'any_all' => '',
595 + );
596 + }
721 597
722 - return $defaults;
598 + return $defaults;
723 599 }
724 600
725 601 public function get_global_switch_fields() {
726 - $switch = $this->get_switch_fields();
602 + $switch = $this->get_switch_fields();
727 603 $switch['conditions'] = array( 'hide_field' );
728 -
729 - $switch = apply_filters( 'frm_global_switch_fields', $switch );
730 -
731 - return $switch;
604 + return $switch;
732 605 }
733 606
734 607 /**
735 608 * Migrate settings from form->options into new action.
@@ -734,28 +607,28 @@
734 607 /**
735 608 * Migrate settings from form->options into new action.
736 609 */
737 610 public function migrate_to_2( $form, $update = 'update' ) {
738 - $action = $this->prepare_new( $form->id );
739 - FrmAppHelper::unserialize_or_decode( $form->options );
611 + $action = $this->prepare_new( $form->id );
612 + $form->options = maybe_unserialize( $form->options );
740 613
741 - // fill with existing options
742 - foreach ( $action->post_content as $name => $val ) {
614 + // fill with existing options
615 + foreach ( $action->post_content as $name => $val ) {
743 616 if ( isset( $form->options[ $name ] ) ) {
744 617 $action->post_content[ $name ] = $form->options[ $name ];
745 618 unset( $form->options[ $name ] );
746 - }
747 - }
619 + }
620 + }
748 621
749 622 $action = $this->migrate_values( $action, $form );
750 623
751 - // check if action already exists
624 + // check if action already exists
752 625 $post_id = get_posts(
753 626 array(
754 - 'name' => $action->post_name,
755 - 'post_type' => FrmFormActionsController::$action_post_type,
756 - 'post_status' => $action->post_status,
757 - 'numberposts' => 1,
627 + 'name' => $action->post_name,
628 + 'post_type' => FrmFormActionsController::$action_post_type,
629 + 'post_status' => $action->post_status,
630 + 'numberposts' => 1,
758 631 )
759 632 );
760 633
761 634 if ( empty( $post_id ) ) {
@@ -762,29 +635,24 @@
762 635 // create action now
763 636 $post_id = $this->save_settings( $action );
764 637 }
765 638
766 - if ( $post_id && 'update' == $update ) {
767 - global $wpdb;
639 + if ( $post_id && 'update' == $update ) {
640 + global $wpdb;
768 641 $form->options = maybe_serialize( $form->options );
769 642
770 - // update form options
643 + // update form options
771 644 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) );
772 - FrmForm::clear_form_cache();
773 - }
645 + FrmForm::clear_form_cache();
646 + }
774 647
775 - return $post_id;
776 - }
648 + return $post_id;
649 + }
777 650
778 651 public static function action_conditions_met( $action, $entry ) {
779 - if ( is_callable( 'FrmProFormActionsController::action_conditions_met' ) ) {
780 - return FrmProFormActionsController::action_conditions_met( $action, $entry );
781 - }
782 -
783 - // This is here for reverse compatibility.
784 652 $notification = $action->post_content;
785 - $stop = false;
786 - $met = array();
653 + $stop = false;
654 + $met = array();
787 655
788 656 if ( ! isset( $notification['conditions'] ) || empty( $notification['conditions'] ) ) {
789 657 return $stop;
790 658 }
@@ -797,9 +665,9 @@
797 665 if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) {
798 666 continue;
799 667 }
800 668
801 - self::prepare_logic_value( $condition['hide_opt'], $action, $entry );
669 + self::prepare_logic_value( $condition['hide_opt'] );
802 670
803 671 $observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] );
804 672
805 673 $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] );
@@ -823,16 +691,11 @@
823 691 /**
824 692 * Prepare the logic value for comparison against the entered value
825 693 *
826 694 * @since 2.01.02
827 - *
828 - * @deprecated 4.06.02
829 - *
830 695 * @param array|string $logic_value
831 - *
832 - * @return void
833 696 */
834 - private static function prepare_logic_value( &$logic_value, $action, $entry ) {
697 + private static function prepare_logic_value( &$logic_value ) {
835 698 if ( is_array( $logic_value ) ) {
836 699 $logic_value = reset( $logic_value );
837 700 }
838 701
@@ -838,26 +701,17 @@
838 701
839 702 if ( $logic_value == 'current_user' ) {
840 703 $logic_value = get_current_user_id();
841 704 }
705 + }
842 706
843 - $logic_value = apply_filters( 'frm_content', $logic_value, $action->menu_order, $entry );
844 707
845 - /**
846 - * @since 4.04.05
847 - */
848 - $logic_value = apply_filters( 'frm_action_logic_value', $logic_value );
849 - }
850 -
851 708 /**
852 709 * Get the value from a specific field and entry
853 710 *
854 711 * @since 2.01.02
855 - * @deprecated 4.06.02
856 - *
857 712 * @param object $entry
858 713 * @param int $field_id
859 - *
860 714 * @return array|bool|mixed|string
861 715 */
862 716 private static function get_value_from_entry( $entry, $field_id ) {
863 717 $observed_value = '';
@@ -863,10 +717,10 @@
863 717 $observed_value = '';
864 718
865 719 if ( isset( $entry->metas[ $field_id ] ) ) {
866 720 $observed_value = $entry->metas[ $field_id ];
867 - } elseif ( $entry->post_id && FrmAppHelper::pro_is_installed() ) {
868 - $field = FrmField::getOne( $field_id );
721 + } else if ( $entry->post_id && FrmAppHelper::pro_is_installed() ) {
722 + $field = FrmField::getOne( $field_id );
869 723 $observed_value = FrmProEntryMetaHelper::get_post_or_meta_value(
870 724 $entry,
871 725 $field,
872 726 array(
@@ -878,49 +732,23 @@
878 732
879 733 return $observed_value;
880 734 }
881 735
882 - /**
883 - * @param string $class
884 - *
885 - * @return array
886 - */
887 736 public static function default_action_opts( $class = '' ) {
888 737 return array(
889 - 'classes' => 'frm_icon_font ' . $class,
890 - 'active' => false,
891 - 'limit' => 0,
738 + 'classes' => 'frm_icon_font ' . $class,
739 + 'active' => false,
740 + 'limit' => 0,
892 741 );
893 742 }
894 743
895 744 public static function trigger_labels() {
896 745 $triggers = array(
897 - 'draft' => __( 'Draft is saved', 'formidable' ),
898 - 'create' => __( 'Entry is created', 'formidable' ),
899 - 'update' => __( 'Entry is updated', 'formidable' ),
900 - 'delete' => __( 'Entry is deleted', 'formidable' ),
901 - 'import' => __( 'Entry is imported', 'formidable' ),
746 + 'draft' => __( 'Save Draft', 'formidable' ),
747 + 'create' => __( 'Create', 'formidable' ),
748 + 'update' => __( 'Update', 'formidable' ),
749 + 'delete' => __( 'Delete', 'formidable' ),
750 + 'import' => __( 'Import', 'formidable' ),
902 751 );
903 -
904 752 return apply_filters( 'frm_action_triggers', $triggers );
905 - }
906 -
907 - /**
908 - * @return void
909 - */
910 - public function render_conditional_logic_call_to_action() {
911 - ?>
912 - <h3>
913 - <a href="javascript:void(0)" class="frm_show_upgrade frm_noallow" data-upgrade="<?php echo esc_attr( $this->get_upgrade_text() ); ?>" data-medium="conditional-<?php echo esc_attr( $this->id_base ); ?>">
914 - <?php esc_html_e( 'Use Conditional Logic', 'formidable' ); ?>
915 - </a>
916 - </h3>
917 - <?php
918 - }
919 -
920 - /**
921 - * @return string
922 - */
923 - protected function get_upgrade_text() {
924 - return __( 'Conditional form actions', 'formidable' );
925 753 }
926 754 }