| @@ -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,10 +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 | |
| 38 | + * @param array $instance Current settings | |
| 92 | 39 | */ |
| 93 | 40 | public function form( $instance, $args = array() ) { |
| 94 | 41 | echo '<p class="no-options-widget">' . esc_html__( 'There are no options for this action.', 'formidable' ) . '</p>'; |
| 95 | 42 | |
| @@ -102,11 +49,8 @@ | ||
| 102 | 49 | public function get_defaults() { |
| 103 | 50 | return array(); |
| 104 | 51 | } |
| 105 | 52 | |
| 106 | - /** | |
| 107 | - * @return array | |
| 108 | - */ | |
| 109 | 53 | public function get_switch_fields() { |
| 110 | 54 | return array(); |
| 111 | 55 | } |
| 112 | 56 | |
| @@ -121,14 +65,14 @@ | ||
| 121 | 65 | * |
| 122 | 66 | * @param string $id_base Optional Base ID for the widget, lower case, |
| 123 | 67 | * if left empty a portion of the widget's class name will be used. Has to be unique. |
| 124 | 68 | * @param string $name Name for the widget displayed on the configuration page. |
| 125 | - * @param array $action_options Optional Passed to wp_register_sidebar_widget(). | |
| 126 | - * - description: shown on the configuration page. | |
| 127 | - * - classname. | |
| 128 | - * @param array $control_options Optional Passed to wp_register_widget_control(). | |
| 129 | - * - width: required if more than 250px. | |
| 130 | - * - height: currently not used but may be needed in the future. | |
| 69 | + * @param array $action_options Optional Passed to wp_register_sidebar_widget() | |
| 70 | + * - description: shown on the configuration page | |
| 71 | + * - classname | |
| 72 | + * @param array $control_options Optional Passed to wp_register_widget_control() | |
| 73 | + * - width: required if more than 250px | |
| 74 | + * - height: currently not used but may be needed in the future | |
| 131 | 75 | */ |
| 132 | 76 | public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) { |
| 133 | 77 | if ( ! defined( 'ABSPATH' ) ) { |
| 134 | 78 | die( 'You are not allowed to call this page directly.' ); |
| @@ -149,9 +93,8 @@ | ||
| 149 | 93 | 'plugin' => $this->id_base, |
| 150 | 94 | 'tooltip' => $name, |
| 151 | 95 | 'group' => $id_base, |
| 152 | 96 | 'color' => '', |
| 153 | - 'keywords' => '', | |
| 154 | 97 | ); |
| 155 | 98 | |
| 156 | 99 | $action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options ); |
| 157 | 100 | $group = $this->get_group( $action_options ); |
| @@ -162,13 +105,13 @@ | ||
| 162 | 105 | shuffle( $colors ); |
| 163 | 106 | $action_options['color'] = 'var(--' . reset( $colors ) . ')'; |
| 164 | 107 | } |
| 165 | 108 | |
| 166 | - $upgrade_class = isset( $action_options['classes'] ) && $action_options['classes'] === 'frm_show_upgrade'; | |
| 109 | + $upgrade_class = $action_options['classes'] === 'frm_show_upgrade'; | |
| 167 | 110 | if ( $action_options['group'] === $id_base ) { |
| 168 | - $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false; | |
| 111 | + $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false; | |
| 169 | 112 | $action_options['classes'] = $group['icon']; |
| 170 | - } elseif ( empty( $action_options['classes'] ) || $upgrade_class ) { | |
| 113 | + } elseif ( ! isset( $action_options['classes'] ) || empty( $action_options['classes'] ) || $upgrade_class ) { | |
| 171 | 114 | $action_options['classes'] = $group['icon']; |
| 172 | 115 | } |
| 173 | 116 | |
| 174 | 117 | if ( $upgrade_class ) { |
| @@ -188,9 +131,9 @@ | ||
| 188 | 131 | |
| 189 | 132 | /** |
| 190 | 133 | * Help to switch old field id by new field id for duplicate form |
| 191 | 134 | * |
| 192 | - * @param string $action id of the field that needs to be switched. | |
| 135 | + * @param string $action id of the field that needs to be switched | |
| 193 | 136 | * |
| 194 | 137 | * @return string |
| 195 | 138 | */ |
| 196 | 139 | public function maybe_switch_field_ids( $action ) { |
| @@ -229,14 +172,14 @@ | ||
| 229 | 172 | * Constructs name attributes for use in form() fields |
| 230 | 173 | * |
| 231 | 174 | * This function should be used in form() methods to create name attributes for fields to be saved by update() |
| 232 | 175 | * |
| 233 | - * @param string $field_name Field name. | |
| 176 | + * @param string $field_name Field name | |
| 234 | 177 | * |
| 235 | 178 | * @return string Name attribute for $field_name |
| 236 | 179 | */ |
| 237 | 180 | public function get_field_name( $field_name, $post_field = 'post_content' ) { |
| 238 | - $name = $this->option_name . '[' . $this->number . ']'; | |
| 181 | + $name = $this->option_name . '[' . $this->number . ']'; | |
| 239 | 182 | $name .= ( empty( $post_field ) ? '' : '[' . $post_field . ']' ); |
| 240 | 183 | $name .= '[' . $field_name . ']'; |
| 241 | 184 | |
| 242 | 185 | return $name; |
| @@ -246,9 +189,9 @@ | ||
| 246 | 189 | * Constructs id attributes for use in form() fields |
| 247 | 190 | * |
| 248 | 191 | * This function should be used in form() methods to create id attributes for fields to be saved by update() |
| 249 | 192 | * |
| 250 | - * @param string $field_name Field name. | |
| 193 | + * @param string $field_name Field name | |
| 251 | 194 | * |
| 252 | 195 | * @return string ID attribute for $field_name |
| 253 | 196 | */ |
| 254 | 197 | public function get_field_id( $field_name ) { |
| @@ -254,20 +197,15 @@ | ||
| 254 | 197 | public function get_field_id( $field_name ) { |
| 255 | 198 | return $field_name . '_' . $this->number; |
| 256 | 199 | } |
| 257 | 200 | |
| 258 | - /** | |
| 259 | - * @param int|string $number | |
| 260 | - * @return void | |
| 261 | - */ | |
| 201 | + // Private Function. Don't worry about this. | |
| 202 | + | |
| 262 | 203 | public function _set( $number ) { |
| 263 | 204 | $this->number = $number; |
| 264 | 205 | $this->id = $this->id_base . '-' . $number; |
| 265 | 206 | } |
| 266 | 207 | |
| 267 | - /** | |
| 268 | - * @return object | |
| 269 | - */ | |
| 270 | 208 | public function prepare_new( $form_id = false ) { |
| 271 | 209 | if ( $form_id ) { |
| 272 | 210 | $this->form_id = $form_id; |
| 273 | 211 | } |
| @@ -304,11 +242,8 @@ | ||
| 304 | 242 | |
| 305 | 243 | return $this->save_settings( $action ); |
| 306 | 244 | } |
| 307 | 245 | |
| 308 | - /** | |
| 309 | - * @return void | |
| 310 | - */ | |
| 311 | 246 | public function duplicate_form_actions( $form_id, $old_id ) { |
| 312 | 247 | if ( $form_id == $old_id ) { |
| 313 | 248 | // don't duplicate the actions if this is a template getting updated |
| 314 | 249 | return; |
| @@ -323,18 +258,17 @@ | ||
| 323 | 258 | unset( $action ); |
| 324 | 259 | } |
| 325 | 260 | } |
| 326 | 261 | |
| 327 | - /** | |
| 328 | - * Check if imported action should be created or updated. | |
| 262 | + /* Check if imported action should be created or updated | |
| 329 | 263 | * |
| 330 | 264 | * @since 2.0 |
| 331 | 265 | * |
| 332 | 266 | * @param array $action |
| 333 | - * @return int $post_id | |
| 267 | + * @return integer $post_id | |
| 334 | 268 | */ |
| 335 | 269 | public function maybe_create_action( $action, $forms ) { |
| 336 | - if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] === 'updated' ) { | |
| 270 | + if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] == 'updated' ) { | |
| 337 | 271 | // Update action only |
| 338 | 272 | $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
| 339 | 273 | $post_id = $this->save_settings( $action ); |
| 340 | 274 | } else { |
| @@ -345,11 +279,8 @@ | ||
| 345 | 279 | |
| 346 | 280 | return $post_id; |
| 347 | 281 | } |
| 348 | 282 | |
| 349 | - /** | |
| 350 | - * @param object $action | |
| 351 | - */ | |
| 352 | 283 | public function duplicate_one( $action, $form_id ) { |
| 353 | 284 | global $frm_duplicate_ids; |
| 354 | 285 | |
| 355 | 286 | $action->menu_order = $form_id; |
| @@ -400,9 +331,9 @@ | ||
| 400 | 331 | } elseif ( $ck == $subkey ) { |
| 401 | 332 | $action[ $ck ] = $this->maybe_switch_field_ids( $action[ $ck ] ); |
| 402 | 333 | } |
| 403 | 334 | } |
| 404 | - }//end if | |
| 335 | + } | |
| 405 | 336 | |
| 406 | 337 | return $action; |
| 407 | 338 | } |
| 408 | 339 | |
| @@ -420,12 +351,11 @@ | ||
| 420 | 351 | if ( $this->updated ) { |
| 421 | 352 | return; |
| 422 | 353 | } |
| 423 | 354 | |
| 424 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 425 | 355 | if ( isset( $_POST[ $this->option_name ] ) && is_array( $_POST[ $this->option_name ] ) ) { |
| 426 | 356 | // Sanitizing removes scripts and <email> type of values. |
| 427 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing | |
| 357 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 428 | 358 | $settings = wp_unslash( $_POST[ $this->option_name ] ); |
| 429 | 359 | } else { |
| 430 | 360 | return; |
| 431 | 361 | } |
| @@ -434,9 +364,9 @@ | ||
| 434 | 364 | |
| 435 | 365 | foreach ( $settings as $number => $new_instance ) { |
| 436 | 366 | $this->_set( $number ); |
| 437 | 367 | |
| 438 | - $old_instance = $all_instances[ $number ] ?? array(); | |
| 368 | + $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array(); | |
| 439 | 369 | |
| 440 | 370 | if ( ! isset( $new_instance['post_status'] ) ) { |
| 441 | 371 | $new_instance['post_status'] = 'draft'; |
| 442 | 372 | } |
| @@ -451,11 +381,12 @@ | ||
| 451 | 381 | |
| 452 | 382 | $new_instance['post_type'] = FrmFormActionsController::$action_post_type; |
| 453 | 383 | $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number; |
| 454 | 384 | $new_instance['menu_order'] = $this->form_id; |
| 455 | - $new_instance['post_date'] = $old_instance->post_date ?? ''; | |
| 456 | - $instance = $this->update( $new_instance, $old_instance ); | |
| 385 | + $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : ''; | |
| 457 | 386 | |
| 387 | + $instance = $this->update( $new_instance, $old_instance ); | |
| 388 | + | |
| 458 | 389 | /** |
| 459 | 390 | * Filter an action's settings before saving. |
| 460 | 391 | * |
| 461 | 392 | * Returning false will effectively short-circuit the widget's ability |
| @@ -462,17 +393,17 @@ | ||
| 462 | 393 | * to update settings. |
| 463 | 394 | * |
| 464 | 395 | * @since 2.0 |
| 465 | 396 | * |
| 466 | - * @param array $instance The current widget instance's settings. | |
| 467 | - * @param array $new_instance Array of new widget settings. | |
| 468 | - * @param array $old_instance Array of old widget settings. | |
| 469 | - * @param FrmFormAction $form_action FrmFormAction instance. | |
| 397 | + * @param array $instance The current widget instance's settings. | |
| 398 | + * @param array $new_instance Array of new widget settings. | |
| 399 | + * @param array $old_instance Array of old widget settings. | |
| 400 | + * @param WP_Widget $this The current widget instance. | |
| 470 | 401 | */ |
| 471 | 402 | $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this ); |
| 472 | 403 | |
| 473 | 404 | $instance['post_content'] = apply_filters( 'frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this ); |
| 474 | - $instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this ); | |
| 405 | + $instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this ); | |
| 475 | 406 | |
| 476 | 407 | if ( false !== $instance ) { |
| 477 | 408 | $all_instances[ $number ] = $instance; |
| 478 | 409 | } |
| @@ -479,9 +410,9 @@ | ||
| 479 | 410 | |
| 480 | 411 | $action_ids[] = $this->save_settings( $instance ); |
| 481 | 412 | |
| 482 | 413 | $this->updated = true; |
| 483 | - }//end foreach | |
| 414 | + } | |
| 484 | 415 | |
| 485 | 416 | return $action_ids; |
| 486 | 417 | } |
| 487 | 418 | |
| @@ -488,31 +419,21 @@ | ||
| 488 | 419 | /** |
| 489 | 420 | * If the status of the action has changed, update it |
| 490 | 421 | * |
| 491 | 422 | * @since 3.04 |
| 492 | - * | |
| 493 | - * @param array $new_instance | |
| 494 | - * @param array|stdClass $old_instance | |
| 495 | - * @return void | |
| 496 | 423 | */ |
| 497 | 424 | protected function maybe_update_status( $new_instance, $old_instance ) { |
| 498 | - if ( ! is_object( $old_instance ) || $new_instance['post_status'] === $old_instance->post_status ) { | |
| 499 | - return; | |
| 425 | + if ( $new_instance['post_status'] !== $old_instance->post_status ) { | |
| 426 | + self::clear_cache(); | |
| 427 | + wp_update_post( | |
| 428 | + array( | |
| 429 | + 'ID' => $new_instance['ID'], | |
| 430 | + 'post_status' => $new_instance['post_status'], | |
| 431 | + ) | |
| 432 | + ); | |
| 500 | 433 | } |
| 501 | - | |
| 502 | - self::clear_cache(); | |
| 503 | - wp_update_post( | |
| 504 | - array( | |
| 505 | - 'ID' => $new_instance['ID'], | |
| 506 | - 'post_status' => $new_instance['post_status'], | |
| 507 | - ) | |
| 508 | - ); | |
| 509 | 434 | } |
| 510 | 435 | |
| 511 | - /** | |
| 512 | - * @param array $settings | |
| 513 | - * @return int|WP_Error | |
| 514 | - */ | |
| 515 | 436 | public function save_settings( $settings ) { |
| 516 | 437 | self::clear_cache(); |
| 517 | 438 | |
| 518 | 439 | return FrmDb::save_settings( $settings, 'frm_actions' ); |
| @@ -538,18 +459,15 @@ | ||
| 538 | 459 | // don't continue if there are no available actions |
| 539 | 460 | return array(); |
| 540 | 461 | } |
| 541 | 462 | |
| 542 | - if ( 'all' !== $type ) { | |
| 543 | - if ( is_array( $action_controls ) ) { | |
| 544 | - return array(); | |
| 545 | - } | |
| 463 | + if ( 'all' != $type ) { | |
| 546 | 464 | return $action_controls->get_all( $form_id, $atts ); |
| 547 | 465 | } |
| 548 | 466 | |
| 549 | 467 | self::prepare_get_action( $atts ); |
| 550 | 468 | |
| 551 | - $limit = self::get_action_limit( $form_id, $atts['limit'] ); | |
| 469 | + $limit = apply_filters( 'frm_form_action_limit', $atts['limit'], compact( 'type', 'form_id' ) ); | |
| 552 | 470 | |
| 553 | 471 | $args = self::action_args( $form_id, $limit ); |
| 554 | 472 | $args['post_status'] = $atts['post_status']; |
| 555 | 473 | $actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' ); |
| @@ -582,30 +500,11 @@ | ||
| 582 | 500 | return $settings; |
| 583 | 501 | } |
| 584 | 502 | |
| 585 | 503 | /** |
| 586 | - * Get the limit for the number of actions for a single form. By default, this is 99, but | |
| 587 | - * it can be modified with a code snippet. | |
| 588 | - * | |
| 589 | - * @since 6.17 This logic from moved from FrmFormAction::get_action_for_form. | |
| 590 | - * | |
| 591 | - * @param int|string $form_id | |
| 592 | - * @param int|string $limit The unfiltered limit value. | |
| 593 | - * | |
| 594 | - * @return int The filtered limit value. | |
| 595 | - */ | |
| 596 | - public static function get_action_limit( $form_id, $limit = 99 ) { | |
| 597 | - $type = 'all'; | |
| 598 | - return (int) apply_filters( 'frm_form_action_limit', (int) $limit, compact( 'type', 'form_id' ) ); | |
| 599 | - } | |
| 600 | - | |
| 601 | - /** | |
| 602 | 504 | * @since 3.04 |
| 603 | - * | |
| 604 | 505 | * @param array $args |
| 605 | 506 | * @param string $default_status |
| 606 | - * | |
| 607 | - * @return void | |
| 608 | 507 | */ |
| 609 | 508 | protected static function prepare_get_action( &$args, $default_status = 'publish' ) { |
| 610 | 509 | if ( is_numeric( $args ) ) { |
| 611 | 510 | // for reverse compatibility. $limit was changed to $args |
| @@ -626,12 +525,8 @@ | ||
| 626 | 525 | public static function get_single_action_type( $action_id, $type ) { |
| 627 | 526 | if ( ! $type ) { |
| 628 | 527 | return false; |
| 629 | 528 | } |
| 630 | - | |
| 631 | - /** | |
| 632 | - * @var FrmFormAction | |
| 633 | - */ | |
| 634 | 529 | $action_control = FrmFormActionsController::get_form_actions( $type ); |
| 635 | 530 | |
| 636 | 531 | return $action_control->get_single_action( $action_id ); |
| 637 | 532 | } |
| @@ -647,14 +542,9 @@ | ||
| 647 | 542 | return ! empty( $payment_actions ); |
| 648 | 543 | } |
| 649 | 544 | |
| 650 | 545 | public function get_all( $form_id = false, $atts = array() ) { |
| 651 | - if ( is_array( $atts ) && ! isset( $atts['limit'] ) && $this->action_options['limit'] > 99 ) { | |
| 652 | - $atts['limit'] = $this->action_options['limit']; | |
| 653 | - } | |
| 654 | - | |
| 655 | 546 | self::prepare_get_action( $atts, 'any' ); |
| 656 | - | |
| 657 | 547 | $limit = $atts['limit']; |
| 658 | 548 | |
| 659 | 549 | if ( $form_id ) { |
| 660 | 550 | $this->form_id = $form_id; |
| @@ -665,10 +555,10 @@ | ||
| 665 | 555 | global $frm_vars; |
| 666 | 556 | $frm_vars['action_type'] = $type; |
| 667 | 557 | |
| 668 | 558 | add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' ); |
| 669 | - $query = self::action_args( $form_id, $limit ); | |
| 670 | - $query['post_status'] = $atts['post_status']; | |
| 559 | + $query = self::action_args( $form_id, $limit ); | |
| 560 | + $query['post_status'] = $atts['post_status']; | |
| 671 | 561 | $query['suppress_filters'] = false; |
| 672 | 562 | |
| 673 | 563 | $actions = FrmDb::check_cache( json_encode( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' ); |
| 674 | 564 | unset( $query ); |
| @@ -696,11 +586,8 @@ | ||
| 696 | 586 | |
| 697 | 587 | return $settings; |
| 698 | 588 | } |
| 699 | 589 | |
| 700 | - /** | |
| 701 | - * @return array | |
| 702 | - */ | |
| 703 | 590 | public static function action_args( $form_id = 0, $limit = 99 ) { |
| 704 | 591 | $args = array( |
| 705 | 592 | 'post_type' => FrmFormActionsController::$action_post_type, |
| 706 | 593 | 'post_status' => 'publish', |
| @@ -715,11 +602,8 @@ | ||
| 715 | 602 | |
| 716 | 603 | return $args; |
| 717 | 604 | } |
| 718 | 605 | |
| 719 | - /** | |
| 720 | - * @param array|WP_Post $action | |
| 721 | - */ | |
| 722 | 606 | public function prepare_action( $action ) { |
| 723 | 607 | $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content ); |
| 724 | 608 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
| 725 | 609 | |
| @@ -729,9 +613,9 @@ | ||
| 729 | 613 | $action->post_content += $default_values; |
| 730 | 614 | |
| 731 | 615 | foreach ( $default_values as $k => $vals ) { |
| 732 | 616 | if ( is_array( $vals ) && ! empty( $vals ) ) { |
| 733 | - if ( 'event' === $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) { | |
| 617 | + if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) { | |
| 734 | 618 | continue; |
| 735 | 619 | } |
| 736 | 620 | $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals ); |
| 737 | 621 | } |
| @@ -743,11 +627,8 @@ | ||
| 743 | 627 | |
| 744 | 628 | return $action; |
| 745 | 629 | } |
| 746 | 630 | |
| 747 | - /** | |
| 748 | - * @return void | |
| 749 | - */ | |
| 750 | 631 | public function destroy( $form_id = false, $type = 'default' ) { |
| 751 | 632 | global $wpdb; |
| 752 | 633 | |
| 753 | 634 | $this->form_id = $form_id; |
| @@ -771,10 +652,8 @@ | ||
| 771 | 652 | /** |
| 772 | 653 | * Delete the action cache when a form action is created, deleted, or updated |
| 773 | 654 | * |
| 774 | 655 | * @since 2.0.5 |
| 775 | - * | |
| 776 | - * @return void | |
| 777 | 656 | */ |
| 778 | 657 | public static function clear_cache() { |
| 779 | 658 | FrmDb::cache_delete_group( 'frm_actions' ); |
| 780 | 659 | } |
| @@ -782,11 +661,8 @@ | ||
| 782 | 661 | public function get_settings() { |
| 783 | 662 | return self::get_action_for_form( $this->form_id, $this->id_base ); |
| 784 | 663 | } |
| 785 | 664 | |
| 786 | - /** | |
| 787 | - * @return array | |
| 788 | - */ | |
| 789 | 665 | public function get_global_defaults() { |
| 790 | 666 | $defaults = $this->get_defaults(); |
| 791 | 667 | |
| 792 | 668 | if ( ! isset( $defaults['event'] ) ) { |
| @@ -815,9 +691,9 @@ | ||
| 815 | 691 | /** |
| 816 | 692 | * Migrate settings from form->options into new action. |
| 817 | 693 | */ |
| 818 | 694 | public function migrate_to_2( $form, $update = 'update' ) { |
| 819 | - $action = $this->prepare_new( $form->id ); | |
| 695 | + $action = $this->prepare_new( $form->id ); | |
| 820 | 696 | FrmAppHelper::unserialize_or_decode( $form->options ); |
| 821 | 697 | |
| 822 | 698 | // fill with existing options |
| 823 | 699 | foreach ( $action->post_content as $name => $val ) { |
| @@ -855,29 +731,86 @@ | ||
| 855 | 731 | |
| 856 | 732 | return $post_id; |
| 857 | 733 | } |
| 858 | 734 | |
| 859 | - /** | |
| 860 | - * @param WP_Post $action | |
| 861 | - * @param stdClass $entry | |
| 862 | - * @return bool | |
| 863 | - */ | |
| 864 | 735 | public static function action_conditions_met( $action, $entry ) { |
| 865 | 736 | if ( is_callable( 'FrmProFormActionsController::action_conditions_met' ) ) { |
| 866 | 737 | return FrmProFormActionsController::action_conditions_met( $action, $entry ); |
| 867 | 738 | } |
| 868 | 739 | |
| 869 | - $stop = false; | |
| 740 | + // This is here for reverse compatibility. | |
| 741 | + $notification = $action->post_content; | |
| 742 | + $stop = false; | |
| 743 | + $met = array(); | |
| 744 | + | |
| 745 | + if ( ! isset( $notification['conditions'] ) || empty( $notification['conditions'] ) ) { | |
| 746 | + return $stop; | |
| 747 | + } | |
| 748 | + | |
| 749 | + foreach ( $notification['conditions'] as $k => $condition ) { | |
| 750 | + if ( ! is_numeric( $k ) ) { | |
| 751 | + continue; | |
| 752 | + } | |
| 753 | + | |
| 754 | + if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) { | |
| 755 | + continue; | |
| 756 | + } | |
| 757 | + | |
| 758 | + self::prepare_logic_value( $condition['hide_opt'], $action, $entry ); | |
| 759 | + | |
| 760 | + $observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] ); | |
| 761 | + | |
| 762 | + $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] ); | |
| 763 | + | |
| 764 | + if ( $notification['conditions']['send_stop'] == 'send' ) { | |
| 765 | + $stop = $stop ? false : true; | |
| 766 | + } | |
| 767 | + | |
| 768 | + $met[ $stop ] = $stop; | |
| 769 | + } | |
| 770 | + | |
| 771 | + if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) { | |
| 772 | + $stop = ( $notification['conditions']['send_stop'] == 'send' ); | |
| 773 | + } elseif ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset( $met[0] ) ) { | |
| 774 | + $stop = false; | |
| 775 | + } | |
| 776 | + | |
| 870 | 777 | return $stop; |
| 871 | 778 | } |
| 872 | 779 | |
| 873 | 780 | /** |
| 781 | + * Prepare the logic value for comparison against the entered value | |
| 782 | + * | |
| 783 | + * @since 2.01.02 | |
| 784 | + * @deprecated 4.06.02 | |
| 785 | + * | |
| 786 | + * @param array|string $logic_value | |
| 787 | + */ | |
| 788 | + private static function prepare_logic_value( &$logic_value, $action, $entry ) { | |
| 789 | + if ( is_array( $logic_value ) ) { | |
| 790 | + $logic_value = reset( $logic_value ); | |
| 791 | + } | |
| 792 | + | |
| 793 | + if ( $logic_value == 'current_user' ) { | |
| 794 | + $logic_value = get_current_user_id(); | |
| 795 | + } | |
| 796 | + | |
| 797 | + $logic_value = apply_filters( 'frm_content', $logic_value, $action->menu_order, $entry ); | |
| 798 | + | |
| 799 | + /** | |
| 800 | + * @since 4.04.05 | |
| 801 | + */ | |
| 802 | + $logic_value = apply_filters( 'frm_action_logic_value', $logic_value ); | |
| 803 | + } | |
| 804 | + | |
| 805 | + /** | |
| 874 | 806 | * Get the value from a specific field and entry |
| 875 | 807 | * |
| 876 | 808 | * @since 2.01.02 |
| 809 | + * @deprecated 4.06.02 | |
| 877 | 810 | * |
| 878 | 811 | * @param object $entry |
| 879 | - * @param int $field_id | |
| 812 | + * @param int $field_id | |
| 880 | 813 | * |
| 881 | 814 | * @return array|bool|mixed|string |
| 882 | 815 | */ |
| 883 | 816 | private static function get_value_from_entry( $entry, $field_id ) { |
| @@ -899,13 +832,8 @@ | ||
| 899 | 832 | |
| 900 | 833 | return $observed_value; |
| 901 | 834 | } |
| 902 | 835 | |
| 903 | - /** | |
| 904 | - * @param string $class | |
| 905 | - * | |
| 906 | - * @return array | |
| 907 | - */ | |
| 908 | 836 | public static function default_action_opts( $class = '' ) { |
| 909 | 837 | return array( |
| 910 | 838 | 'classes' => 'frm_icon_font ' . $class, |
| 911 | 839 | 'active' => false, |
| @@ -924,11 +852,8 @@ | ||
| 924 | 852 | |
| 925 | 853 | return apply_filters( 'frm_action_triggers', $triggers ); |
| 926 | 854 | } |
| 927 | 855 | |
| 928 | - /** | |
| 929 | - * @return void | |
| 930 | - */ | |
| 931 | 856 | public function render_conditional_logic_call_to_action() { |
| 932 | 857 | ?> |
| 933 | 858 | <h3> |
| 934 | 859 | <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 ); ?>"> |
| @@ -937,30 +862,8 @@ | ||
| 937 | 862 | </h3> |
| 938 | 863 | <?php |
| 939 | 864 | } |
| 940 | 865 | |
| 941 | - /** | |
| 942 | - * @return string | |
| 943 | - */ | |
| 944 | 866 | protected function get_upgrade_text() { |
| 945 | 867 | return __( 'Conditional form actions', 'formidable' ); |
| 946 | - } | |
| 947 | - | |
| 948 | - /** | |
| 949 | - * Gets form fields for form action settings. | |
| 950 | - * | |
| 951 | - * @since 6.10 | |
| 952 | - * | |
| 953 | - * @param int $form_id Form ID. | |
| 954 | - * @return object[] | |
| 955 | - */ | |
| 956 | - protected function get_form_fields( $form_id ) { | |
| 957 | - // Get form fields, include embedded and repeater child fields. | |
| 958 | - $form_fields = FrmField::get_all_for_form( $form_id, '', 'include' ); | |
| 959 | - return array_filter( | |
| 960 | - $form_fields, | |
| 961 | - function ( $form_field ) { | |
| 962 | - return ! FrmField::is_no_save_field( $form_field->type ); | |
| 963 | - } | |
| 964 | - ); | |
| 965 | 868 | } |
| 966 | 869 | } |