| @@ -49,11 +49,8 @@ | ||
| 49 | 49 | public function get_defaults() { |
| 50 | 50 | return array(); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - /** | |
| 54 | - * @return array | |
| 55 | - */ | |
| 56 | 53 | public function get_switch_fields() { |
| 57 | 54 | return array(); |
| 58 | 55 | } |
| 59 | 56 | |
| @@ -96,9 +93,8 @@ | ||
| 96 | 93 | 'plugin' => $this->id_base, |
| 97 | 94 | 'tooltip' => $name, |
| 98 | 95 | 'group' => $id_base, |
| 99 | 96 | 'color' => '', |
| 100 | - 'keywords' => '', | |
| 101 | 97 | ); |
| 102 | 98 | |
| 103 | 99 | $action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options ); |
| 104 | 100 | $group = $this->get_group( $action_options ); |
| @@ -109,9 +105,9 @@ | ||
| 109 | 105 | shuffle( $colors ); |
| 110 | 106 | $action_options['color'] = 'var(--' . reset( $colors ) . ')'; |
| 111 | 107 | } |
| 112 | 108 | |
| 113 | - $upgrade_class = isset( $action_options['classes'] ) && $action_options['classes'] === 'frm_show_upgrade'; | |
| 109 | + $upgrade_class = $action_options['classes'] === 'frm_show_upgrade'; | |
| 114 | 110 | if ( $action_options['group'] === $id_base ) { |
| 115 | 111 | $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false; |
| 116 | 112 | $action_options['classes'] = $group['icon']; |
| 117 | 113 | } elseif ( ! isset( $action_options['classes'] ) || empty( $action_options['classes'] ) || $upgrade_class ) { |
| @@ -133,23 +129,8 @@ | ||
| 133 | 129 | self::__construct( $id_base, $name, $action_options, $control_options ); |
| 134 | 130 | } |
| 135 | 131 | |
| 136 | 132 | /** |
| 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 | 133 | * @since 4.0 |
| 153 | 134 | */ |
| 154 | 135 | protected function get_group( $action_options ) { |
| 155 | 136 | $groups = FrmFormActionsController::form_action_groups(); |
| @@ -201,20 +182,15 @@ | ||
| 201 | 182 | public function get_field_id( $field_name ) { |
| 202 | 183 | return $field_name . '_' . $this->number; |
| 203 | 184 | } |
| 204 | 185 | |
| 205 | - /** | |
| 206 | - * @param int|string $number | |
| 207 | - * @return void | |
| 208 | - */ | |
| 186 | + // Private Function. Don't worry about this. | |
| 187 | + | |
| 209 | 188 | public function _set( $number ) { |
| 210 | 189 | $this->number = $number; |
| 211 | 190 | $this->id = $this->id_base . '-' . $number; |
| 212 | 191 | } |
| 213 | 192 | |
| 214 | - /** | |
| 215 | - * @return object | |
| 216 | - */ | |
| 217 | 193 | public function prepare_new( $form_id = false ) { |
| 218 | 194 | if ( $form_id ) { |
| 219 | 195 | $this->form_id = $form_id; |
| 220 | 196 | } |
| @@ -251,11 +227,8 @@ | ||
| 251 | 227 | |
| 252 | 228 | return $this->save_settings( $action ); |
| 253 | 229 | } |
| 254 | 230 | |
| 255 | - /** | |
| 256 | - * @return void | |
| 257 | - */ | |
| 258 | 231 | public function duplicate_form_actions( $form_id, $old_id ) { |
| 259 | 232 | if ( $form_id == $old_id ) { |
| 260 | 233 | // don't duplicate the actions if this is a template getting updated |
| 261 | 234 | return; |
| @@ -291,17 +264,13 @@ | ||
| 291 | 264 | |
| 292 | 265 | return $post_id; |
| 293 | 266 | } |
| 294 | 267 | |
| 295 | - /** | |
| 296 | - * @param object $action | |
| 297 | - */ | |
| 298 | 268 | public function duplicate_one( $action, $form_id ) { |
| 299 | 269 | global $frm_duplicate_ids; |
| 300 | 270 | |
| 301 | 271 | $action->menu_order = $form_id; |
| 302 | 272 | $switch = $this->get_global_switch_fields(); |
| 303 | - | |
| 304 | 273 | foreach ( (array) $action->post_content as $key => $val ) { |
| 305 | 274 | if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) { |
| 306 | 275 | $action->post_content[ $key ] = $frm_duplicate_ids[ $val ]; |
| 307 | 276 | } elseif ( ! is_array( $val ) ) { |
| @@ -343,9 +312,9 @@ | ||
| 343 | 312 | $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv ); |
| 344 | 313 | } elseif ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) { |
| 345 | 314 | $action[ $ck ] = $frm_duplicate_ids[ $cv ]; |
| 346 | 315 | } elseif ( $ck == $subkey ) { |
| 347 | - $action[ $ck ] = $this->maybe_switch_field_ids( $action[ $ck ] ); | |
| 316 | + $action[ $ck ] = FrmFieldsHelper::switch_field_ids( $action[ $ck ] ); | |
| 348 | 317 | } |
| 349 | 318 | } |
| 350 | 319 | } |
| 351 | 320 | |
| @@ -366,12 +335,11 @@ | ||
| 366 | 335 | if ( $this->updated ) { |
| 367 | 336 | return; |
| 368 | 337 | } |
| 369 | 338 | |
| 370 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 371 | 339 | if ( isset( $_POST[ $this->option_name ] ) && is_array( $_POST[ $this->option_name ] ) ) { |
| 372 | 340 | // Sanitizing removes scripts and <email> type of values. |
| 373 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing | |
| 341 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 374 | 342 | $settings = wp_unslash( $_POST[ $this->option_name ] ); |
| 375 | 343 | } else { |
| 376 | 344 | return; |
| 377 | 345 | } |
| @@ -398,8 +366,9 @@ | ||
| 398 | 366 | $new_instance['post_type'] = FrmFormActionsController::$action_post_type; |
| 399 | 367 | $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number; |
| 400 | 368 | $new_instance['menu_order'] = $this->form_id; |
| 401 | 369 | $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : ''; |
| 370 | + | |
| 402 | 371 | $instance = $this->update( $new_instance, $old_instance ); |
| 403 | 372 | |
| 404 | 373 | /** |
| 405 | 374 | * Filter an action's settings before saving. |
| @@ -416,9 +385,9 @@ | ||
| 416 | 385 | */ |
| 417 | 386 | $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this ); |
| 418 | 387 | |
| 419 | 388 | $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 ); | |
| 389 | + $instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this ); | |
| 421 | 390 | |
| 422 | 391 | if ( false !== $instance ) { |
| 423 | 392 | $all_instances[ $number ] = $instance; |
| 424 | 393 | } |
| @@ -434,25 +403,19 @@ | ||
| 434 | 403 | /** |
| 435 | 404 | * If the status of the action has changed, update it |
| 436 | 405 | * |
| 437 | 406 | * @since 3.04 |
| 438 | - * | |
| 439 | - * @param array $new_instance | |
| 440 | - * @param stdClass|array $old_instance | |
| 441 | - * @return void | |
| 442 | 407 | */ |
| 443 | 408 | 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; | |
| 409 | + if ( $new_instance['post_status'] !== $old_instance->post_status ) { | |
| 410 | + self::clear_cache(); | |
| 411 | + wp_update_post( | |
| 412 | + array( | |
| 413 | + 'ID' => $new_instance['ID'], | |
| 414 | + 'post_status' => $new_instance['post_status'], | |
| 415 | + ) | |
| 416 | + ); | |
| 446 | 417 | } |
| 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 | 418 | } |
| 456 | 419 | |
| 457 | 420 | public function save_settings( $settings ) { |
| 458 | 421 | self::clear_cache(); |
| @@ -522,13 +485,10 @@ | ||
| 522 | 485 | } |
| 523 | 486 | |
| 524 | 487 | /** |
| 525 | 488 | * @since 3.04 |
| 526 | - * | |
| 527 | 489 | * @param array $args |
| 528 | 490 | * @param string $default_status |
| 529 | - * | |
| 530 | - * @return void | |
| 531 | 491 | */ |
| 532 | 492 | protected static function prepare_get_action( &$args, $default_status = 'publish' ) { |
| 533 | 493 | if ( is_numeric( $args ) ) { |
| 534 | 494 | // for reverse compatibility. $limit was changed to $args |
| @@ -566,14 +526,9 @@ | ||
| 566 | 526 | return ! empty( $payment_actions ); |
| 567 | 527 | } |
| 568 | 528 | |
| 569 | 529 | 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 | 530 | self::prepare_get_action( $atts, 'any' ); |
| 575 | - | |
| 576 | 531 | $limit = $atts['limit']; |
| 577 | 532 | |
| 578 | 533 | if ( $form_id ) { |
| 579 | 534 | $this->form_id = $form_id; |
| @@ -615,11 +570,8 @@ | ||
| 615 | 570 | |
| 616 | 571 | return $settings; |
| 617 | 572 | } |
| 618 | 573 | |
| 619 | - /** | |
| 620 | - * @return array | |
| 621 | - */ | |
| 622 | 574 | public static function action_args( $form_id = 0, $limit = 99 ) { |
| 623 | 575 | $args = array( |
| 624 | 576 | 'post_type' => FrmFormActionsController::$action_post_type, |
| 625 | 577 | 'post_status' => 'publish', |
| @@ -634,11 +586,8 @@ | ||
| 634 | 586 | |
| 635 | 587 | return $args; |
| 636 | 588 | } |
| 637 | 589 | |
| 638 | - /** | |
| 639 | - * @param WP_Post|array $action | |
| 640 | - */ | |
| 641 | 590 | public function prepare_action( $action ) { |
| 642 | 591 | $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content ); |
| 643 | 592 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
| 644 | 593 | |
| @@ -662,11 +611,8 @@ | ||
| 662 | 611 | |
| 663 | 612 | return $action; |
| 664 | 613 | } |
| 665 | 614 | |
| 666 | - /** | |
| 667 | - * @return void | |
| 668 | - */ | |
| 669 | 615 | public function destroy( $form_id = false, $type = 'default' ) { |
| 670 | 616 | global $wpdb; |
| 671 | 617 | |
| 672 | 618 | $this->form_id = $form_id; |
| @@ -690,10 +636,8 @@ | ||
| 690 | 636 | /** |
| 691 | 637 | * Delete the action cache when a form action is created, deleted, or updated |
| 692 | 638 | * |
| 693 | 639 | * @since 2.0.5 |
| 694 | - * | |
| 695 | - * @return void | |
| 696 | 640 | */ |
| 697 | 641 | public static function clear_cache() { |
| 698 | 642 | FrmDb::cache_delete_group( 'frm_actions' ); |
| 699 | 643 | } |
| @@ -701,11 +645,8 @@ | ||
| 701 | 645 | public function get_settings() { |
| 702 | 646 | return self::get_action_for_form( $this->form_id, $this->id_base ); |
| 703 | 647 | } |
| 704 | 648 | |
| 705 | - /** | |
| 706 | - * @return array | |
| 707 | - */ | |
| 708 | 649 | public function get_global_defaults() { |
| 709 | 650 | $defaults = $this->get_defaults(); |
| 710 | 651 | |
| 711 | 652 | if ( ! isset( $defaults['event'] ) ) { |
| @@ -725,10 +666,8 @@ | ||
| 725 | 666 | public function get_global_switch_fields() { |
| 726 | 667 | $switch = $this->get_switch_fields(); |
| 727 | 668 | $switch['conditions'] = array( 'hide_field' ); |
| 728 | 669 | |
| 729 | - $switch = apply_filters( 'frm_global_switch_fields', $switch ); | |
| 730 | - | |
| 731 | 670 | return $switch; |
| 732 | 671 | } |
| 733 | 672 | |
| 734 | 673 | /** |
| @@ -823,14 +762,11 @@ | ||
| 823 | 762 | /** |
| 824 | 763 | * Prepare the logic value for comparison against the entered value |
| 825 | 764 | * |
| 826 | 765 | * @since 2.01.02 |
| 827 | - * | |
| 828 | 766 | * @deprecated 4.06.02 |
| 829 | 767 | * |
| 830 | 768 | * @param array|string $logic_value |
| 831 | - * | |
| 832 | - * @return void | |
| 833 | 769 | */ |
| 834 | 770 | private static function prepare_logic_value( &$logic_value, $action, $entry ) { |
| 835 | 771 | if ( is_array( $logic_value ) ) { |
| 836 | 772 | $logic_value = reset( $logic_value ); |
| @@ -878,13 +814,8 @@ | ||
| 878 | 814 | |
| 879 | 815 | return $observed_value; |
| 880 | 816 | } |
| 881 | 817 | |
| 882 | - /** | |
| 883 | - * @param string $class | |
| 884 | - * | |
| 885 | - * @return array | |
| 886 | - */ | |
| 887 | 818 | public static function default_action_opts( $class = '' ) { |
| 888 | 819 | return array( |
| 889 | 820 | 'classes' => 'frm_icon_font ' . $class, |
| 890 | 821 | 'active' => false, |
| @@ -901,26 +832,6 @@ | ||
| 901 | 832 | 'import' => __( 'Entry is imported', 'formidable' ), |
| 902 | 833 | ); |
| 903 | 834 | |
| 904 | 835 | 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 | 836 | } |
| 926 | 837 | } |