| @@ -3,12 +3,8 @@ | ||
| 3 | 3 | die( 'You are not allowed to call this page directly.' ); |
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmFormActionsController { |
| 7 | - | |
| 8 | - /** | |
| 9 | - * @var string | |
| 10 | - */ | |
| 11 | 7 | public static $action_post_type = 'frm_form_actions'; |
| 12 | 8 | |
| 13 | 9 | /** |
| 14 | 10 | * @var array|null |
| @@ -67,9 +63,8 @@ | ||
| 67 | 63 | 'constantcontact' => 'FrmDefConstContactAction', |
| 68 | 64 | 'getresponse' => 'FrmDefGetResponseAction', |
| 69 | 65 | 'hubspot' => 'FrmDefHubspotAction', |
| 70 | 66 | 'zapier' => 'FrmDefZapierAction', |
| 71 | - 'n8n' => 'FrmDefN8NAction', | |
| 72 | 67 | 'twilio' => 'FrmDefTwilioAction', |
| 73 | 68 | 'highrise' => 'FrmDefHighriseAction', |
| 74 | 69 | 'mailpoet' => 'FrmDefMailpoetAction', |
| 75 | 70 | 'aweber' => 'FrmDefAweberAction', |
| @@ -77,9 +72,8 @@ | ||
| 77 | 72 | 'googlespreadsheet' => 'FrmDefGoogleSpreadsheetAction', |
| 78 | 73 | ); |
| 79 | 74 | |
| 80 | 75 | $action_classes = apply_filters( 'frm_registered_form_actions', $action_classes ); |
| 81 | - $action_classes = self::maybe_unset_highrise( $action_classes ); | |
| 82 | 76 | |
| 83 | 77 | include_once FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php'; |
| 84 | 78 | include_once FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php'; |
| 85 | 79 | |
| @@ -88,31 +82,16 @@ | ||
| 88 | 82 | } |
| 89 | 83 | } |
| 90 | 84 | |
| 91 | 85 | /** |
| 92 | - * Remove the Highrise action if it is not registered. | |
| 93 | - * | |
| 94 | - * @since 6.23 | |
| 95 | - * | |
| 96 | - * @param array $action_classes | |
| 97 | - * | |
| 98 | - * @return array | |
| 99 | - */ | |
| 100 | - private static function maybe_unset_highrise( $action_classes ) { | |
| 101 | - if ( 'FrmDefHighriseAction' === ( $action_classes['highrise'] ?? '' ) ) { | |
| 102 | - unset( $action_classes['highrise'] ); | |
| 103 | - } | |
| 104 | - return $action_classes; | |
| 105 | - } | |
| 106 | - | |
| 107 | - /** | |
| 108 | 86 | * @since 4.0 |
| 109 | 87 | * |
| 110 | 88 | * @param array $values |
| 111 | 89 | */ |
| 112 | 90 | public static function email_settings( $values ) { |
| 113 | - $form = FrmForm::getOne( $values['id'] ); | |
| 114 | - $groups = self::form_action_groups(); | |
| 91 | + $form = FrmForm::getOne( $values['id'] ); | |
| 92 | + $groups = self::form_action_groups(); | |
| 93 | + | |
| 115 | 94 | $action_controls = self::get_form_actions(); |
| 116 | 95 | self::maybe_add_action_to_group( $action_controls, $groups ); |
| 117 | 96 | |
| 118 | 97 | $allowed = self::active_actions( $action_controls ); |
| @@ -123,17 +102,11 @@ | ||
| 123 | 102 | /** |
| 124 | 103 | * Add unknown actions to a group. |
| 125 | 104 | * |
| 126 | 105 | * @since 4.0 |
| 127 | - * | |
| 128 | - * @param array $action_controls | |
| 129 | - * @param array $groups | |
| 130 | - * | |
| 131 | - * @return void | |
| 132 | 106 | */ |
| 133 | 107 | private static function maybe_add_action_to_group( $action_controls, &$groups ) { |
| 134 | 108 | $grouped = array(); |
| 135 | - | |
| 136 | 109 | foreach ( $groups as $group ) { |
| 137 | 110 | if ( isset( $group['actions'] ) ) { |
| 138 | 111 | $grouped = array_merge( $grouped, $group['actions'] ); |
| 139 | 112 | } |
| @@ -139,14 +112,13 @@ | ||
| 139 | 112 | } |
| 140 | 113 | } |
| 141 | 114 | |
| 142 | 115 | foreach ( $action_controls as $action ) { |
| 143 | - if ( isset( $groups[ $action->id_base ] ) || in_array( $action->id_base, $grouped, true ) ) { | |
| 116 | + if ( isset( $groups[ $action->id_base ] ) || in_array( $action->id_base, $grouped ) ) { | |
| 144 | 117 | continue; |
| 145 | 118 | } |
| 146 | 119 | |
| 147 | 120 | $this_group = $action->action_options['group']; |
| 148 | - | |
| 149 | 121 | if ( ! isset( $groups[ $this_group ] ) ) { |
| 150 | 122 | $this_group = 'misc'; |
| 151 | 123 | } |
| 152 | 124 | |
| @@ -167,9 +139,9 @@ | ||
| 167 | 139 | public static function form_action_groups() { |
| 168 | 140 | $groups = array( |
| 169 | 141 | 'misc' => array( |
| 170 | 142 | 'name' => '', |
| 171 | - 'icon' => 'frmfont frm_shuffle_icon', | |
| 143 | + 'icon' => 'frm_icon_font frm_shuffle_icon', | |
| 172 | 144 | 'actions' => array( |
| 173 | 145 | 'email', |
| 174 | 146 | 'wppost', |
| 175 | 147 | 'register', |
| @@ -179,9 +151,9 @@ | ||
| 179 | 151 | ), |
| 180 | 152 | ), |
| 181 | 153 | 'payment' => array( |
| 182 | 154 | 'name' => __( 'eCommerce', 'formidable' ), |
| 183 | - 'icon' => 'frmfont frm_credit_card_alt_icon', | |
| 155 | + 'icon' => 'frm_icon_font frm_credit_card_alt_icon', | |
| 184 | 156 | 'actions' => array( |
| 185 | 157 | 'paypal', |
| 186 | 158 | 'payment', |
| 187 | 159 | ), |
| @@ -187,9 +159,9 @@ | ||
| 187 | 159 | ), |
| 188 | 160 | ), |
| 189 | 161 | 'marketing' => array( |
| 190 | 162 | 'name' => __( 'Email Marketing', 'formidable' ), |
| 191 | - 'icon' => 'frmfont frm_mail_bulk_icon', | |
| 163 | + 'icon' => 'frm_icon_font frm_mail_bulk_icon', | |
| 192 | 164 | 'actions' => array( |
| 193 | 165 | 'mailchimp', |
| 194 | 166 | 'activecampaign', |
| 195 | 167 | 'constantcontact', |
| @@ -195,15 +167,18 @@ | ||
| 195 | 167 | 'constantcontact', |
| 196 | 168 | 'getresponse', |
| 197 | 169 | 'aweber', |
| 198 | 170 | 'mailpoet', |
| 199 | - 'convertkit', | |
| 200 | 171 | ), |
| 201 | 172 | ), |
| 202 | 173 | 'crm' => array( |
| 203 | 174 | 'name' => __( 'CRM', 'formidable' ), |
| 204 | - 'icon' => 'frmfont frm_address_card_icon', | |
| 205 | - 'actions' => self::get_crm_actions(), | |
| 175 | + 'icon' => 'frm_icon_font frm_address_card_icon', | |
| 176 | + 'actions' => array( | |
| 177 | + 'salesforce', | |
| 178 | + 'hubspot', | |
| 179 | + 'highrise', | |
| 180 | + ), | |
| 206 | 181 | ), |
| 207 | 182 | ); |
| 208 | 183 | |
| 209 | 184 | return apply_filters( 'frm_action_groups', $groups ); |
| @@ -209,47 +184,21 @@ | ||
| 209 | 184 | return apply_filters( 'frm_action_groups', $groups ); |
| 210 | 185 | } |
| 211 | 186 | |
| 212 | 187 | /** |
| 213 | - * Get the actions to include in the CRM section. | |
| 214 | - * | |
| 215 | - * @since 6.23 | |
| 216 | - * | |
| 217 | - * @return array | |
| 218 | - */ | |
| 219 | - private static function get_crm_actions() { | |
| 220 | - $crm_actions = array( | |
| 221 | - 'salesforce', | |
| 222 | - 'hubspot', | |
| 223 | - ); | |
| 224 | - | |
| 225 | - // Only include Highrise when the add-on is active. | |
| 226 | - // This is because Highrise is deprecated. We don't want to show it in Lite. | |
| 227 | - if ( class_exists( 'FrmHrsSettings' ) ) { | |
| 228 | - $crm_actions[] = 'highrise'; | |
| 229 | - } | |
| 230 | - | |
| 231 | - return $crm_actions; | |
| 232 | - } | |
| 233 | - | |
| 234 | - /** | |
| 235 | 188 | * Get the number of currently active form actions. |
| 236 | 189 | * |
| 237 | 190 | * @since 4.0 |
| 238 | 191 | * |
| 239 | - * @param array $action_controls | |
| 240 | - * | |
| 241 | 192 | * @return array |
| 242 | 193 | */ |
| 243 | 194 | private static function active_actions( $action_controls ) { |
| 244 | 195 | $allowed = array(); |
| 245 | - | |
| 246 | 196 | foreach ( $action_controls as $action_control ) { |
| 247 | - if ( ! empty( $action_control->action_options['active'] ) ) { | |
| 197 | + if ( isset( $action_control->action_options['active'] ) && $action_control->action_options['active'] ) { | |
| 248 | 198 | $allowed[] = $action_control->id_base; |
| 249 | 199 | } |
| 250 | 200 | } |
| 251 | - | |
| 252 | 201 | return $allowed; |
| 253 | 202 | } |
| 254 | 203 | |
| 255 | 204 | /** |
| @@ -255,15 +204,15 @@ | ||
| 255 | 204 | /** |
| 256 | 205 | * For each add-on, add an li, class, and javascript function. If active, add an additional class. |
| 257 | 206 | * |
| 258 | 207 | * @since 4.0 |
| 259 | - * | |
| 260 | 208 | * @param object $action_control |
| 261 | 209 | * @param array $allowed |
| 262 | 210 | */ |
| 263 | 211 | public static function show_action_icon_link( $action_control, $allowed ) { |
| 264 | - $data = array(); | |
| 265 | - $classes = ' frm_' . $action_control->id_base . '_action frm_single_action'; | |
| 212 | + $data = array(); | |
| 213 | + $classes = ' frm_' . $action_control->id_base . '_action frm_single_action'; | |
| 214 | + | |
| 266 | 215 | $group_class = ' frm-group-' . $action_control->action_options['group']; |
| 267 | 216 | |
| 268 | 217 | /* translators: %s: Name of form action */ |
| 269 | 218 | $upgrade_label = sprintf( esc_html__( '%s form actions', 'formidable' ), $action_control->action_options['tooltip'] ); |
| @@ -269,16 +218,15 @@ | ||
| 269 | 218 | $upgrade_label = sprintf( esc_html__( '%s form actions', 'formidable' ), $action_control->action_options['tooltip'] ); |
| 270 | 219 | |
| 271 | 220 | $default_shown = array( 'wppost', 'register', 'payment', 'quiz', 'hubspot' ); |
| 272 | 221 | $default_shown = array_values( array_diff( $default_shown, $allowed ) ); |
| 273 | - $default_position = array_search( $action_control->id_base, $default_shown, true ); | |
| 222 | + $default_position = array_search( $action_control->id_base, $default_shown ); | |
| 274 | 223 | $allowed_count = count( $allowed ); |
| 275 | 224 | |
| 276 | - if ( ! empty( $action_control->action_options['active'] ) ) { | |
| 225 | + if ( isset( $action_control->action_options['active'] ) && $action_control->action_options['active'] ) { | |
| 277 | 226 | $classes .= ' frm_active_action'; |
| 278 | 227 | } else { |
| 279 | 228 | $classes .= ' frm_inactive_action'; |
| 280 | - | |
| 281 | 229 | if ( $default_position !== false && ( $allowed_count + $default_position ) < 6 ) { |
| 282 | 230 | $group_class .= ' frm-default-show'; |
| 283 | 231 | } |
| 284 | 232 | |
| @@ -285,9 +233,8 @@ | ||
| 285 | 233 | $data['data-upgrade'] = $upgrade_label; |
| 286 | 234 | $data['data-medium'] = 'settings-' . $action_control->id_base; |
| 287 | 235 | |
| 288 | 236 | $upgrading = FrmAddonsController::install_link( $action_control->action_options['plugin'] ); |
| 289 | - | |
| 290 | 237 | if ( isset( $upgrading['url'] ) ) { |
| 291 | 238 | $data['data-oneclick'] = json_encode( $upgrading ); |
| 292 | 239 | } |
| 293 | 240 | |
| @@ -295,9 +242,8 @@ | ||
| 295 | 242 | $data['data-message'] = $action_control->action_options['message']; |
| 296 | 243 | } |
| 297 | 244 | |
| 298 | 245 | $requires = FrmFormsHelper::get_plan_required( $upgrading ); |
| 299 | - | |
| 300 | 246 | if ( $requires && 'free' !== $requires ) { |
| 301 | 247 | $data['data-requires'] = $requires; |
| 302 | 248 | } |
| 303 | 249 | }//end if |
| @@ -303,9 +249,8 @@ | ||
| 303 | 249 | }//end if |
| 304 | 250 | |
| 305 | 251 | // HTML to include on the icon. |
| 306 | 252 | $icon_atts = array(); |
| 307 | - | |
| 308 | 253 | if ( $action_control->action_options['color'] !== 'var(--primary-700)' ) { |
| 309 | 254 | $icon_atts = array( |
| 310 | 255 | 'style' => '--primary-700:' . $action_control->action_options['color'], |
| 311 | 256 | ); |
| @@ -315,15 +260,13 @@ | ||
| 315 | 260 | } |
| 316 | 261 | |
| 317 | 262 | /** |
| 318 | 263 | * @param string $action |
| 319 | - * | |
| 320 | 264 | * @return array|FrmFormAction A single form action is returned when a specific $action value is requested. |
| 321 | 265 | */ |
| 322 | 266 | public static function get_form_actions( $action = 'all' ) { |
| 323 | 267 | $temp_actions = self::$registered_actions; |
| 324 | - | |
| 325 | - if ( ! $temp_actions ) { | |
| 268 | + if ( empty( $temp_actions ) ) { | |
| 326 | 269 | self::actions_init(); |
| 327 | 270 | $temp_actions = self::$registered_actions->actions; |
| 328 | 271 | } else { |
| 329 | 272 | $temp_actions = $temp_actions->actions; |
| @@ -331,9 +274,9 @@ | ||
| 331 | 274 | |
| 332 | 275 | $actions = array(); |
| 333 | 276 | |
| 334 | 277 | foreach ( $temp_actions as $a ) { |
| 335 | - if ( 'all' !== $action && $a->id_base === $action ) { | |
| 278 | + if ( 'all' !== $action && $a->id_base == $action ) { | |
| 336 | 279 | return $a; |
| 337 | 280 | } |
| 338 | 281 | |
| 339 | 282 | $actions[ $a->id_base ] = $a; |
| @@ -343,16 +286,11 @@ | ||
| 343 | 286 | } |
| 344 | 287 | |
| 345 | 288 | /** |
| 346 | 289 | * @since 2.0 |
| 347 | - * | |
| 348 | - * @param object $form | |
| 349 | - * @param array $values | |
| 350 | - * | |
| 351 | - * @return void | |
| 352 | 290 | */ |
| 353 | 291 | public static function list_actions( $form, $values ) { |
| 354 | - if ( ! $form ) { | |
| 292 | + if ( empty( $form ) ) { | |
| 355 | 293 | return; |
| 356 | 294 | } |
| 357 | 295 | |
| 358 | 296 | /** |
| @@ -381,9 +319,9 @@ | ||
| 381 | 319 | self::maybe_show_limit_warning( $form->id, $form_actions ); |
| 382 | 320 | |
| 383 | 321 | foreach ( $form_actions as $action ) { |
| 384 | 322 | if ( ! isset( $action_map[ $action->post_excerpt ] ) ) { |
| 385 | - // Don't try and show settings if action no longer exists | |
| 323 | + // don't try and show settings if action no longer exists | |
| 386 | 324 | continue; |
| 387 | 325 | } |
| 388 | 326 | |
| 389 | 327 | self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values ); |
| @@ -397,20 +335,17 @@ | ||
| 397 | 335 | * @since 6.17 |
| 398 | 336 | * |
| 399 | 337 | * @param int|string $form_id |
| 400 | 338 | * @param array $form_actions |
| 401 | - * | |
| 402 | 339 | * @return void |
| 403 | 340 | */ |
| 404 | 341 | private static function maybe_show_limit_warning( $form_id, $form_actions ) { |
| 405 | 342 | $count = count( $form_actions ); |
| 406 | - | |
| 407 | 343 | if ( $count < 99 ) { |
| 408 | 344 | return; |
| 409 | 345 | } |
| 410 | 346 | |
| 411 | 347 | $limit = FrmFormAction::get_action_limit( $form_id ); |
| 412 | - | |
| 413 | 348 | if ( $limit < 99 || $count < $limit ) { |
| 414 | 349 | return; |
| 415 | 350 | } |
| 416 | 351 | |
| @@ -416,9 +351,9 @@ | ||
| 416 | 351 | |
| 417 | 352 | $documentation_url = 'https://formidableforms.com/knowledgebase/frm_form_action_limit/#kb-increase-limit-of-form-actions'; |
| 418 | 353 | |
| 419 | 354 | echo '<div class="frm_warning_style">'; |
| 420 | - FrmAppHelper::icon_by_class( 'frmfont frm_alert_icon' ); | |
| 355 | + FrmAppHelper::icon_by_class( 'frm_icon_font frm_alert_icon' ); | |
| 421 | 356 | echo ' '; |
| 422 | 357 | printf( |
| 423 | 358 | // translators: %s: URL to documentation |
| 424 | 359 | esc_html__( 'You have reached your form action limit. To increase this limit, you will require additional code. Visit our documentation at %s.', 'formidable' ), |
| @@ -426,17 +361,8 @@ | ||
| 426 | 361 | ); |
| 427 | 362 | echo '</div>'; |
| 428 | 363 | } |
| 429 | 364 | |
| 430 | - /** | |
| 431 | - * @param WP_Post $form_action | |
| 432 | - * @param object $form | |
| 433 | - * @param int $action_key Action ID. | |
| 434 | - * @param FrmFormAction $action_control | |
| 435 | - * @param array $values | |
| 436 | - * | |
| 437 | - * @return void | |
| 438 | - */ | |
| 439 | 365 | public static function action_control( $form_action, $form, $action_key, $action_control, $values ) { |
| 440 | 366 | $action_control->_set( $action_key ); |
| 441 | 367 | |
| 442 | 368 | $use_logging = self::should_show_log_message( $form_action->post_excerpt ); |
| @@ -458,14 +384,16 @@ | ||
| 458 | 384 | */ |
| 459 | 385 | $action_control = self::get_form_actions( $action_type ); |
| 460 | 386 | $action_control->_set( $action_key ); |
| 461 | 387 | |
| 462 | - $form_id = FrmAppHelper::get_param( 'form_id', '', 'post', 'absint' ); | |
| 388 | + $form_id = FrmAppHelper::get_param( 'form_id', '', 'post', 'absint' ); | |
| 389 | + | |
| 463 | 390 | $form_action = $action_control->prepare_new( $form_id ); |
| 464 | 391 | $use_logging = self::should_show_log_message( $action_type ); |
| 465 | - $values = array(); | |
| 466 | - $form = self::fields_to_values( $form_id, $values ); | |
| 467 | 392 | |
| 393 | + $values = array(); | |
| 394 | + $form = self::fields_to_values( $form_id, $values ); | |
| 395 | + | |
| 468 | 396 | include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php'; |
| 469 | 397 | wp_die(); |
| 470 | 398 | } |
| 471 | 399 | |
| @@ -472,19 +400,21 @@ | ||
| 472 | 400 | public static function fill_action() { |
| 473 | 401 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 474 | 402 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 475 | 403 | |
| 476 | - $action_key = FrmAppHelper::get_param( 'action_id', '', 'post', 'absint' ); | |
| 477 | - $action_type = FrmAppHelper::get_param( 'action_type', '', 'post', 'sanitize_text_field' ); | |
| 404 | + $action_key = FrmAppHelper::get_param( 'action_id', '', 'post', 'absint' ); | |
| 405 | + $action_type = FrmAppHelper::get_param( 'action_type', '', 'post', 'sanitize_text_field' ); | |
| 406 | + | |
| 478 | 407 | $action_control = self::get_form_actions( $action_type ); |
| 479 | - | |
| 480 | - if ( ! $action_control ) { | |
| 408 | + if ( empty( $action_control ) ) { | |
| 481 | 409 | wp_die(); |
| 482 | 410 | } |
| 483 | 411 | |
| 484 | 412 | $form_action = $action_control->get_single_action( $action_key ); |
| 485 | - $values = array(); | |
| 486 | - $form = self::fields_to_values( $form_action->menu_order, $values ); | |
| 413 | + | |
| 414 | + $values = array(); | |
| 415 | + $form = self::fields_to_values( $form_action->menu_order, $values ); | |
| 416 | + | |
| 487 | 417 | $use_logging = self::should_show_log_message( $action_type ); |
| 488 | 418 | |
| 489 | 419 | include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_inside.php'; |
| 490 | 420 | wp_die(); |
| @@ -491,11 +421,8 @@ | ||
| 491 | 421 | } |
| 492 | 422 | |
| 493 | 423 | /** |
| 494 | 424 | * @since 3.06.04 |
| 495 | - * | |
| 496 | - * @param string $action_type | |
| 497 | - * | |
| 498 | 425 | * @return bool |
| 499 | 426 | */ |
| 500 | 427 | private static function should_show_log_message( $action_type ) { |
| 501 | 428 | $logging = array( 'api', 'salesforce', 'constantcontact', 'activecampaign' ); |
| @@ -501,14 +428,8 @@ | ||
| 501 | 428 | $logging = array( 'api', 'salesforce', 'constantcontact', 'activecampaign' ); |
| 502 | 429 | return in_array( $action_type, $logging, true ) && ! function_exists( 'frm_log_autoloader' ); |
| 503 | 430 | } |
| 504 | 431 | |
| 505 | - /** | |
| 506 | - * @param int|string $form_id | |
| 507 | - * @param array $values | |
| 508 | - * | |
| 509 | - * @return object | |
| 510 | - */ | |
| 511 | 432 | private static function fields_to_values( $form_id, array &$values ) { |
| 512 | 433 | $form = FrmForm::getOne( $form_id ); |
| 513 | 434 | |
| 514 | 435 | $values = array( |
| @@ -516,14 +437,12 @@ | ||
| 516 | 437 | 'id' => $form->id, |
| 517 | 438 | ); |
| 518 | 439 | |
| 519 | 440 | $fields = FrmField::get_all_for_form( $form->id ); |
| 520 | - | |
| 521 | 441 | foreach ( $fields as $k => $f ) { |
| 522 | 442 | $f = (array) $f; |
| 523 | 443 | $opts = (array) $f['field_options']; |
| 524 | 444 | $f = array_merge( $opts, $f ); |
| 525 | - | |
| 526 | 445 | if ( ! isset( $f['post_field'] ) ) { |
| 527 | 446 | $f['post_field'] = ''; |
| 528 | 447 | } |
| 529 | 448 | $values['fields'][] = $f; |
| @@ -534,15 +453,13 @@ | ||
| 534 | 453 | } |
| 535 | 454 | |
| 536 | 455 | /** |
| 537 | 456 | * @param int $form_id |
| 538 | - * | |
| 539 | 457 | * @return void |
| 540 | 458 | */ |
| 541 | 459 | public static function update_settings( $form_id ) { |
| 542 | 460 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 543 | 461 | $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' ); |
| 544 | - | |
| 545 | 462 | if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) { |
| 546 | 463 | $frm_settings = FrmAppHelper::get_settings(); |
| 547 | 464 | $error_args = array( |
| 548 | 465 | 'title' => __( 'Verification failed', 'formidable' ), |
| @@ -575,19 +492,17 @@ | ||
| 575 | 492 | $new_actions = array(); |
| 576 | 493 | |
| 577 | 494 | foreach ( $registered_actions as $registered_action ) { |
| 578 | 495 | $action_ids = $registered_action->update_callback( $form_id ); |
| 579 | - | |
| 580 | - if ( $action_ids ) { | |
| 496 | + if ( ! empty( $action_ids ) ) { | |
| 581 | 497 | $new_actions[] = $action_ids; |
| 582 | 498 | } |
| 583 | 499 | } |
| 584 | 500 | |
| 585 | 501 | // Only use array_merge if there are new actions. |
| 586 | - if ( $new_actions ) { | |
| 502 | + if ( ! empty( $new_actions ) ) { | |
| 587 | 503 | $new_actions = call_user_func_array( 'array_merge', $new_actions ); |
| 588 | 504 | } |
| 589 | - | |
| 590 | 505 | $old_actions = array_diff( $old_actions, $new_actions ); |
| 591 | 506 | |
| 592 | 507 | self::delete_missing_actions( $old_actions ); |
| 593 | 508 | |
| @@ -593,15 +508,10 @@ | ||
| 593 | 508 | |
| 594 | 509 | FrmOnSubmitHelper::save_on_submit_settings( $form_id ); |
| 595 | 510 | } |
| 596 | 511 | |
| 597 | - /** | |
| 598 | - * @param array $old_actions | |
| 599 | - * | |
| 600 | - * @return void | |
| 601 | - */ | |
| 602 | 512 | public static function delete_missing_actions( $old_actions ) { |
| 603 | - if ( $old_actions ) { | |
| 513 | + if ( ! empty( $old_actions ) ) { | |
| 604 | 514 | foreach ( $old_actions as $old_id ) { |
| 605 | 515 | wp_delete_post( $old_id ); |
| 606 | 516 | } |
| 607 | 517 | FrmDb::cache_delete_group( 'frm_actions' ); |
| @@ -607,15 +517,8 @@ | ||
| 607 | 517 | FrmDb::cache_delete_group( 'frm_actions' ); |
| 608 | 518 | } |
| 609 | 519 | } |
| 610 | 520 | |
| 611 | - /** | |
| 612 | - * @param int|string $entry_id | |
| 613 | - * @param int|string $form_id | |
| 614 | - * @param array $args | |
| 615 | - * | |
| 616 | - * @return void | |
| 617 | - */ | |
| 618 | 521 | public static function trigger_create_actions( $entry_id, $form_id, $args = array() ) { |
| 619 | 522 | $filter_args = $args; |
| 620 | 523 | $filter_args['entry_id'] = $entry_id; |
| 621 | 524 | $filter_args['form_id'] = $form_id; |
| @@ -632,34 +535,26 @@ | ||
| 632 | 535 | self::trigger_actions( $event, $form_id, $entry_id, 'all', $args ); |
| 633 | 536 | } |
| 634 | 537 | |
| 635 | 538 | /** |
| 636 | - * @param string $event | |
| 637 | - * @param int|object|string $form | |
| 638 | - * @param int|object|string $entry | |
| 639 | - * @param string $type | |
| 640 | - * @param array $args | |
| 641 | - * | |
| 642 | - * @return void | |
| 539 | + * @param string $event | |
| 643 | 540 | */ |
| 644 | - public static function trigger_actions( $event, $form, $entry, $type = 'all', $args = array() ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh | |
| 541 | + public static function trigger_actions( $event, $form, $entry, $type = 'all', $args = array() ) { | |
| 645 | 542 | $action_status = array( |
| 646 | 543 | 'post_status' => 'publish', |
| 647 | 544 | ); |
| 648 | - $form_actions = FrmFormAction::get_action_for_form( is_object( $form ) ? $form->id : $form, $type, $action_status ); | |
| 545 | + $form_actions = FrmFormAction::get_action_for_form( ( is_object( $form ) ? $form->id : $form ), $type, $action_status ); | |
| 649 | 546 | |
| 650 | - if ( ! $form_actions ) { | |
| 547 | + if ( empty( $form_actions ) ) { | |
| 651 | 548 | return; |
| 652 | 549 | } |
| 653 | 550 | |
| 654 | 551 | FrmForm::maybe_get_form( $form ); |
| 655 | - | |
| 656 | 552 | if ( ! is_object( $form ) ) { |
| 657 | 553 | return; |
| 658 | 554 | } |
| 659 | 555 | |
| 660 | 556 | $link_settings = self::get_form_actions( $type ); |
| 661 | - | |
| 662 | 557 | if ( 'all' !== $type ) { |
| 663 | 558 | $link_settings = array( $type => $link_settings ); |
| 664 | 559 | } |
| 665 | 560 | |
| @@ -672,11 +567,11 @@ | ||
| 672 | 567 | $this_event = $event; |
| 673 | 568 | } |
| 674 | 569 | |
| 675 | 570 | foreach ( $form_actions as $action ) { |
| 571 | + | |
| 676 | 572 | $skip_this_action = ! in_array( $this_event, $action->post_content['event'], true ) || FrmOnSubmitAction::$slug === $action->post_excerpt; |
| 677 | 573 | $skip_this_action = apply_filters( 'frm_skip_form_action', $skip_this_action, compact( 'action', 'entry', 'form', 'event' ) ); |
| 678 | - | |
| 679 | 574 | if ( $skip_this_action ) { |
| 680 | 575 | continue; |
| 681 | 576 | } |
| 682 | 577 | |
| @@ -683,18 +578,17 @@ | ||
| 683 | 578 | if ( ! is_object( $entry ) ) { |
| 684 | 579 | $entry = FrmEntry::getOne( $entry, true ); |
| 685 | 580 | } |
| 686 | 581 | |
| 687 | - if ( ! $entry || ( FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $entry->is_draft && 'draft' !== $event ) ) { | |
| 582 | + if ( empty( $entry ) || ( FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $entry->is_draft && 'draft' !== $event ) ) { | |
| 688 | 583 | continue; |
| 689 | 584 | } |
| 690 | 585 | |
| 691 | - $child_entry = ( is_numeric( $form->parent_form_id ) && $form->parent_form_id ) || ( $entry && ( (int) $entry->form_id !== (int) $form->id || $entry->parent_item_id ) ) || ! empty( $args['is_child'] ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 586 | + $child_entry = ( is_numeric( $form->parent_form_id ) && $form->parent_form_id ) || ( $entry && ( $entry->form_id != $form->id || $entry->parent_item_id ) ) || ! empty( $args['is_child'] ); | |
| 692 | 587 | |
| 693 | 588 | if ( $child_entry ) { |
| 694 | - // Maybe trigger actions for sub forms | |
| 589 | + // maybe trigger actions for sub forms | |
| 695 | 590 | $trigger_children = apply_filters( 'frm_use_embedded_form_actions', false, compact( 'form', 'entry' ) ); |
| 696 | - | |
| 697 | 591 | if ( ! $trigger_children ) { |
| 698 | 592 | continue; |
| 699 | 593 | } |
| 700 | 594 | } |
| @@ -700,9 +594,8 @@ | ||
| 700 | 594 | } |
| 701 | 595 | |
| 702 | 596 | // Check conditional logic. |
| 703 | 597 | $stop = FrmFormAction::action_conditions_met( $action, $entry ); |
| 704 | - | |
| 705 | 598 | if ( $stop ) { |
| 706 | 599 | continue; |
| 707 | 600 | } |
| 708 | 601 | |
| @@ -712,9 +605,9 @@ | ||
| 712 | 605 | |
| 713 | 606 | unset( $action ); |
| 714 | 607 | }//end foreach |
| 715 | 608 | |
| 716 | - if ( $stored_actions ) { | |
| 609 | + if ( ! empty( $stored_actions ) ) { | |
| 717 | 610 | asort( $action_priority ); |
| 718 | 611 | |
| 719 | 612 | // Make sure hooks are loaded. |
| 720 | 613 | new FrmNotification(); |
| @@ -745,15 +638,8 @@ | ||
| 745 | 638 | }//end foreach |
| 746 | 639 | }//end if |
| 747 | 640 | } |
| 748 | 641 | |
| 749 | - /** | |
| 750 | - * @param int|string $form_id | |
| 751 | - * @param array $values | |
| 752 | - * @param array $args | |
| 753 | - * | |
| 754 | - * @return void | |
| 755 | - */ | |
| 756 | 642 | public static function duplicate_form_actions( $form_id, $values, $args = array() ) { |
| 757 | 643 | if ( empty( $args['old_id'] ) ) { |
| 758 | 644 | // Continue if we know which actions to copy. |
| 759 | 645 | return; |
| @@ -769,13 +655,8 @@ | ||
| 769 | 655 | unset( $action_control ); |
| 770 | 656 | } |
| 771 | 657 | } |
| 772 | 658 | |
| 773 | - /** | |
| 774 | - * @param string $where | |
| 775 | - * | |
| 776 | - * @return string | |
| 777 | - */ | |
| 778 | 659 | public static function limit_by_type( $where ) { |
| 779 | 660 | global $frm_vars, $wpdb; |
| 780 | 661 | |
| 781 | 662 | if ( ! isset( $frm_vars['action_type'] ) ) { |
| @@ -781,9 +662,11 @@ | ||
| 781 | 662 | if ( ! isset( $frm_vars['action_type'] ) ) { |
| 782 | 663 | return $where; |
| 783 | 664 | } |
| 784 | 665 | |
| 785 | - return $where . $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] ); | |
| 666 | + $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] ); | |
| 667 | + | |
| 668 | + return $where; | |
| 786 | 669 | } |
| 787 | 670 | |
| 788 | 671 | /** |
| 789 | 672 | * Prevent WPML from filtering form actions based on the active language. |
| @@ -791,21 +674,19 @@ | ||
| 791 | 674 | * @since 6.20 |
| 792 | 675 | * |
| 793 | 676 | * @param bool|null $null |
| 794 | 677 | * @param string $post_type |
| 795 | - * | |
| 796 | 678 | * @return bool|null |
| 797 | 679 | */ |
| 798 | 680 | public static function prevent_wpml_translations( $null, $post_type ) { |
| 799 | - return self::$action_post_type === $post_type ? false : $null; | |
| 681 | + if ( self::$action_post_type === $post_type ) { | |
| 682 | + return false; | |
| 683 | + } | |
| 684 | + return $null; | |
| 800 | 685 | } |
| 801 | 686 | } |
| 802 | 687 | |
| 803 | 688 | class Frm_Form_Action_Factory { |
| 804 | - | |
| 805 | - /** | |
| 806 | - * @var array | |
| 807 | - */ | |
| 808 | 689 | public $actions = array(); |
| 809 | 690 | |
| 810 | 691 | public function __construct() { |
| 811 | 692 | add_action( 'frm_form_actions_init', array( $this, '_register_actions' ), 100 ); |
| @@ -810,22 +691,12 @@ | ||
| 810 | 691 | public function __construct() { |
| 811 | 692 | add_action( 'frm_form_actions_init', array( $this, '_register_actions' ), 100 ); |
| 812 | 693 | } |
| 813 | 694 | |
| 814 | - /** | |
| 815 | - * @param string $action_class | |
| 816 | - * | |
| 817 | - * @return void | |
| 818 | - */ | |
| 819 | 695 | public function register( $action_class ) { |
| 820 | 696 | $this->actions[ $action_class ] = new $action_class(); |
| 821 | 697 | } |
| 822 | 698 | |
| 823 | - /** | |
| 824 | - * @param string $action_class | |
| 825 | - * | |
| 826 | - * @return void | |
| 827 | - */ | |
| 828 | 699 | public function unregister( $action_class ) { |
| 829 | 700 | if ( isset( $this->actions[ $action_class ] ) ) { |
| 830 | 701 | unset( $this->actions[ $action_class ] ); |
| 831 | 702 | } |
| @@ -834,9 +705,9 @@ | ||
| 834 | 705 | public function _register_actions() { |
| 835 | 706 | $keys = array_keys( $this->actions ); |
| 836 | 707 | |
| 837 | 708 | foreach ( $keys as $key ) { |
| 838 | - // Don't register new action if old action with the same id is already registered | |
| 709 | + // don't register new action if old action with the same id is already registered | |
| 839 | 710 | if ( ! isset( $this->actions[ $key ] ) ) { |
| 840 | 711 | $this->actions[ $key ]->_register(); |
| 841 | 712 | } |
| 842 | 713 | } |