Completed
Push — master ( 67ab10...dbf55d )
by Stephanie
03:13
created

FrmFormsController   F

Complexity

Total Complexity 302

Size/Duplication

Total Lines 1764
Duplicated Lines 0 %

Coupling/Cohesion

Components 5
Dependencies 13

Importance

Changes 0
Metric Value
dl 0
loc 1764
rs 0.8
c 0
b 0
f 0
wmc 302
lcom 5
cbo 13

97 Methods

Rating   Name   Duplication   Size   Complexity  
A menu() 0 9 2
A maybe_load_listing_hooks() 0 11 3
A head() 0 7 2
A register_widgets() 0 4 1
A prevent_divi_conflict() 0 4 1
A list_form() 0 9 1
A new_form() 0 25 5
A create_default_email_action() 0 8 2
B create() 0 39 9
A edit() 0 6 2
A settings() 0 8 3
A update_settings() 0 17 2
B update() 0 29 7
A _create_from_template() 0 14 2
A duplicate() 0 12 3
A page_preview() 0 11 3
A show_page_preview() 0 3 1
A preview() 0 18 2
A load_wp() 0 9 3
A set_preview_query() 0 20 2
A load_theme_preview() 0 8 1
A preview_page_title() 0 6 2
A preview_title() 0 3 1
A preview_content() 0 6 2
A load_direct_preview() 0 15 3
A untrash() 0 3 1
A bulk_untrash() 0 8 1
A trash() 0 3 1
A change_form_status() 0 42 3
A bulk_trash() 0 25 3
A destroy() 0 17 2
A bulk_destroy() 0 15 3
A delete_all() 0 13 2
A insert_form_button() 0 9 2
A insert_form_popup() 0 19 2
B get_shortcode_opts() 0 47 5
A display_forms_list() 0 23 4
A get_columns() 0 36 2
A get_sortable_columns() 0 9 1
A hidden_columns() 0 15 2
A save_per_page() 0 6 2
B get_edit_vars() 0 46 9
A get_settings_vars() 0 27 4
A clean_submit_html() 0 5 3
A mb_tags_box() 0 13 2
A advanced_helpers() 0 29 3
A get_advanced_shortcodes() 0 18 1
A user_shortcodes() 0 13 1
A get_shortcode_helpers() 0 32 3
A form_classes() 0 9 4
A get_email_html() 0 13 1
A filter_content() 0 15 3
A get_entry_by_param() 0 9 5
A replace_content_shortcodes() 0 3 1
C process_bulk_form_actions() 0 49 13
B add_default_templates() 0 41 8
F route() 0 67 20
A json_error() 0 4 1
A admin_bar_css() 0 8 3
A admin_bar_configure() 0 21 5
A add_menu_to_admin_bar() 0 14 1
A add_forms_to_admin_bar() 0 17 3
A get_form_shortcode() 0 30 5
B show_form() 0 40 6
A maybe_get_form_to_show() 0 12 5
A is_viewable_draft_form() 0 5 3
A user_should_login() 0 3 2
A user_has_permission_to_view() 0 3 5
A get_form() 0 15 1
A enqueue_scripts() 0 3 1
B get_form_contents() 0 39 7
A get_saved_errors() 0 10 4
A just_created_entry() 0 4 4
A get_confirmation_method() 0 11 6
A maybe_trigger_redirect() 0 17 3
A trigger_redirect() 0 14 2
A run_success_action() 0 16 6
A load_page_after_submit() 0 12 3
B redirect_after_submit() 0 35 6
A get_redirect_message() 0 12 1
A show_message_after_save() 0 9 3
A show_form_after_submit() 0 23 3
A fill_atts_for_form_display() 0 12 1
A show_lone_success_messsage() 0 12 1
A prepare_submit_message() 0 14 4
A front_head() 0 20 4
A has_combo_js_file() 0 3 1
A maybe_load_css() 0 9 2
A defer_script_loading() 0 6 3
A footer_js() 0 10 4
A maybe_minimize_form() 0 6 2
A is_minification_on() 0 3 2
A bulk_create_template() 0 10 2
A register_pro_scripts() 0 6 2
A edit_key() 0 6 1
A edit_description() 0 6 1
A edit_in_place_value() 0 14 1

How to fix   Complexity   

Complex Class

Complex classes like FrmFormsController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use FrmFormsController, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
class FrmFormsController {
4
5
    public static function menu() {
6
		$menu_label = __( 'Forms', 'formidable' );
7
		if ( ! FrmAppHelper::pro_is_installed() ) {
8
			$menu_label .= ' (Lite)';
9
		}
10
		add_submenu_page( 'formidable', 'Formidable | ' . $menu_label, $menu_label, 'frm_view_forms', 'formidable', 'FrmFormsController::route' );
11
12
		self::maybe_load_listing_hooks();
13
    }
14
15
	public static function maybe_load_listing_hooks() {
16
		$action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
17
		if ( ! empty( $action ) && ! in_array( $action, array( 'list', 'trash', 'untrash', 'destroy' ) ) ) {
18
			return;
19
		}
20
21
		add_filter( 'get_user_option_managetoplevel_page_formidablecolumnshidden', 'FrmFormsController::hidden_columns' );
22
23
		add_filter( 'manage_toplevel_page_formidable_columns', 'FrmFormsController::get_columns', 0 );
24
		add_filter( 'manage_toplevel_page_formidable_sortable_columns', 'FrmFormsController::get_sortable_columns' );
25
	}
26
27
    public static function head() {
28
		wp_enqueue_script( 'formidable-editinplace' );
29
30
        if ( wp_is_mobile() ) {
31
    		wp_enqueue_script( 'jquery-touch-punch' );
32
    	}
33
    }
34
35
	public static function register_widgets() {
36
		require_once( FrmAppHelper::plugin_path() . '/classes/widgets/FrmShowForm.php' );
37
		register_widget( 'FrmShowForm' );
38
	}
39
40
	/**
41
	 * By default, Divi processes form shortcodes on the edit post page.
42
	 * Now that won't do.
43
	 *
44
	 * @since 3.01
45
	 */
46
	public static function prevent_divi_conflict( $shortcodes ) {
47
		$shortcodes[] = 'formidable';
48
		return $shortcodes;
49
	}
50
51
	public static function list_form() {
52
		FrmAppHelper::permission_check( 'frm_view_forms' );
53
54
		$params = FrmForm::list_page_params();
55
		$errors = self::process_bulk_form_actions( array() );
56
		$errors = apply_filters( 'frm_admin_list_form_action', $errors );
57
58
		return self::display_forms_list( $params, '', $errors );
59
	}
60
61
	public static function new_form( $values = array() ) {
62
		FrmAppHelper::permission_check( 'frm_edit_forms' );
63
64
        global $frm_vars;
65
66
		$action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
67
		$action = empty( $values ) ? FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ) : $values[ $action ];
68
69
		if ( $action == 'create' ) {
70
			self::create( $values );
71
			return;
72
		} else if ( $action == 'new' ) {
73
			$frm_field_selection = FrmField::field_selection();
74
			$values = FrmFormsHelper::setup_new_vars( $values );
75
            $id = FrmForm::create( $values );
76
			$form = FrmForm::getOne( $id );
77
78
			self::create_default_email_action( $form );
79
80
			$all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
81
82
            $values['id'] = $id;
83
			require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php' );
84
        }
85
    }
86
87
	/**
88
	 * Create the default email action
89
	 *
90
	 * @since 2.02.11
91
	 *
92
	 * @param object $form
93
	 */
94
    private static function create_default_email_action( $form ) {
95
    	$create_email = apply_filters( 'frm_create_default_email_action', true, $form );
96
97
	    if ( $create_email ) {
98
		    $action_control = FrmFormActionsController::get_form_actions( 'email' );
99
		    $action_control->create( $form->id );
100
	    }
101
    }
102
103
	public static function create( $values = array() ) {
104
		FrmAppHelper::permission_check( 'frm_edit_forms' );
105
106
        global $frm_vars;
107
        if ( empty( $values ) ) {
108
            $values = $_POST;
109
        }
110
111
        //Set radio button and checkbox meta equal to "other" value
112
        if ( FrmAppHelper::pro_is_installed() ) {
113
            $values = FrmProEntry::mod_other_vals( $values, 'back' );
114
        }
115
116
		$id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
117
118
        if ( ! current_user_can( 'frm_edit_forms' ) || ( $_POST && ( ! isset( $values['frm_save_form'] ) || ! wp_verify_nonce( $values['frm_save_form'], 'frm_save_form_nonce' ) ) ) ) {
119
            $frm_settings = FrmAppHelper::get_settings();
120
            $errors = array( 'form' => $frm_settings->admin_permission );
121
        } else {
122
			$errors = FrmForm::validate( $values );
123
        }
124
125
		if ( count( $errors ) > 0 ) {
126
            $hide_preview = true;
127
			$frm_field_selection = FrmField::field_selection();
128
            $form = FrmForm::getOne( $id );
129
			$fields = FrmField::get_all_for_form( $id );
130
131
			$values = FrmAppHelper::setup_edit_vars( $form, 'forms', '', true );
132
			$values['fields'] = $fields;
133
			$all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
134
135
			require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php' );
136
        } else {
137
            FrmForm::update( $id, $values, true );
138
			$url = admin_url( 'admin.php?page=formidable&frm_action=settings&id=' . $id );
139
			die( FrmAppHelper::js_redirect( $url ) ); // WPCS: XSS ok.
140
        }
141
    }
142
143
    public static function edit( $values = false ) {
144
		FrmAppHelper::permission_check( 'frm_edit_forms' );
145
146
		$id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
147
		return self::get_edit_vars( $id );
148
    }
149
150
    public static function settings( $id = false, $message = '' ) {
151
		FrmAppHelper::permission_check( 'frm_edit_forms' );
152
153
		if ( ! $id || ! is_numeric( $id ) ) {
154
			$id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
155
        }
156
		return self::get_settings_vars( $id, array(), $message );
157
    }
158
159
    public static function update_settings() {
160
		FrmAppHelper::permission_check( 'frm_edit_forms' );
161
162
		$id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
163
164
		$errors = FrmForm::validate( $_POST );
165
		if ( count( $errors ) > 0 ) {
166
			return self::get_settings_vars( $id, $errors );
167
		}
168
169
		do_action( 'frm_before_update_form_settings', $id );
170
171
		FrmForm::update( $id, $_POST );
172
173
        $message = __( 'Settings Successfully Updated', 'formidable' );
174
		return self::get_settings_vars( $id, array(), $message );
175
    }
176
177
	public static function update( $values = array() ) {
178
		if ( empty( $values ) ) {
179
            $values = $_POST;
180
        }
181
182
        //Set radio button and checkbox meta equal to "other" value
183
        if ( FrmAppHelper::pro_is_installed() ) {
184
            $values = FrmProEntry::mod_other_vals( $values, 'back' );
185
        }
186
187
        $errors = FrmForm::validate( $values );
188
        $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form', 'frm_save_form_nonce' );
189
        if ( $permission_error !== false ) {
190
            $errors['form'] = $permission_error;
191
        }
192
193
		$id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
194
195
		if ( count( $errors ) > 0 ) {
196
            return self::get_edit_vars( $id, $errors );
197
		} else {
198
            FrmForm::update( $id, $values );
199
            $message = __( 'Form was Successfully Updated', 'formidable' );
200
            if ( defined( 'DOING_AJAX' ) ) {
201
				wp_die( esc_html( $message ) );
202
            }
203
			return self::get_edit_vars( $id, array(), $message );
204
        }
205
    }
206
207
	/**
208
	 * Redirect to the url for creating from a template
209
	 * Also delete the current form
210
	 * @since 2.0
211
	 */
212
	public static function _create_from_template() {
213
		FrmAppHelper::permission_check( 'frm_edit_forms' );
214
		check_ajax_referer( 'frm_ajax', 'nonce' );
215
216
		$current_form = FrmAppHelper::get_param( 'this_form', '', 'get', 'absint' );
217
		$template_id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
218
219
		if ( $current_form ) {
220
			FrmForm::destroy( $current_form );
221
		}
222
223
		echo esc_url_raw( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template_id ) ) );
224
		wp_die();
225
	}
226
227
    public static function duplicate() {
228
		FrmAppHelper::permission_check( 'frm_edit_forms' );
229
230
		$params = FrmForm::list_page_params();
231
        $form = FrmForm::duplicate( $params['id'], $params['template'], true );
232
        $message = $params['template'] ? __( 'Form template was Successfully Created', 'formidable' ) : __( 'Form was Successfully Copied', 'formidable' );
233
        if ( $form ) {
234
			return self::get_edit_vars( $form, array(), $message, true );
235
        } else {
236
			return self::display_forms_list( $params, __( 'There was a problem creating the new template.', 'formidable' ) );
237
        }
238
    }
239
240
    public static function page_preview() {
241
		$params = FrmForm::list_page_params();
242
        if ( ! $params['form'] ) {
243
            return;
244
        }
245
246
        $form = FrmForm::getOne( $params['form'] );
247
		if ( $form ) {
248
			return self::show_form( $form->id, '', true, true );
249
		}
250
    }
251
252
	/**
253
	 * @since 3.0
254
	 */
255
	public static function show_page_preview() {
256
		echo self::page_preview(); // WPCS: XSS ok.
257
	}
258
259
    public static function preview() {
260
        do_action( 'frm_wp' );
261
262
        global $frm_vars;
263
        $frm_vars['preview'] = true;
264
265
		self::load_wp();
266
267
		$include_theme = FrmAppHelper::get_param( 'theme', '', 'get', 'absint' );
268
		if ( $include_theme ) {
269
			self::set_preview_query();
270
			self::load_theme_preview();
271
		} else {
272
			self::load_direct_preview();
273
		}
274
275
		wp_die();
276
	}
277
278
	/**
279
	 * @since 3.0
280
	 */
281
	private static function load_wp() {
282
		if ( ! defined( 'ABSPATH' ) && ! defined( 'XMLRPC_REQUEST' ) ) {
283
			global $wp;
284
			$root = dirname( dirname( dirname( dirname( __FILE__ ) ) ) );
285
			include_once( $root . '/wp-config.php' );
286
			$wp->init();
287
			$wp->register_globals();
288
		}
289
	}
290
291
	private static function set_preview_query() {
292
		$random_page = get_posts(
293
			array(
294
				'numberposts' => 1,
295
				'orderby'     => 'date',
296
				'order'       => 'ASC',
297
				'post_type'   => 'page',
298
			)
299
		);
300
301
		if ( ! empty( $random_page ) ) {
302
			$random_page = reset( $random_page );
303
			query_posts(
0 ignored issues
show
Coding Style introduced by
The use of function query_posts() is discouraged; use WP_Query() instead
Loading history...
304
				array(
305
					'post_type' => 'page',
306
					'page_id'   => $random_page->ID,
307
				)
308
			);
309
		}
310
	}
311
312
	/**
313
	 * @since 3.0
314
	 */
315
	private static function load_theme_preview() {
316
		add_filter( 'wp_title', 'FrmFormsController::preview_title', 9999 );
317
		add_filter( 'the_title', 'FrmFormsController::preview_page_title', 9999 );
318
		add_filter( 'the_content', 'FrmFormsController::preview_content', 9999 );
319
		add_action( 'loop_no_results', 'FrmFormsController::show_page_preview' );
320
		add_filter( 'is_active_sidebar', '__return_false' );
321
		get_template_part( 'page' );
322
	}
323
324
325
	/**
326
	 * Set the page title for the theme preview page
327
	 *
328
	 * @since 3.0
329
	 */
330
	public static function preview_page_title( $title ) {
331
		if ( in_the_loop() ) {
332
			$title = self::preview_title( $title );
333
		}
334
		return $title;
335
	}
336
337
	/**
338
	 * Set the page title for the theme preview page
339
	 *
340
	 * @since 3.0
341
	 */
342
	public static function preview_title( $title ) {
343
		return __( 'Form Preview', 'formidable' );
344
	}
345
346
	/**
347
	 * Set the page content for the theme preview page
348
	 *
349
	 * @since 3.0
350
	 */
351
	public static function preview_content( $content ) {
352
		if ( in_the_loop() ) {
353
			$content = FrmFormsController::show_page_preview();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $content is correct as \FrmFormsController::show_page_preview() (which targets FrmFormsController::show_page_preview()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
354
		}
355
		return $content;
356
	}
357
358
	/**
359
	 * @since 3.0
360
	 */
361
	private static function load_direct_preview() {
362
		header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
363
364
		$key = FrmAppHelper::simple_get( 'form', 'sanitize_title' );
365
		if ( $key == '' ) {
366
			$key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' );
367
		}
368
369
		$form = FrmForm::getAll( array( 'form_key' => $key ), '', 1 );
370
		if ( empty( $form ) ) {
371
			$form = FrmForm::getAll( array(), '', 1 );
372
		}
373
374
		require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' );
375
	}
376
377
    public static function untrash() {
378
		self::change_form_status( 'untrash' );
379
    }
380
381
	public static function bulk_untrash( $ids ) {
382
		FrmAppHelper::permission_check( 'frm_edit_forms' );
383
384
        $count = FrmForm::set_status( $ids, 'published' );
385
386
		$message = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), 1 );
387
        return $message;
388
    }
389
390
    public static function trash() {
391
		self::change_form_status( 'trash' );
392
    }
393
394
	/**
395
	 * @param string $status
396
	 *
397
	 * @return int The number of forms changed
398
	 */
399
	public static function change_form_status( $status ) {
400
		$available_status = array(
401
			'untrash' => array(
402
				'permission' => 'frm_edit_forms',
403
				'new_status' => 'published',
404
			),
405
			'trash'   => array(
406
				'permission' => 'frm_delete_forms',
407
				'new_status' => 'trash',
408
			),
409
		);
410
411
		if ( ! isset( $available_status[ $status ] ) ) {
412
			return;
413
		}
414
415
		FrmAppHelper::permission_check( $available_status[ $status ]['permission'] );
416
417
		$params = FrmForm::list_page_params();
418
419
		//check nonce url
420
		check_admin_referer( $status . '_form_' . $params['id'] );
421
422
		$count = 0;
423
		if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) {
424
			$count++;
425
		}
426
427
		$form_type = FrmAppHelper::get_simple_request(
428
			array(
429
				'param' => 'form_type',
430
				'type' => 'request',
431
			)
432
		);
433
434
		$available_status['untrash']['message'] = sprintf( _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
435
		$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>' );
436
437
		$message = $available_status[ $status ]['message'];
438
439
		self::display_forms_list( $params, $message );
440
	}
441
442
	public static function bulk_trash( $ids ) {
443
		FrmAppHelper::permission_check( 'frm_delete_forms' );
444
445
        $count = 0;
446
        foreach ( $ids as $id ) {
447
            if ( FrmForm::trash( $id ) ) {
448
                $count++;
449
            }
450
        }
451
452
		$current_page = FrmAppHelper::get_simple_request(
453
			array(
454
				'param' => 'form_type',
455
				'type' => 'request',
456
			)
457
		);
458
		$message = sprintf(
459
			_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' ),
460
			$count,
461
			'<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' ) ) . '">',
462
			'</a>'
463
		);
464
465
        return $message;
466
    }
467
468
    public static function destroy() {
469
		FrmAppHelper::permission_check( 'frm_delete_forms' );
470
471
		$params = FrmForm::list_page_params();
472
473
        //check nonce url
474
		check_admin_referer( 'destroy_form_' . $params['id'] );
475
476
        $count = 0;
477
        if ( FrmForm::destroy( $params['id'] ) ) {
478
            $count++;
479
        }
480
481
		$message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
482
483
		self::display_forms_list( $params, $message );
484
    }
485
486
	public static function bulk_destroy( $ids ) {
487
		FrmAppHelper::permission_check( 'frm_delete_forms' );
488
489
        $count = 0;
490
        foreach ( $ids as $id ) {
491
            $d = FrmForm::destroy( $id );
492
            if ( $d ) {
493
                $count++;
494
            }
495
        }
496
497
		$message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
498
499
        return $message;
500
    }
501
502
    private static function delete_all() {
503
        //check nonce url
504
		$permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' );
505
        if ( $permission_error !== false ) {
506
			self::display_forms_list( array(), '', array( $permission_error ) );
507
            return;
508
        }
509
510
		$count = FrmForm::scheduled_delete( time() );
511
		$message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count );
512
513
		self::display_forms_list( array(), $message );
514
    }
515
516
	/**
517
	* Inserts Formidable button
518
	* Hook exists since 2.5.0
519
	*
520
	* @since 2.0.15
521
	*/
522
	public static function insert_form_button() {
523
		if ( current_user_can( 'frm_view_forms' ) ) {
524
			$menu_name = FrmAppHelper::get_menu_name();
525
			$content = '<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' ) . '">
526
				<span class="frm-buttons-icon wp-media-buttons-icon"></span> ' .
527
				$menu_name . '</a>';
528
			echo wp_kses_post( $content );
529
		}
530
	}
531
532
    public static function insert_form_popup() {
533
		$page = basename( FrmAppHelper::get_server_value( 'PHP_SELF' ) );
534
		if ( ! in_array( $page, array( 'post.php', 'page.php', 'page-new.php', 'post-new.php' ) ) ) {
535
            return;
536
        }
537
538
        FrmAppHelper::load_admin_wide_js();
539
540
        $shortcodes = array(
541
			'formidable' => array(
542
				'name'  => __( 'Form', 'formidable' ),
543
				'label' => __( 'Insert a Form', 'formidable' ),
544
			),
545
        );
546
547
		$shortcodes = apply_filters( 'frm_popup_shortcodes', $shortcodes );
548
549
		include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/insert_form_popup.php' );
550
    }
551
552
    public static function get_shortcode_opts() {
553
		FrmAppHelper::permission_check( 'frm_view_forms' );
554
        check_ajax_referer( 'frm_ajax', 'nonce' );
555
556
		$shortcode = FrmAppHelper::get_post_param( 'shortcode', '', 'sanitize_text_field' );
557
		if ( empty( $shortcode ) ) {
558
            wp_die();
559
        }
560
561
		echo '<div id="sc-opts-' . esc_attr( $shortcode ) . '" class="frm_shortcode_option">';
562
		echo '<input type="radio" name="frmsc" value="' . esc_attr( $shortcode ) . '" id="sc-' . esc_attr( $shortcode ) . '" class="frm_hidden" />';
563
564
        $form_id = '';
565
        $opts = array();
566
		switch ( $shortcode ) {
567
            case 'formidable':
568
                $opts = array(
569
					'form_id'       => 'id',
570
                    //'key' => ',
571
					'title'         => array(
572
						'val'   => 1,
573
						'label' => __( 'Display form title', 'formidable' ),
574
					),
575
					'description'   => array(
576
						'val'   => 1,
577
						'label' => __( 'Display form description', 'formidable' ),
578
					),
579
					'minimize'      => array(
580
						'val'   => 1,
581
						'label' => __( 'Minimize form HTML', 'formidable' ),
582
					),
583
                );
584
        }
585
		$opts = apply_filters( 'frm_sc_popup_opts', $opts, $shortcode );
586
587
		if ( isset( $opts['form_id'] ) && is_string( $opts['form_id'] ) ) {
588
			// allow other shortcodes to use the required form id option
589
			$form_id = $opts['form_id'];
590
			unset( $opts['form_id'] );
591
		}
592
593
		include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' );
594
595
        echo '</div>';
596
597
        wp_die();
598
    }
599
600
	public static function display_forms_list( $params = array(), $message = '', $errors = array() ) {
601
        FrmAppHelper::permission_check( 'frm_view_forms' );
602
603
        global $wpdb, $frm_vars;
604
605
		if ( empty( $params ) ) {
606
			$params = FrmForm::list_page_params();
607
        }
608
609
        $wp_list_table = new FrmFormsListHelper( compact( 'params' ) );
610
611
        $pagenum = $wp_list_table->get_pagenum();
612
613
        $wp_list_table->prepare_items();
614
615
        $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
616
        if ( $pagenum > $total_pages && $total_pages > 0 ) {
617
			wp_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
618
            die();
619
        }
620
621
		require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/list.php' );
622
    }
623
624
	public static function get_columns( $columns ) {
625
	    $columns['cb'] = '<input type="checkbox" />';
626
	    $columns['id'] = 'ID';
627
628
		$type = FrmAppHelper::get_simple_request(
629
			array(
630
				'param'   => 'form_type',
631
				'type'    => 'request',
632
				'default' => 'published',
633
			)
634
		);
635
636
        if ( 'template' == $type ) {
637
            $columns['name']        = __( 'Template Name', 'formidable' );
638
            $columns['type']        = __( 'Type', 'formidable' );
639
            $columns['form_key']    = __( 'Key', 'formidable' );
640
        } else {
641
            $columns['name']        = __( 'Form Title', 'formidable' );
642
            $columns['entries']     = __( 'Entries', 'formidable' );
643
            $columns['form_key']    = __( 'Key', 'formidable' );
644
            $columns['shortcode']   = __( 'Shortcodes', 'formidable' );
645
        }
646
647
        $columns['created_at'] = __( 'Date', 'formidable' );
648
649
		add_screen_option(
650
			'per_page',
651
			array(
652
				'label'   => __( 'Forms', 'formidable' ),
653
				'default' => 20,
654
				'option'  => 'formidable_page_formidable_per_page',
655
			)
656
		);
657
658
        return $columns;
659
	}
660
661
	public static function get_sortable_columns() {
662
		return array(
663
			'id'            => 'id',
664
			'name'          => 'name',
665
			'description'   => 'description',
666
			'form_key'      => 'form_key',
667
			'created_at'    => 'created_at',
668
		);
669
	}
670
671
	public static function hidden_columns( $hidden_columns ) {
672
		$type = FrmAppHelper::get_simple_request(
673
			array(
674
				'param' => 'form_type',
675
				'type'  => 'request',
676
			)
677
		);
678
679
		if ( $type === 'template' ) {
680
			$hidden_columns[] = 'id';
681
			$hidden_columns[] = 'form_key';
682
		}
683
684
		return $hidden_columns;
685
	}
686
687
	public static function save_per_page( $save, $option, $value ) {
688
        if ( $option == 'formidable_page_formidable_per_page' ) {
689
            $save = (int) $value;
690
        }
691
        return $save;
692
    }
693
694
	private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
695
        global $frm_vars;
696
697
        $form = FrmForm::getOne( $id );
698
        if ( ! $form ) {
699
            wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) );
700
        }
701
702
        if ( $form->parent_form_id ) {
703
			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( admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form->parent_form_id ) ) . '">', '</a>' ) );
704
        }
705
706
		$frm_field_selection = FrmField::field_selection();
707
		$fields = FrmField::get_all_for_form( $form->id );
708
709
        // Automatically add end section fields if they don't exist (2.0 migration)
710
        $reset_fields = false;
711
        FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
712
713
        if ( $reset_fields ) {
714
            $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' );
715
        }
716
717
		unset( $end_section_values, $last_order, $open, $reset_fields );
718
719
		$args = array( 'parent_form_id' => $form->id );
720
		$values = FrmAppHelper::setup_edit_vars( $form, 'forms', '', true, array(), $args );
721
		$values['fields'] = $fields;
722
723
        $edit_message = __( 'Form was Successfully Updated', 'formidable' );
724
        if ( $form->is_template && $message == $edit_message ) {
725
            $message = __( 'Template was Successfully Updated', 'formidable' );
726
        }
727
728
		$all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
729
730
        if ( $form->default_template ) {
731
			wp_die( esc_html__( 'That template cannot be edited', 'formidable' ) );
732
		} elseif ( defined( 'DOING_AJAX' ) ) {
733
            wp_die();
734
        } else if ( $create_link ) {
735
			require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php' );
736
        } else {
737
			require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' );
738
        }
739
    }
740
741
	public static function get_settings_vars( $id, $errors = array(), $message = '' ) {
742
		FrmAppHelper::permission_check( 'frm_edit_forms' );
743
744
        global $frm_vars;
745
746
        $form = FrmForm::getOne( $id );
747
748
		$fields = FrmField::get_all_for_form( $id );
749
		$values = FrmAppHelper::setup_edit_vars( $form, 'forms', $fields, true );
750
751
		if ( isset( $values['default_template'] ) && $values['default_template'] ) {
752
			wp_die( esc_html__( 'That template cannot be edited', 'formidable' ) );
753
		}
754
755
		self::clean_submit_html( $values );
756
757
        $action_controls = FrmFormActionsController::get_form_actions();
758
759
		$sections = apply_filters( 'frm_add_form_settings_section', array(), $values );
760
        $pro_feature = FrmAppHelper::pro_is_installed() ? '' : ' class="pro_feature"';
761
762
		$styles = apply_filters( 'frm_get_style_opts', array() );
763
764
		$first_h3 = 'frm_first_h3';
765
766
		require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' );
767
    }
768
769
	/**
770
	 * Replace old Submit Button href with new href to avoid errors in Chrome
771
	 *
772
	 * @since 2.03.08
773
	 *
774
	 * @param array|boolean $values
775
	 */
776
	private static function clean_submit_html( &$values ) {
777
		if ( is_array( $values ) && isset( $values['submit_html'] ) ) {
778
			$values['submit_html'] = str_replace( 'javascript:void(0)', '#', $values['submit_html'] );
779
		}
780
	}
781
782
    public static function mb_tags_box( $form_id, $class = '' ) {
783
		$fields = FrmField::get_all_for_form( $form_id, '', 'include' );
784
        $linked_forms = array();
785
        $col = 'one';
786
		$settings_tab = FrmAppHelper::is_admin_page( 'formidable' ) ? true : false;
787
788
		$cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
789
		$entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
790
791
		$advanced_helpers = self::advanced_helpers( compact( 'fields', 'form_id' ) );
792
793
		include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' );
794
    }
795
796
	/**
797
	 * @since 3.04.01
798
	 */
799
	private static function advanced_helpers( $atts ) {
800
		$advanced_helpers = array(
801
			'default' => array(
802
				'heading' => __( 'Customize the field values with the following parameters. Click to see a sample.', 'formidable' ),
803
				'codes'   => self::get_advanced_shortcodes(),
804
			),
805
		);
806
807
		$user_fields = self::user_shortcodes();
808
		if ( ! empty( $user_fields ) ) {
809
			$user_helpers = array();
810
			foreach ( $user_fields as $uk => $uf ) {
811
				$user_helpers[ '|user_id| show="' . $uk . '"' ] = $uf;
812
				unset( $uk, $uf );
813
			}
814
815
			$advanced_helpers['user_id'] = array(
816
				'heading' => __( 'Insert user information', 'formidable' ),
817
				'codes'   => $user_helpers,
818
			);
819
		}
820
821
		/**
822
		 * Add extra helper shortcodes on the Advanced tab in form settings and views
823
		 * @since 3.04.01
824
		 * @param array $atts - Includes fields and form_id
825
		 */
826
		return apply_filters( 'frm_advanced_helpers', $advanced_helpers, $atts );
827
	}
828
829
	/**
830
	 * Get an array of the options to display in the advanced tab
831
	 * of the customization panel
832
	 * @since 2.0.6
833
	 */
834
	private static function get_advanced_shortcodes() {
835
		$adv_shortcodes = array(
836
			'sep=", "'       => array(
837
				'label' => __( 'Separator', 'formidable' ),
838
				'title' => __( 'Use a different separator for checkbox fields', 'formidable' ),
839
			),
840
			'format="d-m-Y"' => __( 'Date Format', 'formidable' ),
841
			'show="field_label"' => __( 'Field Label', 'formidable' ),
842
			'wpautop=0'      => array(
843
				'label' => __( 'No Auto P', 'formidable' ),
844
				'title' => __( 'Do not automatically add any paragraphs or line breaks', 'formidable' ),
845
			),
846
		);
847
		$adv_shortcodes = apply_filters( 'frm_advanced_shortcodes', $adv_shortcodes );
848
		// __( 'Leave blank instead of defaulting to User Login', 'formidable' ) : blank=1
849
850
		return $adv_shortcodes;
851
	}
852
853
	/**
854
	 * @since 3.04.01
855
	 */
856
	private static function user_shortcodes() {
857
		$options = array(
858
			'ID'            => __( 'User ID', 'formidable' ),
859
			'first_name'    => __( 'First Name', 'formidable' ),
860
			'last_name'     => __( 'Last Name', 'formidable' ),
861
			'display_name'  => __( 'Display Name', 'formidable' ),
862
			'user_login'    => __( 'User Login', 'formidable' ),
863
			'user_email'    => __( 'Email', 'formidable' ),
864
			'avatar'        => __( 'Avatar', 'formidable' ),
865
			'author_link'   => __( 'Author Link', 'formidable' ),
866
		);
867
		return apply_filters( 'frm_user_shortcodes', $options );
868
	}
869
870
	/**
871
	 * Get an array of the helper shortcodes to display in the customization panel
872
	 * @since 2.0.6
873
	 */
874
	private static function get_shortcode_helpers( $settings_tab ) {
875
		$entry_shortcodes = array(
876
			'id'        => __( 'Entry ID', 'formidable' ),
877
			'key'       => __( 'Entry Key', 'formidable' ),
878
			'post_id'   => __( 'Post ID', 'formidable' ),
879
			'ip'        => __( 'User IP', 'formidable' ),
880
			'created-at' => __( 'Entry created', 'formidable' ),
881
			'updated-at' => __( 'Entry updated', 'formidable' ),
882
			''          => '',
883
			'siteurl'   => __( 'Site URL', 'formidable' ),
884
			'sitename'  => __( 'Site Name', 'formidable' ),
885
        );
886
887
		if ( ! FrmAppHelper::pro_is_installed() ) {
888
			unset( $entry_shortcodes['post_id'] );
889
		}
890
891
		if ( $settings_tab ) {
892
			$entry_shortcodes['default-message'] = __( 'Default Msg', 'formidable' );
893
			$entry_shortcodes['default-html'] = __( 'Default HTML', 'formidable' );
894
			$entry_shortcodes['default-plain'] = __( 'Default Plain', 'formidable' );
895
		}
896
897
		/**
898
		 * Use this hook to add or remove buttons in the helpers section
899
		 * in the customization panel
900
		 * @since 2.0.6
901
		 */
902
		$entry_shortcodes = apply_filters( 'frm_helper_shortcodes', $entry_shortcodes, $settings_tab );
903
904
		return $entry_shortcodes;
905
	}
906
907
	/**
908
	 * Insert the form class setting into the form
909
	 */
910
	public static function form_classes( $form ) {
911
		if ( isset( $form->options['form_class'] ) ) {
912
			echo esc_attr( sanitize_text_field( $form->options['form_class'] ) );
913
		}
914
915
		if ( isset( $form->options['js_validate'] ) && $form->options['js_validate'] ) {
916
			echo ' frm_js_validate ';
917
		}
918
	}
919
920
	public static function get_email_html() {
921
		FrmAppHelper::permission_check( 'frm_view_forms' );
922
		check_ajax_referer( 'frm_ajax', 'nonce' );
923
924
		echo FrmEntriesController::show_entry_shortcode( // WPCS: XSS ok.
925
			array(
926
				'form_id'       => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ),
927
				'default_email' => true,
928
				'plain_text'    => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ),
929
			)
930
		);
931
		wp_die();
932
	}
933
934
    public static function filter_content( $content, $form, $entry = false ) {
935
		self::get_entry_by_param( $entry );
936
        if ( ! $entry ) {
937
            return $content;
938
        }
939
940
        if ( is_object( $form ) ) {
941
            $form = $form->id;
942
        }
943
944
        $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
945
        $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
946
947
        return $content;
948
    }
949
950
	private static function get_entry_by_param( &$entry ) {
951
		if ( ! $entry || ! is_object( $entry ) ) {
952
			if ( ! $entry || ! is_numeric( $entry ) ) {
953
				$entry = FrmAppHelper::get_post_param( 'id', false, 'sanitize_title' );
954
			}
955
956
			FrmEntry::maybe_get_entry( $entry );
957
		}
958
	}
959
960
    public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
961
        return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
962
    }
963
964
    public static function process_bulk_form_actions( $errors ) {
965
        if ( ! $_REQUEST ) {
966
            return $errors;
967
        }
968
969
		$bulkaction = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
970
        if ( $bulkaction == -1 ) {
971
			$bulkaction = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
972
        }
973
974
        if ( ! empty( $bulkaction ) && strpos( $bulkaction, 'bulk_' ) === 0 ) {
975
            FrmAppHelper::remove_get_action();
976
977
            $bulkaction = str_replace( 'bulk_', '', $bulkaction );
978
        }
979
980
		$ids = FrmAppHelper::get_param( 'item-action', '', 'get', 'sanitize_text_field' );
981
        if ( empty( $ids ) ) {
982
            $errors[] = __( 'No forms were specified', 'formidable' );
983
            return $errors;
984
        }
985
986
        $permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' );
987
        if ( $permission_error !== false ) {
988
            $errors[] = $permission_error;
989
            return $errors;
990
        }
991
992
        if ( ! is_array( $ids ) ) {
993
            $ids = explode( ',', $ids );
994
        }
995
996
        switch ( $bulkaction ) {
997
            case 'delete':
998
                $message = self::bulk_destroy( $ids );
999
				break;
1000
            case 'trash':
1001
                $message = self::bulk_trash( $ids );
1002
				break;
1003
            case 'untrash':
1004
                $message = self::bulk_untrash( $ids );
1005
        }
1006
1007
        if ( isset( $message ) && ! empty( $message ) ) {
1008
			echo '<div id="message" class="updated frm_updated_message">' . FrmAppHelper::kses( $message, array( 'a' ) ) . '</div>'; // WPCS: XSS ok.
1009
        }
1010
1011
        return $errors;
1012
    }
1013
1014
	/**
1015
	 * @deprecated 1.07.05
1016
	 * @codeCoverageIgnore
1017
	 */
1018
    public static function add_default_templates( $path, $default = true, $template = true ) {
1019
        _deprecated_function( __FUNCTION__, '1.07.05', 'FrmXMLController::add_default_templates()' );
1020
1021
		$path = untrailingslashit( trim( $path ) );
1022
		$templates = glob( $path . '/*.php' );
1023
1024
		for ( $i = count( $templates ) - 1; $i >= 0; $i-- ) {
1025
			$filename = str_replace( '.php', '', str_replace( $path . '/', '', $templates[ $i ] ) );
1026
			$template_query = array( 'form_key' => $filename );
1027
            if ( $template ) {
1028
                $template_query['is_template'] = 1;
1029
            }
1030
            if ( $default ) {
1031
                $template_query['default_template'] = 1;
1032
            }
1033
			$form = FrmForm::getAll( $template_query, '', 1 );
1034
1035
            $values = FrmFormsHelper::setup_new_vars();
1036
            $values['form_key'] = $filename;
1037
            $values['is_template'] = $template;
1038
            $values['status'] = 'published';
1039
            if ( $default ) {
1040
                $values['default_template'] = 1;
1041
            }
1042
1043
            include( $templates[ $i ] );
1044
1045
            //get updated form
1046
			if ( isset( $form ) && ! empty( $form ) ) {
1047
                $old_id = $form->id;
1048
				$form = FrmForm::getOne( $form->id );
1049
            } else {
1050
                $old_id = false;
1051
				$form = FrmForm::getAll( $template_query, '', 1 );
1052
            }
1053
1054
            if ( $form ) {
1055
				do_action( 'frm_after_duplicate_form', $form->id, (array) $form, array( 'old_id' => $old_id ) );
1056
            }
1057
        }
1058
    }
1059
1060
    public static function route() {
1061
		$action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
1062
        $vars = array();
1063
		if ( isset( $_POST['frm_compact_fields'] ) ) {
1064
			FrmAppHelper::permission_check( 'frm_edit_forms' );
1065
1066
			$json_vars = htmlspecialchars_decode( nl2br( stripslashes( str_replace( '&quot;', '\\\"', $_POST['frm_compact_fields'] ) ) ) );
1067
			$json_vars = json_decode( $json_vars, true );
1068
			if ( empty( $json_vars ) ) {
1069
                // json decoding failed so we should return an error message
1070
				$action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1071
                if ( 'edit' == $action ) {
1072
                    $action = 'update';
1073
                }
1074
1075
				add_filter( 'frm_validate_form', 'FrmFormsController::json_error' );
1076
            } else {
1077
				$vars = FrmAppHelper::json_to_array( $json_vars );
1078
                $action = $vars[ $action ];
1079
				unset( $_REQUEST['frm_compact_fields'], $_POST['frm_compact_fields'] );
1080
				$_REQUEST = array_merge( $_REQUEST, $vars );
1081
				$_POST = array_merge( $_POST, $_REQUEST );
1082
            }
1083
        } else {
1084
			$action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1085
    		if ( isset( $_REQUEST['delete_all'] ) ) {
1086
                // override the action for this page
1087
    			$action = 'delete_all';
1088
            }
1089
        }
1090
1091
		add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1092
        FrmAppHelper::trigger_hook_load( 'form' );
1093
1094
        switch ( $action ) {
1095
            case 'new':
1096
				return self::new_form( $vars );
1097
            case 'create':
1098
            case 'edit':
1099
            case 'update':
1100
            case 'duplicate':
1101
            case 'trash':
1102
            case 'untrash':
1103
            case 'destroy':
1104
            case 'delete_all':
1105
            case 'settings':
1106
            case 'update_settings':
1107
				return self::$action( $vars );
1108
            default:
1109
				do_action( 'frm_form_action_' . $action );
1110
				if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) {
1111
                    return;
1112
                }
1113
1114
				$action = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
1115
                if ( $action == -1 ) {
1116
					$action = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
1117
                }
1118
1119
				if ( strpos( $action, 'bulk_' ) === 0 ) {
1120
                    FrmAppHelper::remove_get_action();
1121
                    return self::list_form();
1122
                }
1123
1124
                return self::display_forms_list();
1125
        }
1126
    }
1127
1128
    public static function json_error( $errors ) {
1129
        $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
1130
        return $errors;
1131
    }
1132
1133
1134
    /* FRONT-END FORMS */
1135
    public static function admin_bar_css() {
1136
		if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
1137
            return;
1138
        }
1139
1140
		add_action( 'wp_before_admin_bar_render', 'FrmFormsController::admin_bar_configure' );
1141
		FrmAppHelper::load_font_style();
1142
	}
1143
1144
	public static function admin_bar_configure() {
1145
        global $frm_vars;
1146
		if ( empty( $frm_vars['forms_loaded'] ) ) {
1147
            return;
1148
        }
1149
1150
        $actions = array();
1151
		foreach ( $frm_vars['forms_loaded'] as $form ) {
1152
			if ( is_object( $form ) ) {
1153
				$actions[ $form->id ] = $form->name;
1154
			}
1155
			unset( $form );
1156
		}
1157
1158
		if ( empty( $actions ) ) {
1159
			return;
1160
		}
1161
1162
		self::add_menu_to_admin_bar();
1163
		self::add_forms_to_admin_bar( $actions );
1164
	}
1165
1166
	/**
1167
	 * @since 2.05.07
1168
	 */
1169
	public static function add_menu_to_admin_bar() {
1170
		global $wp_admin_bar;
1171
1172
		$wp_admin_bar->add_node(
1173
			array(
1174
				'id'    => 'frm-forms',
1175
				'title' => '<span class="ab-icon"></span><span class="ab-label">' . FrmAppHelper::get_menu_name() . '</span>',
1176
				'href'  => admin_url( 'admin.php?page=formidable' ),
1177
				'meta'  => array(
1178
					'title' => FrmAppHelper::get_menu_name(),
1179
				),
1180
			)
1181
		);
1182
	}
1183
1184
	/**
1185
	 * @since 2.05.07
1186
	 */
1187
	private static function add_forms_to_admin_bar( $actions ) {
1188
		global $wp_admin_bar;
1189
1190
		asort( $actions );
1191
1192
		foreach ( $actions as $form_id => $name ) {
1193
1194
			$wp_admin_bar->add_node(
1195
				array(
1196
					'parent'    => 'frm-forms',
1197
					'id'        => 'edit_form_' . $form_id,
1198
					'title'     => empty( $name ) ? __( '(no title)' ) : $name,
1199
					'href'      => admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id ),
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1200
				)
1201
			);
1202
		}
1203
	}
1204
1205
    //formidable shortcode
1206
	public static function get_form_shortcode( $atts ) {
1207
        global $frm_vars;
1208
		if ( isset( $frm_vars['skip_shortcode'] ) && $frm_vars['skip_shortcode'] ) {
1209
            $sc = '[formidable';
1210
			if ( ! empty( $atts ) ) {
1211
				foreach ( $atts as $k => $v ) {
1212
					$sc .= ' ' . $k . '="' . esc_attr( $v ) . '"';
1213
				}
1214
			}
1215
			return $sc . ']';
1216
        }
1217
1218
		$shortcode_atts = shortcode_atts(
1219
			array(
1220
				'id'          => '',
1221
				'key'         => '',
1222
				'title'       => false,
1223
				'description' => false,
1224
				'readonly'    => false,
1225
				'entry_id'    => false,
1226
				'fields'      => array(),
1227
				'exclude_fields' => array(),
1228
				'minimize'    => false,
1229
			),
1230
			$atts
1231
		);
1232
		do_action( 'formidable_shortcode_atts', $shortcode_atts, $atts );
1233
1234
        return self::show_form( $shortcode_atts['id'], $shortcode_atts['key'], $shortcode_atts['title'], $shortcode_atts['description'], $atts );
1235
    }
1236
1237
    public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
1238
        if ( empty( $id ) ) {
1239
            $id = $key;
1240
        }
1241
1242
        $form = self::maybe_get_form_to_show( $id );
1243
        if ( ! $form ) {
1244
            return __( 'Please select a valid form', 'formidable' );
1245
        }
1246
1247
		FrmAppController::maybe_update_styles();
1248
1249
		add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
1250
        FrmAppHelper::trigger_hook_load( 'form', $form );
1251
1252
        $form = apply_filters( 'frm_pre_display_form', $form );
1253
1254
        $frm_settings = FrmAppHelper::get_settings();
1255
1256
		if ( self::is_viewable_draft_form( $form ) ) {
1257
			// don't show a draft form on a page
1258
			$form = __( 'Please select a valid form', 'formidable' );
1259
		} else if ( self::user_should_login( $form ) ) {
1260
			$form = do_shortcode( $frm_settings->login_msg );
1261
		} else if ( self::user_has_permission_to_view( $form ) ) {
1262
			$form = do_shortcode( $frm_settings->login_msg );
1263
		} else {
1264
			do_action( 'frm_pre_get_form', $form );
1265
			$form = self::get_form( $form, $title, $description, $atts );
1266
1267
			/**
1268
			 * Use this shortcode to check for external shortcodes that may span
1269
			 * across multiple fields in the customizable HTML
1270
			 * @since 2.0.8
1271
			 */
1272
			$form = apply_filters( 'frm_filter_final_form', $form );
1273
		}
1274
1275
		return $form;
1276
    }
1277
1278
	private static function maybe_get_form_to_show( $id ) {
1279
		$form = false;
1280
1281
		if ( ! empty( $id ) ) { // no form id or key set
1282
			$form = FrmForm::getOne( $id );
1283
			if ( ! $form || $form->parent_form_id || $form->status == 'trash' ) {
1284
				$form = false;
1285
			}
1286
		}
1287
1288
		return $form;
1289
	}
1290
1291
	private static function is_viewable_draft_form( $form ) {
1292
		global $post;
1293
		$frm_settings = FrmAppHelper::get_settings();
0 ignored issues
show
Unused Code introduced by
$frm_settings is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1294
		return $form->status == 'draft' && current_user_can( 'frm_edit_forms' ) && ! FrmAppHelper::is_preview_page();
1295
	}
1296
1297
	private static function user_should_login( $form ) {
1298
		return $form->logged_in && ! is_user_logged_in();
1299
	}
1300
1301
	private static function user_has_permission_to_view( $form ) {
1302
		return $form->logged_in && get_current_user_id() && isset( $form->options['logged_in_role'] ) && $form->options['logged_in_role'] != '' && ! FrmAppHelper::user_has_permission( $form->options['logged_in_role'] );
1303
	}
1304
1305
    public static function get_form( $form, $title, $description, $atts = array() ) {
1306
		ob_start();
1307
1308
		do_action( 'frm_before_get_form', $atts );
1309
1310
        self::get_form_contents( $form, $title, $description, $atts );
1311
		self::enqueue_scripts( FrmForm::get_params( $form ) );
1312
1313
        $contents = ob_get_contents();
1314
        ob_end_clean();
1315
1316
		self::maybe_minimize_form( $atts, $contents );
1317
1318
        return $contents;
1319
    }
1320
1321
	public static function enqueue_scripts( $params ) {
1322
		do_action( 'frm_enqueue_form_scripts', $params );
1323
	}
1324
1325
	public static function get_form_contents( $form, $title, $description, $atts ) {
1326
		$params = FrmForm::get_params( $form );
1327
		$errors = self::get_saved_errors( $form, $params );
1328
		$fields = FrmFieldsHelper::get_form_fields( $form->id, $errors );
1329
		$reset = false;
1330
		$pass_args = compact( 'form', 'fields', 'errors', 'title', 'description', 'reset' );
1331
1332
		$handle_process_here = $params['action'] == 'create' && $params['posted_form_id'] == $form->id && $_POST;
1333
1334
		if ( ! $handle_process_here ) {
1335
			do_action( 'frm_display_form_action', $params, $fields, $form, $title, $description );
1336
			if ( apply_filters( 'frm_continue_to_new', true, $form->id, $params['action'] ) ) {
1337
				self::show_form_after_submit( $pass_args );
1338
			}
1339
		} elseif ( ! empty( $errors ) ) {
1340
			self::show_form_after_submit( $pass_args );
1341
1342
		} else {
1343
1344
			do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description );
1345
1346
			if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) {
1347
				$entry_id = self::just_created_entry( $form->id );
1348
				$pass_args['entry_id'] = $entry_id;
1349
				$pass_args['reset'] = true;
1350
				$pass_args['conf_method'] = self::get_confirmation_method( compact( 'form', 'entry_id' ) );
1351
1352
				self::run_success_action( $pass_args );
1353
1354
				do_action(
1355
					'frm_after_entry_processed',
1356
					array(
1357
						'entry_id' => $entry_id,
1358
						'form'     => $form,
1359
					)
1360
				);
1361
			}
1362
		}
1363
	}
1364
1365
	/**
1366
	 * If the form was processed earlier (init), get the generated errors
1367
	 * @since 2.05
1368
	 */
1369
	private static function get_saved_errors( $form, $params ) {
1370
		global $frm_vars;
1371
1372
		if ( $params['posted_form_id'] == $form->id && $_POST && isset( $frm_vars['created_entries'][ $form->id ] ) ) {
1373
			$errors = $frm_vars['created_entries'][ $form->id ]['errors'];
1374
		} else {
1375
			$errors = array();
1376
		}
1377
		return $errors;
1378
	}
1379
1380
	/**
1381
	 * @since 2.2.7
1382
	 */
1383
	public static function just_created_entry( $form_id ) {
1384
		global $frm_vars;
1385
		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;
1386
	}
1387
1388
	/**
1389
	 * @since 3.0
1390
	 */
1391
	private static function get_confirmation_method( $atts ) {
1392
		$opt = 'success_action';
1393
		$method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message';
1394
		$method = apply_filters( 'frm_success_filter', $method, $atts['form'], 'create' );
1395
1396
		if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
1397
			$method = 'message';
1398
		}
1399
1400
		return $method;
1401
	}
1402
1403
	public static function maybe_trigger_redirect( $form, $params, $args ) {
1404
		if ( ! isset( $params['id'] ) ) {
1405
			global $frm_vars;
1406
			$params['id'] = $frm_vars['created_entries'][ $form->id ]['entry_id'];
1407
		}
1408
1409
		$conf_method = self::get_confirmation_method(
1410
			array(
1411
				'form'     => $form,
1412
				'entry_id' => $params['id'],
1413
			)
1414
		);
1415
1416
		if ( 'redirect' === $conf_method ) {
1417
			self::trigger_redirect( $form, $params, $args );
1418
		}
1419
	}
1420
1421
	public static function trigger_redirect( $form, $params, $args ) {
1422
		$success_args = array(
1423
			'action'      => $params['action'],
1424
			'conf_method' => 'redirect',
1425
			'form'        => $form,
1426
			'entry_id'    => $params['id'],
1427
		);
1428
1429
		if ( isset( $args['ajax'] ) ) {
1430
			$success_args['ajax'] = $args['ajax'];
1431
		}
1432
1433
		self::run_success_action( $success_args );
1434
	}
1435
1436
	/**
1437
	 * Used when the success action is not 'message'
1438
	 * @since 2.05
1439
	 */
1440
	public static function run_success_action( $args ) {
1441
		$extra_args = $args;
1442
		unset( $extra_args['form'] );
1443
1444
		do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args );
1445
1446
		$opt = ( ! isset( $args['action'] ) || $args['action'] == 'create' ) ? 'success' : 'edit';
1447
		$args['success_opt'] = $opt;
1448
		if ( $args['conf_method'] == 'page' && is_numeric( $args['form']->options[ $opt . '_page_id' ] ) ) {
1449
			self::load_page_after_submit( $args );
1450
		} elseif ( $args['conf_method'] == 'redirect' ) {
1451
			self::redirect_after_submit( $args );
1452
		} else {
1453
			self::show_message_after_save( $args );
1454
		}
1455
	}
1456
1457
	/**
1458
	 * @since 3.0
1459
	 */
1460
	private static function load_page_after_submit( $args ) {
1461
		global $post;
1462
		$opt = $args['success_opt'];
1463
		if ( ! $post || $args['form']->options[ $opt . '_page_id' ] != $post->ID ) {
1464
			$page = get_post( $args['form']->options[ $opt . '_page_id' ] );
1465
			$old_post = $post;
1466
			$post = $page;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
1467
			$content = apply_filters( 'frm_content', $page->post_content, $args['form'], $args['entry_id'] );
1468
			echo apply_filters( 'the_content', $content ); // WPCS: XSS ok.
1469
			$post = $old_post;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
1470
		}
1471
	}
1472
1473
	/**
1474
	 * @since 3.0
1475
	 */
1476
	private static function redirect_after_submit( $args ) {
1477
		global $frm_vars;
1478
1479
		add_filter( 'frm_use_wpautop', '__return_false' );
1480
1481
		$opt = $args['success_opt'];
1482
		$success_url = trim( $args['form']->options[ $opt . '_url' ] );
1483
		$success_url = apply_filters( 'frm_content', $success_url, $args['form'], $args['entry_id'] );
1484
		$success_url = do_shortcode( $success_url );
1485
1486
		$success_msg = isset( $args['form']->options[ $opt . '_msg' ] ) ? $args['form']->options[ $opt . '_msg' ] : __( 'Please wait while you are redirected.', 'formidable' );
1487
1488
		$redirect_msg = self::get_redirect_message( $success_url, $success_msg, $args );
1489
1490
		$args['id'] = $args['entry_id'];
1491
		FrmEntriesController::delete_entry_before_redirect( $success_url, $args['form'], $args );
1492
1493
		add_filter( 'frm_redirect_url', 'FrmEntriesController::prepare_redirect_url' );
1494
		$success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args );
1495
1496
		$doing_ajax = FrmAppHelper::doing_ajax();
1497
1498
		if ( isset( $args['ajax'] ) && $args['ajax'] && $doing_ajax ) {
1499
			echo json_encode( array( 'redirect' => $success_url ) );
1500
			wp_die();
1501
		} elseif ( ! headers_sent() ) {
1502
			wp_redirect( esc_url_raw( $success_url ) );
1503
			die(); // do not use wp_die or redirect fails
1504
		} else {
1505
			add_filter( 'frm_use_wpautop', '__return_true' );
1506
1507
			echo $redirect_msg; // WPCS: XSS ok.
1508
			echo "<script type='text/javascript'>window.onload = function(){setTimeout(window.location='" . esc_url_raw( $success_url ) . "', 8000);}</script>";
1509
		}
1510
	}
1511
1512
	/**
1513
	 * @since 3.0
1514
	 * @param string $success_url
1515
	 * @param string $success_msg
1516
	 * @param array $args
1517
	 */
1518
	private static function get_redirect_message( $success_url, $success_msg, $args ) {
1519
		$redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg frm_message">' . $success_msg . '<br/>' .
1520
			sprintf( __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), '<a href="' . esc_url( $success_url ) . '">', '</a>' ) .
1521
			'</div></div>';
1522
1523
		$redirect_args = array(
1524
			'entry_id' => $args['entry_id'],
1525
			'form_id'  => $args['form']->id,
1526
			'form'     => $args['form'],
1527
		);
1528
		return apply_filters( 'frm_redirect_msg', $redirect_msg, $redirect_args );
1529
	}
1530
1531
	/**
1532
	 * Prepare to show the success message and empty form after submit
1533
	 * @since 2.05
1534
	 */
1535
	public static function show_message_after_save( $atts ) {
1536
		$atts['message'] = self::prepare_submit_message( $atts['form'], $atts['entry_id'] );
1537
1538
		if ( ! isset( $atts['form']->options['show_form'] ) || $atts['form']->options['show_form'] ) {
1539
			self::show_form_after_submit( $atts );
1540
		} else {
1541
			self::show_lone_success_messsage( $atts );
1542
		}
1543
	}
1544
1545
	/**
1546
	 * Show an empty form
1547
	 * @since 2.05
1548
	 */
1549
	private static function show_form_after_submit( $args ) {
1550
		self::fill_atts_for_form_display( $args );
1551
1552
		$errors = $args['errors'];
1553
		$message = $args['message'];
1554
		$form = $args['form'];
1555
		$title = $args['title'];
1556
		$description = $args['description'];
1557
1558
		if ( empty( $args['fields'] ) ) {
1559
			$values = array();
1560
		} else {
1561
			$values = FrmEntriesHelper::setup_new_vars( $args['fields'], $form, $args['reset'] );
1562
		}
1563
		unset( $args );
1564
1565
		$include_form_tag = apply_filters( 'frm_include_form_tag', true, $form );
1566
1567
		$frm_settings = FrmAppHelper::get_settings();
1568
		$submit = isset( $form->options['submit_value'] ) ? $form->options['submit_value'] : $frm_settings->submit_value;
1569
1570
		include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php' );
1571
	}
1572
1573
	/**
1574
	 * Get all the values needed on the new.php entry page
1575
	 * @since 2.05
1576
	 */
1577
	private static function fill_atts_for_form_display( &$args ) {
1578
		$defaults = array(
1579
			'errors'  => array(),
1580
			'message' => '',
1581
			'fields'  => array(),
1582
			'form'    => array(),
1583
			'title'   => true,
1584
			'description' => false,
1585
			'reset'   => false,
1586
		);
1587
		$args = wp_parse_args( $args, $defaults );
1588
	}
1589
1590
	/**
1591
	 * Show the success message without the form
1592
	 * @since 2.05
1593
	 */
1594
	private static function show_lone_success_messsage( $atts ) {
1595
		global $frm_vars;
1596
		$values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true );
1597
		self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] );
1598
1599
		$include_extra_container = 'frm_forms' . FrmFormsHelper::get_form_style_class( $values );
1600
		$errors = array();
1601
		$form = $atts['form'];
1602
		$message = $atts['message'];
1603
1604
		include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' );
1605
	}
1606
1607
	/**
1608
	 * Prepare the success message before it's shown
1609
	 * @since 2.05
1610
	 */
1611
	private static function prepare_submit_message( $form, $entry_id ) {
1612
		$frm_settings = FrmAppHelper::get_settings();
1613
1614
		if ( $entry_id && is_numeric( $entry_id ) ) {
1615
			$message = isset( $form->options['success_msg'] ) ? $form->options['success_msg'] : $frm_settings->success_msg;
1616
			$class = 'frm_message';
1617
		} else {
1618
			$message = $frm_settings->failed_msg;
1619
			$class = FrmFormsHelper::form_error_class();
1620
		}
1621
1622
		$message = FrmFormsHelper::get_success_message( compact( 'message', 'form', 'entry_id', 'class' ) );
1623
		return apply_filters( 'frm_main_feedback', $message, $form, $entry_id );
1624
	}
1625
1626
	public static function front_head() {
1627
		$version = FrmAppHelper::plugin_version();
1628
		$suffix = FrmAppHelper::js_suffix();
1629
1630
		if ( ! empty( $suffix ) && self::has_combo_js_file() ) {
1631
			wp_register_script( 'formidable', FrmAppHelper::plugin_url() . '/js/frm.min.js', array( 'jquery' ), $version, true );
1632
		} else {
1633
			wp_register_script( 'formidable', FrmAppHelper::plugin_url() . "/js/formidable{$suffix}.js", array( 'jquery' ), $version, true );
1634
		}
1635
1636
		add_filter( 'script_loader_tag', 'FrmFormsController::defer_script_loading', 10, 2 );
1637
1638
		if ( FrmAppHelper::is_admin() ) {
1639
			// don't load this in back-end
1640
			return;
1641
		}
1642
1643
		FrmAppHelper::localize_script( 'front' );
1644
		FrmStylesController::enqueue_css( 'register' );
1645
	}
1646
1647
	/**
1648
	 * @since 3.0
1649
	 */
1650
	public static function has_combo_js_file() {
1651
		return is_readable( FrmAppHelper::plugin_path() . '/js/frm.min.js' );
1652
	}
1653
1654
	public static function maybe_load_css( $form, $this_load, $global_load ) {
1655
		$load_css = FrmForm::is_form_loaded( $form, $this_load, $global_load );
1656
1657
		if ( $load_css ) {
1658
			global $frm_vars;
1659
			self::footer_js( 'header' );
1660
			$frm_vars['css_loaded'] = true;
1661
		}
1662
	}
1663
1664
	public static function defer_script_loading( $tag, $handle ) {
1665
	    if ( 'recaptcha-api' == $handle && ! strpos( $tag, 'defer' ) ) {
1666
	        $tag = str_replace( ' src', ' defer="defer" async="async" src', $tag );
1667
		}
1668
	    return $tag;
1669
	}
1670
1671
	public static function footer_js( $location = 'footer' ) {
1672
		global $frm_vars;
1673
1674
		FrmStylesController::enqueue_css();
1675
1676
		if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
1677
			//load formidable js
1678
			wp_enqueue_script( 'formidable' );
1679
		}
1680
	}
1681
1682
	/**
1683
	 * @since 2.0.8
1684
	 */
1685
	private static function maybe_minimize_form( $atts, &$content ) {
1686
		// check if minimizing is turned on
1687
		if ( self::is_minification_on( $atts ) ) {
1688
			$content = str_replace( array( "\r\n", "\r", "\n", "\t", '    ' ), '', $content );
1689
		}
1690
	}
1691
1692
	/**
1693
	 * @since 2.0.8
1694
	 * @return boolean
1695
	 */
1696
	private static function is_minification_on( $atts ) {
1697
		return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] );
1698
	}
1699
1700
	/**
1701
	 * @deprecated 3.0
1702
	 * @codeCoverageIgnore
1703
	 */
1704
	public static function bulk_create_template( $ids ) {
1705
		_deprecated_function( __METHOD__, '3.0', 'FrmForm::duplicate( $id, true, true )' );
1706
		FrmAppHelper::permission_check( 'frm_edit_forms' );
1707
1708
		foreach ( $ids as $id ) {
1709
			FrmForm::duplicate( $id, true, true );
1710
		}
1711
1712
		return __( 'Form template was Successfully Created', 'formidable' );
1713
	}
1714
1715
	/**
1716
	 * @deprecated 2.03
1717
	 * @codeCoverageIgnore
1718
	 */
1719
	public static function register_pro_scripts() {
1720
		_deprecated_function( __FUNCTION__, '2.03', 'FrmProEntriesController::register_scripts' );
1721
		if ( FrmAppHelper::pro_is_installed() ) {
1722
			FrmProEntriesController::register_scripts();
1723
		}
1724
	}
1725
1726
	/**
1727
	 * @deprecated 3.0
1728
	 * @codeCoverageIgnore
1729
	 */
1730
	public static function edit_key() {
1731
		_deprecated_function( __METHOD__, '3.0' );
1732
		$values = self::edit_in_place_value( 'form_key' );
1733
		echo wp_kses( stripslashes( FrmForm::get_key_by_id( $values['form_id'] ) ), array() );
1734
		wp_die();
1735
	}
1736
1737
	/**
1738
	 * @deprecated 3.0
1739
	 * @codeCoverageIgnore
1740
	 */
1741
	public static function edit_description() {
1742
		_deprecated_function( __METHOD__, '3.0' );
1743
		$values = self::edit_in_place_value( 'description' );
1744
		echo wp_kses_post( FrmAppHelper::use_wpautop( stripslashes( $values['description'] ) ) );
1745
		wp_die();
1746
	}
1747
1748
	/**
1749
	 * @deprecated 3.0
1750
	 * @codeCoverageIgnore
1751
	 */
1752
	private static function edit_in_place_value( $field ) {
1753
		_deprecated_function( __METHOD__, '3.0' );
1754
		check_ajax_referer( 'frm_ajax', 'nonce' );
1755
		FrmAppHelper::permission_check( 'frm_edit_forms', 'hide' );
1756
1757
		$form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
1758
		$value = FrmAppHelper::get_post_param( 'update_value', '', 'wp_filter_post_kses' );
1759
1760
		$values = array( $field => trim( $value ) );
1761
		FrmForm::update( $form_id, $values );
1762
		$values['form_id'] = $form_id;
1763
1764
		return $values;
1765
	}
1766
}
1767