PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.32
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.32
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/controllers/FrmFormsController.php +1317 -576 6.36.32 View file →
@@ -4,13 +4,35 @@
4 4 }
5 5
6 6 class FrmFormsController {
7 7
8 + /**
9 + * Track the form that opened the redirect URL in a new tab. This is used to check if we should show the default
10 + * message in the current tab.
11 + *
12 + * @since 6.2
13 + *
14 + * @var array Keys are form IDs and values are 1.
15 + */
16 + private static $redirected_in_new_tab = array();
17 +
18 + /**
19 + * The HTML for the Formdiable TinyMCE button (That triggers a popup to insert shortcodes)
20 + * is stored here and re-used as an optimization.
21 + *
22 + * @since 6.11
23 + *
24 + * @var string|null
25 + */
26 + private static $formidable_tinymce_button;
27 +
8 28 public static function menu() {
9 29 $menu_label = __( 'Forms', 'formidable' );
30 +
10 31 if ( ! FrmAppHelper::pro_is_installed() ) {
11 32 $menu_label .= ' (Lite)';
12 33 }
34 +
13 35 add_submenu_page( 'formidable', 'Formidable | ' . $menu_label, $menu_label, 'frm_view_forms', 'formidable', 'FrmFormsController::route' );
14 36
15 37 self::maybe_load_listing_hooks();
16 38 }
@@ -25,8 +47,15 @@
25 47 add_filter( 'manage_toplevel_page_formidable_columns', 'FrmFormsController::get_columns', 0 );
26 48 add_filter( 'manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns' );
27 49 }
28 50
51 + /**
52 + * Runs on admin head of the formidable forms page.
53 + *
54 + * @since 6.32 This adds screen options.
55 + *
56 + * @return void
57 + */
29 58 public static function head() {
30 59 if ( wp_is_mobile() ) {
31 60 wp_enqueue_script( 'jquery-touch-punch' );
32 61 }
@@ -44,12 +73,12 @@
44 73 */
45 74 public static function logic_tip() {
46 75 $images_url = FrmAppHelper::plugin_url() . '/images/';
47 76 $data_message = __( 'Only show the fields you need and create branching forms. Upgrade to get conditional logic and question branching.', 'formidable' );
48 - $data_message .= ' <img src="' . esc_attr( $images_url ) . '/survey-logic.png" srcset="' . esc_attr( $images_url ) . 'survey-logic@2x.png 2x" alt="' . esc_attr__( 'Conditional Logic options', 'formidable' ) . '"/>';
49 - echo '<a href="javascript:void(0)" class="frm_noallow frm_show_upgrade frm_add_logic_link frm-collapsed frm-flex-justify" data-upgrade="' . esc_attr__( 'Conditional Logic options', 'formidable' ) . '" data-message="' . esc_attr( $data_message ) . '" data-medium="builder" data-content="logic">';
77 + $data_message .= ' <img src="' . esc_url( $images_url ) . '/survey-logic.png" srcset="' . esc_url( $images_url ) . 'survey-logic@2x.png 2x" alt="' . esc_attr__( 'Conditional Logic options', 'formidable' ) . '"/>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
78 + echo '<a href="javascript:void(0)" class="frm_noallow frm_show_upgrade frm_add_logic_link frm-collapsed frm-flex-justify" data-upgrade="' . esc_attr__( 'Conditional Logic options', 'formidable' ) . '" data-message="' . esc_attr( $data_message ) . '" data-medium="builder" data-content="logic">'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
50 79 esc_html_e( 'Conditional Logic', 'formidable' );
51 - FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown6_icon', array( 'aria-hidden' => 'true' ) );
80 + FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon', array( 'aria-hidden' => 'true' ) );
52 81 echo '</a>';
53 82 }
54 83
55 84 /**
@@ -56,12 +85,15 @@
56 85 * By default, Divi processes form shortcodes on the edit post page.
57 86 * Now that won't do.
58 87 *
59 88 * @since 3.01
89 + *
90 + * @param array $shortcodes List of shortcodes to process.
91 + *
92 + * @return array
60 93 */
61 94 public static function prevent_divi_conflict( $shortcodes ) {
62 95 $shortcodes[] = 'formidable';
63 -
64 96 return $shortcodes;
65 97 }
66 98
67 99 /**
@@ -72,12 +104,14 @@
72 104
73 105 $message = '';
74 106 $params = FrmForm::list_page_params();
75 107 $errors = self::process_bulk_form_actions( array() );
108 +
76 109 if ( isset( $errors['message'] ) ) {
77 110 $message = $errors['message'];
78 111 unset( $errors['message'] );
79 112 }
113 +
80 114 $errors = apply_filters( 'frm_admin_list_form_action', $errors );
81 115
82 116 self::display_forms_list( $params, $message, $errors );
83 117 }
@@ -86,18 +120,30 @@
86 120 * Create the default email action
87 121 *
88 122 * @since 2.02.11
89 123 *
90 - * @param object|int $form
124 + * @param int|object $form
125 + *
126 + * @return void
91 127 */
92 128 private static function create_default_email_action( $form ) {
93 129 FrmForm::maybe_get_form( $form );
130 +
131 + if ( ! is_object( $form ) ) {
132 + return;
133 + }
134 +
94 135 $create_email = apply_filters( 'frm_create_default_email_action', true, $form );
95 136
96 - if ( $create_email ) {
97 - $action_control = FrmFormActionsController::get_form_actions( 'email' );
98 - $action_control->create( $form->id );
137 + if ( ! $create_email ) {
138 + return;
99 139 }
140 +
141 + /**
142 + * @var FrmFormAction
143 + */
144 + $action_control = FrmFormActionsController::get_form_actions( 'email' );
145 + $action_control->create( $form->id );
100 146 }
101 147
102 148 /**
103 149 * Create the default On submit action
@@ -103,13 +149,19 @@
103 149 * Create the default On submit action
104 150 *
105 151 * @since 6.0.0
106 152 *
107 - * @param object|int $form Form object or ID.
153 + * @param int|object $form Form object or ID.
154 + *
155 + * @return void
108 156 */
109 157 private static function create_default_on_submit_action( $form ) {
110 158 FrmForm::maybe_get_form( $form );
111 159
160 + if ( ! is_object( $form ) ) {
161 + return;
162 + }
163 +
112 164 /**
113 165 * Enable or disable the default On Submit action.
114 166 *
115 167 * @since 6.0.0
@@ -118,22 +170,73 @@
118 170 * @param object $form Form object.
119 171 */
120 172 $create = apply_filters( 'frm_create_default_on_submit_action', true, $form );
121 173
122 - if ( $create ) {
123 - $action_control = FrmFormActionsController::get_form_actions( FrmOnSubmitAction::$slug );
124 - $action_control->create( $form->id );
174 + if ( ! $create ) {
175 + return;
125 176 }
177 +
178 + /**
179 + * @var FrmFormAction
180 + */
181 + $action_control = FrmFormActionsController::get_form_actions( FrmOnSubmitAction::$slug );
182 + $action_control->create( $form->id );
126 183 }
127 184
185 + /**
186 + * Creates submit button field.
187 + *
188 + * @since 6.9
189 + *
190 + * @param int|object $form Form ID or object.
191 + *
192 + * @return void
193 + */
194 + private static function create_submit_button_field( $form ) {
195 + FrmForm::maybe_get_form( $form );
196 +
197 + if ( ! is_object( $form ) ) {
198 + return;
199 + }
200 +
201 + if ( FrmSubmitHelper::get_submit_field( $form->id ) ) {
202 + // Do not create submit button field if it exists.
203 + return;
204 + }
205 +
206 + FrmField::create(
207 + array(
208 + 'type' => FrmSubmitHelper::FIELD_TYPE,
209 + 'name' => __( 'Submit', 'formidable' ),
210 + 'field_order' => FrmSubmitHelper::DEFAULT_ORDER,
211 + 'form_id' => $form->id,
212 + 'field_options' => FrmFieldsHelper::get_default_field_options( FrmSubmitHelper::FIELD_TYPE ),
213 + 'description' => '',
214 + 'default_value' => '',
215 + 'options' => array(),
216 + )
217 + );
218 + }
219 +
220 + /**
221 + * @param array|false $values
222 + *
223 + * @return void
224 + */
128 225 public static function edit( $values = false ) {
129 226 FrmAppHelper::permission_check( 'frm_edit_forms' );
130 227
131 228 $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
132 229
133 - return self::get_edit_vars( $id );
230 + self::get_edit_vars( $id );
134 231 }
135 232
233 + /**
234 + * @param mixed $id
235 + * @param string $message
236 + *
237 + * @return void
238 + */
136 239 public static function settings( $id = false, $message = '' ) {
137 240 FrmAppHelper::permission_check( 'frm_edit_forms' );
138 241
139 242 if ( ! $id || ! is_numeric( $id ) ) {
@@ -141,30 +244,43 @@
141 244 }
142 245
143 246 FrmOnSubmitHelper::maybe_migrate_submit_settings_to_action( $id );
144 247
145 - return self::get_settings_vars( $id, array(), $message );
248 + self::get_settings_vars( $id, array(), $message );
146 249 }
147 250
148 251 public static function update_settings() {
149 252 FrmAppHelper::permission_check( 'frm_edit_forms' );
253 + $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
150 254
151 - $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
255 + if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) {
256 + $frm_settings = FrmAppHelper::get_settings();
257 + $error_args = array(
258 + 'title' => __( 'Verification failed', 'formidable' ),
259 + 'body' => $frm_settings->admin_permission,
260 + 'cancel_text' => __( 'Cancel', 'formidable' ),
261 + );
262 + FrmAppController::show_error_modal( $error_args );
263 + return;
264 + }
152 265
153 - $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
266 + $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
267 + $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
154 268 $warnings = FrmFormsHelper::check_for_warnings( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
155 269
156 270 if ( count( $errors ) > 0 ) {
157 - return self::get_settings_vars( $id, $errors, compact( 'warnings' ) );
271 + self::get_settings_vars( $id, $errors, compact( 'warnings' ) );
272 + return;
158 273 }
159 274
160 275 do_action( 'frm_before_update_form_settings', $id );
161 276
162 - $antispam_was_on = self::antispam_was_on( $id );
277 + $antispam_was_on = self::antispam_was_on( $id ); // phpcs:ignore Formidable.CodeAnalysis.InlineSingleUseVariable
163 278
164 279 FrmForm::update( $id, $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
165 280
166 281 $antispam_is_on = ! empty( $_POST['options']['antispam'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
282 +
167 283 if ( $antispam_is_on !== $antispam_was_on ) {
168 284 FrmAntiSpam::clear_caches();
169 285 }
170 286
@@ -169,13 +285,14 @@
169 285 }
170 286
171 287 $message = __( 'Settings Successfully Updated', 'formidable' );
172 288
173 - return self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) );
289 + self::get_settings_vars( $id, array(), compact( 'message', 'warnings' ) );
174 290 }
175 291
176 292 /**
177 293 * @param int $form_id
294 + *
178 295 * @return bool
179 296 */
180 297 private static function antispam_was_on( $form_id ) {
181 298 $form = FrmForm::getOne( $form_id );
@@ -181,10 +298,15 @@
181 298 $form = FrmForm::getOne( $form_id );
182 299 return ! empty( $form->options['antispam'] );
183 300 }
184 301
302 + /**
303 + * @param array $values
304 + *
305 + * @return void
306 + */
185 307 public static function update( $values = array() ) {
186 - if ( empty( $values ) ) {
308 + if ( ! $values ) {
187 309 $values = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing
188 310 }
189 311
190 312 // Set radio button and checkbox meta equal to "other" value.
@@ -193,8 +315,9 @@
193 315 }
194 316
195 317 $errors = FrmForm::validate( $values );
196 318 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form', 'frm_save_form_nonce' );
319 +
197 320 if ( $permission_error !== false ) {
198 321 $errors['form'] = $permission_error;
199 322 }
200 323
@@ -200,65 +323,93 @@
200 323
201 324 $id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
202 325
203 326 if ( count( $errors ) > 0 ) {
204 - return self::get_edit_vars( $id, $errors );
205 - } else {
206 - FrmForm::update( $id, $values );
207 - $message = __( 'Form was successfully updated.', 'formidable' );
327 + self::get_edit_vars( $id, $errors );
328 + return;
329 + }
208 330
209 - if ( self::is_too_long( $values ) ) {
210 - $message .= '<br/> ' . sprintf(
211 - /* translators: %1$s: Start link HTML, %2$s: end link HTML */
212 - __( 'However, your form is very long and may be %1$sreaching server limits%2$s.', 'formidable' ),
213 - '<a href="https://formidableforms.com/knowledgebase/i-have-a-long-form-why-did-the-options-at-the-end-of-the-form-stop-saving/?utm_source=WordPress&utm_medium=builder&utm_campaign=liteplugin" target="_blank" rel="noopener">',
214 - '</a>'
215 - );
216 - }
331 + self::maybe_remove_draft_option_from_fields( $id );
217 332
218 - if ( defined( 'DOING_AJAX' ) ) {
219 - wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
220 - }
333 + FrmForm::update( $id, $values );
334 + $message = __( 'Form was successfully updated.', 'formidable' );
221 335
222 - return self::get_edit_vars( $id, array(), $message );
336 + if ( self::is_too_long( $values ) ) {
337 + $message .= '<br/> ' . sprintf(
338 + /* translators: %1$s: Start link HTML, %2$s: end link HTML */
339 + __( 'However, your form is very long and may be %1$sreaching server limits%2$s.', 'formidable' ),
340 + '<a href="' . esc_url( self::get_form_too_long_docs_url() ) . '" target="_blank" rel="noopener">',
341 + '</a>'
342 + );
223 343 }
344 +
345 + if ( defined( 'DOING_AJAX' ) ) {
346 + wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
347 + }
348 +
349 + self::get_edit_vars( $id, array(), $message );
224 350 }
225 351
226 352 /**
227 - * Check if the value at the end of the form was included.
228 - * If it's missing, it means other values at the end of the form
229 - * were likely not saved either.
353 + * @since 6.25.1
230 354 *
231 - * @since 3.06.01
355 + * @return string
232 356 */
233 - private static function is_too_long( $values ) {
234 - return ( ! isset( $values['frm_end'] ) ) || empty( $values['frm_end'] );
357 + private static function get_form_too_long_docs_url() {
358 + $utm = array(
359 + 'campaign' => 'builder',
360 + 'content' => 'form-too-long',
361 + );
362 + return FrmAppHelper::admin_upgrade_link( $utm, 'knowledgebase/i-have-a-long-form-why-did-the-options-at-the-end-of-the-form-stop-saving/' );
235 363 }
236 364
237 365 /**
238 - * Redirect to the url for creating from a template
239 - * Also delete the current form
366 + * Remove the draft flag from any new fields from this current session.
240 367 *
241 - * @since 2.0
242 - * @deprecated 3.06
368 + * @since 6.8
369 + *
370 + * @param int $form_id
371 + *
372 + * @return void
243 373 */
244 - public static function _create_from_template() {
245 - _deprecated_function( __FUNCTION__, '3.06' );
374 + private static function maybe_remove_draft_option_from_fields( $form_id ) {
375 + $draft_field_ids_csv = FrmAppHelper::get_post_param( 'draft_fields', '', 'sanitize_text_field' );
246 376
247 - FrmAppHelper::permission_check( 'frm_edit_forms' );
248 - check_ajax_referer( 'frm_ajax', 'nonce' );
377 + if ( ! $draft_field_ids_csv ) {
378 + // If the draft_fields input is empty there are no new fields in the session.
379 + return;
380 + }
249 381
250 - $current_form = FrmAppHelper::get_param( 'this_form', '', 'get', 'absint' );
251 - $template_id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
382 + $draft_field_ids = array_filter( explode( ',', $draft_field_ids_csv ), 'is_numeric' );
252 383
253 - if ( $current_form ) {
254 - FrmForm::destroy( $current_form );
384 + if ( ! $draft_field_ids ) {
385 + // Exit early if the draft fields input is invalid. It should be a CSV of integer values.
386 + return;
255 387 }
256 388
257 - echo esc_url_raw( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template_id ) ) );
258 - wp_die();
389 + $draft_field_rows = FrmFieldsHelper::get_draft_field_results( $form_id, $draft_field_ids );
390 +
391 + foreach ( $draft_field_rows as $row ) {
392 + $row->field_options['draft'] = 0;
393 + FrmField::update( $row->id, array( 'field_options' => $row->field_options ) );
394 + }
259 395 }
260 396
397 + /**
398 + * Check if the value at the end of the form was included.
399 + * If it's missing, it means other values at the end of the form
400 + * were likely not saved either.
401 + *
402 + * @since 3.06.01
403 + *
404 + * @param array $values
405 + *
406 + * @return bool
407 + */
408 + private static function is_too_long( $values ) {
409 + return empty( $values['frm_end'] );
410 + }
411 +
261 412 public static function duplicate() {
262 413 FrmAppHelper::permission_check( 'frm_edit_forms' );
263 414 $nonce = FrmAppHelper::simple_get( '_wpnonce' );
264 415
@@ -272,10 +423,11 @@
272 423 $url = admin_url( 'admin.php?page=formidable' );
273 424 $message = 'form_duplicate_error';
274 425
275 426 if ( $form ) {
276 - $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) );
277 - $message = 'form_duplicated';
427 + $new_template = FrmAppHelper::simple_get( 'new_template' ) ? '&new_template=true' : '';
428 + $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) . $new_template );
429 + $message = 'form_duplicated';
278 430 }
279 431
280 432 $url .= '&message=' . $message;
281 433
@@ -283,27 +435,45 @@
283 435 exit();
284 436 }
285 437
286 438 /**
287 - * @return string
439 + * @return string|null
288 440 */
289 441 public static function page_preview() {
290 442 $params = FrmForm::list_page_params();
291 - if ( ! $params['form'] ) {
292 - return;
443 +
444 + if ( ! $params['form'] || is_numeric( $params['form'] ) ) {
445 + return null;
293 446 }
294 447
448 + self::maybe_block_preview( $params['form'] );
449 +
295 450 $form = FrmForm::getOne( $params['form'] );
296 - if ( $form ) {
297 - return self::show_form( $form->id, '', 'auto', 'auto' );
451 +
452 + if ( ! $form ) {
453 + return null;
298 454 }
455 +
456 + return self::show_form( $form->id, '', 'auto', 'auto' );
299 457 }
300 458
301 459 /**
302 460 * @since 3.0
461 + *
462 + * @return void
303 463 */
304 464 public static function show_page_preview() {
305 - echo self::page_preview(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
465 + $preview = self::page_preview();
466 +
467 + if ( is_null( $preview ) ) {
468 + wp_die(
469 + '<h1>' . esc_html__( 'Form key is invalid', 'formidable' ) . '</h1>',
470 + '<p>' . esc_html__( 'Form key is invalid', 'formidable' ) . '</p>',
471 + 404
472 + );
473 + }
474 +
475 + echo $preview; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
306 476 }
307 477
308 478 /**
309 479 * @return void
@@ -314,9 +484,19 @@
314 484
315 485 global $frm_vars;
316 486 $frm_vars['preview'] = true;
317 487
488 + // print_emoji_styles is deprecated.
489 + remove_action( 'wp_print_styles', 'print_emoji_styles' );
490 +
491 + if ( FrmTestModeController::should_add_test_mode_container() ) {
492 + do_action( 'frm_test_mode_init' );
493 + add_action( 'wp_enqueue_scripts', 'FrmTestModeController::register_and_enqueue_required_scripts' );
494 + add_filter( 'frm_filter_final_form', 'FrmTestModeController::maybe_add_test_mode_container', 99 );
495 + }
496 +
318 497 $include_theme = FrmAppHelper::get_param( 'theme', '', 'get', 'absint' );
498 +
319 499 if ( $include_theme ) {
320 500 self::set_preview_query();
321 501 self::load_theme_preview();
322 502 } else {
@@ -339,8 +519,9 @@
339 519 'post_type' => 'page',
340 520 );
341 521
342 522 $page_for_posts = get_option( 'page_for_posts' );
523 +
343 524 if ( is_numeric( $page_for_posts ) ) {
344 525 // Avoid querying for the "Posts Page" or "Blog Page" so we don't display 10 forms.
345 526 $page_query['post__not_in'] = array( $page_for_posts );
346 527 }
@@ -345,13 +526,20 @@
345 526 $page_query['post__not_in'] = array( $page_for_posts );
346 527 }
347 528
348 529 $random_page = get_posts( $page_query );
530 +
349 531 if ( ! $random_page ) {
350 532 return;
351 533 }
352 534
353 535 $random_page = reset( $random_page );
536 +
537 + if ( ! is_a( $random_page, 'WP_Post' ) ) {
538 + // The return type can also be int.
539 + return;
540 + }
541 +
354 542 query_posts(
355 543 array(
356 544 'post_type' => 'page',
357 545 'page_id' => $random_page->ID,
@@ -367,9 +555,10 @@
367 555 * Set the WP $post global object. Used for in-theme preview when defining a page.
368 556 *
369 557 * @since 5.5.2
370 558 *
371 - * @param WP_Post $post
559 + * @param WP_Post $page The page object.
560 + *
372 561 * @return void
373 562 */
374 563 private static function set_post_global( $page ) {
375 564 global $post;
@@ -377,8 +566,10 @@
377 566 }
378 567
379 568 /**
380 569 * @since 3.0
570 + *
571 + * @return void
381 572 */
382 573 private static function load_theme_preview() {
383 574 add_filter( 'wp_title', 'FrmFormsController::preview_title', 9999 );
384 575 add_filter( 'the_title', 'FrmFormsController::preview_page_title', 9999 );
@@ -386,48 +577,125 @@
386 577 add_action( 'loop_no_results', 'FrmFormsController::show_page_preview' );
387 578 add_filter( 'is_active_sidebar', '__return_false' );
388 579 FrmStylesController::enqueue_css( 'enqueue', true );
389 580
390 - if ( false === get_template_part( 'page' ) ) {
391 - self::fallback_when_page_template_part_is_not_supported_by_theme();
581 + if ( false !== get_template_part( 'page' ) ) {
582 + return;
392 583 }
584 +
585 + if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) {
586 + add_filter( 'body_class', 'FrmFormsController::preview_block_theme_body_classnames' );
587 + }
588 + self::fallback_when_page_template_part_is_not_supported_by_theme();
393 589 }
394 590
395 591 /**
592 + * Add padding to the body for block themes.
593 + *
594 + * @since 6.5.2
595 + *
596 + * @param array $classes The body classes list.
597 + *
598 + * @return array
599 + */
600 + public static function preview_block_theme_body_classnames( $classes ) {
601 + $classes[] = 'has-global-padding';
602 + return $classes;
603 + }
604 +
605 + /**
396 606 * Not every theme supports get_template_part( 'page' ).
397 607 * When this is not supported, false is returned, and we can handle a fallback.
608 + *
609 + * @return void
398 610 */
399 611 private static function fallback_when_page_template_part_is_not_supported_by_theme() {
400 - if ( have_posts() ) {
401 - the_post();
402 - get_header( '' );
403 - // add some generic class names to the container to add some natural padding to the content.
404 - // .entry-content catches the WordPress TwentyTwenty theme.
405 - // .container catches Customizr content.
406 - echo '<div class="container entry-content">';
407 - the_content();
408 - echo '</div>';
409 - get_footer();
612 + if ( ! have_posts() ) {
613 + return;
410 614 }
615 +
616 + the_post();
617 + self::get_template( 'header' );
618 +
619 + // Add some generic class names to the container to add some natural padding to the content.
620 + // .entry-content catches the WordPress TwentyTwenty theme.
621 + // .container catches Customizr content.
622 + echo '<div class="container entry-content">';
623 + the_content();
624 + echo '</div>';
625 +
626 + // Prevent extra unexpected forms in the footer.
627 + // For some reason this happens in the Twenty Twenty Five theme.
628 + add_filter( 'frm_filter_final_form', '__return_empty_string' );
629 +
630 + self::get_template( 'footer' );
411 631 }
412 632
413 633 /**
634 + * Calls core function to get a template part if it doesn't cause deprecation warnings. Otherwise skips the deprecation function call
635 + * and renders required html fragments calling required functions.
636 + *
637 + * @since 6.7.1
638 + *
639 + * @param string $template
640 + *
641 + * @return void
642 + */
643 + private static function get_template( $template ) {
644 + if ( self::should_try_getting_template( $template ) ) {
645 + call_user_func( 'get_' . $template );
646 + return;
647 + }
648 +
649 + if ( 'header' === $template ) {
650 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/header.php';
651 + return;
652 + }
653 +
654 + if ( 'footer' === $template ) {
655 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/footer.php';
656 + }
657 + }
658 +
659 + /**
660 + * Returns true if calling a template function doesn't trigger deprecation warnings.
661 + *
662 + * @since 6.7.1
663 + *
664 + * @param string $template
665 + *
666 + * @return bool
667 + */
668 + private static function should_try_getting_template( $template ) {
669 + $stylesheet_path = get_stylesheet_directory();
670 + $template_path = get_template_directory();
671 + $is_child_theme = $stylesheet_path !== $template_path;
672 + $template_name = $template . '.php';
673 +
674 + return file_exists( $stylesheet_path . '/' . $template_name ) || $is_child_theme && file_exists( $template_path . '/' . $template_name );
675 + }
676 +
677 + /**
414 678 * Set the page title for the theme preview page
415 679 *
416 680 * @since 3.0
681 + *
682 + * @param string $title
683 + *
684 + * @return string
417 685 */
418 686 public static function preview_page_title( $title ) {
419 - if ( in_the_loop() ) {
420 - $title = self::preview_title( $title );
421 - }
422 -
423 - return $title;
687 + return in_the_loop() ? self::preview_title( $title ) : $title;
424 688 }
425 689
426 690 /**
427 - * Set the page title for the theme preview page
691 + * Set the page title for the theme preview page.
428 692 *
429 693 * @since 3.0
694 + *
695 + * @param string $title
696 + *
697 + * @return string
430 698 */
431 699 public static function preview_title( $title ) {
432 700 return __( 'Form Preview', 'formidable' );
433 701 }
@@ -432,15 +700,21 @@
432 700 return __( 'Form Preview', 'formidable' );
433 701 }
434 702
435 703 /**
436 - * Set the page content for the theme preview page
704 + * Set the page content for the theme preview page.
437 705 *
438 706 * @since 3.0
707 + *
708 + * @param string $content
709 + *
710 + * @return string
439 711 */
440 712 public static function preview_content( $content ) {
441 713 if ( in_the_loop() ) {
442 - $content = self::show_page_preview();
714 + self::show_page_preview();
715 + // Clear the content for the page we're using.
716 + $content = '';
443 717 }
444 718
445 719 return $content;
446 720 }
@@ -448,23 +722,92 @@
448 722 /**
449 723 * @since 3.0
450 724 */
451 725 private static function load_direct_preview() {
452 - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
726 + $key = FrmAppHelper::simple_get( 'form', 'sanitize_title' );
453 727
454 - $key = FrmAppHelper::simple_get( 'form', 'sanitize_title' );
728 + // phpcs:ignore Universal.Operators.StrictComparisons
455 729 if ( $key == '' ) {
456 730 $key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' );
457 731 }
458 732
733 + if ( ! $key ) {
734 + $error = __( 'Form key is missing', 'formidable' );
735 + wp_die(
736 + '<h1>' . esc_html( $error ) . '</h1>',
737 + '<p>' . esc_html( $error ) . '</p>',
738 + 404
739 + );
740 + }
741 +
742 + self::maybe_block_preview( $key );
743 +
459 744 $form = FrmForm::getAll( array( 'form_key' => $key ), '', 1 );
460 - if ( empty( $form ) ) {
461 - $form = FrmForm::getAll( array(), '', 1 );
745 +
746 + if ( ! $form ) {
747 + $error = __( 'Form does not exist', 'formidable' );
748 + wp_die(
749 + '<h1>' . esc_html( $error ) . '</h1>',
750 + '<p>' . esc_html( $error ) . '</p>',
751 + 404
752 + );
462 753 }
463 754
464 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' );
755 + header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
756 +
757 + self::fix_deprecated_null_param_warning();
758 +
759 + require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php';
465 760 }
466 761
762 + /**
763 + * Block the form preview for the contact form by default if the user cannot view forms.
764 + * This is to prevent the contact form being exploited.
765 + * Since this form is added by default and every site uses the same key, it is too easy
766 + * to guess this form.
767 + *
768 + * @since 6.20
769 + *
770 + * @param string $form_key Form key.
771 + *
772 + * @return void
773 + */
774 + public static function maybe_block_preview( $form_key ) {
775 + if ( ! FrmFormsHelper::should_block_preview( $form_key ) ) {
776 + return;
777 + }
778 +
779 + $error = __( 'You do not have permission to view this form', 'formidable' );
780 + wp_die(
781 + '<h1>' . esc_html( $error ) . '</h1>',
782 + '<p>' . esc_html( $error ) . '</p>',
783 + 403
784 + );
785 + }
786 +
787 + /**
788 + * Some themes have a null $src value.
789 + * This function adds a filter to ensure that $src is not null.
790 + * WP will call str_starts_with with the null value triggering a deprecated message otherwise.
791 + *
792 + * @since 6.10
793 + *
794 + * @return void
795 + */
796 + private static function fix_deprecated_null_param_warning() {
797 + add_filter(
798 + 'script_loader_src',
799 + /**
800 + * @param string|null $src
801 + *
802 + * @return string
803 + */
804 + function ( $src ) {
805 + return is_null( $src ) ? '' : $src;
806 + }
807 + );
808 + }
809 +
467 810 public static function untrash() {
468 811 self::change_form_status( 'untrash' );
469 812 }
470 813
@@ -469,8 +812,9 @@
469 812 }
470 813
471 814 /**
472 815 * @param array $ids
816 + *
473 817 * @return string
474 818 */
475 819 public static function bulk_untrash( $ids ) {
476 820 FrmAppHelper::permission_check( 'frm_edit_forms' );
@@ -482,11 +826,9 @@
482 826 return '';
483 827 }
484 828
485 829 /* translators: %1$s: Number of forms */
486 - $message = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
487 -
488 - return $message;
830 + return sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
489 831 }
490 832
491 833 /**
492 834 * @since 3.06
@@ -527,14 +869,15 @@
527 869 FrmAppHelper::permission_check( $available_status[ $status ]['permission'] );
528 870
529 871 $params = FrmForm::list_page_params();
530 872
531 - //check nonce url
873 + // Check nonce url.
532 874 check_admin_referer( $status . '_form_' . $params['id'] );
533 875
534 876 $count = 0;
877 +
535 878 if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) {
536 - $count ++;
879 + ++$count;
537 880 }
538 881
539 882 $form_type = FrmAppHelper::get_simple_request(
540 883 array(
@@ -546,9 +889,9 @@
546 889 /* translators: %1$s: Number of forms */
547 890 $available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
548 891
549 892 /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */
550 - $available_status['trash']['message'] = sprintf( _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=untrash&form_type=' . $form_type . '&id=' . $params['id'], 'untrash_form_' . $params['id'] ) ) . '">', '</a>' );
893 + $available_status['trash']['message'] = sprintf( _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ), $count, '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=untrash&form_type=' . $form_type . '&id=' . $params['id'], 'untrash_form_' . $params['id'] ) ) . '">', '</a>' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
551 894
552 895 $message = $available_status[ $status ]['message'];
553 896
554 897 self::display_forms_list( $params, $message );
@@ -553,18 +896,28 @@
553 896
554 897 self::display_forms_list( $params, $message );
555 898 }
556 899
900 + /**
901 + * @param array $ids
902 + *
903 + * @return string
904 + */
557 905 public static function bulk_trash( $ids ) {
558 906 FrmAppHelper::permission_check( 'frm_delete_forms' );
559 907
560 908 $count = 0;
909 +
561 910 foreach ( $ids as $id ) {
562 911 if ( FrmForm::trash( $id ) ) {
563 - $count ++;
912 + ++$count;
564 913 }
565 914 }
566 915
916 + if ( ! $count ) {
917 + return '';
918 + }
919 +
567 920 $current_page = FrmAppHelper::get_simple_request(
568 921 array(
569 922 'param' => 'form_type',
570 923 'type' => 'request',
@@ -569,17 +922,16 @@
569 922 'param' => 'form_type',
570 923 'type' => 'request',
571 924 )
572 925 );
573 - $message = sprintf(
926 +
927 + return sprintf(
574 928 /* translators: %1$s: Number of forms, %2$s: Start link HTML, %3$s: End link HTML */
575 929 _n( '%1$s form moved to the Trash. %2$sUndo%3$s', '%1$s forms moved to the Trash. %2$sUndo%3$s', $count, 'formidable' ),
576 930 $count,
577 - '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=list&action=bulk_untrash&form_type=' . $current_page . '&item-action=' . implode( ',', $ids ), 'bulk-toplevel_page_formidable' ) ) . '">',
931 + '<a href="' . esc_url( wp_nonce_url( '?page=formidable&frm_action=list&action=bulk_untrash&form_type=' . $current_page . '&item-action=' . implode( ',', $ids ), 'bulk-toplevel_page_formidable' ) ) . '">', // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
578 932 '</a>'
579 933 );
580 -
581 - return $message;
582 934 }
583 935
584 936 public static function destroy() {
585 937 FrmAppHelper::permission_check( 'frm_delete_forms' );
@@ -589,10 +941,11 @@
589 941 // Check nonce url.
590 942 check_admin_referer( 'destroy_form_' . $params['id'] );
591 943
592 944 $count = 0;
945 +
593 946 if ( FrmForm::destroy( $params['id'] ) ) {
594 - $count ++;
947 + ++$count;
595 948 }
596 949
597 950 /* translators: %1$s: Number of forms */
598 951 $message = sprintf( _n( '%1$s Form Permanently Deleted', '%1$s Forms Permanently Deleted', $count, 'formidable' ), $count );
@@ -599,40 +952,52 @@
599 952
600 953 self::display_forms_list( $params, $message );
601 954 }
602 955
956 + /**
957 + * @param array $ids
958 + *
959 + * @return string
960 + */
603 961 public static function bulk_destroy( $ids ) {
604 962 FrmAppHelper::permission_check( 'frm_delete_forms' );
605 963
606 964 $count = 0;
965 +
607 966 foreach ( $ids as $id ) {
608 967 $d = FrmForm::destroy( $id );
968 +
609 969 if ( $d ) {
610 - $count ++;
970 + ++$count;
611 971 }
612 972 }
613 973
614 - /* translators: %1$s: Number of forms */
615 - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
974 + if ( $count ) {
975 + /* translators: %1$s: Number of forms */
976 + return sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
977 + }
616 978
617 - return $message;
979 + return '';
618 980 }
619 981
620 - private static function delete_all() {
982 + /**
983 + * @since 6.7.1 Function went from private to public.
984 + */
985 + public static function delete_all() {
621 986 // Check nonce url.
622 987 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' );
988 +
623 989 if ( $permission_error !== false ) {
624 990 self::display_forms_list( array(), '', array( $permission_error ) );
625 -
626 991 return;
627 992 }
628 993
629 - $count = FrmForm::scheduled_delete( time() );
994 + $count = FrmForm::scheduled_delete( time() );
995 + $url = remove_query_arg( array( 'delete_all' ) );
996 + $url .= '&message=forms_permanently_deleted&forms_deleted=' . $count;
630 997
631 - /* translators: %1$s: Number of forms */
632 - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
633 -
634 - self::display_forms_list( array(), $message );
998 + wp_safe_redirect( $url );
999 + die();
635 1000 }
636 1001
637 1002 /**
638 1003 * Create a new form from the modal.
@@ -645,9 +1010,9 @@
645 1010
646 1011 $new_values = self::get_modal_values();
647 1012 $new_values['form_key'] = $new_values['name'];
648 1013 $new_values['options'] = array(
649 - 'antispam' => 1,
1014 + 'antispam' => 1,
650 1015 'on_submit_migrated' => 1,
651 1016 );
652 1017
653 1018 /**
@@ -666,13 +1031,14 @@
666 1031 * @param int $form_id
667 1032 */
668 1033 do_action( 'frm_build_new_form', $form_id );
669 1034
1035 + self::create_submit_button_field( $form_id );
670 1036 self::create_default_on_submit_action( $form_id );
671 1037 self::create_default_email_action( $form_id );
672 1038
673 1039 $response = array(
674 - 'redirect' => FrmForm::get_edit_link( $form_id ),
1040 + 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true',
675 1041 );
676 1042
677 1043 echo wp_json_encode( $response );
678 1044 wp_die();
@@ -678,46 +1044,15 @@
678 1044 wp_die();
679 1045 }
680 1046
681 1047 /**
682 - * Create a custom template from a form
683 - *
684 - * @since 3.06
685 - */
686 - public static function build_template() {
687 - global $wpdb;
688 -
689 - FrmAppHelper::permission_check( 'frm_edit_forms' );
690 - check_ajax_referer( 'frm_ajax', 'nonce' );
691 -
692 - $form_id = FrmAppHelper::get_param( 'xml', '', 'post', 'absint' );
693 - $new_form_id = FrmForm::duplicate( $form_id, 1, true );
694 - if ( ! $new_form_id ) {
695 - $response = array(
696 - 'message' => __( 'There was an error creating a template.', 'formidable' ),
697 - );
698 - } else {
699 - $new_values = self::get_modal_values();
700 - $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $new_form_id ) );
701 - if ( $query_results ) {
702 - FrmForm::clear_form_cache();
703 - }
704 -
705 - $response = array(
706 - 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . $new_form_id ) . '&_wpnonce=' . wp_create_nonce(),
707 - );
708 - }
709 -
710 - echo wp_json_encode( $response );
711 - wp_die();
712 - }
713 -
714 - /**
715 1048 * Before creating a new form, get the name and description from the modal.
716 1049 *
717 1050 * @since 4.0
1051 + *
1052 + * @return array<string,string>
718 1053 */
719 - private static function get_modal_values() {
1054 + public static function get_modal_values() {
720 1055 $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' );
721 1056 $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' );
722 1057
723 1058 return array(
@@ -730,18 +1065,26 @@
730 1065 * Inserts Formidable button
731 1066 * Hook exists since 2.5.0
732 1067 *
733 1068 * @since 2.0.15
1069 + *
1070 + * @return void
734 1071 */
735 1072 public static function insert_form_button() {
736 - if ( current_user_can( 'frm_view_forms' ) ) {
1073 + if ( ! current_user_can( 'frm_view_forms' ) ) {
1074 + return;
1075 + }
1076 +
1077 + // Store the result in memory and re-use it when this function is called multiple times.
1078 + // This helps speed up the form builder when there are a lot of HTML fields, where this
1079 + // Button is inserted once per HTML field.
1080 + // In a form with 66 HTML fields, this saves 0.5 seconds on page load time, tested locally.
1081 + if ( ! isset( self::$formidable_tinymce_button ) ) {
737 1082 FrmAppHelper::load_admin_wide_js();
738 - $menu_name = FrmAppHelper::get_menu_name();
739 - $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
740 - echo '<a href="#TB_inline?width=50&height=50&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . esc_attr__( 'Add forms and content', 'formidable' ) . '">' .
741 - FrmAppHelper::kses( $icon, 'all' ) . // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
742 - ' ' . esc_html( $menu_name ) . '</a>';
1083 + $icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
1084 + self::$formidable_tinymce_button = '<a href="#TB_inline?width=50&height=50&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . esc_attr__( 'Add forms and content', 'formidable' ) . '">' . FrmAppHelper::kses( $icon, 'all' ) . ' ' . esc_html( FrmAppHelper::get_menu_name() ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
743 1085 }
1086 + echo self::$formidable_tinymce_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
744 1087 }
745 1088
746 1089 /**
747 1090 * @return void
@@ -762,17 +1105,21 @@
762 1105 $shortcodes = apply_filters( 'frm_popup_shortcodes', $shortcodes );
763 1106
764 1107 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/insert_form_popup.php';
765 1108
766 - if ( FrmAppHelper::is_form_builder_page() && ! class_exists( '_WP_Editors', false ) ) {
767 - // initialize a wysiwyg so we have usable settings defined in tinyMCEPreInit.mceInit
768 - require ABSPATH . WPINC . '/class-wp-editor.php';
769 - ?>
770 - <div class="frm_hidden">
771 - <?php wp_editor( '', 'frm_description_placeholder', array() ); ?>
772 - </div>
773 - <?php
1109 + if ( ! FrmAppHelper::is_form_builder_page() || class_exists( '_WP_Editors', false ) ) {
1110 + return;
774 1111 }
1112 +
1113 + // Initialize a wysiwyg so we have usable settings defined in tinyMCEPreInit.mceInit
1114 + require ABSPATH . WPINC . '/class-wp-editor.php';
1115 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
1116 + ?>
1117 + <div class="frm_hidden">
1118 + <?php wp_editor( '', 'frm_description_placeholder', array() ); ?>
1119 + </div>
1120 + <?php
1121 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
775 1122 }
776 1123
777 1124 /**
778 1125 * Check the page being loaded, determine if this is a page that should include the form popup.
@@ -784,8 +1131,9 @@
784 1131 private static function should_insert_form_popup() {
785 1132 if ( FrmAppHelper::is_form_builder_page() ) {
786 1133 return true;
787 1134 }
1135 +
788 1136 $page = basename( FrmAppHelper::get_server_value( 'PHP_SELF' ) );
789 1137 return in_array( $page, array( 'post.php', 'page.php', 'page-new.php', 'post-new.php' ), true );
790 1138 }
791 1139
@@ -793,9 +1141,10 @@
793 1141 FrmAppHelper::permission_check( 'frm_view_forms' );
794 1142 check_ajax_referer( 'frm_ajax', 'nonce' );
795 1143
796 1144 $shortcode = FrmAppHelper::get_post_param( 'shortcode', '', 'sanitize_text_field' );
797 - if ( empty( $shortcode ) ) {
1145 +
1146 + if ( ! $shortcode ) {
798 1147 wp_die();
799 1148 }
800 1149
801 1150 echo '<div id="sc-opts-' . esc_attr( $shortcode ) . '" class="frm_shortcode_option">';
@@ -820,17 +1169,18 @@
820 1169 'label' => __( 'Minimize form HTML', 'formidable' ),
821 1170 ),
822 1171 );
823 1172 }
1173 +
824 1174 $opts = apply_filters( 'frm_sc_popup_opts', $opts, $shortcode );
825 1175
826 1176 if ( isset( $opts['form_id'] ) && is_string( $opts['form_id'] ) ) {
827 - // allow other shortcodes to use the required form id option
1177 + // Allow other shortcodes to use the required form id option
828 1178 $form_id = $opts['form_id'];
829 1179 unset( $opts['form_id'] );
830 1180 }
831 1181
832 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' );
1182 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php';
833 1183
834 1184 echo '</div>';
835 1185
836 1186 wp_die();
@@ -841,8 +1191,9 @@
841 1191 *
842 1192 * @param array $params
843 1193 * @param string $message
844 1194 * @param array $errors
1195 + *
845 1196 * @return void
846 1197 */
847 1198 public static function display_forms_list( $params = array(), $message = '', $errors = array() ) {
848 1199 FrmAppHelper::permission_check( 'frm_view_forms' );
@@ -859,35 +1210,56 @@
859 1210 * @param string $table_class Class name for List Helper.
860 1211 */
861 1212 $table_class = apply_filters( 'frm_forms_list_class', 'FrmFormsListHelper' );
862 1213 $wp_list_table = new $table_class( compact( 'params' ) );
1214 + $pagenum = $wp_list_table->get_pagenum();
863 1215
864 - $pagenum = $wp_list_table->get_pagenum();
865 -
866 1216 $wp_list_table->prepare_items();
867 1217
868 1218 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
1219 +
869 1220 if ( $pagenum > $total_pages && $total_pages > 0 ) {
870 - wp_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
1221 + wp_safe_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
871 1222 die();
872 1223 }
873 1224
1225 + $error = FrmInbox::check_for_error();
1226 +
1227 + if ( $error ) {
1228 + $show_messages = array( $error['subject'] . '. ' . $error['message'] );
1229 + }
1230 +
874 1231 require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/list.php';
875 1232 }
876 1233
877 1234 /**
878 1235 * @param array<string,string> $columns
1236 + *
879 1237 * @return array<string,string>
880 1238 */
881 1239 public static function get_columns( $columns ) {
882 - $columns['cb'] = '<input type="checkbox" />';
883 - $columns['name'] = __( 'Form Title', 'formidable' );
884 - $columns['entries'] = __( 'Entries', 'formidable' );
885 - $columns['id'] = 'ID';
886 - $columns['form_key'] = __( 'Key', 'formidable' );
887 - $columns['shortcode'] = __( 'Actions', 'formidable' );
888 - $columns['created_at'] = __( 'Date', 'formidable' );
1240 + $columns['cb'] = '<input type="checkbox" />';
1241 + $columns['name'] = esc_html__( 'Form Title', 'formidable' );
1242 + $columns['entries'] = esc_html__( 'Entries', 'formidable' );
1243 + $columns['views'] = esc_html__( 'Views', 'formidable' );
1244 + $columns['id'] = 'ID';
1245 + $columns['form_key'] = esc_html__( 'Key', 'formidable' );
889 1246
1247 + if ( 'trash' !== FrmAppHelper::simple_get( 'form_type' ) && has_filter( 'frm_form_list_actions' ) ) {
1248 + // If there is any filters added, keep this column.
1249 + $columns['shortcode'] = esc_html__( 'Actions', 'formidable' );
1250 + }
1251 +
1252 + $columns['created_at'] = esc_html__( 'Date', 'formidable' );
1253 +
1254 + if ( 'trash' !== FrmAppHelper::simple_get( 'form_type' ) ) {
1255 + $columns['embeds'] = esc_html__( 'Embeds', 'formidable' );
1256 + $columns['settings'] = '<div class="frm-forms-list-settings-btn-wrapper"><a href="#" class="frm-forms-list-settings-btn">';
1257 + $columns['settings'] .= FrmAppHelper::icon_by_class( 'frmfont frm_settings_icon', array( 'echo' => false ) );
1258 + $columns['settings'] .= '<span class="screen-reader-text">' . esc_html__( 'List settings', 'formidable' ) . '</span>';
1259 + $columns['settings'] .= '</a></div>';
1260 + }
1261 +
890 1262 add_screen_option(
891 1263 'per_page',
892 1264 array(
893 1265 'label' => __( 'Forms', 'formidable' ),
@@ -898,8 +1270,11 @@
898 1270
899 1271 return $columns;
900 1272 }
901 1273
1274 + /**
1275 + * @return array<string,string>
1276 + */
902 1277 public static function get_sortable_columns() {
903 1278 return array(
904 1279 'id' => 'id',
905 1280 'name' => 'name',
@@ -910,8 +1285,9 @@
910 1285 }
911 1286
912 1287 /**
913 1288 * @param mixed $hidden_columns
1289 + *
914 1290 * @return array
915 1291 */
916 1292 public static function hidden_columns( $hidden_columns ) {
917 1293 if ( ! is_array( $hidden_columns ) ) {
@@ -932,11 +1308,18 @@
932 1308
933 1309 return $hidden_columns;
934 1310 }
935 1311
1312 + /**
1313 + * @param mixed $save
1314 + * @param string $option
1315 + * @param int|string $value
1316 + *
1317 + * @return mixed
1318 + */
936 1319 public static function save_per_page( $save, $option, $value ) {
937 - if ( $option == 'formidable_page_formidable_per_page' ) {
938 - $save = (int) $value;
1320 + if ( $option === 'formidable_page_formidable_per_page' ) {
1321 + return (int) $value;
939 1322 }
940 1323
941 1324 return $save;
942 1325 }
@@ -941,158 +1324,63 @@
941 1324 return $save;
942 1325 }
943 1326
944 1327 /**
945 - * @return bool
946 - */
947 - public static function expired() {
948 - global $frm_expired;
949 - return $frm_expired;
950 - }
951 -
952 - /**
953 - * Get data from api before rendering it so that we can flag the modal as expired
1328 + * @param int|string $id
1329 + * @param array $errors
1330 + * @param string $message
1331 + * @param bool $create_link
954 1332 *
955 1333 * @return void
956 1334 */
957 - public static function before_list_templates() {
958 - global $frm_templates;
959 - global $frm_expired;
960 - global $frm_license_type;
1335 + private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
1336 + global $frm_vars;
961 1337
962 - $api = new FrmFormTemplateApi();
963 - $frm_templates = $api->get_api_info();
964 - $expired = false;
965 - $license_type = '';
966 - if ( isset( $frm_templates['error'] ) ) {
967 - $error = $frm_templates['error']['message'];
968 - $error = str_replace( 'utm_medium=addons', 'utm_medium=form-templates', $error );
969 - $expired = 'expired' === $frm_templates['error']['code'];
970 - $license_type = isset( $frm_templates['error']['type'] ) ? $frm_templates['error']['type'] : '';
971 - unset( $frm_templates['error'] );
972 - }
973 -
974 - $frm_expired = $expired;
975 - $frm_license_type = $license_type;
976 - }
977 -
978 - /**
979 - * @return void
980 - */
981 - public static function list_templates() {
982 - global $frm_templates;
983 - global $frm_license_type;
984 -
985 - $templates = $frm_templates;
986 - $custom_templates = array();
987 - $templates_by_category = array();
988 -
989 - self::add_user_templates( $custom_templates );
990 -
991 - foreach ( $templates as $template ) {
992 - if ( ! isset( $template['categories'] ) ) {
993 - continue;
994 - }
995 -
996 - foreach ( $template['categories'] as $category ) {
997 - if ( ! isset( $templates_by_category[ $category ] ) ) {
998 - $templates_by_category[ $category ] = array();
999 - }
1000 -
1001 - $templates_by_category[ $category ][] = $template;
1002 - }
1003 - }
1004 - unset( $template );
1005 -
1006 - // Subcategories that are included elsewhere.
1007 - $redundant_cats = array( 'PayPal', 'Stripe', 'Twilio' );
1008 -
1009 - $categories = array_keys( $templates_by_category );
1010 - $categories = array_diff( $categories, FrmFormsHelper::ignore_template_categories() );
1011 - $categories = array_diff( $categories, $redundant_cats );
1012 - sort( $categories );
1013 -
1014 - array_walk(
1015 - $custom_templates,
1016 - function( &$template ) {
1017 - $template['custom'] = true;
1018 - }
1338 + $form = FrmForm::getOne( $id );
1339 + $error_args = array(
1340 + 'title' => __( 'You can\'t edit the form', 'formidable' ),
1341 + 'body' => __( 'You are trying to edit a form that does not exist', 'formidable' ),
1342 + 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
1343 + 'continue_url' => add_query_arg(
1344 + array(
1345 + 'page' => 'formidable',
1346 + )
1347 + ),
1019 1348 );
1020 1349
1021 - $my_templates_translation = __( 'My Templates', 'formidable' );
1022 - $categories = array_merge( array( $my_templates_translation ), $categories );
1023 - $pricing = FrmAppHelper::admin_upgrade_link( 'form-templates' );
1024 - $license_type = $frm_license_type;
1025 - $args = compact( 'pricing', 'license_type' );
1026 - $where = apply_filters( 'frm_forms_dropdown', array(), '' );
1027 - $forms = FrmForm::get_published_forms( $where );
1028 - $view_path = FrmAppHelper::plugin_path() . '/classes/views/frm-forms/';
1029 -
1030 - $templates_by_category[ $my_templates_translation ] = $custom_templates;
1031 -
1032 - unset( $pricing, $license_type, $where );
1033 - wp_enqueue_script( 'accordion' ); // register accordion for template groups
1034 - require $view_path . 'list-templates.php';
1035 - }
1036 -
1037 - /**
1038 - * @since 4.03.01
1039 - */
1040 - private static function get_template_categories( $templates ) {
1041 - $categories = array();
1042 - foreach ( $templates as $template ) {
1043 - if ( isset( $template['categories'] ) ) {
1044 - $categories = array_merge( $categories, $template['categories'] );
1045 - }
1350 + if ( ! $form ) {
1351 + FrmAppController::show_error_modal( $error_args );
1352 + return;
1046 1353 }
1047 - $exclude_cats = FrmFormsHelper::ignore_template_categories();
1048 - $categories = array_unique( $categories );
1049 - $categories = array_diff( $categories, $exclude_cats );
1050 - sort( $categories );
1051 - return $categories;
1052 - }
1053 1354
1054 - private static function add_user_templates( &$templates ) {
1055 - $user_templates = array(
1056 - 'is_template' => 1,
1057 - 'default_template' => 0,
1058 - );
1059 - $user_templates = FrmForm::getAll( $user_templates, 'name' );
1060 - foreach ( $user_templates as $template ) {
1061 - $template = array(
1062 - 'id' => $template->id,
1063 - 'name' => $template->name,
1064 - 'key' => $template->form_key,
1065 - 'description' => $template->description,
1066 - 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template->id ) ) ),
1067 - 'released' => $template->created_at,
1068 - 'installed' => 1,
1355 + if ( 'trash' === $form->status ) {
1356 + $error_args['body'] = __( 'The form you\'re trying to edit is in trash. You must restore it first before you can make changes', 'formidable' );
1357 + $error_args['continue_url'] = add_query_arg(
1358 + array(
1359 + 'page' => 'formidable',
1360 + '_wpnonce' => wp_create_nonce( 'untrash_form_' . $id ),
1361 + 'form_type' => 'trash',
1362 + 'frm_action' => 'untrash',
1363 + 'id' => $id,
1364 + )
1069 1365 );
1070 - array_unshift( $templates, $template );
1071 - unset( $template );
1366 + $error_args['continue_text'] = __( 'Restore form', 'formidable' );
1367 + FrmAppController::show_error_modal( $error_args );
1368 + return;
1072 1369 }
1073 - }
1074 1370
1075 - private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
1076 - global $frm_vars;
1077 -
1078 - $form = FrmForm::getOne( $id );
1079 - if ( ! $form ) {
1080 - wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) );
1081 - }
1082 -
1083 1371 if ( $form->parent_form_id ) {
1084 1372 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1085 - wp_die( sprintf( esc_html__( 'You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable' ), '<a href="' . esc_url( FrmForm::get_edit_link( $form->parent_form_id ) ) . '">', '</a>' ) );
1373 + wp_die( sprintf( esc_html__( 'You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable' ), '<a href="' . esc_url( FrmForm::get_edit_link( $form->parent_form_id ) ) . '">', '</a>' ) ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
1086 1374 }
1087 1375
1088 1376 $frm_field_selection = FrmField::field_selection();
1377 + $fields = FrmField::get_all_for_form( $form->id );
1089 1378
1090 - $fields = FrmField::get_all_for_form( $form->id );
1091 -
1092 1379 // Automatically add end section fields if they don't exist (2.0 migration).
1093 1380 $reset_fields = false;
1094 1381 FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
1382 + FrmSubmitHelper::maybe_create_submit_field( $form, $fields, $reset_fields );
1095 1383
1096 1384 if ( $reset_fields ) {
1097 1385 $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' );
1098 1386 }
@@ -1112,25 +1400,30 @@
1112 1400 */
1113 1401 $values['fields'] = apply_filters( 'frm_fields_in_form_builder', $fields, compact( 'form' ) );
1114 1402
1115 1403 $edit_message = __( 'Form was successfully updated.', 'formidable' );
1116 - if ( $form->is_template && $message == $edit_message ) {
1404 +
1405 + if ( $form->is_template && $message === $edit_message ) {
1117 1406 $message = __( 'Template was successfully updated.', 'formidable' );
1118 1407 }
1119 1408
1120 1409 self::maybe_update_form_builder_message( $message );
1121 1410
1122 - $all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
1123 - $has_fields = isset( $values['fields'] ) && ! empty( $values['fields'] );
1411 + $has_fields = ! empty( $values['fields'] ) && ! FrmSubmitHelper::only_contains_submit_field( $values['fields'] );
1124 1412
1125 1413 if ( defined( 'DOING_AJAX' ) ) {
1126 1414 wp_die();
1127 - } else {
1128 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' );
1129 1415 }
1416 +
1417 + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php';
1130 1418 }
1131 1419
1132 - public static function update_form_builder_fields( $fields, $form ) {
1420 + /**
1421 + * @param array $fields
1422 + *
1423 + * @return array
1424 + */
1425 + public static function update_form_builder_fields( $fields ) {
1133 1426 foreach ( $fields as $field ) {
1134 1427 $field->do_not_include_icons = true;
1135 1428 }
1136 1429 return $fields;
@@ -1135,8 +1428,13 @@
1135 1428 }
1136 1429 return $fields;
1137 1430 }
1138 1431
1432 + /**
1433 + * @param string $message
1434 + *
1435 + * @return void
1436 + */
1139 1437 public static function maybe_update_form_builder_message( &$message ) {
1140 1438 if ( 'form_duplicated' === FrmAppHelper::simple_get( 'message' ) ) {
1141 1439 $message = __( 'Form was Successfully Copied', 'formidable' );
1142 1440 }
@@ -1141,13 +1439,22 @@
1141 1439 $message = __( 'Form was Successfully Copied', 'formidable' );
1142 1440 }
1143 1441 }
1144 1442
1443 + /**
1444 + * @param int|string $id
1445 + * @param array $errors
1446 + * @param array|string $args
1447 + *
1448 + * @return void
1449 + */
1145 1450 public static function get_settings_vars( $id, $errors = array(), $args = array() ) {
1146 1451 FrmAppHelper::permission_check( 'frm_edit_forms' );
1147 1452
1148 1453 global $frm_vars;
1149 1454
1455 + self::maybe_print_media_templates();
1456 +
1150 1457 if ( ! is_array( $args ) ) {
1151 1458 // For reverse compatibility.
1152 1459 $args = array(
1153 1460 'message' => $args,
@@ -1160,13 +1467,12 @@
1160 1467 );
1161 1468 $args = array_merge( $defaults, $args );
1162 1469 $message = $args['message'];
1163 1470 $warnings = $args['warnings'];
1471 + $form = FrmForm::getOne( $id );
1472 + $fields = FrmField::get_all_for_form( $id );
1473 + $values = FrmAppHelper::setup_edit_vars( $form, 'forms', $fields, true );
1164 1474
1165 - $form = FrmForm::getOne( $id );
1166 - $fields = FrmField::get_all_for_form( $id );
1167 - $values = FrmAppHelper::setup_edit_vars( $form, 'forms', $fields, true );
1168 -
1169 1475 /**
1170 1476 * Allows changing fields in the form settings.
1171 1477 *
1172 1478 * @since 5.0.04
@@ -1180,17 +1486,42 @@
1180 1486
1181 1487 $sections = self::get_settings_tabs( $values );
1182 1488 $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'advanced_settings' );
1183 1489
1184 - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' );
1490 + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php';
1185 1491 }
1186 1492
1187 1493 /**
1494 + * Print WordPress media templates email actions does not trigger a "Uncaught Error: Template not found: #tmpl-media-selection" error when the media button is clicked.
1495 + *
1496 + * @since 6.10
1497 + *
1498 + * @return void
1499 + */
1500 + private static function maybe_print_media_templates() {
1501 + if ( FrmAppHelper::pro_is_included() ) {
1502 + // This issue does not exist when Pro is active so exit early.
1503 + return;
1504 + }
1505 +
1506 + add_action(
1507 + 'wp_enqueue_editor',
1508 + function () {
1509 + wp_print_media_templates();
1510 + }
1511 + );
1512 + }
1513 +
1514 + /**
1188 1515 * @since 4.0
1516 + *
1517 + * @param array $atts
1518 + *
1519 + * @return void
1189 1520 */
1190 1521 public static function form_publish_button( $atts ) {
1191 1522 $values = $atts['values'];
1192 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php' );
1523 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/_publish_box.php';
1193 1524 }
1194 1525
1195 1526 /**
1196 1527 * Get a list of all the settings tabs for the form settings page.
@@ -1197,8 +1528,9 @@
1197 1528 *
1198 1529 * @since 4.0
1199 1530 *
1200 1531 * @param array $values
1532 + *
1201 1533 * @return array
1202 1534 */
1203 1535 private static function get_settings_tabs( $values ) {
1204 1536 $sections = array(
@@ -1204,20 +1536,20 @@
1204 1536 $sections = array(
1205 1537 'advanced' => array(
1206 1538 'name' => __( 'General', 'formidable' ),
1207 1539 'title' => __( 'General Form Settings', 'formidable' ),
1208 - 'function' => array( __CLASS__, 'advanced_settings' ),
1209 - 'icon' => 'frm_icon_font frm_settings_icon',
1540 + 'function' => array( self::class, 'advanced_settings' ),
1541 + 'icon' => 'frmfont frm_small_settings_icon',
1210 1542 ),
1211 1543 'email' => array(
1212 1544 'name' => __( 'Actions & Notifications', 'formidable' ),
1213 1545 'function' => array( 'FrmFormActionsController', 'email_settings' ),
1214 1546 'id' => 'frm_notification_settings',
1215 - 'icon' => 'frm_icon_font frm_mail_bulk_icon',
1547 + 'icon' => 'frmfont frm_notification_check_icon',
1216 1548 ),
1217 1549 'permissions' => array(
1218 1550 'name' => __( 'Form Permissions', 'formidable' ),
1219 - 'icon' => 'frm_icon_font frm_lock_icon',
1551 + 'icon' => 'frmfont frm_lock_closed2_icon',
1220 1552 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1221 1553 'data' => array(
1222 1554 'medium' => 'permissions',
1223 1555 'upgrade' => __( 'Form Permissions', 'formidable' ),
@@ -1222,35 +1554,37 @@
1222 1554 'medium' => 'permissions',
1223 1555 'upgrade' => __( 'Form Permissions', 'formidable' ),
1224 1556 'message' => __( 'Allow editing, protect forms and files, limit entries, and save drafts. Upgrade to get form and entry permissions.', 'formidable' ),
1225 1557 'screenshot' => 'permissions.png',
1558 + 'learn-more' => FrmAppHelper::get_doc_url( 'general-form-settings/#kb-form-permissions', 'form-permissions-settings' ),
1226 1559 ),
1227 1560 ),
1228 - 'scheduling' => array(
1561 + 'scheduling' => array(
1229 1562 'name' => __( 'Form Scheduling', 'formidable' ),
1230 - 'icon' => 'frm_icon_font frm_calendar_icon',
1563 + 'icon' => 'frmfont frm_schedule_icon',
1231 1564 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1232 1565 'data' => array(
1233 1566 'medium' => 'scheduling',
1234 1567 'upgrade' => __( 'Form scheduling settings', 'formidable' ),
1235 1568 'screenshot' => 'scheduling.png',
1569 + 'learn-more' => FrmAppHelper::get_doc_url( 'general-form-settings/#kb-form-scheduling', 'form-scheduling-settings' ),
1236 1570 ),
1237 1571 ),
1238 1572 'buttons' => array(
1239 1573 'name' => __( 'Buttons', 'formidable' ),
1240 - 'class' => __CLASS__,
1574 + 'class' => self::class,
1241 1575 'function' => 'buttons_settings',
1242 - 'icon' => 'frm_icon_font frm_button_icon',
1576 + 'icon' => 'frmfont frm-buttons-style',
1243 1577 ),
1244 1578 'landing' => array(
1245 1579 'name' => __( 'Form Landing Page', 'formidable' ),
1246 - 'icon' => 'frm_icon_font frm_file_text_icon',
1580 + 'icon' => 'frmfont frm_cross_device_icon',
1247 1581 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1248 1582 'data' => FrmAppHelper::get_landing_page_upgrade_data_params(),
1249 1583 ),
1250 1584 'chat' => array(
1251 1585 'name' => __( 'Conversational Forms', 'formidable' ),
1252 - 'icon' => 'frm_icon_font frm_chat_forms_icon',
1586 + 'icon' => 'frmfont frm_chat_bubbles_icon',
1253 1587 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1254 1588 'data' => FrmAppHelper::get_upgrade_data_params(
1255 1589 'chat',
1256 1590 array(
@@ -1256,37 +1590,45 @@
1256 1590 array(
1257 1591 'upgrade' => __( 'Conversational Forms', 'formidable' ),
1258 1592 'message' => __( 'Ask one question at a time for automated conversations.', 'formidable' ),
1259 1593 'screenshot' => 'chat.png',
1594 + 'learn-more' => FrmAppHelper::get_doc_url( 'conversational-forms', 'conversational-forms-settings', false ),
1260 1595 )
1261 1596 ),
1262 1597 ),
1598 + 'abandonment' => array(
1599 + 'name' => __( 'Form Abandonment', 'formidable' ),
1600 + 'icon' => 'frmfont frm_abandoned_icon',
1601 + 'html_class' => 'frm_show_upgrade_tab frm_noallow',
1602 + 'data' => FrmAppHelper::get_upgrade_data_params(
1603 + 'abandonment',
1604 + array(
1605 + 'upgrade' => __( 'Form abandonment settings', 'formidable' ),
1606 + 'message' => __( 'Unlock the power of data capture to boost lead generation and master the art of form optimization.', 'formidable' ),
1607 + 'screenshot' => 'abandonment.png',
1608 + 'learn-more' => FrmAppHelper::get_doc_url( 'features/form-abandonment-wordpress-plugin', 'form-abandonment-settings', false ),
1609 + )
1610 + ),
1611 + ),
1263 1612 'html' => array(
1264 1613 'name' => __( 'Customize HTML', 'formidable' ),
1265 - 'class' => __CLASS__,
1614 + 'class' => self::class,
1266 1615 'function' => 'html_settings',
1267 - 'icon' => 'frm_icon_font frm_code_icon',
1616 + 'icon' => 'frmfont frm_code2_icon',
1268 1617 ),
1269 1618 );
1270 1619
1271 - foreach ( array( 'landing', 'chat' ) as $feature ) {
1272 - if ( ! FrmAppHelper::show_new_feature( $feature ) ) {
1273 - unset( $sections[ $feature ] );
1274 - }
1620 + if ( ! has_action( 'frm_add_form_style_tab_options' ) && ! has_action( 'frm_add_form_button_options' ) ) {
1621 + unset( $sections['buttons'] );
1275 1622 }
1276 1623
1277 1624 $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values );
1278 1625
1279 - if ( FrmAppHelper::pro_is_installed() && ! FrmAppHelper::meets_min_pro_version( '4.0' ) ) {
1280 - // Prevent settings from showing in 2 spots.
1281 - unset( $sections['permissions'], $sections['scheduling'] );
1282 - }
1283 -
1284 1626 foreach ( $sections as $key => $section ) {
1285 1627 $defaults = array(
1286 1628 'html_class' => '',
1287 1629 'name' => ucfirst( $key ),
1288 - 'icon' => 'frm_icon_font frm_settings_icon',
1630 + 'icon' => 'frmfont frm_settings_icon',
1289 1631 );
1290 1632
1291 1633 $section = array_merge( $defaults, $section );
1292 1634
@@ -1292,8 +1634,9 @@
1292 1634
1293 1635 if ( ! isset( $section['anchor'] ) ) {
1294 1636 $section['anchor'] = $key;
1295 1637 }
1638 +
1296 1639 $section['anchor'] .= '_settings';
1297 1640
1298 1641 if ( ! isset( $section['title'] ) ) {
1299 1642 $section['title'] = $section['name'];
@@ -1303,9 +1646,9 @@
1303 1646 $section['id'] = $section['anchor'];
1304 1647 }
1305 1648
1306 1649 $sections[ $key ] = $section;
1307 - }
1650 + }//end foreach
1308 1651
1309 1652 return $sections;
1310 1653 }
1311 1654
@@ -1312,23 +1655,26 @@
1312 1655 /**
1313 1656 * @since 4.0
1314 1657 *
1315 1658 * @param array $values
1659 + *
1660 + * @return void
1316 1661 */
1317 1662 public static function advanced_settings( $values ) {
1318 1663 $first_h3 = 'frm_first_h3';
1319 -
1320 1664 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-advanced.php';
1321 1665 }
1322 1666
1323 1667 /**
1324 1668 * @param array $values
1669 + *
1670 + * @return void
1325 1671 */
1326 1672 public static function render_spam_settings( $values ) {
1327 1673 if ( function_exists( 'akismet_http_post' ) ) {
1328 1674 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/akismet.php';
1329 1675 }
1330 - include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/honeypot.php';
1676 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/stopforumspam.php';
1331 1677 include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/spam-settings/antispam.php';
1332 1678 }
1333 1679
1334 1680 /**
@@ -1334,16 +1680,13 @@
1334 1680 /**
1335 1681 * @since 4.0
1336 1682 *
1337 1683 * @param array $values
1684 + *
1685 + * @return void
1338 1686 */
1339 1687 public static function buttons_settings( $values ) {
1340 - $styles = apply_filters( 'frm_get_style_opts', array() );
1341 -
1342 - $frm_settings = FrmAppHelper::get_settings();
1343 - $no_global_style = $frm_settings->load_style === 'none';
1344 -
1345 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php' );
1688 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-buttons.php';
1346 1689 }
1347 1690
1348 1691 /**
1349 1692 * @since 4.0
@@ -1348,11 +1691,13 @@
1348 1691 /**
1349 1692 * @since 4.0
1350 1693 *
1351 1694 * @param array $values
1695 + *
1696 + * @return void
1352 1697 */
1353 1698 public static function html_settings( $values ) {
1354 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php' );
1699 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings-html.php';
1355 1700 }
1356 1701
1357 1702 /**
1358 1703 * Replace old Submit Button href with new href to avoid errors in Chrome
@@ -1358,9 +1703,11 @@
1358 1703 * Replace old Submit Button href with new href to avoid errors in Chrome
1359 1704 *
1360 1705 * @since 2.03.08
1361 1706 *
1362 - * @param array|boolean $values
1707 + * @param array|bool $values
1708 + *
1709 + * @return void
1363 1710 */
1364 1711 private static function clean_submit_html( &$values ) {
1365 1712 if ( is_array( $values ) && isset( $values['submit_html'] ) ) {
1366 1713 $values['submit_html'] = str_replace( 'javascript:void(0)', '#', $values['submit_html'] );
@@ -1381,9 +1728,18 @@
1381 1728
1382 1729 return $classes;
1383 1730 }
1384 1731
1385 - public static function mb_tags_box( $form_id, $class = '' ) {
1732 + /**
1733 + * @since 6.27 Added $template_path parameter.
1734 + *
1735 + * @param int|string $form_id
1736 + * @param string $class
1737 + * @param string $template_path The path to a template file to use instead of the default.
1738 + *
1739 + * @return void
1740 + */
1741 + public static function mb_tags_box( $form_id, $class = '', $template_path = 'default' ) {
1386 1742 $fields = FrmField::get_all_for_form( $form_id, '', 'include' );
1387 1743
1388 1744 /**
1389 1745 * Allows modifying the list of fields in the tags box.
@@ -1392,23 +1748,30 @@
1392 1748 *
1393 1749 * @param array $fields The list of fields.
1394 1750 * @param array $args The arguments. Contains `form_id`.
1395 1751 */
1396 - $fields = apply_filters( 'frm_fields_in_tags_box', $fields, compact( 'form_id' ) );
1397 - $linked_forms = array();
1398 - $col = 'one';
1399 - $settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false;
1400 -
1752 + $fields = apply_filters( 'frm_fields_in_tags_box', $fields, compact( 'form_id' ) );
1753 + $linked_forms = array();
1754 + $col = 'one';
1755 + $settings_tab = FrmAppHelper::is_admin_page( 'formidable' );
1401 1756 $cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
1402 1757 $entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
1758 + $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) );
1403 1759
1404 - $advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) );
1760 + if ( 'default' === $template_path || ! file_exists( $template_path ) ) {
1761 + include FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php';
1762 + return;
1763 + }
1405 1764
1406 - include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' );
1765 + include $template_path;
1407 1766 }
1408 1767
1409 1768 /**
1410 1769 * @since 3.04.01
1770 + *
1771 + * @param array $atts
1772 + *
1773 + * @return array
1411 1774 */
1412 1775 private static function advanced_helpers( $atts ) {
1413 1776 $advanced_helpers = array(
1414 1777 'default' => array(
@@ -1417,10 +1780,12 @@
1417 1780 ),
1418 1781 );
1419 1782
1420 1783 $user_fields = self::user_shortcodes();
1421 - if ( ! empty( $user_fields ) ) {
1784 +
1785 + if ( $user_fields ) {
1422 1786 $user_helpers = array();
1787 +
1423 1788 foreach ( $user_fields as $uk => $uf ) {
1424 1789 $user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf;
1425 1790 unset( $uk, $uf );
1426 1791 }
@@ -1425,9 +1790,9 @@
1425 1790 unset( $uk, $uf );
1426 1791 }
1427 1792
1428 1793 $advanced_helpers['user_id'] = array(
1429 - 'codes' => $user_helpers,
1794 + 'codes' => $user_helpers,
1430 1795 );
1431 1796 }
1432 1797
1433 1798 /**
@@ -1445,8 +1810,10 @@
1445 1810 * Get an array of the options to display in the advanced tab
1446 1811 * of the customization panel
1447 1812 *
1448 1813 * @since 2.0.6
1814 + *
1815 + * @return array
1449 1816 */
1450 1817 private static function get_advanced_shortcodes() {
1451 1818 $adv_shortcodes = array(
1452 1819 'x sep=", "' => array(
@@ -1463,17 +1830,18 @@
1463 1830 'label' => __( 'No Auto P', 'formidable' ),
1464 1831 'title' => __( 'Do not automatically add any paragraphs or line breaks', 'formidable' ),
1465 1832 ),
1466 1833 );
1467 - $adv_shortcodes = apply_filters( 'frm_advanced_shortcodes', $adv_shortcodes );
1468 1834
1469 1835 // __( 'Leave blank instead of defaulting to User Login', 'formidable' ) : blank=1
1470 1836
1471 - return $adv_shortcodes;
1837 + return apply_filters( 'frm_advanced_shortcodes', $adv_shortcodes );
1472 1838 }
1473 1839
1474 1840 /**
1475 1841 * @since 3.04.01
1842 + *
1843 + * @return array
1476 1844 */
1477 1845 private static function user_shortcodes() {
1478 1846 $options = array(
1479 1847 'ID' => __( 'User ID', 'formidable' ),
@@ -1492,8 +1860,12 @@
1492 1860 /**
1493 1861 * Get an array of the helper shortcodes to display in the customization panel
1494 1862 *
1495 1863 * @since 2.0.6
1864 + *
1865 + * @param bool $settings_tab
1866 + *
1867 + * @return array
1496 1868 */
1497 1869 private static function get_shortcode_helpers( $settings_tab ) {
1498 1870 $entry_shortcodes = array(
1499 1871 'id' => __( 'Entry ID', 'formidable' ),
@@ -1504,30 +1876,27 @@
1504 1876 'updated-at' => __( 'Entry updated', 'formidable' ),
1505 1877 '' => '',
1506 1878 'siteurl' => __( 'Site URL', 'formidable' ),
1507 1879 'sitename' => __( 'Site Name', 'formidable' ),
1880 + 'form_name' => __( 'Form Name', 'formidable' ),
1508 1881 );
1509 1882
1883 + $entry_shortcodes = array_merge( FrmShortcodeHelper::get_contextual_shortcode_values(), $entry_shortcodes );
1884 +
1510 1885 if ( ! FrmAppHelper::pro_is_installed() ) {
1511 1886 unset( $entry_shortcodes['post_id'] );
1512 1887 }
1513 1888
1514 - if ( $settings_tab ) {
1515 - $entry_shortcodes['default-message'] = __( 'Default Msg', 'formidable' );
1516 - $entry_shortcodes['default-html'] = __( 'Default HTML', 'formidable' );
1517 - $entry_shortcodes['default-plain'] = __( 'Default Plain', 'formidable' );
1518 - $entry_shortcodes['form_name'] = __( 'Form Name', 'formidable' );
1519 - }
1520 -
1521 1889 /**
1522 1890 * Use this hook to add or remove buttons in the helpers section
1523 1891 * in the customization panel
1524 1892 *
1525 1893 * @since 2.0.6
1894 + *
1895 + * @param array $entry_shortcodes
1896 + * @param bool $settings_tab
1526 1897 */
1527 - $entry_shortcodes = apply_filters( 'frm_helper_shortcodes', $entry_shortcodes, $settings_tab );
1528 -
1529 - return $entry_shortcodes;
1898 + return apply_filters( 'frm_helper_shortcodes', $entry_shortcodes, $settings_tab );
1530 1899 }
1531 1900
1532 1901 /**
1533 1902 * Insert the form class setting into the form.
@@ -1532,8 +1901,9 @@
1532 1901 /**
1533 1902 * Insert the form class setting into the form.
1534 1903 *
1535 1904 * @param stdClass $form
1905 + *
1536 1906 * @return void
1537 1907 */
1538 1908 public static function form_classes( $form ) {
1539 1909 if ( isset( $form->options['form_class'] ) ) {
@@ -1544,9 +1914,9 @@
1544 1914 echo ' frm_js_validate ';
1545 1915 self::add_js_validate_form_to_global_vars( $form );
1546 1916 }
1547 1917
1548 - if ( ! FrmFormsHelper::should_use_pro_for_ajax_submit() && FrmForm::is_ajax_on( $form ) ) {
1918 + if ( FrmForm::is_ajax_on( $form ) ) {
1549 1919 echo ' frm_ajax_submit ';
1550 1920 }
1551 1921 }
1552 1922
@@ -1556,8 +1926,9 @@
1556 1926 * @param stdClass $form
1557 1927 */
1558 1928 public static function add_js_validate_form_to_global_vars( $form ) {
1559 1929 global $frm_vars;
1930 +
1560 1931 if ( ! isset( $frm_vars['js_validate_forms'] ) ) {
1561 1932 $frm_vars['js_validate_forms'] = array();
1562 1933 }
1563 1934 $frm_vars['js_validate_forms'][ $form->id ] = $form;
@@ -1568,11 +1939,11 @@
1568 1939 check_ajax_referer( 'frm_ajax', 'nonce' );
1569 1940
1570 1941 echo FrmEntriesController::show_entry_shortcode( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1571 1942 array(
1572 - 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ),
1943 + 'form_id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1573 1944 'default_email' => true,
1574 - 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ),
1945 + 'plain_text' => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1575 1946 )
1576 1947 );
1577 1948 wp_die();
1578 1949 }
@@ -1578,10 +1949,11 @@
1578 1949 }
1579 1950
1580 1951 /**
1581 1952 * @param string $content
1582 - * @param stdClass|string|int $form
1583 - * @param stdClass|string|int|false $entry
1953 + * @param int|stdClass|string $form
1954 + * @param false|int|stdClass|string $entry
1955 + *
1584 1956 * @return string
1585 1957 */
1586 1958 public static function filter_content( $content, $form, $entry = false ) {
1587 1959 $content = self::replace_form_name_shortcodes( $content, $form );
@@ -1586,8 +1958,9 @@
1586 1958 public static function filter_content( $content, $form, $entry = false ) {
1587 1959 $content = self::replace_form_name_shortcodes( $content, $form );
1588 1960
1589 1961 self::get_entry_by_param( $entry );
1962 +
1590 1963 if ( ! $entry ) {
1591 1964 return $content;
1592 1965 }
1593 1966
@@ -1594,12 +1967,19 @@
1594 1967 if ( is_object( $form ) ) {
1595 1968 $form = $form->id;
1596 1969 }
1597 1970
1971 + /*
1972 + * Repeater actions adds `parent_entry` to `$entry` store the parent entry data. If `parent_entry` is not empty,
1973 + * use the parent form ID instead of repeater form ID to fix the parent form field shortcodes doesn't work.
1974 + */
1975 + if ( ! empty( $entry->parent_entry ) ) {
1976 + $form = $entry->parent_entry->form_id;
1977 + }
1978 +
1598 1979 $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
1599 - $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
1600 1980
1601 - return $content;
1981 + return apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
1602 1982 }
1603 1983
1604 1984 /**
1605 1985 * Replace any [form_name] shortcodes in a string.
@@ -1605,17 +1985,22 @@
1605 1985 * Replace any [form_name] shortcodes in a string.
1606 1986 *
1607 1987 * @since 5.5
1608 1988 *
1609 - * @param string $string
1610 - * @param stdClass|string|int $form
1611 - * @return string
1989 + * @param array|string $string
1990 + * @param int|stdClass|string $form
1991 + *
1992 + * @return array|string
1612 1993 */
1613 1994 public static function replace_form_name_shortcodes( $string, $form ) {
1614 - if ( false === strpos( $string, '[form_name]' ) ) {
1995 + if ( ! is_string( $string ) ) {
1615 1996 return $string;
1616 1997 }
1617 1998
1999 + if ( ! str_contains( $string, '[form_name]' ) ) {
2000 + return $string;
2001 + }
2002 +
1618 2003 if ( ! is_object( $form ) ) {
1619 2004 $form = FrmForm::getOne( $form );
1620 2005 }
1621 2006
@@ -1623,25 +2008,40 @@
1623 2008 return str_replace( '[form_name]', $form_name, $string );
1624 2009 }
1625 2010
1626 2011 /**
1627 - * @param stdClass|string|int|false $entry
2012 + * @param false|int|stdClass|string $entry
2013 + *
1628 2014 * @return void
1629 2015 */
1630 2016 private static function get_entry_by_param( &$entry ) {
1631 - if ( ! $entry || ! is_object( $entry ) ) {
1632 - if ( ! $entry || ! is_numeric( $entry ) ) {
1633 - $entry = FrmAppHelper::get_post_param( 'id', false, 'sanitize_title' );
1634 - }
2017 + if ( $entry && is_object( $entry ) ) {
2018 + return;
2019 + }
1635 2020
1636 - FrmEntry::maybe_get_entry( $entry );
2021 + if ( ! $entry || ! is_numeric( $entry ) ) {
2022 + $entry = FrmAppHelper::get_post_param( 'id', false, 'sanitize_title' );
1637 2023 }
2024 +
2025 + FrmEntry::maybe_get_entry( $entry );
1638 2026 }
1639 2027
2028 + /**
2029 + * @param string $content
2030 + * @param false|object $entry
2031 + * @param array $shortcodes
2032 + *
2033 + * @return string
2034 + */
1640 2035 public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
1641 2036 return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
1642 2037 }
1643 2038
2039 + /**
2040 + * @param array $errors
2041 + *
2042 + * @return array
2043 + */
1644 2044 public static function process_bulk_form_actions( $errors ) {
1645 2045 if ( ! $_REQUEST ) {
1646 2046 return $errors;
1647 2047 }
@@ -1646,29 +2046,30 @@
1646 2046 return $errors;
1647 2047 }
1648 2048
1649 2049 $bulkaction = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
2050 +
2051 + // phpcs:ignore Universal.Operators.StrictComparisons
1650 2052 if ( $bulkaction == - 1 ) {
1651 2053 $bulkaction = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
1652 2054 }
1653 2055
1654 - if ( ! empty( $bulkaction ) && strpos( $bulkaction, 'bulk_' ) === 0 ) {
2056 + if ( $bulkaction && str_starts_with( $bulkaction, 'bulk_' ) ) {
1655 2057 FrmAppHelper::remove_get_action();
1656 -
1657 2058 $bulkaction = str_replace( 'bulk_', '', $bulkaction );
1658 2059 }
1659 2060
1660 2061 $ids = FrmAppHelper::get_param( 'item-action', '', 'get', 'sanitize_text_field' );
1661 - if ( empty( $ids ) ) {
2062 +
2063 + if ( ! $ids ) {
1662 2064 $errors[] = __( 'No forms were specified', 'formidable' );
1663 -
1664 2065 return $errors;
1665 2066 }
1666 2067
1667 2068 $permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' );
2069 +
1668 2070 if ( $permission_error !== false ) {
1669 2071 $errors[] = $permission_error;
1670 -
1671 2072 return $errors;
1672 2073 }
1673 2074
1674 2075 if ( ! is_array( $ids ) ) {
@@ -1685,9 +2086,9 @@
1685 2086 case 'untrash':
1686 2087 $message = self::bulk_untrash( $ids );
1687 2088 }
1688 2089
1689 - if ( isset( $message ) && ! empty( $message ) ) {
2090 + if ( ! empty( $message ) ) {
1690 2091 $errors['message'] = $message;
1691 2092 }
1692 2093
1693 2094 return $errors;
@@ -1692,9 +2093,24 @@
1692 2093
1693 2094 return $errors;
1694 2095 }
1695 2096
1696 - public static function route() {
2097 + /**
2098 + * Includes html that shows a message when the device is too small to use Formidable Forms admin pages.
2099 + *
2100 + * @since 6.20
2101 + *
2102 + * @return void
2103 + */
2104 + public static function include_device_too_small_message() {
2105 + if ( ! FrmAppHelper::is_formidable_admin() ) {
2106 + return;
2107 + }
2108 +
2109 + include FrmAppHelper::plugin_path() . '/classes/views/shared/small-device-message.php';
2110 + }
2111 +
2112 + public static function route() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded
1697 2113 $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
1698 2114 $vars = array();
1699 2115 FrmAppHelper::include_svg();
1700 2116
@@ -1704,37 +2120,38 @@
1704 2120 // Javascript needs to be allowed in some field settings.
1705 2121 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
1706 2122 $json_vars = htmlspecialchars_decode( nl2br( str_replace( '&quot;', '"', wp_unslash( $_POST['frm_compact_fields'] ) ) ) );
1707 2123 $json_vars = json_decode( $json_vars, true );
1708 - if ( empty( $json_vars ) ) {
1709 - // json decoding failed so we should return an error message.
1710 - $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1711 - if ( 'edit' == $action ) {
1712 - $action = 'update';
1713 - }
1714 2124
1715 - add_filter( 'frm_validate_form', 'FrmFormsController::json_error' );
1716 - } else {
2125 + if ( $json_vars ) {
1717 2126 $vars = FrmAppHelper::json_to_array( $json_vars );
1718 2127 $action = $vars[ $action ];
1719 2128 unset( $_REQUEST['frm_compact_fields'], $_POST['frm_compact_fields'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
1720 2129 $_REQUEST = array_merge( $_REQUEST, $vars ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
1721 2130 $_POST = array_merge( $_POST, $_REQUEST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
2131 + } else {
2132 + // Json decoding failed so we should return an error message.
2133 + $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
2134 +
2135 + if ( 'edit' === $action ) {
2136 + $action = 'update';
2137 + }
2138 +
2139 + add_filter( 'frm_validate_form', 'FrmFormsController::json_error' );
1722 2140 }
1723 2141 } else {
1724 2142 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
2143 +
1725 2144 if ( isset( $_REQUEST['delete_all'] ) ) {
1726 2145 // Override the action for this page.
1727 2146 $action = 'delete_all';
1728 2147 }
1729 - }
2148 + }//end if
1730 2149
1731 2150 add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1732 2151 FrmAppHelper::trigger_hook_load( 'form' );
1733 2152
1734 2153 switch ( $action ) {
1735 - case 'new':
1736 - return self::new_form( $vars );
1737 2154 case 'create':
1738 2155 case 'edit':
1739 2156 case 'update':
1740 2157 case 'trash':
@@ -1739,59 +2156,113 @@
1739 2156 case 'update':
1740 2157 case 'trash':
1741 2158 case 'untrash':
1742 2159 case 'destroy':
1743 - case 'delete_all':
1744 2160 case 'settings':
1745 2161 case 'update_settings':
1746 2162 return self::$action( $vars );
1747 2163 case 'lite-reports':
1748 - return self::no_reports( $vars );
2164 + self::no_reports( $vars );
2165 + return null;
1749 2166 case 'views':
1750 - return self::no_views( $vars );
2167 + self::no_views( $vars );
2168 + return null;
1751 2169 default:
1752 2170 do_action( 'frm_form_action_' . $action );
2171 +
1753 2172 if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) {
1754 - return;
2173 + return null;
1755 2174 }
1756 2175
1757 2176 $action = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
2177 +
2178 + // phpcs:ignore Universal.Operators.StrictComparisons
1758 2179 if ( $action == - 1 ) {
1759 2180 $action = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
1760 2181 }
1761 2182
1762 - if ( strpos( $action, 'bulk_' ) === 0 ) {
2183 + if ( str_starts_with( $action, 'bulk_' ) ) {
1763 2184 FrmAppHelper::remove_get_action();
1764 2185
1765 2186 self::list_form();
1766 - return;
2187 + return null;
1767 2188 }
1768 2189
1769 2190 $message = FrmAppHelper::get_param( 'message' );
2191 +
1770 2192 if ( 'form_duplicate_error' === $message ) {
1771 2193 self::display_forms_list( array(), '', array( __( 'There was a problem duplicating the form', 'formidable' ) ) );
1772 - return;
2194 + return null;
1773 2195 }
1774 2196
2197 + if ( 'forms_permanently_deleted' === $message ) {
2198 + $count = FrmAppHelper::get_param( 'forms_deleted', 0, 'get', 'absint' );
2199 + /* translators: %1$s: Number of forms */
2200 + $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
2201 + self::display_forms_list( array(), $message, '' );
2202 + return null;
2203 + }
2204 +
1775 2205 self::display_forms_list();
1776 2206
1777 - return;
2207 + return null;
2208 + }//end switch
2209 + }
2210 +
2211 + /**
2212 + * Rename a form.
2213 + *
2214 + * Handles the AJAX request for renaming a form.
2215 + *
2216 + * @since 6.7
2217 + *
2218 + * @return void
2219 + */
2220 + public static function rename_form() {
2221 + // Check permission and nonce
2222 + FrmAppHelper::permission_check( 'frm_edit_forms' );
2223 + check_ajax_referer( 'frm_ajax', 'nonce' );
2224 +
2225 + // Get posted data
2226 + $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
2227 + $name = FrmAppHelper::get_post_param( 'form_name', '', 'sanitize_text_field' );
2228 + $form = FrmForm::getOne( $form_id );
2229 +
2230 + if ( ! $form ) {
2231 + wp_send_json_error( __( 'Form not found', 'formidable' ) );
1778 2232 }
1779 - }
1780 2233
1781 - public static function json_error( $errors ) {
1782 - $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
2234 + if ( $name === $form->name ) {
2235 + // Nothing to change so exit early.
2236 + $form_key = $form->form_key;
2237 + wp_send_json_success( compact( 'form_key' ) );
2238 + }
1783 2239
1784 - return $errors;
2240 + $to_update = array(
2241 + 'name' => $name,
2242 + );
2243 +
2244 + if ( '' === $name ) {
2245 + $form_key = $form->form_key;
2246 + } else {
2247 + // Only update form_key if name is not empty.
2248 + $form_key = FrmAppHelper::get_unique_key( sanitize_title( $name ), 'frm_forms', 'form_key' );
2249 + $to_update['form_key'] = $form_key;
2250 + }
2251 +
2252 + FrmForm::update( $form_id, $to_update );
2253 +
2254 + wp_send_json_success( compact( 'form_key' ) );
1785 2255 }
1786 2256
1787 2257 /**
1788 - * Education for premium features.
2258 + * @param array $errors
1789 2259 *
1790 - * @since 4.05
2260 + * @return array
1791 2261 */
1792 - public static function add_form_style_tab_options() {
1793 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_form_style_options.php' );
2262 + public static function json_error( $errors ) {
2263 + $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
2264 + return $errors;
1794 2265 }
1795 2266
1796 2267 /**
1797 2268 * Add education about views.
@@ -1796,8 +2267,12 @@
1796 2267 /**
1797 2268 * Add education about views.
1798 2269 *
1799 2270 * @since 4.07
2271 + *
2272 + * @param array $values
2273 + *
2274 + * @return void
1800 2275 */
1801 2276 public static function no_views( $values = array() ) {
1802 2277 FrmAppHelper::include_svg();
1803 2278 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
@@ -1809,8 +2284,12 @@
1809 2284 /**
1810 2285 * Add education about reports.
1811 2286 *
1812 2287 * @since 4.07
2288 + *
2289 + * @param array $values
2290 + *
2291 + * @return void
1813 2292 */
1814 2293 public static function no_reports( $values = array() ) {
1815 2294 $id = FrmAppHelper::get_param( 'form', '', 'get', 'absint' );
1816 2295 $form = $id ? FrmForm::getOne( $id ) : false;
@@ -1817,9 +2296,11 @@
1817 2296
1818 2297 include FrmAppHelper::plugin_path() . '/classes/views/shared/reports-info.php';
1819 2298 }
1820 2299
1821 - /* FRONT-END FORMS */
2300 + /**
2301 + * FRONT-END FORMS.
2302 + */
1822 2303 public static function admin_bar_css() {
1823 2304 if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
1824 2305 return;
1825 2306 }
@@ -1833,10 +2314,9 @@
1833 2314 /**
1834 2315 * @since 4.05.02
1835 2316 */
1836 2317 private static function move_menu_to_footer() {
1837 - $settings = FrmAppHelper::get_settings();
1838 - if ( empty( $settings->admin_bar ) ) {
2318 + if ( empty( FrmAppHelper::get_settings()->admin_bar ) ) {
1839 2319 remove_action( 'wp_body_open', 'wp_admin_bar_render', 0 );
1840 2320 }
1841 2321 }
1842 2322
@@ -1841,13 +2321,15 @@
1841 2321 }
1842 2322
1843 2323 public static function admin_bar_configure() {
1844 2324 global $frm_vars;
2325 +
1845 2326 if ( empty( $frm_vars['forms_loaded'] ) ) {
1846 2327 return;
1847 2328 }
1848 2329
1849 2330 $actions = array();
2331 +
1850 2332 foreach ( $frm_vars['forms_loaded'] as $form ) {
1851 2333 if ( is_object( $form ) ) {
1852 2334 $actions[ $form->id ] = $form->name;
1853 2335 }
@@ -1853,9 +2335,9 @@
1853 2335 }
1854 2336 unset( $form );
1855 2337 }
1856 2338
1857 - if ( empty( $actions ) ) {
2339 + if ( ! $actions ) {
1858 2340 return;
1859 2341 }
1860 2342
1861 2343 self::add_menu_to_admin_bar();
@@ -1881,8 +2363,12 @@
1881 2363 }
1882 2364
1883 2365 /**
1884 2366 * @since 2.05.07
2367 + *
2368 + * @param array $actions
2369 + *
2370 + * @return void
1885 2371 */
1886 2372 private static function add_forms_to_admin_bar( $actions ) {
1887 2373 global $wp_admin_bar;
1888 2374
@@ -1888,14 +2374,13 @@
1888 2374
1889 2375 asort( $actions );
1890 2376
1891 2377 foreach ( $actions as $form_id => $name ) {
1892 -
1893 2378 $wp_admin_bar->add_node(
1894 2379 array(
1895 2380 'parent' => 'frm-forms',
1896 2381 'id' => 'edit_form_' . $form_id,
1897 - 'title' => empty( $name ) ? __( '(no title)', 'formidable' ) : $name,
2382 + 'title' => $name ? $name : FrmFormsHelper::get_no_title_text(),
1898 2383 'href' => FrmForm::get_edit_link( $form_id ),
1899 2384 )
1900 2385 );
1901 2386 }
@@ -1904,14 +2389,16 @@
1904 2389 /**
1905 2390 * The formidable shortcode
1906 2391 *
1907 2392 * @param array $atts The params from the shortcode.
2393 + *
1908 2394 * @return string
1909 2395 */
1910 2396 public static function get_form_shortcode( $atts ) {
1911 2397 global $frm_vars;
1912 - if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) {
1913 - $sc = '[formidable';
2398 +
2399 + if ( ! empty( $frm_vars['skip_shortcode'] ) ) {
2400 + $sc = '[formidable';
1914 2401 $sc .= FrmAppHelper::array_to_html_params( $atts );
1915 2402 return $sc . ']';
1916 2403 }
1917 2404
@@ -1936,11 +2423,12 @@
1936 2423
1937 2424 /**
1938 2425 * @since 5.2.01
1939 2426 *
1940 - * @param string|int|false $id
1941 - * @param string|false $key
1942 - * @return stdClass|false
2427 + * @param false|int|string $id
2428 + * @param false|string $key
2429 + *
2430 + * @return false|stdClass
1943 2431 */
1944 2432 private static function maybe_get_form_by_id_or_key( $id, $key ) {
1945 2433 if ( ! $id ) {
1946 2434 $id = $key;
@@ -1948,13 +2436,14 @@
1948 2436 return self::maybe_get_form_to_show( $id );
1949 2437 }
1950 2438
1951 2439 /**
1952 - * @param string|int|false $id
1953 - * @param string|false $key
1954 - * @param string|int|bool $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
1955 - * @param string|int|bool $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
2440 + * @param false|int|string $id
2441 + * @param false|string $key
2442 + * @param bool|int|string $title may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
2443 + * @param bool|int|string $description may be 'auto', true, false, 'true', 'false', 'yes', '1', 1, '0', 0.
1956 2444 * @param array $atts
2445 + *
1957 2446 * @return string
1958 2447 */
1959 2448 public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
1960 2449 $form = self::maybe_get_form_by_id_or_key( $id, $key );
@@ -1975,14 +2464,13 @@
1975 2464
1976 2465 add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1977 2466 FrmAppHelper::trigger_hook_load( 'form', $form );
1978 2467
1979 - $form = apply_filters( 'frm_pre_display_form', $form );
1980 -
2468 + $form = apply_filters( 'frm_pre_display_form', $form );
1981 2469 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
1982 2470
1983 2471 if ( self::is_viewable_draft_form( $form ) ) {
1984 - // don't show a draft form on a page
2472 + // Don't show a draft form on a page
1985 2473 $form = __( 'Please select a valid form', 'formidable' );
1986 2474 } elseif ( ! FrmForm::is_visible_to_user( $form ) ) {
1987 2475 $form = do_shortcode( $frm_settings->login_msg );
1988 2476 } else {
@@ -2001,16 +2489,19 @@
2001 2489 return $form;
2002 2490 }
2003 2491
2004 2492 /**
2005 - * @param string|int|false $id
2006 - * @return stdClass|false
2493 + * @param false|int|string $id
2494 + *
2495 + * @return false|stdClass
2007 2496 */
2008 2497 private static function maybe_get_form_to_show( $id ) {
2009 2498 $form = false;
2010 2499
2011 - if ( ! empty( $id ) ) { // form id or key is set
2500 + if ( $id ) {
2501 + // Form id or key is set.
2012 2502 $form = FrmForm::getOne( $id );
2503 +
2013 2504 if ( ! $form || $form->parent_form_id || $form->status === 'trash' ) {
2014 2505 $form = false;
2015 2506 }
2016 2507 }
@@ -2017,12 +2508,25 @@
2017 2508
2018 2509 return $form;
2019 2510 }
2020 2511
2512 + /**
2513 + * @param object $form
2514 + *
2515 + * @return bool
2516 + */
2021 2517 private static function is_viewable_draft_form( $form ) {
2022 2518 return $form->status === 'draft' && current_user_can( 'frm_edit_forms' ) && ! FrmAppHelper::is_preview_page();
2023 2519 }
2024 2520
2521 + /**
2522 + * @param object $form
2523 + * @param bool $title
2524 + * @param bool $description
2525 + * @param array $atts
2526 + *
2527 + * @return string
2528 + */
2025 2529 public static function get_form( $form, $title, $description, $atts = array() ) {
2026 2530 ob_start();
2027 2531
2028 2532 do_action( 'frm_before_get_form', $atts );
@@ -2029,10 +2533,9 @@
2029 2533
2030 2534 self::get_form_contents( $form, $title, $description, $atts );
2031 2535 self::enqueue_scripts( FrmForm::get_params( $form ) );
2032 2536
2033 - $contents = ob_get_contents();
2034 - ob_end_clean();
2537 + $contents = ob_get_clean();
2035 2538
2036 2539 self::maybe_minimize_form( $atts, $contents );
2037 2540
2038 2541 return $contents;
@@ -2037,12 +2540,25 @@
2037 2540
2038 2541 return $contents;
2039 2542 }
2040 2543
2544 + /**
2545 + * @param array $params
2546 + *
2547 + * @return void
2548 + */
2041 2549 public static function enqueue_scripts( $params ) {
2042 2550 do_action( 'frm_enqueue_form_scripts', $params );
2043 2551 }
2044 2552
2553 + /**
2554 + * @param object $form
2555 + * @param bool $title
2556 + * @param bool $description
2557 + * @param array $atts
2558 + *
2559 + * @return void
2560 + */
2045 2561 public static function get_form_contents( $form, $title, $description, $atts ) {
2046 2562 $params = FrmForm::get_params( $form );
2047 2563 $errors = self::get_saved_errors( $form, $params );
2048 2564 $fields = FrmFieldsHelper::get_form_fields( $form->id, $errors );
@@ -2049,9 +2565,10 @@
2049 2565 $reset = false;
2050 2566 $pass_args = compact( 'form', 'fields', 'errors', 'title', 'description', 'reset' );
2051 2567
2052 2568 $pass_args['action'] = $params['action'];
2053 - $handle_process_here = $params['action'] === 'create' && $params['posted_form_id'] == $form->id && $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing
2569 + // phpcs:ignore WordPress.Security.NonceVerification.Missing, Universal.Operators.StrictComparisons
2570 + $handle_process_here = $params['action'] === 'create' && $params['posted_form_id'] == $form->id && $_POST;
2054 2571
2055 2572 if ( ! $handle_process_here ) {
2056 2573 FrmFormState::set_initial_value( 'title', $title );
2057 2574 FrmFormState::set_initial_value( 'description', $description );
@@ -2056,22 +2573,21 @@
2056 2573 FrmFormState::set_initial_value( 'title', $title );
2057 2574 FrmFormState::set_initial_value( 'description', $description );
2058 2575
2059 2576 do_action( 'frm_display_form_action', $params, $fields, $form, $title, $description );
2577 +
2060 2578 if ( apply_filters( 'frm_continue_to_new', true, $form->id, $params['action'] ) ) {
2061 2579 self::show_form_after_submit( $pass_args );
2062 2580 }
2063 - } elseif ( ! empty( $errors ) ) {
2581 + } elseif ( $errors ) {
2064 2582 self::show_form_after_submit( $pass_args );
2065 -
2066 2583 } else {
2067 -
2068 2584 do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description );
2069 2585
2070 2586 if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) {
2071 - $entry_id = self::just_created_entry( $form->id );
2072 - $pass_args['entry_id'] = $entry_id;
2073 - $pass_args['reset'] = true;
2587 + $entry_id = self::just_created_entry( $form->id );
2588 + $pass_args['entry_id'] = $entry_id;
2589 + $pass_args['reset'] = true;
2074 2590
2075 2591 self::run_on_submit_actions( $pass_args );
2076 2592
2077 2593 do_action(
@@ -2081,9 +2597,9 @@
2081 2597 'form' => $form,
2082 2598 )
2083 2599 );
2084 2600 }
2085 - }
2601 + }//end if
2086 2602 }
2087 2603
2088 2604 /**
2089 2605 * If the form was processed earlier (init), get the generated errors
@@ -2088,13 +2604,19 @@
2088 2604 /**
2089 2605 * If the form was processed earlier (init), get the generated errors
2090 2606 *
2091 2607 * @since 2.05
2608 + *
2609 + * @param object $form
2610 + * @param array $params
2611 + *
2612 + * @return array
2092 2613 */
2093 2614 private static function get_saved_errors( $form, $params ) {
2094 2615 global $frm_vars;
2095 2616
2096 - if ( $params['posted_form_id'] == $form->id && $_POST && isset( $frm_vars['created_entries'][ $form->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
2617 + // phpcs:ignore WordPress.Security.NonceVerification.Missing, Universal.Operators.StrictComparisons
2618 + if ( $params['posted_form_id'] == $form->id && $_POST && isset( $frm_vars['created_entries'][ $form->id ] ) ) {
2097 2619 $errors = $frm_vars['created_entries'][ $form->id ]['errors'];
2098 2620 } else {
2099 2621 $errors = array();
2100 2622 }
@@ -2111,13 +2633,16 @@
2111 2633 }
2112 2634
2113 2635 /**
2114 2636 * @since 2.2.7
2637 + *
2638 + * @param int|string $form_id
2639 + *
2640 + * @return int
2115 2641 */
2116 2642 public static function just_created_entry( $form_id ) {
2117 2643 global $frm_vars;
2118 -
2119 - return ( isset( $frm_vars['created_entries'] ) && isset( $frm_vars['created_entries'][ $form_id ] ) && isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) ? $frm_vars['created_entries'][ $form_id ]['entry_id'] : 0;
2644 + return isset( $frm_vars['created_entries'] ) && isset( $frm_vars['created_entries'][ $form_id ] ) && isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ? $frm_vars['created_entries'][ $form_id ]['entry_id'] : 0; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
2120 2645 }
2121 2646
2122 2647 /**
2123 2648 * Gets confirmation method.
@@ -2130,17 +2655,19 @@
2130 2655 *
2131 2656 * @type object $form Form object.
2132 2657 * @type int $entry_id Entry ID.
2133 2658 * }
2134 - * @return string|array
2659 + *
2660 + * @return array|string
2135 2661 */
2136 2662 private static function get_confirmation_method( $atts ) {
2137 2663 $action = FrmOnSubmitHelper::current_event( $atts );
2138 2664 $opt = 'update' === $action ? 'edit_action' : 'success_action';
2139 - $method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message';
2665 + $method = ! empty( $atts['form']->options[ $opt ] ) ? $atts['form']->options[ $opt ] : 'message';
2140 2666
2141 2667 if ( ! empty( $atts['entry_id'] ) ) {
2142 2668 $met_actions = self::get_met_on_submit_actions( $atts, $action );
2669 +
2143 2670 if ( $met_actions ) {
2144 2671 $method = $met_actions;
2145 2672 }
2146 2673 }
@@ -2146,15 +2673,22 @@
2146 2673 }
2147 2674
2148 2675 $method = apply_filters( 'frm_success_filter', $method, $atts['form'], $action );
2149 2676
2150 - if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2151 - $method = 'message';
2677 + if ( $method !== 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
2678 + return 'message';
2152 2679 }
2153 2680
2154 2681 return $method;
2155 2682 }
2156 2683
2684 + /**
2685 + * @param object $form
2686 + * @param array $params
2687 + * @param array $args
2688 + *
2689 + * @return void
2690 + */
2157 2691 public static function maybe_trigger_redirect( $form, $params, $args ) {
2158 2692 if ( ! isset( $params['id'] ) ) {
2159 2693 global $frm_vars;
2160 2694 $params['id'] = $frm_vars['created_entries'][ $form->id ]['entry_id'];
@@ -2181,14 +2715,12 @@
2181 2715 * @param array $params See {@see FrmFormsController::maybe_trigger_redirect()}.
2182 2716 * @param array $args See {@see FrmFormsController::maybe_trigger_redirect()}.
2183 2717 */
2184 2718 public static function maybe_trigger_redirect_with_action( $conf_method, $form, $params, $args ) {
2185 - if ( is_array( $conf_method ) && 1 === count( $conf_method ) ) {
2186 - if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $conf_method[0] ) ) {
2187 - $event = FrmOnSubmitHelper::current_event( $params );
2188 - FrmOnSubmitHelper::populate_on_submit_data( $form->options, $conf_method[0], $event );
2189 - $conf_method = 'redirect';
2190 - }
2719 + if ( is_array( $conf_method ) && 1 === count( $conf_method ) && 'redirect' === FrmOnSubmitHelper::get_action_type( $conf_method[0] ) && empty( $conf_method[0]->post_content['redirect_delay'] ) ) { // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
2720 + $event = FrmOnSubmitHelper::current_event( $params );
2721 + FrmOnSubmitHelper::populate_on_submit_data( $form->options, $conf_method[0], $event );
2722 + $conf_method = 'redirect';
2191 2723 }
2192 2724
2193 2725 if ( 'redirect' === $conf_method ) {
2194 2726 self::trigger_redirect( $form, $params, $args );
@@ -2194,8 +2726,15 @@
2194 2726 self::trigger_redirect( $form, $params, $args );
2195 2727 }
2196 2728 }
2197 2729
2730 + /**
2731 + * @param object $form
2732 + * @param array $params
2733 + * @param array $args
2734 + *
2735 + * @return void
2736 + */
2198 2737 public static function trigger_redirect( $form, $params, $args ) {
2199 2738 $success_args = array(
2200 2739 'action' => $params['action'],
2201 2740 'conf_method' => 'redirect',
@@ -2233,9 +2772,9 @@
2233 2772 unset( $extra_args['form'] );
2234 2773
2235 2774 do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args );
2236 2775
2237 - $opt = ( ! isset( $args['action'] ) || $args['action'] === 'create' ) ? 'success' : 'edit';
2776 + $opt = ! isset( $args['action'] ) || $args['action'] === 'create' ? 'success' : 'edit';
2238 2777
2239 2778 $args['success_opt'] = $opt;
2240 2779 $args['ajax'] = ! empty( $frm_vars['ajax'] );
2241 2780
@@ -2254,8 +2793,9 @@
2254 2793 * @since 6.0
2255 2794 *
2256 2795 * @param array $args See {@see FrmFormsController::run_success_action()}.
2257 2796 * @param string $event Form event. Default is `create`.
2797 + *
2258 2798 * @return array Array of actions that meet the conditional logics.
2259 2799 */
2260 2800 public static function get_met_on_submit_actions( $args, $event = 'create' ) {
2261 2801 if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) {
@@ -2261,11 +2801,16 @@
2261 2801 if ( ! FrmOnSubmitHelper::form_has_migrated( $args['form'] ) ) {
2262 2802 return array();
2263 2803 }
2264 2804
2265 - $entry = FrmEntry::getOne( $args['entry_id'], true );
2266 - $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2267 - $met_actions = array();
2805 + // If a redirect action has already opened the URL in a new tab, we show the default message in the current tab.
2806 + if ( ! empty( self::$redirected_in_new_tab[ $args['form']->id ] ) ) {
2807 + return array( FrmOnSubmitHelper::get_fallback_action_after_open_in_new_tab( $event ) );
2808 + }
2809 +
2810 + $entry = FrmEntry::getOne( $args['entry_id'], true );
2811 + $actions = FrmOnSubmitHelper::get_actions( $args['form']->id );
2812 + $met_actions = array();
2268 2813 $has_redirect = false;
2269 2814
2270 2815 foreach ( $actions as $action ) {
2271 2816 if ( ! in_array( $event, $action->post_content['event'], true ) ) {
@@ -2277,12 +2822,11 @@
2277 2822 }
2278 2823
2279 2824 $action_type = FrmOnSubmitHelper::get_action_type( $action );
2280 2825
2281 - if ( 'redirect' === $action_type ) {
2282 - if ( $has_redirect ) { // Do not process because we run the first redirect action only.
2283 - continue;
2284 - }
2826 + if ( 'redirect' === $action_type && $has_redirect ) {
2827 + // Do not process because we run the first redirect action only.
2828 + continue;
2285 2829 }
2286 2830
2287 2831 if ( ! self::is_valid_on_submit_action( $action, $args, $event ) ) {
2288 2832 continue;
@@ -2293,9 +2837,9 @@
2293 2837 }
2294 2838
2295 2839 $met_actions[] = $action;
2296 2840 unset( $action );
2297 - }
2841 + }//end foreach
2298 2842
2299 2843 $args['event'] = $event;
2300 2844
2301 2845 /**
@@ -2307,10 +2851,10 @@
2307 2851 * @param array $args See {@see FrmFormsController::run_success_action()}. `$args['event']` is also added.
2308 2852 */
2309 2853 $met_actions = apply_filters( 'frm_get_met_on_submit_actions', $met_actions, $args );
2310 2854
2311 - if ( empty( $met_actions ) ) {
2312 - $met_actions = array( FrmOnSubmitHelper::get_fallback_action( $event ) );
2855 + if ( ! $met_actions ) {
2856 + return array( FrmOnSubmitHelper::get_fallback_action( $event ) );
2313 2857 }
2314 2858
2315 2859 return $met_actions;
2316 2860 }
@@ -2322,8 +2866,9 @@
2322 2866 *
2323 2867 * @param object $action Form action object.
2324 2868 * @param array $args See {@see FrmFormsController::run_success_action()}.
2325 2869 * @param string $event Form event. Default is `create`.
2870 + *
2326 2871 * @return bool
2327 2872 */
2328 2873 private static function is_valid_on_submit_action( $action, $args, $event = 'create' ) {
2329 2874 $action_type = FrmOnSubmitHelper::get_action_type( $action );
@@ -2345,8 +2890,9 @@
2345 2890 return false;
2346 2891 }
2347 2892
2348 2893 $page = get_post( $action->post_content['success_page_id'] );
2894 +
2349 2895 if ( ! $page || 'trash' === $page->post_status ) {
2350 2896 return false;
2351 2897 }
2352 2898 }
@@ -2368,8 +2914,9 @@
2368 2914 'entry_id' => $args['entry_id'],
2369 2915 'action' => FrmOnSubmitHelper::current_event( $args ),
2370 2916 )
2371 2917 );
2918 +
2372 2919 if ( ! is_array( $args['conf_method'] ) ) {
2373 2920 self::run_success_action( $args );
2374 2921 return;
2375 2922 }
@@ -2396,8 +2943,9 @@
2396 2943 * @param array $args See {@see FrmFormsController::run_success_action()}.
2397 2944 */
2398 2945 public static function run_multi_on_submit_actions( $args ) {
2399 2946 $redirect_action = null;
2947 +
2400 2948 foreach ( $args['conf_method'] as $action ) {
2401 2949 if ( 'redirect' === FrmOnSubmitHelper::get_action_type( $action ) ) {
2402 2950 // We catch the redirect action to run it last.
2403 2951 $redirect_action = $action;
@@ -2408,13 +2956,15 @@
2408 2956
2409 2957 unset( $action );
2410 2958 }
2411 2959
2412 - if ( $redirect_action ) {
2413 - // Show script to delay the redirection.
2414 - $args['force_delay_redirect'] = true;
2415 - self::run_single_on_submit_action( $args, $redirect_action );
2960 + if ( ! $redirect_action ) {
2961 + return;
2416 2962 }
2963 +
2964 + // Show script to delay the redirection.
2965 + $args['force_delay_redirect'] = true;
2966 + self::run_single_on_submit_action( $args, $redirect_action );
2417 2967 }
2418 2968
2419 2969 /**
2420 2970 * Runs single On Submit action.
@@ -2435,8 +2985,9 @@
2435 2985 * @since 6.0
2436 2986 *
2437 2987 * @param array $args See {@see FrmFormsController::run_success_action()}.
2438 2988 * @param object $action On Submit action object.
2989 + *
2439 2990 * @return array
2440 2991 */
2441 2992 private static function get_run_success_action_args( $args, $action ) {
2442 2993 $new_args = $args;
@@ -2442,10 +2993,9 @@
2442 2993 $new_args = $args;
2443 2994
2444 2995 FrmOnSubmitHelper::populate_on_submit_data( $new_args['form']->options, $action, $args['action'] );
2445 2996
2446 - $opt = 'update' === $args['action'] ? 'edit_' : 'success_';
2447 -
2997 + $opt = 'update' === $args['action'] ? 'edit_' : 'success_';
2448 2998 $new_args['conf_method'] = $new_args['form']->options[ $opt . 'action' ];
2449 2999
2450 3000 /**
2451 3001 * Filters the run success action args.
@@ -2460,12 +3010,18 @@
2460 3010 }
2461 3011
2462 3012 /**
2463 3013 * @since 3.0
3014 + *
3015 + * @param array $args
3016 + *
3017 + * @return void
2464 3018 */
2465 3019 private static function load_page_after_submit( $args ) {
2466 3020 global $post;
2467 3021 $opt = $args['success_opt'];
3022 +
3023 + // phpcs:ignore Universal.Operators.StrictComparisons
2468 3024 if ( ! $post || $args['form']->options[ $opt . '_page_id' ] != $post->ID ) {
2469 3025 $page = get_post( $args['form']->options[ $opt . '_page_id' ] );
2470 3026 $old_post = $post;
2471 3027 $post = $page;
@@ -2484,13 +3040,14 @@
2484 3040 add_filter( 'the_content', 'FrmFormsController::preview_content', 9999 );
2485 3041 }
2486 3042
2487 3043 $post = $old_post;
2488 - }
3044 + }//end if
2489 3045 }
2490 3046
2491 3047 /**
2492 3048 * @since 3.0
3049 + *
2493 3050 * @param array $args See {@see FrmFormsController::run_success_action()}.
2494 3051 */
2495 3052 private static function redirect_after_submit( $args ) {
2496 3053 add_filter( 'frm_use_wpautop', '__return_false' );
@@ -2504,19 +3061,27 @@
2504 3061 FrmEntriesController::delete_entry_before_redirect( $success_url, $args['form'], $args );
2505 3062
2506 3063 add_filter( 'frm_redirect_url', 'FrmEntriesController::prepare_redirect_url' );
2507 3064 $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args );
3065 + $doing_ajax = FrmAppHelper::doing_ajax();
2508 3066
2509 - $doing_ajax = FrmAppHelper::doing_ajax();
2510 -
2511 - if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) { // Is AJAX submit and there is just one Redirect action runs.
2512 - echo json_encode( array( 'redirect' => $success_url ) );
3067 + if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) {
3068 + // Is AJAX submit and there is just one Redirect action runs.
3069 + echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) );
2513 3070 wp_die();
2514 3071 }
2515 3072
2516 - if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { // Not AJAX submit, no headers sent, and there is just one Redirect action runs.
3073 + if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) && empty( $args['form']->options['redirect_delay'] ) ) {
3074 + // Not AJAX submit, no headers sent, and there is just one Redirect action runs.
3075 + if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
3076 + self::print_open_in_new_tab_js_with_fallback_handler( $success_url, $args );
3077 + self::$redirected_in_new_tab[ $args['form']->id ] = 1;
3078 + return;
3079 + }
3080 +
2517 3081 wp_redirect( esc_url_raw( $success_url ) );
2518 - die(); // do not use wp_die or redirect fails
3082 + // Do not use wp_die or redirect fails.
3083 + die();
2519 3084 }
2520 3085
2521 3086 // Redirect with a delay.
2522 3087 self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) );
@@ -2522,8 +3087,83 @@
2522 3087 self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) );
2523 3088 }
2524 3089
2525 3090 /**
3091 + * Prints open in new tab js with fallback handler.
3092 + *
3093 + * @since 6.3.1
3094 + *
3095 + * @param string $success_url Success URL.
3096 + * @param array $args See {@see FrmFormsController::redirect_after_submit()}.
3097 + */
3098 + private static function print_open_in_new_tab_js_with_fallback_handler( $success_url, $args ) {
3099 + echo '<script>var newTab = window.open("' . esc_url_raw( $success_url ) . '", "_blank");';
3100 + echo 'if ( ! newTab ) {';
3101 +
3102 + $data = array(
3103 + 'formId' => intval( $args['form']->id ),
3104 + 'message' => self::get_redirect_fallback_message( $success_url, $args ),
3105 + );
3106 + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3107 + echo 'frmShowNewTabFallback = ' . FrmAppHelper::maybe_json_encode( $data ) . ';';
3108 + echo '}</script>';
3109 + }
3110 +
3111 + /**
3112 + * Gets response data for redirect action when AJAX submitting.
3113 + *
3114 + * @since 6.3.1
3115 + *
3116 + * @param array $args See {@see FrmFormsController::run_success_action()}.
3117 + *
3118 + * @return array
3119 + */
3120 + private static function get_ajax_redirect_response_data( $args ) {
3121 + $response_data = array(
3122 + 'redirect' => $args['success_url'],
3123 + 'content' => '',
3124 + );
3125 + $unset_content = true;
3126 +
3127 + if ( ! empty( $args['form']->options['redirect_delay'] ) ) {
3128 + $response_data['delay'] = $args['form']->options['redirect_delay_time'];
3129 + $response_data['content'] .= self::get_redirect_message( $args['success_url'], $args['form']->options['redirect_delay_msg'], $args );
3130 + $unset_content = false;
3131 + }
3132 +
3133 + if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
3134 + $response_data['openInNewTab'] = 1;
3135 +
3136 + // Only show open in new tab text if there is no delay.
3137 + if ( empty( $response_data['content'] ) ) {
3138 + $args['message'] = FrmOnSubmitHelper::get_default_new_tab_msg();
3139 +
3140 + $args['form']->options['success_msg'] = $args['message'];
3141 + $args['form']->options['edit_msg'] = $args['message'];
3142 +
3143 + if ( ! isset( $args['fields'] ) ) {
3144 + $args['fields'] = FrmField::get_all_for_form( $args['form']->id );
3145 + }
3146 +
3147 + $args['message'] = self::prepare_submit_message( $args['form'], $args['entry_id'], $args );
3148 +
3149 + ob_start();
3150 + self::show_lone_success_message( $args );
3151 + $response_data['content'] .= ob_get_clean();
3152 + $unset_content = false;
3153 + }//end if
3154 +
3155 + $response_data['fallbackMsg'] = self::get_redirect_fallback_message( $args['success_url'], $args );
3156 + }//end if
3157 +
3158 + if ( $unset_content && '' === $response_data['content'] ) {
3159 + unset( $response_data['content'] );
3160 + }
3161 +
3162 + return $response_data;
3163 + }
3164 +
3165 + /**
2526 3166 * Redirects after submitting using JS. This is used when showing message before redirecting.
2527 3167 *
2528 3168 * @since 6.0
2529 3169 *
@@ -2529,10 +3169,11 @@
2529 3169 *
2530 3170 * @param array $args See {@see FrmFormsController::run_success_action()}.
2531 3171 */
2532 3172 private static function redirect_after_submit_using_js( $args ) {
2533 - $success_msg = FrmOnSubmitHelper::get_default_redirect_msg();
3173 + $success_msg = $args['form']->options['redirect_delay_msg'];
2534 3174 $redirect_msg = self::get_redirect_message( $args['success_url'], $success_msg, $args );
3175 + $success_url = esc_url_raw( $args['success_url'] );
2535 3176
2536 3177 /**
2537 3178 * Filters the delay time before redirecting when On Submit Redirect action is delayed.
2538 3179 *
@@ -2537,20 +3178,29 @@
2537 3178 * Filters the delay time before redirecting when On Submit Redirect action is delayed.
2538 3179 *
2539 3180 * @since 6.0
2540 3181 *
2541 - * @param int $delay_time Delay time in miliseconds.
3182 + * @param int $delay_time Delay time in milliseconds.
2542 3183 */
2543 - $delay_time = apply_filters( 'frm_redirect_delay_time', 8000 );
3184 + $delay_time = apply_filters( 'frm_redirect_delay_time', 1000 * $args['form']->options['redirect_delay_time'] );
2544 3185
3186 + if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
3187 + $redirect_js = 'window.open("' . $success_url . '", "_blank")';
3188 + } else {
3189 + $redirect_js = 'window.location="' . $success_url . '";';
3190 + }
3191 +
2545 3192 add_filter( 'frm_use_wpautop', '__return_true' );
2546 3193
2547 3194 echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2548 3195 echo '<script>';
2549 - if ( empty( $args['doing_ajax'] ) ) { // Not AJAX submit, delay JS until window.load.
3196 +
3197 + if ( empty( $args['doing_ajax'] ) ) {
3198 + // Not AJAX submit, delay JS until window.load.
2550 3199 echo 'window.onload=function(){';
2551 3200 }
2552 - echo 'setTimeout(function(){window.location="' . esc_url_raw( $args['success_url'] ) . '";}, ' . intval( $delay_time ) . ');';
3201 + echo 'setTimeout(function(){' . $redirect_js . '}, ' . intval( $delay_time ) . ');'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3202 +
2553 3203 if ( empty( $args['doing_ajax'] ) ) {
2554 3204 echo '};';
2555 3205 }
2556 3206 echo '</script>';
@@ -2560,15 +3210,19 @@
2560 3210 * @since 3.0
2561 3211 *
2562 3212 * @param string $success_url
2563 3213 * @param string $success_msg
2564 - * @param array $args
3214 + * @param array $args
2565 3215 */
2566 3216 private static function get_redirect_message( $success_url, $success_msg, $args ) {
2567 - $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg" role="status">' . $success_msg . '<br/>' .
2568 - /* translators: %1$s: Start link HTML, %2$s: End link HTML */
2569 - sprintf( __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), '<a href="' . esc_url( $success_url ) . '">', '</a>' ) .
3217 + $success_msg = apply_filters( 'frm_content', $success_msg, $args['form'], $args['entry_id'] );
3218 + $success_msg = do_shortcode( FrmAppHelper::use_wpautop( $success_msg ) );
3219 +
3220 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
3221 + $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg" role="status">' . $success_msg . '<br/>' . // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
3222 + self::get_redirect_fallback_message( $success_url, $args ) .
2570 3223 '</div></div>';
3224 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
2571 3225
2572 3226 $redirect_args = array(
2573 3227 'entry_id' => $args['entry_id'],
2574 3228 'form_id' => $args['form']->id,
@@ -2578,11 +3232,40 @@
2578 3232 return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args );
2579 3233 }
2580 3234
2581 3235 /**
3236 + * Gets fallback message when redirecting failed.
3237 + *
3238 + * @since 6.3.1
3239 + *
3240 + * @param string $success_url Redirect URL.
3241 + * @param array $args Contains `form` object.
3242 + *
3243 + * @return string
3244 + */
3245 + private static function get_redirect_fallback_message( $success_url, $args ) {
3246 + $target = '';
3247 +
3248 + if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) {
3249 + $target = ' target="_blank"';
3250 + }
3251 +
3252 + return sprintf(
3253 + /* translators: %1$s: Start link HTML, %2$s: End link HTML */
3254 + __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ),
3255 + '<a href="' . esc_url( $success_url ) . '"' . $target . '>',
3256 + '</a>'
3257 + );
3258 + }
3259 +
3260 + /**
2582 3261 * Prepare to show the success message and empty form after submit
2583 3262 *
2584 3263 * @since 2.05
3264 + *
3265 + * @param array $atts
3266 + *
3267 + * @return void
2585 3268 */
2586 3269 public static function show_message_after_save( $atts ) {
2587 3270 $atts['message'] = self::prepare_submit_message( $atts['form'], $atts['entry_id'], $atts );
2588 3271
@@ -2588,8 +3271,9 @@
2588 3271
2589 3272 if ( ! isset( $atts['form']->options['show_form'] ) || $atts['form']->options['show_form'] ) {
2590 3273 if ( isset( $atts['action'] ) && 'update' === $atts['action'] && is_callable( array( 'FrmProEntriesController', 'show_front_end_form_with_entry' ) ) ) {
2591 3274 $entry = FrmEntry::getOne( $atts['entry_id'] );
3275 +
2592 3276 if ( $entry ) {
2593 3277 // This is copied from the Pro plugin.
2594 3278 $atts['conf_message'] = FrmProEntriesController::confirmation( 'message', $atts['form'], $atts['form']->options, $entry->id, $atts );
2595 3279 $atts['show_form'] = FrmProEntriesController::is_form_displayed_after_edit( $atts['form'] );
@@ -2598,9 +3282,9 @@
2598 3282 } else {
2599 3283 self::show_form_after_submit( $atts );
2600 3284 }
2601 3285 } else {
2602 - self::show_lone_success_messsage( $atts );
3286 + self::show_lone_success_message( $atts );
2603 3287 }
2604 3288 }
2605 3289
2606 3290 /**
@@ -2606,8 +3290,12 @@
2606 3290 /**
2607 3291 * Show an empty form
2608 3292 *
2609 3293 * @since 2.05
3294 + *
3295 + * @param array $args
3296 + *
3297 + * @return void
2610 3298 */
2611 3299 private static function show_form_after_submit( $args ) {
2612 3300 self::fill_atts_for_form_display( $args );
2613 3301
@@ -2626,12 +3314,11 @@
2626 3314 }
2627 3315 unset( $args );
2628 3316
2629 3317 $include_form_tag = apply_filters( 'frm_include_form_tag', true, $form );
3318 + $frm_settings = FrmAppHelper::get_settings();
3319 + $submit = $form->options['submit_value'] ?? $frm_settings->submit_value;
2630 3320
2631 - $frm_settings = FrmAppHelper::get_settings();
2632 - $submit = isset( $form->options['submit_value'] ) ? $form->options['submit_value'] : $frm_settings->submit_value;
2633 -
2634 3321 global $frm_vars;
2635 3322 self::maybe_load_css( $form, $values['custom_style'], $frm_vars['load_css'] );
2636 3323
2637 3324 $message_placement = self::message_placement( $form, $message );
@@ -2639,27 +3326,36 @@
2639 3326 include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
2640 3327 }
2641 3328
2642 3329 /**
2643 - * @return string - 'before', 'after', or 'submit'
3330 + * Gets message placement.
2644 3331 *
2645 3332 * @since 4.05.02
3333 + * @since 6.26 This method changed from `private` to `public`.
3334 + *
3335 + * @param object $form Form object.
3336 + * @param string $message The message.
3337 + *
3338 + * @return string Accepts 'before', 'after', or 'submit'.
2646 3339 */
2647 - private static function message_placement( $form, $message ) {
3340 + public static function message_placement( $form, $message ) {
2648 3341 $place = 'before';
2649 3342
2650 3343 if ( $message && isset( $form->options['form_class'] ) ) {
2651 - if ( strpos( $form->options['form_class'], 'frm_below_success' ) !== false ) {
3344 + if ( str_contains( $form->options['form_class'], 'frm_below_success' ) ) {
2652 3345 $place = 'after';
2653 - } elseif ( strpos( $form->options['form_class'], 'frm_inline_success' ) !== false ) {
3346 + } elseif ( str_contains( $form->options['form_class'], 'frm_inline_success' ) ) {
2654 3347 $place = 'submit';
2655 3348 }
2656 3349 }
2657 3350
2658 3351 /**
2659 - * @return string - 'before' or 'after'
3352 + * Filter the message placement.
2660 3353 *
2661 3354 * @since 4.05.02
3355 + *
3356 + * @param string $place Accepts 'before', 'after', or 'submit'.
3357 + * @param array $args Args.
2662 3358 */
2663 3359 return apply_filters( 'frm_message_placement', $place, compact( 'form', 'message' ) );
2664 3360 }
2665 3361
@@ -2666,8 +3362,12 @@
2666 3362 /**
2667 3363 * Get all the values needed on the new.php entry page
2668 3364 *
2669 3365 * @since 2.05
3366 + *
3367 + * @param array $args
3368 + *
3369 + * @return void
2670 3370 */
2671 3371 private static function fill_atts_for_form_display( &$args ) {
2672 3372 if ( ! isset( $args['title'] ) && isset( $args['show_title'] ) ) {
2673 3373 $args['title'] = $args['show_title'];
@@ -2692,21 +3392,24 @@
2692 3392 /**
2693 3393 * Show the success message without the form
2694 3394 *
2695 3395 * @since 2.05
3396 + *
3397 + * @param array $atts
3398 + *
3399 + * @return void
2696 3400 */
2697 - private static function show_lone_success_messsage( $atts ) {
3401 + private static function show_lone_success_message( $atts ) {
2698 3402 global $frm_vars;
2699 3403 $values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true );
2700 3404 self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] );
2701 3405
2702 3406 $include_extra_container = 'frm_forms' . FrmFormsHelper::get_form_style_class( $values );
3407 + $errors = array();
3408 + $form = $atts['form'];
3409 + $message = $atts['message'];
2703 3410
2704 - $errors = array();
2705 - $form = $atts['form'];
2706 - $message = $atts['message'];
2707 -
2708 - include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' );
3411 + include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php';
2709 3412 }
2710 3413
2711 3414 /**
2712 3415 * Prepare the success message before it's shown
@@ -2713,19 +3416,20 @@
2713 3416 *
2714 3417 * @since 2.05
2715 3418 * @since 6.0.x Added the third parameter.
2716 3419 *
2717 - * @param object $form Form object.
2718 - * @param int $entry_id Entry ID.
2719 - * @param array $args See {@see FrmFormsController::run_success_action()}.
3420 + * @param object $form Form object.
3421 + * @param int|string $entry_id Entry ID.
3422 + * @param array $args See {@see FrmFormsController::run_success_action()}.
3423 + *
2720 3424 * @return string
2721 3425 */
2722 3426 private static function prepare_submit_message( $form, $entry_id, $args = array() ) {
2723 3427 $frm_settings = FrmAppHelper::get_settings( array( 'current_form' => $form->id ) );
2724 - $opt = isset( $args['success_opt'] ) ? $args['success_opt'] : 'success';
3428 + $opt = $args['success_opt'] ?? 'success';
2725 3429
2726 3430 if ( $entry_id && is_numeric( $entry_id ) ) {
2727 - $message = isset( $form->options[ $opt . '_msg' ] ) ? $form->options[ $opt . '_msg' ] : $frm_settings->success_msg;
3431 + $message = $form->options[ $opt . '_msg' ] ?? $frm_settings->success_msg;
2728 3432 $class = 'frm_message';
2729 3433 } else {
2730 3434 $message = $frm_settings->failed_msg;
2731 3435 $class = FrmFormsHelper::form_error_class();
@@ -2742,9 +3446,9 @@
2742 3446 public static function front_head() {
2743 3447 $version = FrmAppHelper::plugin_version();
2744 3448 $suffix = FrmAppHelper::js_suffix();
2745 3449
2746 - if ( ! empty( $suffix ) && self::has_combo_js_file() ) {
3450 + if ( $suffix && self::has_combo_js_file() ) {
2747 3451 wp_register_script( 'formidable', FrmAppHelper::plugin_url() . '/js/frm.min.js', array( 'jquery' ), $version, true );
2748 3452 } else {
2749 3453 wp_register_script( 'formidable', FrmAppHelper::plugin_url() . "/js/formidable{$suffix}.js", array( 'jquery' ), $version, true );
2750 3454 }
@@ -2751,9 +3455,9 @@
2751 3455
2752 3456 add_filter( 'script_loader_tag', 'FrmFormsController::defer_script_loading', 10, 2 );
2753 3457
2754 3458 if ( FrmAppHelper::is_admin() ) {
2755 - // don't load this in back-end
3459 + // Don't load this in back-end
2756 3460 return;
2757 3461 }
2758 3462
2759 3463 FrmAppHelper::localize_script( 'front' );
@@ -2766,8 +3470,15 @@
2766 3470 public static function has_combo_js_file() {
2767 3471 return is_readable( FrmAppHelper::plugin_path() . '/js/frm.min.js' );
2768 3472 }
2769 3473
3474 + /**
3475 + * @param object $form
3476 + * @param int|string $this_load
3477 + * @param bool $global_load
3478 + *
3479 + * @return void
3480 + */
2770 3481 public static function maybe_load_css( $form, $this_load, $global_load ) {
2771 3482 $load_css = FrmForm::is_form_loaded( $form, $this_load, $global_load );
2772 3483
2773 3484 if ( ! $load_css ) {
@@ -2797,8 +3508,9 @@
2797 3508 return;
2798 3509 }
2799 3510
2800 3511 global $wp_styles;
3512 +
2801 3513 if ( is_array( $wp_styles->queue ) && in_array( 'formidable', $wp_styles->queue, true ) ) {
2802 3514 wp_print_styles( 'formidable' );
2803 3515 }
2804 3516 }
@@ -2813,32 +3525,57 @@
2813 3525 private static function should_load_late() {
2814 3526 return ! function_exists( 'aioseo' );
2815 3527 }
2816 3528
3529 + /**
3530 + * @param string $tag
3531 + * @param string $handle
3532 + *
3533 + * @return string
3534 + */
2817 3535 public static function defer_script_loading( $tag, $handle ) {
2818 - if ( 'captcha-api' == $handle && ! strpos( $tag, 'defer' ) ) {
2819 - $tag = str_replace( ' src', ' defer="defer" async="async" src', $tag );
3536 + if ( 'captcha-api' === $handle && ! str_contains( $tag, 'defer' ) ) {
3537 + return str_replace( ' src', ' defer="defer" async="async" src', $tag );
2820 3538 }
2821 3539
2822 3540 return $tag;
2823 3541 }
2824 3542
3543 + /**
3544 + * @param string $location
3545 + *
3546 + * @return void
3547 + */
2825 3548 public static function footer_js( $location = 'footer' ) {
2826 3549 global $frm_vars;
2827 3550
2828 3551 FrmStylesController::enqueue_css();
2829 3552
2830 - if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
2831 - // load formidable js
2832 - wp_enqueue_script( 'formidable' );
3553 + if ( FrmAppHelper::is_admin() || $location === 'header' || empty( $frm_vars['forms_loaded'] ) ) {
3554 + return;
2833 3555 }
3556 +
3557 + // Load formidable js
3558 + wp_enqueue_script( 'formidable' );
3559 +
3560 + FrmHoneypot::maybe_print_honeypot_js();
3561 +
3562 + if ( ! method_exists( 'FrmProFormsHelper', 'load_currency_js' ) ) {
3563 + // Load currency JS if Pro is not installed.
3564 + FrmFormsHelper::load_currency_js();
3565 + }
2834 3566 }
2835 3567
2836 3568 /**
2837 3569 * @since 2.0.8
3570 + *
3571 + * @param array $atts
3572 + * @param string $content
3573 + *
3574 + * @return void
2838 3575 */
2839 3576 private static function maybe_minimize_form( $atts, &$content ) {
2840 - // check if minimizing is turned on
3577 + // Check if minimizing is turned on
2841 3578 if ( self::is_minification_on( $atts ) ) {
2842 3579 $content = str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', $content );
2843 3580 }
2844 3581 }
@@ -2844,12 +3581,15 @@
2844 3581 }
2845 3582
2846 3583 /**
2847 3584 * @since 2.0.8
2848 - * @return boolean
3585 + *
3586 + * @param array $atts
3587 + *
3588 + * @return bool
2849 3589 */
2850 3590 private static function is_minification_on( $atts ) {
2851 - return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] );
3591 + return ! empty( $atts['minimize'] );
2852 3592 }
2853 3593
2854 3594 /**
2855 3595 * @since 5.0.16
@@ -2857,11 +3597,13 @@
2857 3597 * @return void
2858 3598 */
2859 3599 public static function landing_page_preview_option() {
2860 3600 $dir = apply_filters( 'frm_landing_page_preview_option', false );
3601 +
2861 3602 if ( false === $dir || ! file_exists( $dir . 'landing-page-preview-option.php' ) ) {
2862 3603 $dir = self::get_form_views_path();
2863 3604 }
3605 +
2864 3606 include $dir . 'landing-page-preview-option.php';
2865 3607 }
2866 3608
2867 3609 /**
@@ -2877,9 +3619,9 @@
2877 3619 * Create a page with an embedded formidable Gutenberg block.
2878 3620 *
2879 3621 * @since 5.2
2880 3622 *
2881 - * @return never
3623 + * @return void
2882 3624 */
2883 3625 public static function create_page_with_shortcode() {
2884 3626 if ( ! current_user_can( 'publish_posts' ) ) {
2885 3627 die( 0 );
@@ -2887,13 +3629,15 @@
2887 3629
2888 3630 check_ajax_referer( 'frm_ajax', 'nonce' );
2889 3631
2890 3632 $type = FrmAppHelper::get_post_param( 'type', '', 'sanitize_text_field' );
3633 +
2891 3634 if ( ! $type || ! in_array( $type, array( 'form', 'view' ), true ) ) {
2892 3635 die( 0 );
2893 3636 }
2894 3637
2895 3638 $object_id = FrmAppHelper::get_post_param( 'object_id', '', 'absint' );
3639 +
2896 3640 if ( ! $object_id ) {
2897 3641 die( 0 );
2898 3642 }
2899 3643
@@ -2905,13 +3649,15 @@
2905 3649 $postarr['post_content'] = apply_filters( 'frm_create_page_with_' . $type . '_shortcode_content', '', $object_id );
2906 3650 }
2907 3651
2908 3652 $name = FrmAppHelper::get_post_param( 'name', '', 'sanitize_text_field' );
3653 +
2909 3654 if ( $name ) {
2910 3655 $postarr['post_title'] = $name;
2911 3656 }
2912 3657
2913 3658 $success = wp_insert_post( $postarr );
3659 +
2914 3660 if ( ! is_numeric( $success ) || ! $success ) {
2915 3661 die( 0 );
2916 3662 }
2917 3663
@@ -2924,10 +3670,10 @@
2924 3670
2925 3671 /**
2926 3672 * @since 5.3
2927 3673 *
2928 - * @param string $content
2929 - * @param int $form_id
3674 + * @param int $form_id
3675 + *
2930 3676 * @return string
2931 3677 */
2932 3678 private static function get_page_shortcode_content_for_form( $form_id ) {
2933 3679 $shortcode = '[formidable id="' . $form_id . '"]';
@@ -2938,9 +3684,9 @@
2938 3684
2939 3685 /**
2940 3686 * Get page dropdown for AJAX request for embedding form in an existing page.
2941 3687 *
2942 - * @return never
3688 + * @return void
2943 3689 */
2944 3690 public static function get_page_dropdown() {
2945 3691 if ( ! current_user_can( 'publish_posts' ) ) {
2946 3692 die( 0 );
@@ -2947,10 +3693,10 @@
2947 3693 }
2948 3694
2949 3695 check_ajax_referer( 'frm_ajax', 'nonce' );
2950 3696
2951 - $html = FrmAppHelper::clip(
2952 - function() {
3697 + $html = FrmAppHelper::clip(
3698 + function () {
2953 3699 FrmAppHelper::maybe_autocomplete_pages_options(
2954 3700 array(
2955 3701 'field_name' => 'frm_page_dropdown',
2956 3702 'page_id' => '',
@@ -2958,60 +3704,55 @@
2958 3704 )
2959 3705 );
2960 3706 }
2961 3707 );
2962 - $post_type_object = get_post_type_object( 'page' );
2963 3708 wp_send_json(
2964 3709 array(
2965 3710 'html' => $html,
2966 - 'edit_page_url' => admin_url( sprintf( $post_type_object->_edit_link . '&action=edit', 0 ) ),
3711 + 'edit_page_url' => admin_url( sprintf( get_post_type_object( 'page' )->_edit_link . '&action=edit', 0 ) ),
2967 3712 )
2968 3713 );
2969 3714 }
2970 3715
2971 3716 /**
2972 - * @deprecated 4.0
3717 + * Prints necessary templates for the forms list page.
3718 + *
3719 + * @since 6.32
3720 + *
3721 + * @return void
2973 3722 */
2974 - public static function new_form( $values = array() ) {
2975 - FrmDeprecated::new_form( $values );
3723 + public static function print_forms_list_templates() {
3724 + if ( ! FrmAppHelper::on_form_listing_page() ) {
3725 + return;
3726 + }
3727 +
3728 + $screen = get_current_screen();
3729 +
3730 + if ( ! $screen ) {
3731 + return;
3732 + }
3733 +
3734 + $columns = get_column_headers( $screen );
3735 + $hidden = get_hidden_columns( $screen );
3736 + $skip_cols = array( 'cb', 'name', 'settings' );
3737 + $per_page = get_user_option( 'formidable_page_formidable_per_page' );
3738 + $show_screen_options = $screen->show_screen_options();
3739 +
3740 + if ( $per_page < 1 ) {
3741 + $per_page = 20;
3742 + }
3743 +
3744 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/forms-list-settings.php';
2976 3745 }
2977 3746
2978 3747 /**
2979 3748 * @deprecated 4.0
3749 + *
3750 + * @param array $values
3751 + *
3752 + * @return void
2980 3753 */
2981 3754 public static function create( $values = array() ) {
2982 3755 _deprecated_function( __METHOD__, '4.0', 'FrmFormsController::update' );
2983 3756 self::update( $values );
2984 - }
2985 -
2986 - /**
2987 - * @deprecated 3.0
2988 - * @codeCoverageIgnore
2989 - */
2990 - public static function bulk_create_template( $ids ) {
2991 - return FrmDeprecated::bulk_create_template( $ids );
2992 - }
2993 -
2994 - /**
2995 - * @deprecated 3.0
2996 - * @codeCoverageIgnore
2997 - */
2998 - public static function edit_key() {
2999 - FrmDeprecated::edit_key();
3000 - }
3001 -
3002 - /**
3003 - * @deprecated 3.0
3004 - * @codeCoverageIgnore
3005 - */
3006 - public static function edit_description() {
3007 - FrmDeprecated::edit_description();
3008 - }
3009 -
3010 - /**
3011 - * @deprecated 4.08
3012 - * @since 3.06
3013 - */
3014 - public static function add_new() {
3015 - _deprecated_function( __FUNCTION__, '4.08' );
3016 3757 }
3017 3758 }