| @@ -88,13 +88,12 @@ | ||
| 88 | 88 | * Echo the settings update form |
| 89 | 89 | * |
| 90 | 90 | * @param WP_Post $instance Current settings. |
| 91 | 91 | * @param array $args |
| 92 | - * | |
| 93 | - * @return string | |
| 94 | 92 | */ |
| 95 | 93 | public function form( $instance, $args = array() ) { |
| 96 | 94 | echo '<p class="no-options-widget">' . esc_html__( 'There are no options for this action.', 'formidable' ) . '</p>'; |
| 95 | + | |
| 97 | 96 | return 'noform'; |
| 98 | 97 | } |
| 99 | 98 | |
| 100 | 99 | /** |
| @@ -110,14 +109,8 @@ | ||
| 110 | 109 | public function get_switch_fields() { |
| 111 | 110 | return array(); |
| 112 | 111 | } |
| 113 | 112 | |
| 114 | - /** | |
| 115 | - * @param object $action | |
| 116 | - * @param object $form | |
| 117 | - * | |
| 118 | - * @return object | |
| 119 | - */ | |
| 120 | 113 | public function migrate_values( $action, $form ) { |
| 121 | 114 | return $action; |
| 122 | 115 | } |
| 123 | 116 | |
| @@ -170,11 +163,10 @@ | ||
| 170 | 163 | $action_options['color'] = 'var(--' . reset( $colors ) . ')'; |
| 171 | 164 | } |
| 172 | 165 | |
| 173 | 166 | $upgrade_class = isset( $action_options['classes'] ) && $action_options['classes'] === 'frm_show_upgrade'; |
| 174 | - | |
| 175 | 167 | if ( $action_options['group'] === $id_base ) { |
| 176 | - $upgrade_class = str_contains( $action_options['classes'], 'frm_show_upgrade' ); | |
| 168 | + $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false; | |
| 177 | 169 | $action_options['classes'] = $group['icon']; |
| 178 | 170 | } elseif ( empty( $action_options['classes'] ) || $upgrade_class ) { |
| 179 | 171 | $action_options['classes'] = $group['icon']; |
| 180 | 172 | } |
| @@ -188,13 +180,8 @@ | ||
| 188 | 180 | } |
| 189 | 181 | |
| 190 | 182 | /** |
| 191 | 183 | * @param string $id_base |
| 192 | - * @param string $name | |
| 193 | - * @param array $action_options | |
| 194 | - * @param array $control_options | |
| 195 | - * | |
| 196 | - * @return void | |
| 197 | 184 | */ |
| 198 | 185 | public function FrmFormAction( $id_base, $name, $action_options = array(), $control_options = array() ) { |
| 199 | 186 | self::__construct( $id_base, $name, $action_options, $control_options ); |
| 200 | 187 | } |
| @@ -207,22 +194,16 @@ | ||
| 207 | 194 | * @return string |
| 208 | 195 | */ |
| 209 | 196 | public function maybe_switch_field_ids( $action ) { |
| 210 | 197 | $updated_action = apply_filters( 'frm_maybe_switch_field_ids', $action ); |
| 211 | - | |
| 212 | 198 | if ( $updated_action === $action ) { |
| 213 | - return FrmFieldsHelper::switch_field_ids( $action ); | |
| 199 | + $updated_action = FrmFieldsHelper::switch_field_ids( $action ); | |
| 214 | 200 | } |
| 215 | - | |
| 216 | 201 | return $updated_action; |
| 217 | 202 | } |
| 218 | 203 | |
| 219 | 204 | /** |
| 220 | 205 | * @since 4.0 |
| 221 | - * | |
| 222 | - * @param array $action_options | |
| 223 | - * | |
| 224 | - * @return array | |
| 225 | 206 | */ |
| 226 | 207 | protected function get_group( $action_options ) { |
| 227 | 208 | $groups = FrmFormActionsController::form_action_groups(); |
| 228 | 209 | $group = 'misc'; |
| @@ -232,9 +213,9 @@ | ||
| 232 | 213 | } elseif ( isset( $groups[ $this->id_base ] ) ) { |
| 233 | 214 | $group = $this->id_base; |
| 234 | 215 | } else { |
| 235 | 216 | foreach ( $groups as $name => $check_group ) { |
| 236 | - if ( isset( $check_group['actions'] ) && in_array( $this->id_base, $check_group['actions'], true ) ) { | |
| 217 | + if ( isset( $check_group['actions'] ) && in_array( $this->id_base, $check_group['actions'] ) ) { | |
| 237 | 218 | $group = $name; |
| 238 | 219 | break; |
| 239 | 220 | } |
| 240 | 221 | } |
| @@ -249,17 +230,17 @@ | ||
| 249 | 230 | * |
| 250 | 231 | * This function should be used in form() methods to create name attributes for fields to be saved by update() |
| 251 | 232 | * |
| 252 | 233 | * @param string $field_name Field name. |
| 253 | - * @param string $post_field | |
| 254 | 234 | * |
| 255 | 235 | * @return string Name attribute for $field_name |
| 256 | 236 | */ |
| 257 | 237 | public function get_field_name( $field_name, $post_field = 'post_content' ) { |
| 258 | 238 | $name = $this->option_name . '[' . $this->number . ']'; |
| 259 | - $name .= $post_field ? '[' . $post_field . ']' : ''; | |
| 239 | + $name .= ( empty( $post_field ) ? '' : '[' . $post_field . ']' ); | |
| 240 | + $name .= '[' . $field_name . ']'; | |
| 260 | 241 | |
| 261 | - return $name . ( '[' . $field_name . ']' ); | |
| 242 | + return $name; | |
| 262 | 243 | } |
| 263 | 244 | |
| 264 | 245 | /** |
| 265 | 246 | * Constructs id attributes for use in form() fields |
| @@ -275,9 +256,8 @@ | ||
| 275 | 256 | } |
| 276 | 257 | |
| 277 | 258 | /** |
| 278 | 259 | * @param int|string $number |
| 279 | - * | |
| 280 | 260 | * @return void |
| 281 | 261 | */ |
| 282 | 262 | public function _set( $number ) { |
| 283 | 263 | $this->number = $number; |
| @@ -284,10 +264,8 @@ | ||
| 284 | 264 | $this->id = $this->id_base . '-' . $number; |
| 285 | 265 | } |
| 286 | 266 | |
| 287 | 267 | /** |
| 288 | - * @param false|int|string $form_id | |
| 289 | - * | |
| 290 | 268 | * @return object |
| 291 | 269 | */ |
| 292 | 270 | public function prepare_new( $form_id = false ) { |
| 293 | 271 | if ( $form_id ) { |
| @@ -296,9 +274,9 @@ | ||
| 296 | 274 | |
| 297 | 275 | $post_content = array(); |
| 298 | 276 | $default_values = $this->get_global_defaults(); |
| 299 | 277 | |
| 300 | - // Fill default values | |
| 278 | + // fill default values | |
| 301 | 279 | $post_content = wp_parse_args( $post_content, $default_values ); |
| 302 | 280 | |
| 303 | 281 | if ( ! isset( $post_content['event'] ) && ! $this->action_options['force_event'] ) { |
| 304 | 282 | $post_content['event'] = array( reset( $this->action_options['event'] ) ); |
| @@ -313,17 +291,13 @@ | ||
| 313 | 291 | 'post_type' => FrmFormActionsController::$action_post_type, |
| 314 | 292 | 'post_name' => $this->form_id . '_' . $this->id_base . '_' . $this->number, |
| 315 | 293 | 'menu_order' => $this->form_id, |
| 316 | 294 | ); |
| 295 | + unset( $post_content ); | |
| 317 | 296 | |
| 318 | 297 | return (object) $form_action; |
| 319 | 298 | } |
| 320 | 299 | |
| 321 | - /** | |
| 322 | - * @param int|string $form_id | |
| 323 | - * | |
| 324 | - * @return int|WP_Error | |
| 325 | - */ | |
| 326 | 300 | public function create( $form_id ) { |
| 327 | 301 | $this->form_id = $form_id; |
| 328 | 302 | |
| 329 | 303 | $action = $this->prepare_new(); |
| @@ -331,17 +305,13 @@ | ||
| 331 | 305 | return $this->save_settings( $action ); |
| 332 | 306 | } |
| 333 | 307 | |
| 334 | 308 | /** |
| 335 | - * @param int|string $form_id | |
| 336 | - * @param int|string $old_id | |
| 337 | - * | |
| 338 | 309 | * @return void |
| 339 | 310 | */ |
| 340 | 311 | public function duplicate_form_actions( $form_id, $old_id ) { |
| 341 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 342 | 312 | if ( $form_id == $old_id ) { |
| 343 | - // Don't duplicate the actions if this is a template getting updated | |
| 313 | + // don't duplicate the actions if this is a template getting updated | |
| 344 | 314 | return; |
| 345 | 315 | } |
| 346 | 316 | |
| 347 | 317 | $this->form_id = $old_id; |
| @@ -347,9 +317,8 @@ | ||
| 347 | 317 | $this->form_id = $old_id; |
| 348 | 318 | $actions = $this->get_all( $old_id ); |
| 349 | 319 | |
| 350 | 320 | $this->form_id = $form_id; |
| 351 | - | |
| 352 | 321 | foreach ( $actions as $action ) { |
| 353 | 322 | $this->duplicate_one( $action, $form_id ); |
| 354 | 323 | unset( $action ); |
| 355 | 324 | } |
| @@ -360,28 +329,26 @@ | ||
| 360 | 329 | * |
| 361 | 330 | * @since 2.0 |
| 362 | 331 | * |
| 363 | 332 | * @param array $action |
| 364 | - * @param array $forms | |
| 365 | - * | |
| 366 | - * @return int Post ID. | |
| 333 | + * @return int $post_id | |
| 367 | 334 | */ |
| 368 | 335 | public function maybe_create_action( $action, $forms ) { |
| 369 | 336 | if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] === 'updated' ) { |
| 370 | 337 | // Update action only |
| 371 | 338 | $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
| 372 | - return $this->save_settings( $action ); | |
| 339 | + $post_id = $this->save_settings( $action ); | |
| 340 | + } else { | |
| 341 | + // Create action | |
| 342 | + $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); | |
| 343 | + $post_id = $this->duplicate_one( (object) $action, $action['menu_order'] ); | |
| 373 | 344 | } |
| 374 | - // Create action | |
| 375 | - $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); | |
| 376 | - return $this->duplicate_one( (object) $action, $action['menu_order'] ); | |
| 345 | + | |
| 346 | + return $post_id; | |
| 377 | 347 | } |
| 378 | 348 | |
| 379 | 349 | /** |
| 380 | - * @param object $action | |
| 381 | - * @param int|string $form_id | |
| 382 | - * | |
| 383 | - * @return int|WP_Error | |
| 350 | + * @param object $action | |
| 384 | 351 | */ |
| 385 | 352 | public function duplicate_one( $action, $form_id ) { |
| 386 | 353 | global $frm_duplicate_ids; |
| 387 | 354 | |
| @@ -393,9 +360,9 @@ | ||
| 393 | 360 | $action->post_content[ $key ] = $frm_duplicate_ids[ $val ]; |
| 394 | 361 | } elseif ( ! is_array( $val ) ) { |
| 395 | 362 | $action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val ); |
| 396 | 363 | } elseif ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) { |
| 397 | - // Loop through each value if empty | |
| 364 | + // loop through each value if empty | |
| 398 | 365 | if ( empty( $switch[ $key ] ) ) { |
| 399 | 366 | $switch[ $key ] = array_keys( $val ); |
| 400 | 367 | } |
| 401 | 368 | |
| @@ -410,15 +377,8 @@ | ||
| 410 | 377 | |
| 411 | 378 | return $this->save_settings( $action ); |
| 412 | 379 | } |
| 413 | 380 | |
| 414 | - /** | |
| 415 | - * @param array $action | |
| 416 | - * @param array|string $subkey | |
| 417 | - * @param mixed $val | |
| 418 | - * | |
| 419 | - * @return array | |
| 420 | - */ | |
| 421 | 381 | private function duplicate_array_walk( $action, $subkey, $val ) { |
| 422 | 382 | global $frm_duplicate_ids; |
| 423 | 383 | |
| 424 | 384 | if ( is_array( $subkey ) ) { |
| @@ -434,11 +394,11 @@ | ||
| 434 | 394 | } else { |
| 435 | 395 | foreach ( (array) $val as $ck => $cv ) { |
| 436 | 396 | if ( is_array( $cv ) ) { |
| 437 | 397 | $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv ); |
| 438 | - } elseif ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) { // phpcs:ignore Universal.Operators.StrictComparisons | |
| 398 | + } elseif ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) { | |
| 439 | 399 | $action[ $ck ] = $frm_duplicate_ids[ $cv ]; |
| 440 | - } elseif ( $ck == $subkey ) { // phpcs:ignore Universal.Operators.StrictComparisons | |
| 400 | + } elseif ( $ck == $subkey ) { | |
| 441 | 401 | $action[ $ck ] = $this->maybe_switch_field_ids( $action[ $ck ] ); |
| 442 | 402 | } |
| 443 | 403 | } |
| 444 | 404 | }//end if |
| @@ -449,12 +409,8 @@ | ||
| 449 | 409 | /** |
| 450 | 410 | * Deal with changed settings. |
| 451 | 411 | * |
| 452 | 412 | * Do NOT over-ride this function |
| 453 | - * | |
| 454 | - * @param int|string $form_id | |
| 455 | - * | |
| 456 | - * @return array|null | |
| 457 | 413 | */ |
| 458 | 414 | public function update_callback( $form_id ) { |
| 459 | 415 | $this->form_id = $form_id; |
| 460 | 416 | |
| @@ -461,32 +417,32 @@ | ||
| 461 | 417 | $all_instances = $this->get_settings(); |
| 462 | 418 | |
| 463 | 419 | // We need to update the data |
| 464 | 420 | if ( $this->updated ) { |
| 465 | - return null; | |
| 421 | + return; | |
| 466 | 422 | } |
| 467 | 423 | |
| 468 | 424 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 469 | - if ( ! isset( $_POST[ $this->option_name ] ) || ! is_array( $_POST[ $this->option_name ] ) ) { | |
| 470 | - return null; | |
| 425 | + if ( isset( $_POST[ $this->option_name ] ) && is_array( $_POST[ $this->option_name ] ) ) { | |
| 426 | + // Sanitizing removes scripts and <email> type of values. | |
| 427 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing | |
| 428 | + $settings = wp_unslash( $_POST[ $this->option_name ] ); | |
| 429 | + } else { | |
| 430 | + return; | |
| 471 | 431 | } |
| 472 | 432 | |
| 473 | - // Sanitizing removes scripts and <email> type of values. | |
| 474 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing | |
| 475 | - $settings = wp_unslash( $_POST[ $this->option_name ] ); | |
| 476 | - | |
| 477 | 433 | $action_ids = array(); |
| 478 | 434 | |
| 479 | 435 | foreach ( $settings as $number => $new_instance ) { |
| 480 | 436 | $this->_set( $number ); |
| 481 | 437 | |
| 482 | - $old_instance = $all_instances[ $number ] ?? array(); | |
| 438 | + $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array(); | |
| 483 | 439 | |
| 484 | 440 | if ( ! isset( $new_instance['post_status'] ) ) { |
| 485 | 441 | $new_instance['post_status'] = 'draft'; |
| 486 | 442 | } |
| 487 | 443 | |
| 488 | - // Settings were never opened, so don't update | |
| 444 | + // settings were never opened, so don't update | |
| 489 | 445 | if ( ! isset( $new_instance['post_title'] ) ) { |
| 490 | 446 | $this->maybe_update_status( $new_instance, $old_instance ); |
| 491 | 447 | $action_ids[] = $new_instance['ID']; |
| 492 | 448 | $this->updated = true; |
| @@ -495,9 +451,9 @@ | ||
| 495 | 451 | |
| 496 | 452 | $new_instance['post_type'] = FrmFormActionsController::$action_post_type; |
| 497 | 453 | $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number; |
| 498 | 454 | $new_instance['menu_order'] = $this->form_id; |
| 499 | - $new_instance['post_date'] = $old_instance->post_date ?? ''; | |
| 455 | + $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : ''; | |
| 500 | 456 | $instance = $this->update( $new_instance, $old_instance ); |
| 501 | 457 | |
| 502 | 458 | /** |
| 503 | 459 | * Filter an action's settings before saving. |
| @@ -535,9 +491,8 @@ | ||
| 535 | 491 | * @since 3.04 |
| 536 | 492 | * |
| 537 | 493 | * @param array $new_instance |
| 538 | 494 | * @param array|stdClass $old_instance |
| 539 | - * | |
| 540 | 495 | * @return void |
| 541 | 496 | */ |
| 542 | 497 | protected function maybe_update_status( $new_instance, $old_instance ) { |
| 543 | 498 | if ( ! is_object( $old_instance ) || $new_instance['post_status'] === $old_instance->post_status ) { |
| @@ -554,24 +509,18 @@ | ||
| 554 | 509 | } |
| 555 | 510 | |
| 556 | 511 | /** |
| 557 | 512 | * @param array $settings |
| 558 | - * | |
| 559 | 513 | * @return int|WP_Error |
| 560 | 514 | */ |
| 561 | 515 | public function save_settings( $settings ) { |
| 562 | 516 | self::clear_cache(); |
| 517 | + | |
| 563 | 518 | return FrmDb::save_settings( $settings, 'frm_actions' ); |
| 564 | 519 | } |
| 565 | 520 | |
| 566 | - /** | |
| 567 | - * @param int $id | |
| 568 | - * | |
| 569 | - * @return object|null | |
| 570 | - */ | |
| 571 | 521 | public function get_single_action( $id ) { |
| 572 | 522 | $action = get_post( $id ); |
| 573 | - | |
| 574 | 523 | if ( $action ) { |
| 575 | 524 | $action = $this->prepare_action( $action ); |
| 576 | 525 | $this->_set( $id ); |
| 577 | 526 | } |
| @@ -578,43 +527,27 @@ | ||
| 578 | 527 | |
| 579 | 528 | return $action; |
| 580 | 529 | } |
| 581 | 530 | |
| 582 | - /** | |
| 583 | - * @param int|string $form_id | |
| 584 | - * | |
| 585 | - * @return array | |
| 586 | - */ | |
| 587 | 531 | public function get_one( $form_id ) { |
| 588 | 532 | return $this->get_all( $form_id, 1 ); |
| 589 | 533 | } |
| 590 | 534 | |
| 591 | - /** | |
| 592 | - * @param int|string $form_id | |
| 593 | - * @param string $type | |
| 594 | - * @param array $atts | |
| 595 | - * | |
| 596 | - * @return array | |
| 597 | - */ | |
| 598 | 535 | public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) { |
| 599 | 536 | $action_controls = FrmFormActionsController::get_form_actions( $type ); |
| 600 | - | |
| 601 | - if ( ! $action_controls ) { | |
| 602 | - // Don't continue if there are no available actions | |
| 537 | + if ( empty( $action_controls ) ) { | |
| 538 | + // don't continue if there are no available actions | |
| 603 | 539 | return array(); |
| 604 | 540 | } |
| 605 | 541 | |
| 606 | 542 | if ( 'all' !== $type ) { |
| 607 | - if ( is_array( $action_controls ) ) { | |
| 608 | - return array(); | |
| 609 | - } | |
| 610 | - | |
| 611 | 543 | return $action_controls->get_all( $form_id, $atts ); |
| 612 | 544 | } |
| 613 | 545 | |
| 614 | 546 | self::prepare_get_action( $atts ); |
| 615 | 547 | |
| 616 | - $limit = self::get_action_limit( $form_id, $atts['limit'] ); | |
| 548 | + $limit = apply_filters( 'frm_form_action_limit', $atts['limit'], compact( 'type', 'form_id' ) ); | |
| 549 | + | |
| 617 | 550 | $args = self::action_args( $form_id, $limit ); |
| 618 | 551 | $args['post_status'] = $atts['post_status']; |
| 619 | 552 | $actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' ); |
| 620 | 553 | |
| @@ -622,11 +555,10 @@ | ||
| 622 | 555 | return array(); |
| 623 | 556 | } |
| 624 | 557 | |
| 625 | 558 | $settings = array(); |
| 626 | - | |
| 627 | 559 | foreach ( $actions as $action ) { |
| 628 | - // Some plugins/themes are formatting the post_excerpt | |
| 560 | + // some plugins/themes are formatting the post_excerpt | |
| 629 | 561 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
| 630 | 562 | |
| 631 | 563 | if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) { |
| 632 | 564 | continue; |
| @@ -639,43 +571,30 @@ | ||
| 639 | 571 | break; |
| 640 | 572 | } |
| 641 | 573 | } |
| 642 | 574 | |
| 643 | - return 1 === $limit ? reset( $settings ) : $settings; | |
| 644 | - } | |
| 575 | + if ( 1 === $limit ) { | |
| 576 | + $settings = reset( $settings ); | |
| 577 | + } | |
| 645 | 578 | |
| 646 | - /** | |
| 647 | - * Get the limit for the number of actions for a single form. By default, this is 99, but | |
| 648 | - * it can be modified with a code snippet. | |
| 649 | - * | |
| 650 | - * @since 6.17 This logic from moved from FrmFormAction::get_action_for_form. | |
| 651 | - * | |
| 652 | - * @param int|string $form_id | |
| 653 | - * @param int|string $limit The unfiltered limit value. | |
| 654 | - * | |
| 655 | - * @return int The filtered limit value. | |
| 656 | - */ | |
| 657 | - public static function get_action_limit( $form_id, $limit = 99 ) { | |
| 658 | - $type = 'all'; | |
| 659 | - return (int) apply_filters( 'frm_form_action_limit', (int) $limit, compact( 'type', 'form_id' ) ); | |
| 579 | + return $settings; | |
| 660 | 580 | } |
| 661 | 581 | |
| 662 | 582 | /** |
| 663 | 583 | * @since 3.04 |
| 664 | 584 | * |
| 665 | - * @param array|string $args | |
| 666 | - * @param string $default_status | |
| 585 | + * @param array $args | |
| 586 | + * @param string $default_status | |
| 667 | 587 | * |
| 668 | 588 | * @return void |
| 669 | 589 | */ |
| 670 | 590 | protected static function prepare_get_action( &$args, $default_status = 'publish' ) { |
| 671 | 591 | if ( is_numeric( $args ) ) { |
| 672 | - // For reverse compatibility. $limit was changed to $args | |
| 592 | + // for reverse compatibility. $limit was changed to $args | |
| 673 | 593 | $args = array( |
| 674 | 594 | 'limit' => $args, |
| 675 | 595 | ); |
| 676 | 596 | } |
| 677 | - | |
| 678 | 597 | $defaults = array( |
| 679 | 598 | 'limit' => 99, |
| 680 | 599 | 'post_status' => $default_status, |
| 681 | 600 | ); |
| @@ -682,12 +601,9 @@ | ||
| 682 | 601 | $args = wp_parse_args( $args, $defaults ); |
| 683 | 602 | } |
| 684 | 603 | |
| 685 | 604 | /** |
| 686 | - * @param int $action_id | |
| 687 | - * @param string $type | |
| 688 | - * | |
| 689 | - * @return bool|object | |
| 605 | + * @param int $action_id | |
| 690 | 606 | */ |
| 691 | 607 | public static function get_single_action_type( $action_id, $type ) { |
| 692 | 608 | if ( ! $type ) { |
| 693 | 609 | return false; |
| @@ -701,24 +617,18 @@ | ||
| 701 | 617 | return $action_control->get_single_action( $action_id ); |
| 702 | 618 | } |
| 703 | 619 | |
| 704 | 620 | /** |
| 705 | - * @param int $form_id | |
| 706 | - * @param string $type | |
| 621 | + * @param int $form_id | |
| 707 | 622 | * |
| 708 | 623 | * @return bool |
| 709 | 624 | */ |
| 710 | 625 | public static function form_has_action_type( $form_id, $type ) { |
| 711 | - $actions = self::get_action_for_form( $form_id, $type ); | |
| 712 | - return ! empty( $actions ); | |
| 626 | + $payment_actions = self::get_action_for_form( $form_id, $type ); | |
| 627 | + | |
| 628 | + return ! empty( $payment_actions ); | |
| 713 | 629 | } |
| 714 | 630 | |
| 715 | - /** | |
| 716 | - * @param false|int|string $form_id | |
| 717 | - * @param array $atts | |
| 718 | - * | |
| 719 | - * @return array | |
| 720 | - */ | |
| 721 | 631 | public function get_all( $form_id = false, $atts = array() ) { |
| 722 | 632 | if ( is_array( $atts ) && ! isset( $atts['limit'] ) && $this->action_options['limit'] > 99 ) { |
| 723 | 633 | $atts['limit'] = $this->action_options['limit']; |
| 724 | 634 | } |
| @@ -745,30 +655,31 @@ | ||
| 745 | 655 | unset( $query ); |
| 746 | 656 | |
| 747 | 657 | remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' ); |
| 748 | 658 | |
| 749 | - if ( ! $actions ) { | |
| 659 | + if ( empty( $actions ) ) { | |
| 750 | 660 | return array(); |
| 751 | 661 | } |
| 752 | 662 | |
| 753 | 663 | $settings = array(); |
| 754 | - | |
| 755 | 664 | foreach ( $actions as $action ) { |
| 756 | 665 | if ( count( $settings ) >= $limit ) { |
| 757 | 666 | continue; |
| 758 | 667 | } |
| 759 | 668 | |
| 760 | - $action = $this->prepare_action( $action ); | |
| 669 | + $action = $this->prepare_action( $action ); | |
| 670 | + | |
| 761 | 671 | $settings[ $action->ID ] = $action; |
| 762 | 672 | } |
| 763 | 673 | |
| 764 | - return 1 === $limit ? reset( $settings ) : $settings; | |
| 674 | + if ( 1 === $limit ) { | |
| 675 | + $settings = reset( $settings ); | |
| 676 | + } | |
| 677 | + | |
| 678 | + return $settings; | |
| 765 | 679 | } |
| 766 | 680 | |
| 767 | 681 | /** |
| 768 | - * @param int|string $form_id | |
| 769 | - * @param int $limit | |
| 770 | - * | |
| 771 | 682 | * @return array |
| 772 | 683 | */ |
| 773 | 684 | public static function action_args( $form_id = 0, $limit = 99 ) { |
| 774 | 685 | $args = array( |
| @@ -778,9 +689,9 @@ | ||
| 778 | 689 | 'orderby' => 'title', |
| 779 | 690 | 'order' => 'ASC', |
| 780 | 691 | ); |
| 781 | 692 | |
| 782 | - if ( $form_id && $form_id !== 'all' ) { | |
| 693 | + if ( $form_id && $form_id != 'all' ) { | |
| 783 | 694 | $args['menu_order'] = $form_id; |
| 784 | 695 | } |
| 785 | 696 | |
| 786 | 697 | return $args; |
| @@ -786,11 +697,9 @@ | ||
| 786 | 697 | return $args; |
| 787 | 698 | } |
| 788 | 699 | |
| 789 | 700 | /** |
| 790 | - * @param WP_Post $action | |
| 791 | - * | |
| 792 | - * @return WP_Post | |
| 701 | + * @param array|WP_Post $action | |
| 793 | 702 | */ |
| 794 | 703 | public function prepare_action( $action ) { |
| 795 | 704 | $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content ); |
| 796 | 705 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
| @@ -796,13 +705,13 @@ | ||
| 796 | 705 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
| 797 | 706 | |
| 798 | 707 | $default_values = $this->get_global_defaults(); |
| 799 | 708 | |
| 800 | - // Fill default values | |
| 709 | + // fill default values | |
| 801 | 710 | $action->post_content += $default_values; |
| 802 | 711 | |
| 803 | 712 | foreach ( $default_values as $k => $vals ) { |
| 804 | - if ( is_array( $vals ) && $vals ) { | |
| 713 | + if ( is_array( $vals ) && ! empty( $vals ) ) { | |
| 805 | 714 | if ( 'event' === $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) { |
| 806 | 715 | continue; |
| 807 | 716 | } |
| 808 | 717 | $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals ); |
| @@ -816,11 +725,8 @@ | ||
| 816 | 725 | return $action; |
| 817 | 726 | } |
| 818 | 727 | |
| 819 | 728 | /** |
| 820 | - * @param false|int|string $form_id | |
| 821 | - * @param string $type | |
| 822 | - * | |
| 823 | 729 | * @return void |
| 824 | 730 | */ |
| 825 | 731 | public function destroy( $form_id = false, $type = 'default' ) { |
| 826 | 732 | global $wpdb; |
| @@ -827,14 +733,12 @@ | ||
| 827 | 733 | |
| 828 | 734 | $this->form_id = $form_id; |
| 829 | 735 | |
| 830 | 736 | $query = array( 'post_type' => FrmFormActionsController::$action_post_type ); |
| 831 | - | |
| 832 | 737 | if ( $form_id ) { |
| 833 | 738 | $query['menu_order'] = $form_id; |
| 834 | 739 | } |
| 835 | - | |
| 836 | - if ( 'all' !== $type ) { | |
| 740 | + if ( 'all' != $type ) { | |
| 837 | 741 | $query['post_excerpt'] = $this->id_base; |
| 838 | 742 | } |
| 839 | 743 | |
| 840 | 744 | $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' ); |
| @@ -855,11 +759,8 @@ | ||
| 855 | 759 | public static function clear_cache() { |
| 856 | 760 | FrmDb::cache_delete_group( 'frm_actions' ); |
| 857 | 761 | } |
| 858 | 762 | |
| 859 | - /** | |
| 860 | - * @return array | |
| 861 | - */ | |
| 862 | 763 | public function get_settings() { |
| 863 | 764 | return self::get_action_for_form( $this->form_id, $this->id_base ); |
| 864 | 765 | } |
| 865 | 766 | |
| @@ -882,31 +783,25 @@ | ||
| 882 | 783 | |
| 883 | 784 | return $defaults; |
| 884 | 785 | } |
| 885 | 786 | |
| 886 | - /** | |
| 887 | - * @return array | |
| 888 | - */ | |
| 889 | 787 | public function get_global_switch_fields() { |
| 890 | 788 | $switch = $this->get_switch_fields(); |
| 891 | 789 | $switch['conditions'] = array( 'hide_field' ); |
| 892 | 790 | |
| 893 | - return apply_filters( 'frm_global_switch_fields', $switch ); | |
| 791 | + $switch = apply_filters( 'frm_global_switch_fields', $switch ); | |
| 792 | + | |
| 793 | + return $switch; | |
| 894 | 794 | } |
| 895 | 795 | |
| 896 | 796 | /** |
| 897 | 797 | * Migrate settings from form->options into new action. |
| 898 | - * | |
| 899 | - * @param object $form | |
| 900 | - * @param string $update | |
| 901 | - * | |
| 902 | - * @return int|WP_Error | |
| 903 | 798 | */ |
| 904 | 799 | public function migrate_to_2( $form, $update = 'update' ) { |
| 905 | 800 | $action = $this->prepare_new( $form->id ); |
| 906 | 801 | FrmAppHelper::unserialize_or_decode( $form->options ); |
| 907 | 802 | |
| 908 | - // Fill with existing options | |
| 803 | + // fill with existing options | |
| 909 | 804 | foreach ( $action->post_content as $name => $val ) { |
| 910 | 805 | if ( isset( $form->options[ $name ] ) ) { |
| 911 | 806 | $action->post_content[ $name ] = $form->options[ $name ]; |
| 912 | 807 | unset( $form->options[ $name ] ); |
| @@ -914,9 +809,9 @@ | ||
| 914 | 809 | } |
| 915 | 810 | |
| 916 | 811 | $action = $this->migrate_values( $action, $form ); |
| 917 | 812 | |
| 918 | - // Check if action already exists | |
| 813 | + // check if action already exists | |
| 919 | 814 | $post_id = get_posts( |
| 920 | 815 | array( |
| 921 | 816 | 'name' => $action->post_name, |
| 922 | 817 | 'post_type' => FrmFormActionsController::$action_post_type, |
| @@ -924,41 +819,127 @@ | ||
| 924 | 819 | 'numberposts' => 1, |
| 925 | 820 | ) |
| 926 | 821 | ); |
| 927 | 822 | |
| 928 | - if ( ! $post_id ) { | |
| 929 | - // Create action now | |
| 823 | + if ( empty( $post_id ) ) { | |
| 824 | + // create action now | |
| 930 | 825 | $post_id = $this->save_settings( $action ); |
| 931 | 826 | } |
| 932 | 827 | |
| 933 | - if ( ! $post_id || 'update' !== $update ) { | |
| 934 | - return $post_id; | |
| 828 | + if ( $post_id && 'update' == $update ) { | |
| 829 | + global $wpdb; | |
| 830 | + $form->options = maybe_serialize( $form->options ); | |
| 831 | + | |
| 832 | + // update form options | |
| 833 | + $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) ); | |
| 834 | + FrmForm::clear_form_cache(); | |
| 935 | 835 | } |
| 936 | 836 | |
| 937 | - global $wpdb; | |
| 938 | - $form->options = maybe_serialize( $form->options ); | |
| 837 | + return $post_id; | |
| 838 | + } | |
| 939 | 839 | |
| 940 | - // Update form options | |
| 941 | - $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) ); | |
| 942 | - FrmForm::clear_form_cache(); | |
| 840 | + public static function action_conditions_met( $action, $entry ) { | |
| 841 | + if ( is_callable( 'FrmProFormActionsController::action_conditions_met' ) ) { | |
| 842 | + return FrmProFormActionsController::action_conditions_met( $action, $entry ); | |
| 843 | + } | |
| 943 | 844 | |
| 944 | - return $post_id; | |
| 845 | + // This is here for reverse compatibility. | |
| 846 | + $notification = $action->post_content; | |
| 847 | + $stop = false; | |
| 848 | + $met = array(); | |
| 849 | + | |
| 850 | + if ( empty( $notification['conditions'] ) ) { | |
| 851 | + return $stop; | |
| 852 | + } | |
| 853 | + | |
| 854 | + foreach ( $notification['conditions'] as $k => $condition ) { | |
| 855 | + if ( ! is_numeric( $k ) ) { | |
| 856 | + continue; | |
| 857 | + } | |
| 858 | + | |
| 859 | + if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) { | |
| 860 | + continue; | |
| 861 | + } | |
| 862 | + | |
| 863 | + self::prepare_logic_value( $condition['hide_opt'], $action, $entry ); | |
| 864 | + | |
| 865 | + $observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] ); | |
| 866 | + | |
| 867 | + $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] ); | |
| 868 | + | |
| 869 | + if ( $notification['conditions']['send_stop'] === 'send' ) { | |
| 870 | + $stop = $stop ? false : true; | |
| 871 | + } | |
| 872 | + | |
| 873 | + $met[ $stop ] = $stop; | |
| 874 | + }//end foreach | |
| 875 | + | |
| 876 | + if ( $notification['conditions']['any_all'] === 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) { | |
| 877 | + $stop = ( $notification['conditions']['send_stop'] === 'send' ); | |
| 878 | + } elseif ( $notification['conditions']['any_all'] === 'any' && $notification['conditions']['send_stop'] === 'send' && isset( $met[0] ) ) { | |
| 879 | + $stop = false; | |
| 880 | + } | |
| 881 | + | |
| 882 | + return $stop; | |
| 945 | 883 | } |
| 946 | 884 | |
| 947 | 885 | /** |
| 948 | - * @param WP_Post $action | |
| 949 | - * @param stdClass $entry | |
| 886 | + * Prepare the logic value for comparison against the entered value | |
| 950 | 887 | * |
| 951 | - * @return bool | |
| 888 | + * @since 2.01.02 | |
| 889 | + * | |
| 890 | + * @param array|string $logic_value | |
| 891 | + * | |
| 892 | + * @return void | |
| 952 | 893 | */ |
| 953 | - public static function action_conditions_met( $action, $entry ) { | |
| 954 | - if ( is_callable( 'FrmProFormActionsController::action_conditions_met' ) ) { | |
| 955 | - return FrmProFormActionsController::action_conditions_met( $action, $entry ); | |
| 894 | + private static function prepare_logic_value( &$logic_value, $action, $entry ) { | |
| 895 | + if ( is_array( $logic_value ) ) { | |
| 896 | + $logic_value = reset( $logic_value ); | |
| 956 | 897 | } |
| 957 | - return false; | |
| 898 | + | |
| 899 | + if ( $logic_value === 'current_user' ) { | |
| 900 | + $logic_value = get_current_user_id(); | |
| 901 | + } | |
| 902 | + | |
| 903 | + $logic_value = apply_filters( 'frm_content', $logic_value, $action->menu_order, $entry ); | |
| 904 | + | |
| 905 | + /** | |
| 906 | + * @since 4.04.05 | |
| 907 | + */ | |
| 908 | + $logic_value = apply_filters( 'frm_action_logic_value', $logic_value ); | |
| 958 | 909 | } |
| 959 | 910 | |
| 960 | 911 | /** |
| 912 | + * Get the value from a specific field and entry | |
| 913 | + * | |
| 914 | + * @since 2.01.02 | |
| 915 | + * | |
| 916 | + * @param object $entry | |
| 917 | + * @param int $field_id | |
| 918 | + * | |
| 919 | + * @return array|bool|mixed|string | |
| 920 | + */ | |
| 921 | + private static function get_value_from_entry( $entry, $field_id ) { | |
| 922 | + $observed_value = ''; | |
| 923 | + | |
| 924 | + if ( isset( $entry->metas[ $field_id ] ) ) { | |
| 925 | + $observed_value = $entry->metas[ $field_id ]; | |
| 926 | + } elseif ( $entry->post_id && FrmAppHelper::pro_is_installed() ) { | |
| 927 | + $field = FrmField::getOne( $field_id ); | |
| 928 | + $observed_value = FrmProEntryMetaHelper::get_post_or_meta_value( | |
| 929 | + $entry, | |
| 930 | + $field, | |
| 931 | + array( | |
| 932 | + 'links' => false, | |
| 933 | + 'truncate' => false, | |
| 934 | + ) | |
| 935 | + ); | |
| 936 | + } | |
| 937 | + | |
| 938 | + return $observed_value; | |
| 939 | + } | |
| 940 | + | |
| 941 | + /** | |
| 961 | 942 | * @param string $class |
| 962 | 943 | * |
| 963 | 944 | * @return array |
| 964 | 945 | */ |
| @@ -963,17 +944,14 @@ | ||
| 963 | 944 | * @return array |
| 964 | 945 | */ |
| 965 | 946 | public static function default_action_opts( $class = '' ) { |
| 966 | 947 | return array( |
| 967 | - 'classes' => 'frmfont ' . $class, | |
| 948 | + 'classes' => 'frm_icon_font ' . $class, | |
| 968 | 949 | 'active' => false, |
| 969 | 950 | 'limit' => 0, |
| 970 | 951 | ); |
| 971 | 952 | } |
| 972 | 953 | |
| 973 | - /** | |
| 974 | - * @return array | |
| 975 | - */ | |
| 976 | 954 | public static function trigger_labels() { |
| 977 | 955 | $triggers = array( |
| 978 | 956 | 'draft' => __( 'Draft is saved', 'formidable' ), |
| 979 | 957 | 'create' => __( 'Entry is created', 'formidable' ), |
| @@ -988,17 +966,15 @@ | ||
| 988 | 966 | /** |
| 989 | 967 | * @return void |
| 990 | 968 | */ |
| 991 | 969 | public function render_conditional_logic_call_to_action() { |
| 992 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 993 | 970 | ?> |
| 994 | 971 | <h3> |
| 995 | - <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 ); ?>"><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?> | |
| 972 | + <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 ); ?>"> | |
| 996 | 973 | <?php esc_html_e( 'Use Conditional Logic', 'formidable' ); ?> |
| 997 | 974 | </a> |
| 998 | 975 | </h3> |
| 999 | 976 | <?php |
| 1000 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 1001 | 977 | } |
| 1002 | 978 | |
| 1003 | 979 | /** |
| 1004 | 980 | * @return string |
| @@ -1012,9 +988,8 @@ | ||
| 1012 | 988 | * |
| 1013 | 989 | * @since 6.10 |
| 1014 | 990 | * |
| 1015 | 991 | * @param int $form_id Form ID. |
| 1016 | - * | |
| 1017 | 992 | * @return object[] |
| 1018 | 993 | */ |
| 1019 | 994 | protected function get_form_fields( $form_id ) { |
| 1020 | 995 | // Get form fields, include embedded and repeater child fields. |