| @@ -4,71 +4,19 @@ | ||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmFormAction { |
| 7 | 7 | |
| 8 | - /** | |
| 9 | - * Root id for all actions of this type. | |
| 10 | - * | |
| 11 | - * @var string | |
| 12 | - */ | |
| 13 | - public $id_base; | |
| 14 | - | |
| 15 | - /** | |
| 16 | - * Name for this action type. | |
| 17 | - * | |
| 18 | - * @var string | |
| 19 | - */ | |
| 20 | - public $name; | |
| 21 | - | |
| 22 | - /** | |
| 23 | - * Name of the option used to store the settings for this action type. | |
| 24 | - * | |
| 25 | - * @var string | |
| 26 | - */ | |
| 8 | + public $id_base; // Root id for all actions of this type. | |
| 9 | + public $name; // Name for this action type. | |
| 27 | 10 | public $option_name; |
| 11 | + public $action_options; // Option array passed to wp_register_sidebar_widget() | |
| 12 | + public $control_options; // Option array passed to wp_register_widget_control() | |
| 28 | 13 | |
| 29 | - /** | |
| 30 | - * Option array passed to wp_register_sidebar_widget(). | |
| 31 | - * | |
| 32 | - * @var array | |
| 33 | - */ | |
| 34 | - public $action_options; | |
| 14 | + public $form_id; // The ID of the form to evaluate | |
| 15 | + public $number = false; // Unique ID number of the current instance. | |
| 16 | + public $id = ''; // Unique ID string of the current instance (id_base-number) | |
| 17 | + public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice. | |
| 35 | 18 | |
| 36 | - /** | |
| 37 | - * Option array passed to wp_register_widget_control(). | |
| 38 | - * | |
| 39 | - * @var array | |
| 40 | - */ | |
| 41 | - public $control_options; | |
| 42 | - | |
| 43 | - /** | |
| 44 | - * The ID of the form to evaluate. | |
| 45 | - * | |
| 46 | - * @var int | |
| 47 | - */ | |
| 48 | - public $form_id; | |
| 49 | - | |
| 50 | - /** | |
| 51 | - * Unique ID number of the current instance. | |
| 52 | - * | |
| 53 | - * @var int | |
| 54 | - */ | |
| 55 | - public $number = false; | |
| 56 | - | |
| 57 | - /** | |
| 58 | - * Unique ID string of the current instance (id_base-number). | |
| 59 | - * | |
| 60 | - * @var string | |
| 61 | - */ | |
| 62 | - public $id = ''; | |
| 63 | - | |
| 64 | - /** | |
| 65 | - * Set true when we update the data after a POST submit - makes sure we don't do it twice. | |
| 66 | - * | |
| 67 | - * @var bool | |
| 68 | - */ | |
| 69 | - public $updated = false; | |
| 70 | - | |
| 71 | 19 | // Member functions that you must over-ride. |
| 72 | 20 | |
| 73 | 21 | /** |
| 74 | 22 | * This function should check that $new_instance is set correctly. |
| @@ -74,10 +22,10 @@ | ||
| 74 | 22 | * This function should check that $new_instance is set correctly. |
| 75 | 23 | * The newly calculated value of $instance should be returned. |
| 76 | 24 | * If "false" is returned, the instance won't be saved/updated. |
| 77 | 25 | * |
| 78 | - * @param array $new_instance New settings for this instance as input by the user via form(). | |
| 79 | - * @param array $old_instance Old settings for this instance. | |
| 26 | + * @param array $new_instance New settings for this instance as input by the user via form() | |
| 27 | + * @param array $old_instance Old settings for this instance | |
| 80 | 28 | * |
| 81 | 29 | * @return array Settings to save or bool false to cancel saving |
| 82 | 30 | */ |
| 83 | 31 | public function update( $new_instance, $old_instance ) { |
| @@ -86,12 +34,9 @@ | ||
| 86 | 34 | |
| 87 | 35 | /** |
| 88 | 36 | * Echo the settings update form |
| 89 | 37 | * |
| 90 | - * @param WP_Post $instance Current settings. | |
| 91 | - * @param array $args | |
| 92 | - * | |
| 93 | - * @return string | |
| 38 | + * @param array $instance Current settings | |
| 94 | 39 | */ |
| 95 | 40 | public function form( $instance, $args = array() ) { |
| 96 | 41 | echo '<p class="no-options-widget">' . esc_html__( 'There are no options for this action.', 'formidable' ) . '</p>'; |
| 97 | 42 | |
| @@ -111,14 +56,8 @@ | ||
| 111 | 56 | public function get_switch_fields() { |
| 112 | 57 | return array(); |
| 113 | 58 | } |
| 114 | 59 | |
| 115 | - /** | |
| 116 | - * @param object $action | |
| 117 | - * @param object $form | |
| 118 | - * | |
| 119 | - * @return object | |
| 120 | - */ | |
| 121 | 60 | public function migrate_values( $action, $form ) { |
| 122 | 61 | return $action; |
| 123 | 62 | } |
| 124 | 63 | |
| @@ -129,14 +68,14 @@ | ||
| 129 | 68 | * |
| 130 | 69 | * @param string $id_base Optional Base ID for the widget, lower case, |
| 131 | 70 | * if left empty a portion of the widget's class name will be used. Has to be unique. |
| 132 | 71 | * @param string $name Name for the widget displayed on the configuration page. |
| 133 | - * @param array $action_options Optional Passed to wp_register_sidebar_widget(). | |
| 134 | - * - description: shown on the configuration page. | |
| 135 | - * - classname. | |
| 136 | - * @param array $control_options Optional Passed to wp_register_widget_control(). | |
| 137 | - * - width: required if more than 250px. | |
| 138 | - * - height: currently not used but may be needed in the future. | |
| 72 | + * @param array $action_options Optional Passed to wp_register_sidebar_widget() | |
| 73 | + * - description: shown on the configuration page | |
| 74 | + * - classname | |
| 75 | + * @param array $control_options Optional Passed to wp_register_widget_control() | |
| 76 | + * - width: required if more than 250px | |
| 77 | + * - height: currently not used but may be needed in the future | |
| 139 | 78 | */ |
| 140 | 79 | public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) { |
| 141 | 80 | if ( ! defined( 'ABSPATH' ) ) { |
| 142 | 81 | die( 'You are not allowed to call this page directly.' ); |
| @@ -171,13 +110,12 @@ | ||
| 171 | 110 | $action_options['color'] = 'var(--' . reset( $colors ) . ')'; |
| 172 | 111 | } |
| 173 | 112 | |
| 174 | 113 | $upgrade_class = isset( $action_options['classes'] ) && $action_options['classes'] === 'frm_show_upgrade'; |
| 175 | - | |
| 176 | 114 | if ( $action_options['group'] === $id_base ) { |
| 177 | - $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false; | |
| 115 | + $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false; | |
| 178 | 116 | $action_options['classes'] = $group['icon']; |
| 179 | - } elseif ( empty( $action_options['classes'] ) || $upgrade_class ) { | |
| 117 | + } elseif ( ! isset( $action_options['classes'] ) || empty( $action_options['classes'] ) || $upgrade_class ) { | |
| 180 | 118 | $action_options['classes'] = $group['icon']; |
| 181 | 119 | } |
| 182 | 120 | |
| 183 | 121 | if ( $upgrade_class ) { |
| @@ -189,13 +127,8 @@ | ||
| 189 | 127 | } |
| 190 | 128 | |
| 191 | 129 | /** |
| 192 | 130 | * @param string $id_base |
| 193 | - * @param string $name | |
| 194 | - * @param array $action_options | |
| 195 | - * @param array $control_options | |
| 196 | - * | |
| 197 | - * @return void | |
| 198 | 131 | */ |
| 199 | 132 | public function FrmFormAction( $id_base, $name, $action_options = array(), $control_options = array() ) { |
| 200 | 133 | self::__construct( $id_base, $name, $action_options, $control_options ); |
| 201 | 134 | } |
| @@ -202,15 +135,14 @@ | ||
| 202 | 135 | |
| 203 | 136 | /** |
| 204 | 137 | * Help to switch old field id by new field id for duplicate form |
| 205 | 138 | * |
| 206 | - * @param string $action id of the field that needs to be switched. | |
| 139 | + * @param string $action id of the field that needs to be switched | |
| 207 | 140 | * |
| 208 | 141 | * @return string |
| 209 | 142 | */ |
| 210 | 143 | public function maybe_switch_field_ids( $action ) { |
| 211 | 144 | $updated_action = apply_filters( 'frm_maybe_switch_field_ids', $action ); |
| 212 | - | |
| 213 | 145 | if ( $updated_action === $action ) { |
| 214 | 146 | $updated_action = FrmFieldsHelper::switch_field_ids( $action ); |
| 215 | 147 | } |
| 216 | 148 | return $updated_action; |
| @@ -217,12 +149,8 @@ | ||
| 217 | 149 | } |
| 218 | 150 | |
| 219 | 151 | /** |
| 220 | 152 | * @since 4.0 |
| 221 | - * | |
| 222 | - * @param array $action_options | |
| 223 | - * | |
| 224 | - * @return array | |
| 225 | 153 | */ |
| 226 | 154 | protected function get_group( $action_options ) { |
| 227 | 155 | $groups = FrmFormActionsController::form_action_groups(); |
| 228 | 156 | $group = 'misc'; |
| @@ -248,15 +176,14 @@ | ||
| 248 | 176 | * Constructs name attributes for use in form() fields |
| 249 | 177 | * |
| 250 | 178 | * This function should be used in form() methods to create name attributes for fields to be saved by update() |
| 251 | 179 | * |
| 252 | - * @param string $field_name Field name. | |
| 253 | - * @param string $post_field | |
| 180 | + * @param string $field_name Field name | |
| 254 | 181 | * |
| 255 | 182 | * @return string Name attribute for $field_name |
| 256 | 183 | */ |
| 257 | 184 | public function get_field_name( $field_name, $post_field = 'post_content' ) { |
| 258 | - $name = $this->option_name . '[' . $this->number . ']'; | |
| 185 | + $name = $this->option_name . '[' . $this->number . ']'; | |
| 259 | 186 | $name .= ( empty( $post_field ) ? '' : '[' . $post_field . ']' ); |
| 260 | 187 | $name .= '[' . $field_name . ']'; |
| 261 | 188 | |
| 262 | 189 | return $name; |
| @@ -266,9 +193,9 @@ | ||
| 266 | 193 | * Constructs id attributes for use in form() fields |
| 267 | 194 | * |
| 268 | 195 | * This function should be used in form() methods to create id attributes for fields to be saved by update() |
| 269 | 196 | * |
| 270 | - * @param string $field_name Field name. | |
| 197 | + * @param string $field_name Field name | |
| 271 | 198 | * |
| 272 | 199 | * @return string ID attribute for $field_name |
| 273 | 200 | */ |
| 274 | 201 | public function get_field_id( $field_name ) { |
| @@ -274,11 +201,12 @@ | ||
| 274 | 201 | public function get_field_id( $field_name ) { |
| 275 | 202 | return $field_name . '_' . $this->number; |
| 276 | 203 | } |
| 277 | 204 | |
| 205 | + // Private Function. Don't worry about this. | |
| 206 | + | |
| 278 | 207 | /** |
| 279 | 208 | * @param int|string $number |
| 280 | - * | |
| 281 | 209 | * @return void |
| 282 | 210 | */ |
| 283 | 211 | public function _set( $number ) { |
| 284 | 212 | $this->number = $number; |
| @@ -285,10 +213,8 @@ | ||
| 285 | 213 | $this->id = $this->id_base . '-' . $number; |
| 286 | 214 | } |
| 287 | 215 | |
| 288 | 216 | /** |
| 289 | - * @param false|int|string $form_id | |
| 290 | - * | |
| 291 | 217 | * @return object |
| 292 | 218 | */ |
| 293 | 219 | public function prepare_new( $form_id = false ) { |
| 294 | 220 | if ( $form_id ) { |
| @@ -319,13 +245,8 @@ | ||
| 319 | 245 | |
| 320 | 246 | return (object) $form_action; |
| 321 | 247 | } |
| 322 | 248 | |
| 323 | - /** | |
| 324 | - * @param int|string $form_id | |
| 325 | - * | |
| 326 | - * @return int|WP_Error | |
| 327 | - */ | |
| 328 | 249 | public function create( $form_id ) { |
| 329 | 250 | $this->form_id = $form_id; |
| 330 | 251 | |
| 331 | 252 | $action = $this->prepare_new(); |
| @@ -333,11 +254,8 @@ | ||
| 333 | 254 | return $this->save_settings( $action ); |
| 334 | 255 | } |
| 335 | 256 | |
| 336 | 257 | /** |
| 337 | - * @param int|string $form_id | |
| 338 | - * @param int|string $old_id | |
| 339 | - * | |
| 340 | 258 | * @return void |
| 341 | 259 | */ |
| 342 | 260 | public function duplicate_form_actions( $form_id, $old_id ) { |
| 343 | 261 | if ( $form_id == $old_id ) { |
| @@ -348,9 +266,8 @@ | ||
| 348 | 266 | $this->form_id = $old_id; |
| 349 | 267 | $actions = $this->get_all( $old_id ); |
| 350 | 268 | |
| 351 | 269 | $this->form_id = $form_id; |
| 352 | - | |
| 353 | 270 | foreach ( $actions as $action ) { |
| 354 | 271 | $this->duplicate_one( $action, $form_id ); |
| 355 | 272 | unset( $action ); |
| 356 | 273 | } |
| @@ -355,20 +272,17 @@ | ||
| 355 | 272 | unset( $action ); |
| 356 | 273 | } |
| 357 | 274 | } |
| 358 | 275 | |
| 359 | - /** | |
| 360 | - * Check if imported action should be created or updated. | |
| 276 | + /* Check if imported action should be created or updated | |
| 361 | 277 | * |
| 362 | 278 | * @since 2.0 |
| 363 | 279 | * |
| 364 | 280 | * @param array $action |
| 365 | - * @param array $forms | |
| 366 | - * | |
| 367 | - * @return int $post_id | |
| 281 | + * @return integer $post_id | |
| 368 | 282 | */ |
| 369 | 283 | public function maybe_create_action( $action, $forms ) { |
| 370 | - if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] === 'updated' ) { | |
| 284 | + if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] == 'updated' ) { | |
| 371 | 285 | // Update action only |
| 372 | 286 | $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
| 373 | 287 | $post_id = $this->save_settings( $action ); |
| 374 | 288 | } else { |
| @@ -380,12 +294,9 @@ | ||
| 380 | 294 | return $post_id; |
| 381 | 295 | } |
| 382 | 296 | |
| 383 | 297 | /** |
| 384 | - * @param object $action | |
| 385 | - * @param int|string $form_id | |
| 386 | - * | |
| 387 | - * @return int|WP_Error | |
| 298 | + * @param object $action | |
| 388 | 299 | */ |
| 389 | 300 | public function duplicate_one( $action, $form_id ) { |
| 390 | 301 | global $frm_duplicate_ids; |
| 391 | 302 | |
| @@ -414,15 +325,8 @@ | ||
| 414 | 325 | |
| 415 | 326 | return $this->save_settings( $action ); |
| 416 | 327 | } |
| 417 | 328 | |
| 418 | - /** | |
| 419 | - * @param array $action | |
| 420 | - * @param array|string $subkey | |
| 421 | - * @param mixed $val | |
| 422 | - * | |
| 423 | - * @return array | |
| 424 | - */ | |
| 425 | 329 | private function duplicate_array_walk( $action, $subkey, $val ) { |
| 426 | 330 | global $frm_duplicate_ids; |
| 427 | 331 | |
| 428 | 332 | if ( is_array( $subkey ) ) { |
| @@ -444,9 +348,9 @@ | ||
| 444 | 348 | } elseif ( $ck == $subkey ) { |
| 445 | 349 | $action[ $ck ] = $this->maybe_switch_field_ids( $action[ $ck ] ); |
| 446 | 350 | } |
| 447 | 351 | } |
| 448 | - }//end if | |
| 352 | + } | |
| 449 | 353 | |
| 450 | 354 | return $action; |
| 451 | 355 | } |
| 452 | 356 | |
| @@ -453,12 +357,8 @@ | ||
| 453 | 357 | /** |
| 454 | 358 | * Deal with changed settings. |
| 455 | 359 | * |
| 456 | 360 | * Do NOT over-ride this function |
| 457 | - * | |
| 458 | - * @param int|string $form_id | |
| 459 | - * | |
| 460 | - * @return array|null | |
| 461 | 361 | */ |
| 462 | 362 | public function update_callback( $form_id ) { |
| 463 | 363 | $this->form_id = $form_id; |
| 464 | 364 | |
| @@ -482,9 +382,9 @@ | ||
| 482 | 382 | |
| 483 | 383 | foreach ( $settings as $number => $new_instance ) { |
| 484 | 384 | $this->_set( $number ); |
| 485 | 385 | |
| 486 | - $old_instance = $all_instances[ $number ] ?? array(); | |
| 386 | + $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array(); | |
| 487 | 387 | |
| 488 | 388 | if ( ! isset( $new_instance['post_status'] ) ) { |
| 489 | 389 | $new_instance['post_status'] = 'draft'; |
| 490 | 390 | } |
| @@ -499,10 +399,10 @@ | ||
| 499 | 399 | |
| 500 | 400 | $new_instance['post_type'] = FrmFormActionsController::$action_post_type; |
| 501 | 401 | $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number; |
| 502 | 402 | $new_instance['menu_order'] = $this->form_id; |
| 503 | - $new_instance['post_date'] = $old_instance->post_date ?? ''; | |
| 504 | - $instance = $this->update( $new_instance, $old_instance ); | |
| 403 | + $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : ''; | |
| 404 | + $instance = $this->update( $new_instance, $old_instance ); | |
| 505 | 405 | |
| 506 | 406 | /** |
| 507 | 407 | * Filter an action's settings before saving. |
| 508 | 408 | * |
| @@ -510,12 +410,12 @@ | ||
| 510 | 410 | * to update settings. |
| 511 | 411 | * |
| 512 | 412 | * @since 2.0 |
| 513 | 413 | * |
| 514 | - * @param array $instance The current widget instance's settings. | |
| 515 | - * @param array $new_instance Array of new widget settings. | |
| 516 | - * @param array $old_instance Array of old widget settings. | |
| 517 | - * @param FrmFormAction $form_action FrmFormAction instance. | |
| 414 | + * @param array $instance The current widget instance's settings. | |
| 415 | + * @param array $new_instance Array of new widget settings. | |
| 416 | + * @param array $old_instance Array of old widget settings. | |
| 417 | + * @param WP_Widget $this The current widget instance. | |
| 518 | 418 | */ |
| 519 | 419 | $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this ); |
| 520 | 420 | |
| 521 | 421 | $instance['post_content'] = apply_filters( 'frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this ); |
| @@ -527,9 +427,9 @@ | ||
| 527 | 427 | |
| 528 | 428 | $action_ids[] = $this->save_settings( $instance ); |
| 529 | 429 | |
| 530 | 430 | $this->updated = true; |
| 531 | - }//end foreach | |
| 431 | + } | |
| 532 | 432 | |
| 533 | 433 | return $action_ids; |
| 534 | 434 | } |
| 535 | 435 | |
| @@ -538,10 +438,9 @@ | ||
| 538 | 438 | * |
| 539 | 439 | * @since 3.04 |
| 540 | 440 | * |
| 541 | 441 | * @param array $new_instance |
| 542 | - * @param array|stdClass $old_instance | |
| 543 | - * | |
| 442 | + * @param stdClass|array $old_instance | |
| 544 | 443 | * @return void |
| 545 | 444 | */ |
| 546 | 445 | protected function maybe_update_status( $new_instance, $old_instance ) { |
| 547 | 446 | if ( ! is_object( $old_instance ) || $new_instance['post_status'] === $old_instance->post_status ) { |
| @@ -556,13 +455,8 @@ | ||
| 556 | 455 | ) |
| 557 | 456 | ); |
| 558 | 457 | } |
| 559 | 458 | |
| 560 | - /** | |
| 561 | - * @param array $settings | |
| 562 | - * | |
| 563 | - * @return int|WP_Error | |
| 564 | - */ | |
| 565 | 459 | public function save_settings( $settings ) { |
| 566 | 460 | self::clear_cache(); |
| 567 | 461 | |
| 568 | 462 | return FrmDb::save_settings( $settings, 'frm_actions' ); |
| @@ -567,16 +461,10 @@ | ||
| 567 | 461 | |
| 568 | 462 | return FrmDb::save_settings( $settings, 'frm_actions' ); |
| 569 | 463 | } |
| 570 | 464 | |
| 571 | - /** | |
| 572 | - * @param int $id | |
| 573 | - * | |
| 574 | - * @return object|null | |
| 575 | - */ | |
| 576 | 465 | public function get_single_action( $id ) { |
| 577 | 466 | $action = get_post( $id ); |
| 578 | - | |
| 579 | 467 | if ( $action ) { |
| 580 | 468 | $action = $this->prepare_action( $action ); |
| 581 | 469 | $this->_set( $id ); |
| 582 | 470 | } |
| @@ -583,42 +471,26 @@ | ||
| 583 | 471 | |
| 584 | 472 | return $action; |
| 585 | 473 | } |
| 586 | 474 | |
| 587 | - /** | |
| 588 | - * @param int|string $form_id | |
| 589 | - * | |
| 590 | - * @return array | |
| 591 | - */ | |
| 592 | 475 | public function get_one( $form_id ) { |
| 593 | 476 | return $this->get_all( $form_id, 1 ); |
| 594 | 477 | } |
| 595 | 478 | |
| 596 | - /** | |
| 597 | - * @param int|string $form_id | |
| 598 | - * @param string $type | |
| 599 | - * @param array $atts | |
| 600 | - * | |
| 601 | - * @return array | |
| 602 | - */ | |
| 603 | 479 | public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) { |
| 604 | 480 | $action_controls = FrmFormActionsController::get_form_actions( $type ); |
| 605 | - | |
| 606 | 481 | if ( empty( $action_controls ) ) { |
| 607 | 482 | // don't continue if there are no available actions |
| 608 | 483 | return array(); |
| 609 | 484 | } |
| 610 | 485 | |
| 611 | - if ( 'all' !== $type ) { | |
| 612 | - if ( is_array( $action_controls ) ) { | |
| 613 | - return array(); | |
| 614 | - } | |
| 486 | + if ( 'all' != $type ) { | |
| 615 | 487 | return $action_controls->get_all( $form_id, $atts ); |
| 616 | 488 | } |
| 617 | 489 | |
| 618 | 490 | self::prepare_get_action( $atts ); |
| 619 | 491 | |
| 620 | - $limit = self::get_action_limit( $form_id, $atts['limit'] ); | |
| 492 | + $limit = apply_filters( 'frm_form_action_limit', $atts['limit'], compact( 'type', 'form_id' ) ); | |
| 621 | 493 | |
| 622 | 494 | $args = self::action_args( $form_id, $limit ); |
| 623 | 495 | $args['post_status'] = $atts['post_status']; |
| 624 | 496 | $actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' ); |
| @@ -627,9 +499,8 @@ | ||
| 627 | 499 | return array(); |
| 628 | 500 | } |
| 629 | 501 | |
| 630 | 502 | $settings = array(); |
| 631 | - | |
| 632 | 503 | foreach ( $actions as $action ) { |
| 633 | 504 | // some plugins/themes are formatting the post_excerpt |
| 634 | 505 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
| 635 | 506 | |
| @@ -652,24 +523,8 @@ | ||
| 652 | 523 | return $settings; |
| 653 | 524 | } |
| 654 | 525 | |
| 655 | 526 | /** |
| 656 | - * Get the limit for the number of actions for a single form. By default, this is 99, but | |
| 657 | - * it can be modified with a code snippet. | |
| 658 | - * | |
| 659 | - * @since 6.17 This logic from moved from FrmFormAction::get_action_for_form. | |
| 660 | - * | |
| 661 | - * @param int|string $form_id | |
| 662 | - * @param int|string $limit The unfiltered limit value. | |
| 663 | - * | |
| 664 | - * @return int The filtered limit value. | |
| 665 | - */ | |
| 666 | - public static function get_action_limit( $form_id, $limit = 99 ) { | |
| 667 | - $type = 'all'; | |
| 668 | - return (int) apply_filters( 'frm_form_action_limit', (int) $limit, compact( 'type', 'form_id' ) ); | |
| 669 | - } | |
| 670 | - | |
| 671 | - /** | |
| 672 | 527 | * @since 3.04 |
| 673 | 528 | * |
| 674 | 529 | * @param array $args |
| 675 | 530 | * @param string $default_status |
| @@ -682,9 +537,8 @@ | ||
| 682 | 537 | $args = array( |
| 683 | 538 | 'limit' => $args, |
| 684 | 539 | ); |
| 685 | 540 | } |
| 686 | - | |
| 687 | 541 | $defaults = array( |
| 688 | 542 | 'limit' => 99, |
| 689 | 543 | 'post_status' => $default_status, |
| 690 | 544 | ); |
| @@ -691,21 +545,14 @@ | ||
| 691 | 545 | $args = wp_parse_args( $args, $defaults ); |
| 692 | 546 | } |
| 693 | 547 | |
| 694 | 548 | /** |
| 695 | - * @param int $action_id | |
| 696 | - * @param string $type | |
| 697 | - * | |
| 698 | - * @return bool|object | |
| 549 | + * @param int $action_id | |
| 699 | 550 | */ |
| 700 | 551 | public static function get_single_action_type( $action_id, $type ) { |
| 701 | 552 | if ( ! $type ) { |
| 702 | 553 | return false; |
| 703 | 554 | } |
| 704 | - | |
| 705 | - /** | |
| 706 | - * @var FrmFormAction | |
| 707 | - */ | |
| 708 | 555 | $action_control = FrmFormActionsController::get_form_actions( $type ); |
| 709 | 556 | |
| 710 | 557 | return $action_control->get_single_action( $action_id ); |
| 711 | 558 | } |
| @@ -710,24 +557,18 @@ | ||
| 710 | 557 | return $action_control->get_single_action( $action_id ); |
| 711 | 558 | } |
| 712 | 559 | |
| 713 | 560 | /** |
| 714 | - * @param int $form_id | |
| 715 | - * @param string $type | |
| 561 | + * @param int $form_id | |
| 716 | 562 | * |
| 717 | 563 | * @return bool |
| 718 | 564 | */ |
| 719 | 565 | public static function form_has_action_type( $form_id, $type ) { |
| 720 | - $actions = self::get_action_for_form( $form_id, $type ); | |
| 721 | - return ! empty( $actions ); | |
| 566 | + $payment_actions = self::get_action_for_form( $form_id, $type ); | |
| 567 | + | |
| 568 | + return ! empty( $payment_actions ); | |
| 722 | 569 | } |
| 723 | 570 | |
| 724 | - /** | |
| 725 | - * @param false|int|string $form_id | |
| 726 | - * @param array $atts | |
| 727 | - * | |
| 728 | - * @return array | |
| 729 | - */ | |
| 730 | 571 | public function get_all( $form_id = false, $atts = array() ) { |
| 731 | 572 | if ( is_array( $atts ) && ! isset( $atts['limit'] ) && $this->action_options['limit'] > 99 ) { |
| 732 | 573 | $atts['limit'] = $this->action_options['limit']; |
| 733 | 574 | } |
| @@ -745,10 +586,10 @@ | ||
| 745 | 586 | global $frm_vars; |
| 746 | 587 | $frm_vars['action_type'] = $type; |
| 747 | 588 | |
| 748 | 589 | add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' ); |
| 749 | - $query = self::action_args( $form_id, $limit ); | |
| 750 | - $query['post_status'] = $atts['post_status']; | |
| 590 | + $query = self::action_args( $form_id, $limit ); | |
| 591 | + $query['post_status'] = $atts['post_status']; | |
| 751 | 592 | $query['suppress_filters'] = false; |
| 752 | 593 | |
| 753 | 594 | $actions = FrmDb::check_cache( json_encode( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' ); |
| 754 | 595 | unset( $query ); |
| @@ -759,9 +600,8 @@ | ||
| 759 | 600 | return array(); |
| 760 | 601 | } |
| 761 | 602 | |
| 762 | 603 | $settings = array(); |
| 763 | - | |
| 764 | 604 | foreach ( $actions as $action ) { |
| 765 | 605 | if ( count( $settings ) >= $limit ) { |
| 766 | 606 | continue; |
| 767 | 607 | } |
| @@ -778,11 +618,8 @@ | ||
| 778 | 618 | return $settings; |
| 779 | 619 | } |
| 780 | 620 | |
| 781 | 621 | /** |
| 782 | - * @param int $form_id | |
| 783 | - * @param int $limit | |
| 784 | - * | |
| 785 | 622 | * @return array |
| 786 | 623 | */ |
| 787 | 624 | public static function action_args( $form_id = 0, $limit = 99 ) { |
| 788 | 625 | $args = array( |
| @@ -800,11 +637,9 @@ | ||
| 800 | 637 | return $args; |
| 801 | 638 | } |
| 802 | 639 | |
| 803 | 640 | /** |
| 804 | - * @param WP_Post $action | |
| 805 | - * | |
| 806 | - * @return WP_Post | |
| 641 | + * @param WP_Post|array $action | |
| 807 | 642 | */ |
| 808 | 643 | public function prepare_action( $action ) { |
| 809 | 644 | $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content ); |
| 810 | 645 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
| @@ -815,9 +650,9 @@ | ||
| 815 | 650 | $action->post_content += $default_values; |
| 816 | 651 | |
| 817 | 652 | foreach ( $default_values as $k => $vals ) { |
| 818 | 653 | if ( is_array( $vals ) && ! empty( $vals ) ) { |
| 819 | - if ( 'event' === $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) { | |
| 654 | + if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) { | |
| 820 | 655 | continue; |
| 821 | 656 | } |
| 822 | 657 | $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals ); |
| 823 | 658 | } |
| @@ -830,11 +665,8 @@ | ||
| 830 | 665 | return $action; |
| 831 | 666 | } |
| 832 | 667 | |
| 833 | 668 | /** |
| 834 | - * @param false|int|string $form_id | |
| 835 | - * @param string $type | |
| 836 | - * | |
| 837 | 669 | * @return void |
| 838 | 670 | */ |
| 839 | 671 | public function destroy( $form_id = false, $type = 'default' ) { |
| 840 | 672 | global $wpdb; |
| @@ -841,13 +673,11 @@ | ||
| 841 | 673 | |
| 842 | 674 | $this->form_id = $form_id; |
| 843 | 675 | |
| 844 | 676 | $query = array( 'post_type' => FrmFormActionsController::$action_post_type ); |
| 845 | - | |
| 846 | 677 | if ( $form_id ) { |
| 847 | 678 | $query['menu_order'] = $form_id; |
| 848 | 679 | } |
| 849 | - | |
| 850 | 680 | if ( 'all' != $type ) { |
| 851 | 681 | $query['post_excerpt'] = $this->id_base; |
| 852 | 682 | } |
| 853 | 683 | |
| @@ -869,11 +699,8 @@ | ||
| 869 | 699 | public static function clear_cache() { |
| 870 | 700 | FrmDb::cache_delete_group( 'frm_actions' ); |
| 871 | 701 | } |
| 872 | 702 | |
| 873 | - /** | |
| 874 | - * @return array | |
| 875 | - */ | |
| 876 | 703 | public function get_settings() { |
| 877 | 704 | return self::get_action_for_form( $this->form_id, $this->id_base ); |
| 878 | 705 | } |
| 879 | 706 | |
| @@ -896,11 +723,8 @@ | ||
| 896 | 723 | |
| 897 | 724 | return $defaults; |
| 898 | 725 | } |
| 899 | 726 | |
| 900 | - /** | |
| 901 | - * @return array | |
| 902 | - */ | |
| 903 | 727 | public function get_global_switch_fields() { |
| 904 | 728 | $switch = $this->get_switch_fields(); |
| 905 | 729 | $switch['conditions'] = array( 'hide_field' ); |
| 906 | 730 | |
| @@ -910,16 +734,11 @@ | ||
| 910 | 734 | } |
| 911 | 735 | |
| 912 | 736 | /** |
| 913 | 737 | * Migrate settings from form->options into new action. |
| 914 | - * | |
| 915 | - * @param object $form | |
| 916 | - * @param string $update | |
| 917 | - * | |
| 918 | - * @return int|WP_Error | |
| 919 | 738 | */ |
| 920 | 739 | public function migrate_to_2( $form, $update = 'update' ) { |
| 921 | - $action = $this->prepare_new( $form->id ); | |
| 740 | + $action = $this->prepare_new( $form->id ); | |
| 922 | 741 | FrmAppHelper::unserialize_or_decode( $form->options ); |
| 923 | 742 | |
| 924 | 743 | // fill with existing options |
| 925 | 744 | foreach ( $action->post_content as $name => $val ) { |
| @@ -957,30 +776,89 @@ | ||
| 957 | 776 | |
| 958 | 777 | return $post_id; |
| 959 | 778 | } |
| 960 | 779 | |
| 961 | - /** | |
| 962 | - * @param WP_Post $action | |
| 963 | - * @param stdClass $entry | |
| 964 | - * | |
| 965 | - * @return bool | |
| 966 | - */ | |
| 967 | 780 | public static function action_conditions_met( $action, $entry ) { |
| 968 | 781 | if ( is_callable( 'FrmProFormActionsController::action_conditions_met' ) ) { |
| 969 | 782 | return FrmProFormActionsController::action_conditions_met( $action, $entry ); |
| 970 | 783 | } |
| 971 | 784 | |
| 972 | - $stop = false; | |
| 785 | + // This is here for reverse compatibility. | |
| 786 | + $notification = $action->post_content; | |
| 787 | + $stop = false; | |
| 788 | + $met = array(); | |
| 789 | + | |
| 790 | + if ( ! isset( $notification['conditions'] ) || empty( $notification['conditions'] ) ) { | |
| 791 | + return $stop; | |
| 792 | + } | |
| 793 | + | |
| 794 | + foreach ( $notification['conditions'] as $k => $condition ) { | |
| 795 | + if ( ! is_numeric( $k ) ) { | |
| 796 | + continue; | |
| 797 | + } | |
| 798 | + | |
| 799 | + if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) { | |
| 800 | + continue; | |
| 801 | + } | |
| 802 | + | |
| 803 | + self::prepare_logic_value( $condition['hide_opt'], $action, $entry ); | |
| 804 | + | |
| 805 | + $observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] ); | |
| 806 | + | |
| 807 | + $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] ); | |
| 808 | + | |
| 809 | + if ( $notification['conditions']['send_stop'] == 'send' ) { | |
| 810 | + $stop = $stop ? false : true; | |
| 811 | + } | |
| 812 | + | |
| 813 | + $met[ $stop ] = $stop; | |
| 814 | + } | |
| 815 | + | |
| 816 | + if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) { | |
| 817 | + $stop = ( $notification['conditions']['send_stop'] == 'send' ); | |
| 818 | + } elseif ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset( $met[0] ) ) { | |
| 819 | + $stop = false; | |
| 820 | + } | |
| 821 | + | |
| 973 | 822 | return $stop; |
| 974 | 823 | } |
| 975 | 824 | |
| 976 | 825 | /** |
| 826 | + * Prepare the logic value for comparison against the entered value | |
| 827 | + * | |
| 828 | + * @since 2.01.02 | |
| 829 | + * | |
| 830 | + * @deprecated 4.06.02 | |
| 831 | + * | |
| 832 | + * @param array|string $logic_value | |
| 833 | + * | |
| 834 | + * @return void | |
| 835 | + */ | |
| 836 | + private static function prepare_logic_value( &$logic_value, $action, $entry ) { | |
| 837 | + if ( is_array( $logic_value ) ) { | |
| 838 | + $logic_value = reset( $logic_value ); | |
| 839 | + } | |
| 840 | + | |
| 841 | + if ( $logic_value == 'current_user' ) { | |
| 842 | + $logic_value = get_current_user_id(); | |
| 843 | + } | |
| 844 | + | |
| 845 | + $logic_value = apply_filters( 'frm_content', $logic_value, $action->menu_order, $entry ); | |
| 846 | + | |
| 847 | + /** | |
| 848 | + * @since 4.04.05 | |
| 849 | + */ | |
| 850 | + $logic_value = apply_filters( 'frm_action_logic_value', $logic_value ); | |
| 851 | + } | |
| 852 | + | |
| 853 | + /** | |
| 977 | 854 | * Get the value from a specific field and entry |
| 978 | 855 | * |
| 979 | 856 | * @since 2.01.02 |
| 857 | + * @deprecated 4.06.02 | |
| 980 | 858 | * |
| 981 | 859 | * @param object $entry |
| 982 | - * @param int $field_id | |
| 860 | + * @param int $field_id | |
| 983 | 861 | * |
| 984 | 862 | * @return array|bool|mixed|string |
| 985 | 863 | */ |
| 986 | 864 | private static function get_value_from_entry( $entry, $field_id ) { |
| @@ -1015,11 +893,8 @@ | ||
| 1015 | 893 | 'limit' => 0, |
| 1016 | 894 | ); |
| 1017 | 895 | } |
| 1018 | 896 | |
| 1019 | - /** | |
| 1020 | - * @return array | |
| 1021 | - */ | |
| 1022 | 897 | public static function trigger_labels() { |
| 1023 | 898 | $triggers = array( |
| 1024 | 899 | 'draft' => __( 'Draft is saved', 'formidable' ), |
| 1025 | 900 | 'create' => __( 'Entry is created', 'formidable' ), |
| @@ -1048,26 +923,6 @@ | ||
| 1048 | 923 | * @return string |
| 1049 | 924 | */ |
| 1050 | 925 | protected function get_upgrade_text() { |
| 1051 | 926 | return __( 'Conditional form actions', 'formidable' ); |
| 1052 | - } | |
| 1053 | - | |
| 1054 | - /** | |
| 1055 | - * Gets form fields for form action settings. | |
| 1056 | - * | |
| 1057 | - * @since 6.10 | |
| 1058 | - * | |
| 1059 | - * @param int $form_id Form ID. | |
| 1060 | - * | |
| 1061 | - * @return object[] | |
| 1062 | - */ | |
| 1063 | - protected function get_form_fields( $form_id ) { | |
| 1064 | - // Get form fields, include embedded and repeater child fields. | |
| 1065 | - $form_fields = FrmField::get_all_for_form( $form_id, '', 'include' ); | |
| 1066 | - return array_filter( | |
| 1067 | - $form_fields, | |
| 1068 | - function ( $form_field ) { | |
| 1069 | - return ! FrmField::is_no_save_field( $form_field->type ); | |
| 1070 | - } | |
| 1071 | - ); | |
| 1072 | 927 | } |
| 1073 | 928 | } |