Passed
Push — master ( ec16eb...0357f3 )
by Stephanie
03:05
created

FrmFormsController::load_theme_preview()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 2
b 0
f 0
1
<?php
2
3
class FrmFormsController {
4
5
    public static function menu() {
6
		$menu_label = __( 'Forms', 'formidable' );
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

6
		$menu_label = /** @scrutinizer ignore-call */ __( 'Forms', 'formidable' );
Loading history...
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' );
0 ignored issues
show
Bug introduced by
The function add_submenu_page was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

10
		/** @scrutinizer ignore-call */ 
11
  add_submenu_page('formidable', 'Formidable | ' . $menu_label, $menu_label, 'frm_view_forms', 'formidable', 'FrmFormsController::route' );
Loading history...
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' );
0 ignored issues
show
Bug introduced by
The function add_filter was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

21
		/** @scrutinizer ignore-call */ 
22
  add_filter( 'get_user_option_managetoplevel_page_formidablecolumnshidden', 'FrmFormsController::hidden_columns' );
Loading history...
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');
0 ignored issues
show
Bug introduced by
The function wp_enqueue_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        /** @scrutinizer ignore-call */ 
29
        wp_enqueue_script('formidable-editinplace');
Loading history...
29
30
        if ( wp_is_mobile() ) {
0 ignored issues
show
Bug introduced by
The function wp_is_mobile was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        if ( /** @scrutinizer ignore-call */ wp_is_mobile() ) {
Loading history...
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');
0 ignored issues
show
Bug introduced by
The function register_widget was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
        /** @scrutinizer ignore-call */ 
38
        register_widget('FrmShowForm');
Loading history...
38
    }
39
40
    public static function list_form() {
41
        FrmAppHelper::permission_check('frm_view_forms');
42
43
		$params = FrmForm::list_page_params();
44
        $errors = self::process_bulk_form_actions( array());
45
        $errors = apply_filters('frm_admin_list_form_action', $errors);
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        $errors = /** @scrutinizer ignore-call */ apply_filters('frm_admin_list_form_action', $errors);
Loading history...
46
47
		return self::display_forms_list( $params, '', $errors );
48
    }
49
50
	public static function new_form( $values = array() ) {
51
        FrmAppHelper::permission_check('frm_edit_forms');
52
53
        global $frm_vars;
54
55
        $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
56
		$action = empty( $values ) ? FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ) : $values[ $action ];
57
58
		if ( $action == 'create' ) {
59
			self::create($values);
60
			return;
61
		} else if ( $action == 'new' ) {
62
			$frm_field_selection = FrmField::field_selection();
63
            $values = FrmFormsHelper::setup_new_vars($values);
64
            $id = FrmForm::create( $values );
65
            $form = FrmForm::getOne($id);
66
67
			self::create_default_email_action( $form );
68
69
			$all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
70
71
            $values['id'] = $id;
72
			require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php' );
73
        }
74
    }
75
76
	/**
77
	 * Create the default email action
78
	 *
79
	 * @since 2.02.11
80
	 *
81
	 * @param object $form
82
	 */
83
    private static function create_default_email_action( $form ) {
84
    	$create_email = apply_filters( 'frm_create_default_email_action', true, $form );
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

84
    	$create_email = /** @scrutinizer ignore-call */ apply_filters( 'frm_create_default_email_action', true, $form );
Loading history...
85
86
	    if ( $create_email ) {
87
		    $action_control = FrmFormActionsController::get_form_actions( 'email' );
88
		    $action_control->create( $form->id );
89
	    }
90
    }
91
92
	public static function create( $values = array() ) {
93
        FrmAppHelper::permission_check('frm_edit_forms');
94
95
        global $frm_vars;
96
        if ( empty( $values ) ) {
97
            $values = $_POST;
98
        }
99
100
        //Set radio button and checkbox meta equal to "other" value
101
        if ( FrmAppHelper::pro_is_installed() ) {
102
            $values = FrmProEntry::mod_other_vals( $values, 'back' );
0 ignored issues
show
Bug introduced by
The type FrmProEntry was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
103
        }
104
105
		$id = isset($values['id']) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
0 ignored issues
show
Bug introduced by
The function absint was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

105
		$id = isset($values['id']) ? /** @scrutinizer ignore-call */ absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
Loading history...
106
107
        if ( ! current_user_can( 'frm_edit_forms' ) || ( $_POST && ( ! isset( $values['frm_save_form'] ) || ! wp_verify_nonce( $values['frm_save_form'], 'frm_save_form_nonce' ) ) ) ) {
0 ignored issues
show
Bug introduced by
The function wp_verify_nonce was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

107
        if ( ! current_user_can( 'frm_edit_forms' ) || ( $_POST && ( ! isset( $values['frm_save_form'] ) || ! /** @scrutinizer ignore-call */ wp_verify_nonce( $values['frm_save_form'], 'frm_save_form_nonce' ) ) ) ) {
Loading history...
Bug introduced by
The function current_user_can was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

107
        if ( ! /** @scrutinizer ignore-call */ current_user_can( 'frm_edit_forms' ) || ( $_POST && ( ! isset( $values['frm_save_form'] ) || ! wp_verify_nonce( $values['frm_save_form'], 'frm_save_form_nonce' ) ) ) ) {
Loading history...
108
            $frm_settings = FrmAppHelper::get_settings();
109
            $errors = array( 'form' => $frm_settings->admin_permission );
110
        } else {
111
            $errors = FrmForm::validate($values);
112
        }
113
114
        if ( count($errors) > 0 ) {
115
            $hide_preview = true;
116
			$frm_field_selection = FrmField::field_selection();
117
            $form = FrmForm::getOne( $id );
118
            $fields = FrmField::get_all_for_form($id);
119
120
			$values = FrmAppHelper::setup_edit_vars($form, 'forms', '', true);
121
			$values['fields'] = $fields;
122
			$all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
123
124
			require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php' );
125
        } else {
126
            FrmForm::update( $id, $values, true );
127
			$url = admin_url( 'admin.php?page=formidable&frm_action=settings&id=' . $id );
0 ignored issues
show
Bug introduced by
The function admin_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

127
			$url = /** @scrutinizer ignore-call */ admin_url( 'admin.php?page=formidable&frm_action=settings&id=' . $id );
Loading history...
128
			die( FrmAppHelper::js_redirect( $url ) );
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
129
        }
130
    }
131
132
    public static function edit( $values = false ) {
133
        FrmAppHelper::permission_check('frm_edit_forms');
134
135
		$id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
0 ignored issues
show
Bug introduced by
The function absint was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

135
		$id = isset( $values['id'] ) ? /** @scrutinizer ignore-call */ absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
Loading history...
136
        return self::get_edit_vars($id);
0 ignored issues
show
Bug introduced by
Are you sure the usage of self::get_edit_vars($id) targeting FrmFormsController::get_edit_vars() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

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

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

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

Loading history...
137
    }
138
139
    public static function settings( $id = false, $message = '' ) {
140
        FrmAppHelper::permission_check('frm_edit_forms');
141
142
        if ( ! $id || ! is_numeric($id) ) {
143
			$id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
144
        }
145
		return self::get_settings_vars( $id, array(), $message );
0 ignored issues
show
Bug introduced by
Are you sure the usage of self::get_settings_vars($id, array(), $message) targeting FrmFormsController::get_settings_vars() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

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

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

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

Loading history...
146
    }
147
148
    public static function update_settings() {
149
        FrmAppHelper::permission_check('frm_edit_forms');
150
151
		$id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
152
153
        $errors = FrmForm::validate($_POST);
154
        if ( count($errors) > 0 ) {
155
            return self::get_settings_vars($id, $errors);
0 ignored issues
show
Bug introduced by
Are you sure the usage of self::get_settings_vars($id, $errors) targeting FrmFormsController::get_settings_vars() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

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

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

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

Loading history...
156
        }
157
158
        do_action('frm_before_update_form_settings', $id);
0 ignored issues
show
Bug introduced by
The function do_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

158
        /** @scrutinizer ignore-call */ 
159
        do_action('frm_before_update_form_settings', $id);
Loading history...
159
160
		FrmForm::update( $id, $_POST );
161
162
        $message = __( 'Settings Successfully Updated', 'formidable' );
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

162
        $message = /** @scrutinizer ignore-call */ __( 'Settings Successfully Updated', 'formidable' );
Loading history...
163
		return self::get_settings_vars( $id, array(), $message );
0 ignored issues
show
Bug introduced by
Are you sure the usage of self::get_settings_vars($id, array(), $message) targeting FrmFormsController::get_settings_vars() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

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

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

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

Loading history...
164
    }
165
166
	public static function edit_key() {
167
		_deprecated_function( __METHOD__, '3.0' );
0 ignored issues
show
Bug introduced by
The function _deprecated_function was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

167
		/** @scrutinizer ignore-call */ 
168
  _deprecated_function( __METHOD__, '3.0' );
Loading history...
168
		$values = self::edit_in_place_value( 'form_key' );
169
		echo wp_kses( stripslashes( FrmForm::get_key_by_id( $values['form_id'] ) ), array() );
0 ignored issues
show
Bug introduced by
The function wp_kses was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

169
		echo /** @scrutinizer ignore-call */ wp_kses( stripslashes( FrmForm::get_key_by_id( $values['form_id'] ) ), array() );
Loading history...
Bug introduced by
$values['form_id'] of type string|array is incompatible with the type integer expected by parameter $id of FrmForm::get_key_by_id(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

169
		echo wp_kses( stripslashes( FrmForm::get_key_by_id( /** @scrutinizer ignore-type */ $values['form_id'] ) ), array() );
Loading history...
170
		wp_die();
0 ignored issues
show
Bug introduced by
The function wp_die was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

170
		/** @scrutinizer ignore-call */ 
171
  wp_die();
Loading history...
171
	}
172
173
	public static function edit_description() {
174
		_deprecated_function( __METHOD__, '3.0' );
0 ignored issues
show
Bug introduced by
The function _deprecated_function was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

174
		/** @scrutinizer ignore-call */ 
175
  _deprecated_function( __METHOD__, '3.0' );
Loading history...
175
		$values = self::edit_in_place_value( 'description' );
176
		echo wp_kses_post( FrmAppHelper::use_wpautop( stripslashes( $values['description'] ) ) );
0 ignored issues
show
Bug introduced by
The function wp_kses_post was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

176
		echo /** @scrutinizer ignore-call */ wp_kses_post( FrmAppHelper::use_wpautop( stripslashes( $values['description'] ) ) );
Loading history...
Bug introduced by
It seems like $values['description'] can also be of type array; however, parameter $str of stripslashes() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

176
		echo wp_kses_post( FrmAppHelper::use_wpautop( stripslashes( /** @scrutinizer ignore-type */ $values['description'] ) ) );
Loading history...
177
		wp_die();
0 ignored issues
show
Bug introduced by
The function wp_die was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

177
		/** @scrutinizer ignore-call */ 
178
  wp_die();
Loading history...
178
	}
179
180
	private static function edit_in_place_value( $field ) {
181
		_deprecated_function( __METHOD__, '3.0' );
0 ignored issues
show
Bug introduced by
The function _deprecated_function was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

181
		/** @scrutinizer ignore-call */ 
182
  _deprecated_function( __METHOD__, '3.0' );
Loading history...
182
		check_ajax_referer( 'frm_ajax', 'nonce' );
0 ignored issues
show
Bug introduced by
The function check_ajax_referer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

182
		/** @scrutinizer ignore-call */ 
183
  check_ajax_referer( 'frm_ajax', 'nonce' );
Loading history...
183
		FrmAppHelper::permission_check('frm_edit_forms', 'hide');
184
185
		$form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
186
		$value = FrmAppHelper::get_post_param( 'update_value', '', 'wp_filter_post_kses' );
187
188
		$values = array( $field => trim( $value ) );
0 ignored issues
show
Bug introduced by
It seems like $value can also be of type array; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

188
		$values = array( $field => trim( /** @scrutinizer ignore-type */ $value ) );
Loading history...
189
		FrmForm::update( $form_id, $values );
190
		$values['form_id'] = $form_id;
191
192
		return $values;
193
	}
194
195
	public static function update( $values = array() ) {
196
		if ( empty( $values ) ) {
197
            $values = $_POST;
198
        }
199
200
        //Set radio button and checkbox meta equal to "other" value
201
        if ( FrmAppHelper::pro_is_installed() ) {
202
            $values = FrmProEntry::mod_other_vals( $values, 'back' );
203
        }
204
205
        $errors = FrmForm::validate( $values );
206
        $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form', 'frm_save_form_nonce' );
207
        if ( $permission_error !== false ) {
208
            $errors['form'] = $permission_error;
209
        }
210
211
		$id = isset( $values['id'] ) ? absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
0 ignored issues
show
Bug introduced by
The function absint was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

211
		$id = isset( $values['id'] ) ? /** @scrutinizer ignore-call */ absint( $values['id'] ) : FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
Loading history...
212
213
		if ( count( $errors ) > 0 ) {
214
            return self::get_edit_vars( $id, $errors );
0 ignored issues
show
Bug introduced by
Are you sure the usage of self::get_edit_vars($id, $errors) targeting FrmFormsController::get_edit_vars() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

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

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

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

Loading history...
215
		} else {
216
            FrmForm::update( $id, $values );
217
            $message = __( 'Form was Successfully Updated', 'formidable' );
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

217
            $message = /** @scrutinizer ignore-call */ __( 'Form was Successfully Updated', 'formidable' );
Loading history...
218
            if ( defined( 'DOING_AJAX' ) ) {
219
				wp_die( $message );
0 ignored issues
show
Bug introduced by
The function wp_die was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

219
				/** @scrutinizer ignore-call */ 
220
    wp_die( $message );
Loading history...
220
            }
221
			return self::get_edit_vars( $id, array(), $message );
0 ignored issues
show
Bug introduced by
Are you sure the usage of self::get_edit_vars($id, array(), $message) targeting FrmFormsController::get_edit_vars() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

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

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

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

Loading history...
222
        }
223
    }
224
225
	/**
226
	 * Redirect to the url for creating from a template
227
	 * Also delete the current form
228
	 * @since 2.0
229
	 */
230
	public static function _create_from_template() {
231
		FrmAppHelper::permission_check('frm_edit_forms');
232
		check_ajax_referer( 'frm_ajax', 'nonce' );
0 ignored issues
show
Bug introduced by
The function check_ajax_referer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

232
		/** @scrutinizer ignore-call */ 
233
  check_ajax_referer( 'frm_ajax', 'nonce' );
Loading history...
233
234
		$current_form = FrmAppHelper::get_param( 'this_form', '', 'get', 'absint' );
235
		$template_id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
236
237
		if ( $current_form ) {
238
			FrmForm::destroy( $current_form );
239
		}
240
241
		echo esc_url_raw( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template_id ) ) );
0 ignored issues
show
Bug introduced by
The function absint was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

241
		echo esc_url_raw( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . /** @scrutinizer ignore-call */ absint( $template_id ) ) );
Loading history...
Bug introduced by
The function admin_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

241
		echo esc_url_raw( /** @scrutinizer ignore-call */ admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template_id ) ) );
Loading history...
Bug introduced by
The function esc_url_raw was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

241
		echo /** @scrutinizer ignore-call */ esc_url_raw( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template_id ) ) );
Loading history...
242
		wp_die();
0 ignored issues
show
Bug introduced by
The function wp_die was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

242
		/** @scrutinizer ignore-call */ 
243
  wp_die();
Loading history...
243
	}
244
245
    public static function duplicate() {
246
        FrmAppHelper::permission_check('frm_edit_forms');
247
248
		$params = FrmForm::list_page_params();
249
        $form = FrmForm::duplicate( $params['id'], $params['template'], true );
250
        $message = $params['template'] ? __( 'Form template was Successfully Created', 'formidable' ) : __( 'Form was Successfully Copied', 'formidable' );
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

250
        $message = $params['template'] ? /** @scrutinizer ignore-call */ __( 'Form template was Successfully Created', 'formidable' ) : __( 'Form was Successfully Copied', 'formidable' );
Loading history...
251
        if ( $form ) {
0 ignored issues
show
introduced by
The condition $form can never be true.
Loading history...
252
			return self::get_edit_vars( $form, array(), $message, true );
253
        } else {
254
            return self::display_forms_list($params, __( 'There was a problem creating the new template.', 'formidable' ));
255
        }
256
    }
257
258
    public static function page_preview() {
259
		$params = FrmForm::list_page_params();
260
        if ( ! $params['form'] ) {
261
            return;
262
        }
263
264
        $form = FrmForm::getOne( $params['form'] );
265
		if ( $form ) {
0 ignored issues
show
introduced by
The condition $form can never be true.
Loading history...
266
			return self::show_form( $form->id, '', true, true );
267
		}
268
    }
269
270
	/**
271
	 * @since 3.0
272
	 */
273
	public static function show_page_preview() {
274
		echo self::page_preview();
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'self'
Loading history...
Bug introduced by
Are you sure the usage of self::page_preview() targeting FrmFormsController::page_preview() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

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

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

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

Loading history...
275
	}
276
277
    public static function preview() {
278
        do_action( 'frm_wp' );
0 ignored issues
show
Bug introduced by
The function do_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

278
        /** @scrutinizer ignore-call */ 
279
        do_action( 'frm_wp' );
Loading history...
279
280
        global $frm_vars;
281
        $frm_vars['preview'] = true;
282
283
		self::load_wp();
284
285
		$include_theme = FrmAppHelper::get_param( 'theme', '', 'get', 'absint' );
286
		if ( $include_theme ) {
287
			self::set_preview_query();
288
			self::load_theme_preview();
289
		} else {
290
			self::load_direct_preview();
291
		}
292
293
		wp_die();
0 ignored issues
show
Bug introduced by
The function wp_die was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

293
		/** @scrutinizer ignore-call */ 
294
  wp_die();
Loading history...
294
	}
295
296
	/**
297
	 * @since 3.0
298
	 */
299
	private static function load_wp() {
300
		if ( ! defined( 'ABSPATH' ) && ! defined( 'XMLRPC_REQUEST' ) ) {
301
			global $wp;
302
			$root = dirname( dirname( dirname( dirname( __FILE__ ) ) ) );
303
			include_once( $root . '/wp-config.php' );
304
			$wp->init();
305
			$wp->register_globals();
306
		}
307
	}
308
309
	private static function set_preview_query() {
310
		$random_page = get_posts( array(
0 ignored issues
show
Bug introduced by
The function get_posts was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

310
		$random_page = /** @scrutinizer ignore-call */ get_posts( array(
Loading history...
311
			'numberposts' => 1,
312
			'orderby'     => 'date',
313
			'order'       => 'ASC',
314
			'post_type'   => 'page',
315
		) );
316
317
		if ( ! empty( $random_page ) ) {
318
			$random_page = reset( $random_page );
319
			query_posts( array(
0 ignored issues
show
Coding Style introduced by
The use of function query_posts() is discouraged; use WP_Query() instead
Loading history...
Bug introduced by
The function query_posts was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

319
			/** @scrutinizer ignore-call */ 
320
   query_posts( array(
Loading history...
320
				'post_type' => 'page',
321
				'page_id'   => $random_page->ID,
322
			) );
323
		}
324
	}
325
326
	/**
327
	 * @since 3.0
328
	 */
329
	private static function load_theme_preview() {
330
		add_filter( 'wp_title', 'FrmFormsController::preview_title', 9999 );
0 ignored issues
show
Bug introduced by
The function add_filter was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

330
		/** @scrutinizer ignore-call */ 
331
  add_filter( 'wp_title', 'FrmFormsController::preview_title', 9999 );
Loading history...
331
		add_filter( 'the_title', 'FrmFormsController::preview_page_title', 9999 );
332
		add_filter( 'the_content', 'FrmFormsController::preview_content', 9999 );
333
		add_action( 'loop_no_results', 'FrmFormsController::show_page_preview' );
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

333
		/** @scrutinizer ignore-call */ 
334
  add_action( 'loop_no_results', 'FrmFormsController::show_page_preview' );
Loading history...
334
		add_filter( 'is_active_sidebar', '__return_false' );
335
		get_template_part( 'page' );
0 ignored issues
show
Bug introduced by
The function get_template_part was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

335
		/** @scrutinizer ignore-call */ 
336
  get_template_part( 'page' );
Loading history...
336
	}
337
338
339
	/**
340
	 * Set the page title for the theme preview page
341
	 *
342
	 * @since 3.0
343
	 */
344
	public static function preview_page_title( $title ) {
345
		if ( in_the_loop() ) {
0 ignored issues
show
Bug introduced by
The function in_the_loop was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

345
		if ( /** @scrutinizer ignore-call */ in_the_loop() ) {
Loading history...
346
			$title = self::preview_title( $title );
347
		}
348
		return $title;
349
	}
350
351
	/**
352
	 * Set the page title for the theme preview page
353
	 *
354
	 * @since 3.0
355
	 */
356
	public static function preview_title( $title ) {
357
		return __( 'Form Preview', 'formidable' );
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

357
		return /** @scrutinizer ignore-call */ __( 'Form Preview', 'formidable' );
Loading history...
358
	}
359
360
	/**
361
	 * Set the page content for the theme preview page
362
	 *
363
	 * @since 3.0
364
	 */
365
	public static function preview_content( $content ) {
366
		if ( in_the_loop() ) {
0 ignored issues
show
Bug introduced by
The function in_the_loop was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

366
		if ( /** @scrutinizer ignore-call */ in_the_loop() ) {
Loading history...
367
			$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() targeting 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...
368
		}
369
		return $content;
370
	}
371
372
	/**
373
	 * @since 3.0
374
	 */
375
	private static function load_direct_preview() {
376
		header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

376
		header( 'Content-Type: text/html; charset=' . /** @scrutinizer ignore-call */ get_option( 'blog_charset' ) );
Loading history...
377
378
		$key = FrmAppHelper::simple_get( 'form', 'sanitize_title' );
379
		if ( $key == '' ) {
380
			$key = FrmAppHelper::get_post_param( 'form', '', 'sanitize_title' );
381
		}
382
383
		$form = FrmForm::getAll( array( 'form_key' => $key ), '', 1 );
384
		if ( empty( $form ) ) {
385
			$form = FrmForm::getAll( array(), '', 1 );
386
		}
387
388
		require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/direct.php' );
389
	}
390
391
	public static function register_pro_scripts() {
392
		_deprecated_function( __FUNCTION__, '2.03', 'FrmProEntriesController::register_scripts' );
0 ignored issues
show
Bug introduced by
The function _deprecated_function was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

392
		/** @scrutinizer ignore-call */ 
393
  _deprecated_function( __FUNCTION__, '2.03', 'FrmProEntriesController::register_scripts' );
Loading history...
393
		if ( FrmAppHelper::pro_is_installed() ) {
394
			FrmProEntriesController::register_scripts();
0 ignored issues
show
Bug introduced by
The type FrmProEntriesController was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
395
		}
396
	}
397
398
    public static function untrash() {
399
		self::change_form_status( 'untrash' );
400
    }
401
402
	public static function bulk_untrash( $ids ) {
403
        FrmAppHelper::permission_check('frm_edit_forms');
404
405
        $count = FrmForm::set_status( $ids, 'published' );
406
407
        $message = sprintf(_n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), 1 );
0 ignored issues
show
Bug introduced by
The function _n was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

407
        $message = sprintf(/** @scrutinizer ignore-call */ _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), 1 );
Loading history...
408
        return $message;
409
    }
410
411
    public static function trash() {
412
		self::change_form_status( 'trash' );
413
    }
414
415
	/**
416
	 * @param string $status
417
	 *
418
	 * @return int The number of forms changed
419
	 */
420
	public static function change_form_status( $status ) {
421
		$available_status = array(
422
			'untrash' => array(
423
				'permission' => 'frm_edit_forms',
424
				'new_status' => 'published',
425
			),
426
			'trash'   => array(
427
				'permission' => 'frm_delete_forms',
428
				'new_status' => 'trash',
429
			),
430
		);
431
432
		if ( ! isset( $available_status[ $status ] ) ) {
433
			return;
434
		}
435
436
		FrmAppHelper::permission_check( $available_status[ $status ]['permission'] );
437
438
		$params = FrmForm::list_page_params();
439
440
		//check nonce url
441
		check_admin_referer( $status . '_form_' . $params['id'] );
0 ignored issues
show
Bug introduced by
The function check_admin_referer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

441
		/** @scrutinizer ignore-call */ 
442
  check_admin_referer( $status . '_form_' . $params['id'] );
Loading history...
442
443
		$count = 0;
444
		if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) {
445
			$count++;
446
		}
447
448
		$form_type = FrmAppHelper::get_simple_request( array(
449
			'param' => 'form_type',
450
			'type' => 'request',
451
		) );
452
453
		$available_status['untrash']['message'] = sprintf(_n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
0 ignored issues
show
Bug introduced by
The function _n was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

453
		$available_status['untrash']['message'] = sprintf(/** @scrutinizer ignore-call */ _n( '%1$s form restored from the Trash.', '%1$s forms restored from the Trash.', $count, 'formidable' ), $count );
Loading history...
454
		$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>' );
0 ignored issues
show
Bug introduced by
The function esc_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

454
		$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="' . /** @scrutinizer ignore-call */ esc_url( wp_nonce_url( '?page=formidable&frm_action=untrash&form_type=' . $form_type . '&id=' . $params['id'], 'untrash_form_' . $params['id'] ) ) . '">', '</a>' );
Loading history...
Bug introduced by
The function wp_nonce_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

454
		$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( /** @scrutinizer ignore-call */ wp_nonce_url( '?page=formidable&frm_action=untrash&form_type=' . $form_type . '&id=' . $params['id'], 'untrash_form_' . $params['id'] ) ) . '">', '</a>' );
Loading history...
Bug introduced by
Are you sure $form_type of type string|array can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

454
		$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=' . /** @scrutinizer ignore-type */ $form_type . '&id=' . $params['id'], 'untrash_form_' . $params['id'] ) ) . '">', '</a>' );
Loading history...
455
456
		$message = $available_status[ $status ]['message'];
457
458
		self::display_forms_list( $params, $message );
459
	}
460
461
	public static function bulk_trash( $ids ) {
462
        FrmAppHelper::permission_check('frm_delete_forms');
463
464
        $count = 0;
465
        foreach ( $ids as $id ) {
466
            if ( FrmForm::trash( $id ) ) {
467
                $count++;
468
            }
469
        }
470
471
		$current_page = FrmAppHelper::get_simple_request( array(
472
			'param' => 'form_type',
473
			'type' => 'request',
474
		) );
475
		$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=list&action=bulk_untrash&form_type=' . $current_page . '&item-action=' . implode( ',', $ids ), 'bulk-toplevel_page_formidable' ) ) . '">', '</a>' );
0 ignored issues
show
Bug introduced by
The function _n was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

475
		$message = sprintf( /** @scrutinizer ignore-call */ _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=list&action=bulk_untrash&form_type=' . $current_page . '&item-action=' . implode( ',', $ids ), 'bulk-toplevel_page_formidable' ) ) . '">', '</a>' );
Loading history...
Bug introduced by
The function wp_nonce_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

475
		$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( /** @scrutinizer ignore-call */ wp_nonce_url( '?page=formidable&frm_action=list&action=bulk_untrash&form_type=' . $current_page . '&item-action=' . implode( ',', $ids ), 'bulk-toplevel_page_formidable' ) ) . '">', '</a>' );
Loading history...
Bug introduced by
Are you sure $current_page of type string|array can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

475
		$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=list&action=bulk_untrash&form_type=' . /** @scrutinizer ignore-type */ $current_page . '&item-action=' . implode( ',', $ids ), 'bulk-toplevel_page_formidable' ) ) . '">', '</a>' );
Loading history...
Bug introduced by
The function esc_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

475
		$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="' . /** @scrutinizer ignore-call */ 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' ) ) . '">', '</a>' );
Loading history...
476
477
        return $message;
478
    }
479
480
    public static function destroy() {
481
        FrmAppHelper::permission_check('frm_delete_forms');
482
483
		$params = FrmForm::list_page_params();
484
485
        //check nonce url
486
        check_admin_referer('destroy_form_' . $params['id']);
0 ignored issues
show
Bug introduced by
The function check_admin_referer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

486
        /** @scrutinizer ignore-call */ 
487
        check_admin_referer('destroy_form_' . $params['id']);
Loading history...
487
488
        $count = 0;
489
        if ( FrmForm::destroy( $params['id'] ) ) {
490
            $count++;
491
        }
492
493
        $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
0 ignored issues
show
Bug introduced by
The function _n was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

493
        $message = sprintf(/** @scrutinizer ignore-call */ _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
Loading history...
494
495
		self::display_forms_list( $params, $message );
496
    }
497
498
	public static function bulk_destroy( $ids ) {
499
        FrmAppHelper::permission_check('frm_delete_forms');
500
501
        $count = 0;
502
        foreach ( $ids as $id ) {
503
            $d = FrmForm::destroy( $id );
504
            if ( $d ) {
505
                $count++;
506
            }
507
        }
508
509
        $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
0 ignored issues
show
Bug introduced by
The function _n was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

509
        $message = sprintf(/** @scrutinizer ignore-call */ _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
Loading history...
510
511
        return $message;
512
    }
513
514
    private static function delete_all() {
515
        //check nonce url
516
        $permission_error = FrmAppHelper::permission_nonce_error('frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable');
517
        if ( $permission_error !== false ) {
518
			self::display_forms_list( array(), '', array( $permission_error ) );
519
            return;
520
        }
521
522
		$count = FrmForm::scheduled_delete( time() );
523
        $message = sprintf(_n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
0 ignored issues
show
Bug introduced by
The function _n was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

523
        $message = sprintf(/** @scrutinizer ignore-call */ _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count);
Loading history...
524
525
		self::display_forms_list( array(), $message );
526
    }
527
528
	/**
529
	* Inserts Formidable button
530
	* Hook exists since 2.5.0
531
	*
532
	* @since 2.0.15
533
	*/
534
	public static function insert_form_button() {
535
		if ( current_user_can('frm_view_forms') ) {
0 ignored issues
show
Bug introduced by
The function current_user_can was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

535
		if ( /** @scrutinizer ignore-call */ current_user_can('frm_view_forms') ) {
Loading history...
536
			$menu_name = FrmAppHelper::get_menu_name();
537
			$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' ) . '">
0 ignored issues
show
Bug introduced by
The function esc_attr__ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

537
			$content = '<a href="#TB_inline?width=50&height=50&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . /** @scrutinizer ignore-call */ esc_attr__( 'Add forms and content', 'formidable' ) . '">
Loading history...
538
				<span class="frm-buttons-icon wp-media-buttons-icon"></span> ' .
539
				$menu_name . '</a>';
540
			echo wp_kses_post( $content );
0 ignored issues
show
Bug introduced by
The function wp_kses_post was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

540
			echo /** @scrutinizer ignore-call */ wp_kses_post( $content );
Loading history...
541
		}
542
	}
543
544
    public static function insert_form_popup() {
545
		$page = basename( FrmAppHelper::get_server_value( 'PHP_SELF' ) );
546
		if ( ! in_array( $page, array( 'post.php', 'page.php', 'page-new.php', 'post-new.php' ) ) ) {
547
            return;
548
        }
549
550
        FrmAppHelper::load_admin_wide_js();
551
552
        $shortcodes = array(
553
			'formidable' => array(
554
				'name'  => __( 'Form', 'formidable' ),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

554
				'name'  => /** @scrutinizer ignore-call */ __( 'Form', 'formidable' ),
Loading history...
555
				'label' => __( 'Insert a Form', 'formidable' ),
556
			),
557
        );
558
559
        $shortcodes = apply_filters('frm_popup_shortcodes', $shortcodes);
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

559
        $shortcodes = /** @scrutinizer ignore-call */ apply_filters('frm_popup_shortcodes', $shortcodes);
Loading history...
560
561
		include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/insert_form_popup.php' );
562
    }
563
564
    public static function get_shortcode_opts() {
565
		FrmAppHelper::permission_check('frm_view_forms');
566
        check_ajax_referer( 'frm_ajax', 'nonce' );
0 ignored issues
show
Bug introduced by
The function check_ajax_referer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

566
        /** @scrutinizer ignore-call */ 
567
        check_ajax_referer( 'frm_ajax', 'nonce' );
Loading history...
567
568
		$shortcode = FrmAppHelper::get_post_param( 'shortcode', '', 'sanitize_text_field' );
569
        if ( empty($shortcode) ) {
570
            wp_die();
0 ignored issues
show
Bug introduced by
The function wp_die was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

570
            /** @scrutinizer ignore-call */ 
571
            wp_die();
Loading history...
571
        }
572
573
		echo '<div id="sc-opts-' . esc_attr( $shortcode ) . '" class="frm_shortcode_option">';
0 ignored issues
show
Bug introduced by
The function esc_attr was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

573
		echo '<div id="sc-opts-' . /** @scrutinizer ignore-call */ esc_attr( $shortcode ) . '" class="frm_shortcode_option">';
Loading history...
574
		echo '<input type="radio" name="frmsc" value="' . esc_attr( $shortcode ) . '" id="sc-' . esc_attr( $shortcode ) . '" class="frm_hidden" />';
575
576
        $form_id = '';
577
        $opts = array();
578
		switch ( $shortcode ) {
579
            case 'formidable':
580
                $opts = array(
581
					'form_id'       => 'id',
582
                    //'key' => ',
583
					'title'         => array(
584
						'val'   => 1,
585
						'label' => __( 'Display form title', 'formidable' ),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

585
						'label' => /** @scrutinizer ignore-call */ __( 'Display form title', 'formidable' ),
Loading history...
586
					),
587
					'description'   => array(
588
						'val'   => 1,
589
						'label' => __( 'Display form description', 'formidable' ),
590
					),
591
					'minimize'      => array(
592
						'val'   => 1,
593
						'label' => __( 'Minimize form HTML', 'formidable' ),
594
					),
595
                );
596
        }
597
		$opts = apply_filters( 'frm_sc_popup_opts', $opts, $shortcode );
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

597
		$opts = /** @scrutinizer ignore-call */ apply_filters( 'frm_sc_popup_opts', $opts, $shortcode );
Loading history...
598
599
		if ( isset( $opts['form_id'] ) && is_string( $opts['form_id'] ) ) {
600
			// allow other shortcodes to use the required form id option
601
			$form_id = $opts['form_id'];
602
			unset( $opts['form_id'] );
603
		}
604
605
		include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/shortcode_opts.php' );
606
607
        echo '</div>';
608
609
        wp_die();
610
    }
611
612
	public static function display_forms_list( $params = array(), $message = '', $errors = array() ) {
613
        FrmAppHelper::permission_check( 'frm_view_forms' );
614
615
        global $wpdb, $frm_vars;
616
617
		if ( empty( $params ) ) {
618
			$params = FrmForm::list_page_params();
619
        }
620
621
        $wp_list_table = new FrmFormsListHelper( compact( 'params' ) );
622
623
        $pagenum = $wp_list_table->get_pagenum();
624
625
        $wp_list_table->prepare_items();
626
627
        $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
628
        if ( $pagenum > $total_pages && $total_pages > 0 ) {
629
			wp_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
0 ignored issues
show
Bug introduced by
The function add_query_arg was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

629
			wp_redirect( esc_url_raw( /** @scrutinizer ignore-call */ add_query_arg( 'paged', $total_pages ) ) );
Loading history...
Bug introduced by
The function wp_redirect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

629
			/** @scrutinizer ignore-call */ 
630
   wp_redirect( esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
Loading history...
Bug introduced by
The function esc_url_raw was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

629
			wp_redirect( /** @scrutinizer ignore-call */ esc_url_raw( add_query_arg( 'paged', $total_pages ) ) );
Loading history...
630
            die();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
631
        }
632
633
		require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/list.php' );
634
    }
635
636
	public static function get_columns( $columns ) {
637
	    $columns['cb'] = '<input type="checkbox" />';
638
	    $columns['id'] = 'ID';
639
640
		$type = FrmAppHelper::get_simple_request( array(
641
			'param'   => 'form_type',
642
			'type'    => 'request',
643
			'default' => 'published',
644
		) );
645
646
        if ( 'template' == $type ) {
647
            $columns['name']        = __( 'Template Name', 'formidable' );
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

647
            $columns['name']        = /** @scrutinizer ignore-call */ __( 'Template Name', 'formidable' );
Loading history...
648
            $columns['type']        = __( 'Type', 'formidable' );
649
            $columns['form_key']    = __( 'Key', 'formidable' );
650
        } else {
651
            $columns['name']        = __( 'Form Title', 'formidable' );
652
            $columns['entries']     = __( 'Entries', 'formidable' );
653
            $columns['form_key']    = __( 'Key', 'formidable' );
654
            $columns['shortcode']   = __( 'Shortcodes', 'formidable' );
655
        }
656
657
        $columns['created_at'] = __( 'Date', 'formidable' );
658
659
		add_screen_option( 'per_page', array(
0 ignored issues
show
Bug introduced by
The function add_screen_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

659
		/** @scrutinizer ignore-call */ 
660
  add_screen_option( 'per_page', array(
Loading history...
660
			'label'   => __( 'Forms', 'formidable' ),
661
			'default' => 20,
662
			'option'  => 'formidable_page_formidable_per_page',
663
		) );
664
665
        return $columns;
666
	}
667
668
	public static function get_sortable_columns() {
669
		return array(
670
			'id'            => 'id',
671
			'name'          => 'name',
672
			'description'   => 'description',
673
			'form_key'      => 'form_key',
674
			'created_at'    => 'created_at',
675
		);
676
	}
677
678
	public static function hidden_columns( $hidden_columns ) {
679
		$type = FrmAppHelper::get_simple_request( array(
680
			'param' => 'form_type',
681
			'type'  => 'request',
682
		) );
683
684
		if ( $type === 'template' ) {
685
			$hidden_columns[] = 'id';
686
			$hidden_columns[] = 'form_key';
687
		}
688
689
		return $hidden_columns;
690
	}
691
692
	public static function save_per_page( $save, $option, $value ) {
693
        if ( $option == 'formidable_page_formidable_per_page' ) {
694
            $save = (int) $value;
695
        }
696
        return $save;
697
    }
698
699
	private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) {
700
        global $frm_vars;
701
702
        $form = FrmForm::getOne( $id );
703
        if ( ! $form ) {
0 ignored issues
show
introduced by
The condition ! $form can never be false.
Loading history...
704
            wp_die( __( 'You are trying to edit a form that does not exist.', 'formidable' ) );
0 ignored issues
show
Bug introduced by
The function wp_die was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

704
            /** @scrutinizer ignore-call */ 
705
            wp_die( __( 'You are trying to edit a form that does not exist.', 'formidable' ) );
Loading history...
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

704
            wp_die( /** @scrutinizer ignore-call */ __( 'You are trying to edit a form that does not exist.', 'formidable' ) );
Loading history...
705
        }
706
707
        if ( $form->parent_form_id ) {
708
			wp_die( sprintf( __( '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>' ));
0 ignored issues
show
Bug introduced by
The function admin_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

708
			wp_die( sprintf( __( 'You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable' ), '<a href="' . esc_url( /** @scrutinizer ignore-call */ admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form->parent_form_id ) ) . '">', '</a>' ));
Loading history...
Bug introduced by
The function esc_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

708
			wp_die( sprintf( __( 'You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable' ), '<a href="' . /** @scrutinizer ignore-call */ esc_url( admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form->parent_form_id ) ) . '">', '</a>' ));
Loading history...
709
        }
710
711
		$frm_field_selection = FrmField::field_selection();
712
        $fields = FrmField::get_all_for_form($form->id);
713
714
        // Automatically add end section fields if they don't exist (2.0 migration)
715
        $reset_fields = false;
716
        FrmFormsHelper::auto_add_end_section_fields( $form, $fields, $reset_fields );
717
718
        if ( $reset_fields ) {
0 ignored issues
show
introduced by
The condition $reset_fields can never be true.
Loading history...
719
            $fields = FrmField::get_all_for_form( $form->id, '', 'exclude' );
720
        }
721
722
        unset($end_section_values, $last_order, $open, $reset_fields);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $last_order seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $open seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $end_section_values does not exist. Did you maybe mean $values?
Loading history...
723
724
		$args = array( 'parent_form_id' => $form->id );
725
		$values = FrmAppHelper::setup_edit_vars( $form, 'forms', '', true, array(), $args );
726
		$values['fields'] = $fields;
727
728
        $edit_message = __( 'Form was Successfully Updated', 'formidable' );
729
        if ( $form->is_template && $message == $edit_message ) {
730
            $message = __( 'Template was Successfully Updated', 'formidable' );
731
        }
732
733
		$all_templates = FrmForm::getAll( array( 'is_template' => 1 ), 'name' );
734
735
        if ( $form->default_template ) {
736
            wp_die(__( 'That template cannot be edited', 'formidable' ));
737
        } else if ( defined('DOING_AJAX') ) {
738
            wp_die();
739
        } else if ( $create_link ) {
740
			require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php' );
741
        } else {
742
			require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' );
743
        }
744
    }
745
746
	public static function get_settings_vars( $id, $errors = array(), $message = '' ) {
747
		FrmAppHelper::permission_check( 'frm_edit_forms' );
748
749
        global $frm_vars;
750
751
        $form = FrmForm::getOne( $id );
752
753
        $fields = FrmField::get_all_for_form($id);
754
        $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
755
756
        if ( isset($values['default_template']) && $values['default_template'] ) {
757
            wp_die(__( 'That template cannot be edited', 'formidable' ));
0 ignored issues
show
Bug introduced by
The function wp_die was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

757
            /** @scrutinizer ignore-call */ 
758
            wp_die(__( 'That template cannot be edited', 'formidable' ));
Loading history...
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

757
            wp_die(/** @scrutinizer ignore-call */ __( 'That template cannot be edited', 'formidable' ));
Loading history...
758
        }
759
760
		self::clean_submit_html( $values );
761
762
        $action_controls = FrmFormActionsController::get_form_actions();
763
764
        $sections = apply_filters('frm_add_form_settings_section', array(), $values);
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

764
        $sections = /** @scrutinizer ignore-call */ apply_filters('frm_add_form_settings_section', array(), $values);
Loading history...
765
        $pro_feature = FrmAppHelper::pro_is_installed() ? '' : ' class="pro_feature"';
766
767
        $styles = apply_filters('frm_get_style_opts', array());
768
769
		$first_h3 = 'frm_first_h3';
770
771
		require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/settings.php' );
772
    }
773
774
	/**
775
	 * Replace old Submit Button href with new href to avoid errors in Chrome
776
	 *
777
	 * @since 2.03.08
778
	 *
779
	 * @param array|boolean $values
780
	 */
781
	private static function clean_submit_html( &$values ) {
782
		if ( is_array( $values ) && isset( $values['submit_html'] ) ) {
783
			$values['submit_html'] = str_replace( 'javascript:void(0)', '#', $values['submit_html'] );
784
		}
785
	}
786
787
    public static function mb_tags_box( $form_id, $class = '' ) {
788
        $fields = FrmField::get_all_for_form($form_id, '', 'include');
789
        $linked_forms = array();
790
        $col = 'one';
791
        $settings_tab = FrmAppHelper::is_admin_page('formidable' ) ? true : false;
792
793
		$cond_shortcodes = apply_filters( 'frm_conditional_shortcodes', array() );
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

793
		$cond_shortcodes = /** @scrutinizer ignore-call */ apply_filters( 'frm_conditional_shortcodes', array() );
Loading history...
794
		$adv_shortcodes = self::get_advanced_shortcodes();
795
		$user_fields = apply_filters( 'frm_user_shortcodes', array() );
796
		$entry_shortcodes = self::get_shortcode_helpers( $settings_tab );
797
798
		include( FrmAppHelper::plugin_path() . '/classes/views/shared/mb_adv_info.php' );
799
    }
800
801
	/**
802
	 * Get an array of the options to display in the advanced tab
803
	 * of the customization panel
804
	 * @since 2.0.6
805
	 */
806
	private static function get_advanced_shortcodes() {
807
		$adv_shortcodes = array(
808
			'sep=", "'       => array(
809
				'label' => __( 'Separator', 'formidable' ),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

809
				'label' => /** @scrutinizer ignore-call */ __( 'Separator', 'formidable' ),
Loading history...
810
				'title' => __( 'Use a different separator for checkbox fields', 'formidable' ),
811
			),
812
			'format="d-m-Y"' => __( 'Date Format', 'formidable' ),
813
			'show="field_label"' => __( 'Field Label', 'formidable' ),
814
			'wpautop=0'      => array(
815
				'label' => __( 'No Auto P', 'formidable' ),
816
				'title' => __( 'Do not automatically add any paragraphs or line breaks', 'formidable' ),
817
			),
818
		);
819
		$adv_shortcodes = apply_filters( 'frm_advanced_shortcodes', $adv_shortcodes );
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

819
		$adv_shortcodes = /** @scrutinizer ignore-call */ apply_filters( 'frm_advanced_shortcodes', $adv_shortcodes );
Loading history...
820
		// __( 'Leave blank instead of defaulting to User Login', 'formidable' ) : blank=1
821
822
		return $adv_shortcodes;
823
	}
824
825
	/**
826
	 * Get an array of the helper shortcodes to display in the customization panel
827
	 * @since 2.0.6
828
	 */
829
	private static function get_shortcode_helpers( $settings_tab ) {
830
		$entry_shortcodes = array(
831
			'id'        => __( 'Entry ID', 'formidable' ),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

831
			'id'        => /** @scrutinizer ignore-call */ __( 'Entry ID', 'formidable' ),
Loading history...
832
			'key'       => __( 'Entry Key', 'formidable' ),
833
			'post_id'   => __( 'Post ID', 'formidable' ),
834
			'ip'        => __( 'User IP', 'formidable' ),
835
			'created-at' => __( 'Entry created', 'formidable' ),
836
			'updated-at' => __( 'Entry updated', 'formidable' ),
837
			''          => '',
838
			'siteurl'   => __( 'Site URL', 'formidable' ),
839
			'sitename'  => __( 'Site Name', 'formidable' ),
840
        );
841
842
		if ( ! FrmAppHelper::pro_is_installed() ) {
843
			unset( $entry_shortcodes['post_id'] );
844
		}
845
846
		if ( $settings_tab ) {
847
			$entry_shortcodes['default-message'] = __( 'Default Msg', 'formidable' );
848
			$entry_shortcodes['default-html'] = __( 'Default HTML', 'formidable' );
849
			$entry_shortcodes['default-plain'] = __( 'Default Plain', 'formidable' );
850
		}
851
852
		/**
853
		 * Use this hook to add or remove buttons in the helpers section
854
		 * in the customization panel
855
		 * @since 2.0.6
856
		 */
857
		$entry_shortcodes = apply_filters( 'frm_helper_shortcodes', $entry_shortcodes, $settings_tab );
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

857
		$entry_shortcodes = /** @scrutinizer ignore-call */ apply_filters( 'frm_helper_shortcodes', $entry_shortcodes, $settings_tab );
Loading history...
858
859
		return $entry_shortcodes;
860
	}
861
862
	/**
863
	 * Insert the form class setting into the form
864
	 */
865
	public static function form_classes( $form ) {
866
		if ( isset($form->options['form_class']) ) {
867
			echo esc_attr( sanitize_text_field( $form->options['form_class'] ) );
0 ignored issues
show
Bug introduced by
The function sanitize_text_field was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

867
			echo esc_attr( /** @scrutinizer ignore-call */ sanitize_text_field( $form->options['form_class'] ) );
Loading history...
Bug introduced by
The function esc_attr was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

867
			echo /** @scrutinizer ignore-call */ esc_attr( sanitize_text_field( $form->options['form_class'] ) );
Loading history...
868
		}
869
870
		if ( isset( $form->options['js_validate'] ) && $form->options['js_validate'] ) {
871
			echo ' frm_js_validate ';
872
		}
873
	}
874
875
	public static function get_email_html() {
876
		FrmAppHelper::permission_check( 'frm_view_forms' );
877
		check_ajax_referer( 'frm_ajax', 'nonce' );
0 ignored issues
show
Bug introduced by
The function check_ajax_referer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

877
		/** @scrutinizer ignore-call */ 
878
  check_ajax_referer( 'frm_ajax', 'nonce' );
Loading history...
878
879
		echo FrmEntriesController::show_entry_shortcode( array(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'FrmEntriesController'
Loading history...
Bug introduced by
Are you sure FrmEntriesController::sh..._text', '', 'absint'))) of type string|array can be used in echo? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

879
		echo /** @scrutinizer ignore-type */ FrmEntriesController::show_entry_shortcode( array(
Loading history...
880
			'form_id'       => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ),
881
			'default_email' => true,
882
			'plain_text'    => FrmAppHelper::get_post_param( 'plain_text', '', 'absint' ),
883
		) );
884
		wp_die();
0 ignored issues
show
Bug introduced by
The function wp_die was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

884
		/** @scrutinizer ignore-call */ 
885
  wp_die();
Loading history...
885
	}
886
887
    public static function filter_content( $content, $form, $entry = false ) {
888
		self::get_entry_by_param( $entry );
889
        if ( ! $entry ) {
890
            return $content;
891
        }
892
893
        if ( is_object( $form ) ) {
894
            $form = $form->id;
895
        }
896
897
        $shortcodes = FrmFieldsHelper::get_shortcodes( $content, $form );
898
        $content = apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

898
        $content = /** @scrutinizer ignore-call */ apply_filters( 'frm_replace_content_shortcodes', $content, $entry, $shortcodes );
Loading history...
899
900
        return $content;
901
    }
902
903
	private static function get_entry_by_param( &$entry ) {
904
		if ( ! $entry || ! is_object( $entry ) ) {
905
			if ( ! $entry || ! is_numeric( $entry ) ) {
906
				$entry = FrmAppHelper::get_post_param( 'id', false, 'sanitize_title' );
907
			}
908
909
			FrmEntry::maybe_get_entry( $entry );
910
		}
911
	}
912
913
    public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
914
        return FrmFieldsHelper::replace_content_shortcodes( $content, $entry, $shortcodes );
915
    }
916
917
    public static function process_bulk_form_actions( $errors ) {
918
        if ( ! $_REQUEST ) {
919
            return $errors;
920
        }
921
922
		$bulkaction = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
923
        if ( $bulkaction == -1 ) {
924
			$bulkaction = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
925
        }
926
927
        if ( ! empty( $bulkaction ) && strpos( $bulkaction, 'bulk_' ) === 0 ) {
928
            FrmAppHelper::remove_get_action();
929
930
            $bulkaction = str_replace( 'bulk_', '', $bulkaction );
931
        }
932
933
		$ids = FrmAppHelper::get_param( 'item-action', '', 'get', 'sanitize_text_field' );
934
        if ( empty( $ids ) ) {
935
            $errors[] = __( 'No forms were specified', 'formidable' );
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

935
            $errors[] = /** @scrutinizer ignore-call */ __( 'No forms were specified', 'formidable' );
Loading history...
936
            return $errors;
937
        }
938
939
        $permission_error = FrmAppHelper::permission_nonce_error( '', '_wpnonce', 'bulk-toplevel_page_formidable' );
940
        if ( $permission_error !== false ) {
941
            $errors[] = $permission_error;
942
            return $errors;
943
        }
944
945
        if ( ! is_array( $ids ) ) {
946
            $ids = explode( ',', $ids );
947
        }
948
949
        switch ( $bulkaction ) {
950
            case 'delete':
951
                $message = self::bulk_destroy( $ids );
952
				break;
953
            case 'trash':
954
                $message = self::bulk_trash( $ids );
955
				break;
956
            case 'untrash':
957
                $message = self::bulk_untrash( $ids );
958
        }
959
960
        if ( isset( $message ) && ! empty( $message ) ) {
961
			echo '<div id="message" class="updated frm_updated_message">' . FrmAppHelper::kses( $message, array( 'a' ) ) . '</div>';
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'FrmAppHelper'
Loading history...
962
        }
963
964
        return $errors;
965
    }
966
967
    public static function add_default_templates( $path, $default = true, $template = true ) {
968
        _deprecated_function( __FUNCTION__, '1.07.05', 'FrmXMLController::add_default_templates()' );
0 ignored issues
show
Bug introduced by
The function _deprecated_function was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

968
        /** @scrutinizer ignore-call */ 
969
        _deprecated_function( __FUNCTION__, '1.07.05', 'FrmXMLController::add_default_templates()' );
Loading history...
969
970
        $path = untrailingslashit(trim($path));
0 ignored issues
show
Bug introduced by
The function untrailingslashit was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

970
        $path = /** @scrutinizer ignore-call */ untrailingslashit(trim($path));
Loading history...
971
		$templates = glob( $path . '/*.php' );
972
973
		for ( $i = count( $templates ) - 1; $i >= 0; $i-- ) {
974
			$filename = str_replace( '.php', '', str_replace( $path . '/', '', $templates[ $i ] ) );
975
			$template_query = array( 'form_key' => $filename );
976
            if ( $template ) {
977
                $template_query['is_template'] = 1;
978
            }
979
            if ( $default ) {
980
                $template_query['default_template'] = 1;
981
            }
982
			$form = FrmForm::getAll( $template_query, '', 1 );
983
984
            $values = FrmFormsHelper::setup_new_vars();
985
            $values['form_key'] = $filename;
986
            $values['is_template'] = $template;
987
            $values['status'] = 'published';
988
            if ( $default ) {
989
                $values['default_template'] = 1;
990
            }
991
992
            include( $templates[ $i ] );
993
994
            //get updated form
995
            if ( isset($form) && ! empty($form) ) {
996
                $old_id = $form->id;
997
                $form = FrmForm::getOne($form->id);
998
            } else {
999
                $old_id = false;
1000
				$form = FrmForm::getAll( $template_query, '', 1 );
1001
            }
1002
1003
            if ( $form ) {
1004
				do_action( 'frm_after_duplicate_form', $form->id, (array) $form, array( 'old_id' => $old_id ) );
0 ignored issues
show
Bug introduced by
The function do_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1004
				/** @scrutinizer ignore-call */ 
1005
    do_action( 'frm_after_duplicate_form', $form->id, (array) $form, array( 'old_id' => $old_id ) );
Loading history...
1005
            }
1006
        }
1007
    }
1008
1009
    public static function route() {
1010
        $action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
1011
        $vars = array();
1012
		if ( isset( $_POST['frm_compact_fields'] ) ) {
1013
			FrmAppHelper::permission_check( 'frm_edit_forms' );
1014
1015
            $json_vars = htmlspecialchars_decode(nl2br(stripslashes(str_replace('&quot;', '\\\"', $_POST['frm_compact_fields'] ))));
1016
            $json_vars = json_decode($json_vars, true);
1017
            if ( empty($json_vars) ) {
1018
                // json decoding failed so we should return an error message
1019
				$action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1020
                if ( 'edit' == $action ) {
1021
                    $action = 'update';
1022
                }
1023
1024
                add_filter('frm_validate_form', 'FrmFormsController::json_error');
0 ignored issues
show
Bug introduced by
The function add_filter was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1024
                /** @scrutinizer ignore-call */ 
1025
                add_filter('frm_validate_form', 'FrmFormsController::json_error');
Loading history...
1025
            } else {
1026
                $vars = FrmAppHelper::json_to_array($json_vars);
1027
                $action = $vars[ $action ];
1028
				unset( $_REQUEST['frm_compact_fields'], $_POST['frm_compact_fields'] );
1029
				$_REQUEST = array_merge( $_REQUEST, $vars );
1030
				$_POST = array_merge( $_POST, $_REQUEST );
1031
            }
1032
        } else {
1033
			$action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
1034
    		if ( isset( $_REQUEST['delete_all'] ) ) {
1035
                // override the action for this page
1036
    			$action = 'delete_all';
1037
            }
1038
        }
1039
1040
		add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1040
		/** @scrutinizer ignore-call */ 
1041
  add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
Loading history...
1041
        FrmAppHelper::trigger_hook_load( 'form' );
1042
1043
        switch ( $action ) {
1044
            case 'new':
1045
                return self::new_form($vars);
0 ignored issues
show
Bug introduced by
Are you sure the usage of self::new_form($vars) targeting FrmFormsController::new_form() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

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

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

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

Loading history...
1046
            case 'create':
1047
            case 'edit':
1048
            case 'update':
1049
            case 'duplicate':
1050
            case 'trash':
1051
            case 'untrash':
1052
            case 'destroy':
1053
            case 'delete_all':
1054
            case 'settings':
1055
            case 'update_settings':
1056
				return self::$action( $vars );
1057
            default:
1058
				do_action( 'frm_form_action_' . $action );
0 ignored issues
show
Bug introduced by
The function do_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1058
				/** @scrutinizer ignore-call */ 
1059
    do_action( 'frm_form_action_' . $action );
Loading history...
1059
				if ( apply_filters( 'frm_form_stop_action_' . $action, false ) ) {
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1059
				if ( /** @scrutinizer ignore-call */ apply_filters( 'frm_form_stop_action_' . $action, false ) ) {
Loading history...
1060
                    return;
1061
                }
1062
1063
				$action = FrmAppHelper::get_param( 'action', '', 'get', 'sanitize_text_field' );
1064
                if ( $action == -1 ) {
1065
					$action = FrmAppHelper::get_param( 'action2', '', 'get', 'sanitize_title' );
1066
                }
1067
1068
                if ( strpos($action, 'bulk_') === 0 ) {
1069
                    FrmAppHelper::remove_get_action();
1070
                    return self::list_form();
1071
                }
1072
1073
                return self::display_forms_list();
1074
        }
1075
    }
1076
1077
    public static function json_error( $errors ) {
1078
        $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1078
        $errors['json'] = /** @scrutinizer ignore-call */ __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' );
Loading history...
1079
        return $errors;
1080
    }
1081
1082
1083
    /* FRONT-END FORMS */
1084
    public static function admin_bar_css() {
1085
		if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
0 ignored issues
show
Bug introduced by
The function is_admin was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1085
		if ( /** @scrutinizer ignore-call */ is_admin() || ! current_user_can( 'frm_edit_forms' ) ) {
Loading history...
Bug introduced by
The function current_user_can was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1085
		if ( is_admin() || ! /** @scrutinizer ignore-call */ current_user_can( 'frm_edit_forms' ) ) {
Loading history...
1086
            return;
1087
        }
1088
1089
		add_action( 'wp_before_admin_bar_render', 'FrmFormsController::admin_bar_configure' );
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1089
		/** @scrutinizer ignore-call */ 
1090
  add_action( 'wp_before_admin_bar_render', 'FrmFormsController::admin_bar_configure' );
Loading history...
1090
		FrmAppHelper::load_font_style();
1091
	}
1092
1093
	public static function admin_bar_configure() {
1094
        global $frm_vars;
1095
        if ( empty($frm_vars['forms_loaded']) ) {
1096
            return;
1097
        }
1098
1099
        $actions = array();
1100
        foreach ( $frm_vars['forms_loaded'] as $form ) {
1101
            if ( is_object($form) ) {
1102
                $actions[ $form->id ] = $form->name;
1103
            }
1104
            unset($form);
1105
        }
1106
1107
        if ( empty($actions) ) {
1108
            return;
1109
        }
1110
1111
		self::add_menu_to_admin_bar();
1112
		self::add_forms_to_admin_bar( $actions );
1113
	}
1114
1115
	/**
1116
	 * @since 2.05.07
1117
	 */
1118
	public static function add_menu_to_admin_bar() {
1119
		global $wp_admin_bar;
1120
1121
		$wp_admin_bar->add_node( array(
1122
			'id'    => 'frm-forms',
1123
			'title' => '<span class="ab-icon"></span><span class="ab-label">' . FrmAppHelper::get_menu_name() . '</span>',
1124
			'href'  => admin_url( 'admin.php?page=formidable' ),
0 ignored issues
show
Bug introduced by
The function admin_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1124
			'href'  => /** @scrutinizer ignore-call */ admin_url( 'admin.php?page=formidable' ),
Loading history...
1125
			'meta'  => array(
1126
				'title' => FrmAppHelper::get_menu_name(),
1127
			),
1128
		) );
1129
	}
1130
1131
	/**
1132
	 * @since 2.05.07
1133
	 */
1134
	private static function add_forms_to_admin_bar( $actions ) {
1135
		global $wp_admin_bar;
1136
1137
		asort( $actions );
1138
1139
		foreach ( $actions as $form_id => $name ) {
1140
1141
			$wp_admin_bar->add_node( array(
1142
				'parent'    => 'frm-forms',
1143
				'id'        => 'edit_form_' . $form_id,
1144
				'title'     => empty( $name ) ? __( '(no title)' ) : $name,
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1144
				'title'     => empty( $name ) ? /** @scrutinizer ignore-call */ __( '(no title)' ) : $name,
Loading history...
1145
				'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...
Bug introduced by
The function admin_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1145
				'href'      => /** @scrutinizer ignore-call */ admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id ),
Loading history...
1146
			) );
1147
		}
1148
	}
1149
1150
    //formidable shortcode
1151
	public static function get_form_shortcode( $atts ) {
1152
        global $frm_vars;
1153
        if ( isset($frm_vars['skip_shortcode']) && $frm_vars['skip_shortcode'] ) {
1154
            $sc = '[formidable';
1155
			if ( ! empty( $atts ) ) {
1156
				foreach ( $atts as $k => $v ) {
1157
					$sc .= ' ' . $k . '="' . esc_attr( $v ) . '"';
0 ignored issues
show
Bug introduced by
The function esc_attr was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1157
					$sc .= ' ' . $k . '="' . /** @scrutinizer ignore-call */ esc_attr( $v ) . '"';
Loading history...
1158
				}
1159
			}
1160
			return $sc . ']';
1161
        }
1162
1163
		$shortcode_atts = shortcode_atts( array(
0 ignored issues
show
Bug introduced by
The function shortcode_atts was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1163
		$shortcode_atts = /** @scrutinizer ignore-call */ shortcode_atts( array(
Loading history...
1164
			'id'          => '',
1165
			'key'         => '',
1166
			'title'       => false,
1167
			'description' => false,
1168
			'readonly'    => false,
1169
			'entry_id'    => false,
1170
			'fields'      => array(),
1171
			'exclude_fields' => array(),
1172
			'minimize'    => false,
1173
		), $atts );
1174
		do_action( 'formidable_shortcode_atts', $shortcode_atts, $atts );
0 ignored issues
show
Bug introduced by
The function do_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1174
		/** @scrutinizer ignore-call */ 
1175
  do_action( 'formidable_shortcode_atts', $shortcode_atts, $atts );
Loading history...
1175
1176
        return self::show_form(
1177
            $shortcode_atts['id'], $shortcode_atts['key'], $shortcode_atts['title'],
1178
            $shortcode_atts['description'], $atts
1179
        );
1180
    }
1181
1182
    public static function show_form( $id = '', $key = '', $title = false, $description = false, $atts = array() ) {
1183
        if ( empty( $id ) ) {
1184
            $id = $key;
1185
        }
1186
1187
        $form = self::maybe_get_form_to_show( $id );
1188
        if ( ! $form ) {
0 ignored issues
show
introduced by
The condition ! $form can never be false.
Loading history...
1189
            return __( 'Please select a valid form', 'formidable' );
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1189
            return /** @scrutinizer ignore-call */ __( 'Please select a valid form', 'formidable' );
Loading history...
1190
        }
1191
1192
		FrmAppController::maybe_update_styles();
1193
1194
		add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1194
		/** @scrutinizer ignore-call */ 
1195
  add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' );
Loading history...
1195
        FrmAppHelper::trigger_hook_load( 'form', $form );
1196
1197
        $form = apply_filters( 'frm_pre_display_form', $form );
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1197
        $form = /** @scrutinizer ignore-call */ apply_filters( 'frm_pre_display_form', $form );
Loading history...
1198
1199
        $frm_settings = FrmAppHelper::get_settings();
1200
1201
		if ( self::is_viewable_draft_form( $form ) ) {
1202
			// don't show a draft form on a page
1203
			$form = __( 'Please select a valid form', 'formidable' );
1204
		} else if ( self::user_should_login( $form ) ) {
1205
			$form = do_shortcode( $frm_settings->login_msg );
0 ignored issues
show
Bug introduced by
The function do_shortcode was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1205
			$form = /** @scrutinizer ignore-call */ do_shortcode( $frm_settings->login_msg );
Loading history...
1206
		} else if ( self::user_has_permission_to_view( $form ) ) {
1207
			$form = do_shortcode( $frm_settings->login_msg );
1208
		} else {
1209
			$form = self::get_form( $form, $title, $description, $atts );
1210
1211
			/**
1212
			 * Use this shortcode to check for external shortcodes that may span
1213
			 * across multiple fields in the customizable HTML
1214
			 * @since 2.0.8
1215
			 */
1216
			$form = apply_filters( 'frm_filter_final_form', $form );
1217
		}
1218
1219
		return $form;
1220
    }
1221
1222
	private static function maybe_get_form_to_show( $id ) {
1223
		$form = false;
1224
1225
		if ( ! empty( $id ) ) { // no form id or key set
1226
			$form = FrmForm::getOne( $id );
1227
			if ( ! $form || $form->parent_form_id || $form->status == 'trash' ) {
0 ignored issues
show
introduced by
The condition ! $form || $form->parent...form->status == 'trash' can never be false.
Loading history...
1228
				$form = false;
1229
			}
1230
		}
1231
1232
		return $form;
1233
	}
1234
1235
	private static function is_viewable_draft_form( $form ) {
1236
		global $post;
1237
		$frm_settings = FrmAppHelper::get_settings();
0 ignored issues
show
Unused Code introduced by
The assignment to $frm_settings is dead and can be removed.
Loading history...
1238
		return $form->status == 'draft' && current_user_can( 'frm_edit_forms' ) && ! FrmAppHelper::is_preview_page();
0 ignored issues
show
Bug introduced by
The function current_user_can was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1238
		return $form->status == 'draft' && /** @scrutinizer ignore-call */ current_user_can( 'frm_edit_forms' ) && ! FrmAppHelper::is_preview_page();
Loading history...
1239
	}
1240
1241
	private static function user_should_login( $form ) {
1242
		return $form->logged_in && ! is_user_logged_in();
0 ignored issues
show
Bug introduced by
The function is_user_logged_in was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1242
		return $form->logged_in && ! /** @scrutinizer ignore-call */ is_user_logged_in();
Loading history...
1243
	}
1244
1245
	private static function user_has_permission_to_view( $form ) {
1246
		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'] );
0 ignored issues
show
Bug introduced by
The function get_current_user_id was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1246
		return $form->logged_in && /** @scrutinizer ignore-call */ get_current_user_id() && isset( $form->options['logged_in_role'] ) && $form->options['logged_in_role'] != '' && ! FrmAppHelper::user_has_permission( $form->options['logged_in_role'] );
Loading history...
1247
	}
1248
1249
    public static function get_form( $form, $title, $description, $atts = array() ) {
1250
        ob_start();
1251
1252
		do_action( 'frm_before_get_form', $atts );
0 ignored issues
show
Bug introduced by
The function do_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1252
		/** @scrutinizer ignore-call */ 
1253
  do_action( 'frm_before_get_form', $atts );
Loading history...
1253
1254
        self::get_form_contents( $form, $title, $description, $atts );
1255
		self::enqueue_scripts( FrmForm::get_params( $form ) );
1256
1257
        $contents = ob_get_contents();
1258
        ob_end_clean();
1259
1260
		self::maybe_minimize_form( $atts, $contents );
1261
1262
        return $contents;
1263
    }
1264
1265
	public static function enqueue_scripts( $params ) {
1266
		do_action( 'frm_enqueue_form_scripts', $params );
0 ignored issues
show
Bug introduced by
The function do_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1266
		/** @scrutinizer ignore-call */ 
1267
  do_action( 'frm_enqueue_form_scripts', $params );
Loading history...
1267
	}
1268
1269
	public static function get_form_contents( $form, $title, $description, $atts ) {
1270
		$params = FrmForm::get_params( $form );
1271
		$errors = self::get_saved_errors( $form, $params );
1272
		$fields = FrmFieldsHelper::get_form_fields( $form->id, $errors );
1273
		$reset = false;
1274
		$pass_args = compact( 'form', 'fields', 'errors', 'title', 'description', 'reset' );
1275
1276
		$handle_process_here = $params['action'] == 'create' && $params['posted_form_id'] == $form->id && $_POST;
1277
1278
		if ( ! $handle_process_here ) {
1279
			do_action( 'frm_display_form_action', $params, $fields, $form, $title, $description );
0 ignored issues
show
Bug introduced by
The function do_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1279
			/** @scrutinizer ignore-call */ 
1280
   do_action( 'frm_display_form_action', $params, $fields, $form, $title, $description );
Loading history...
1280
			if ( apply_filters( 'frm_continue_to_new', true, $form->id, $params['action'] ) ) {
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1280
			if ( /** @scrutinizer ignore-call */ apply_filters( 'frm_continue_to_new', true, $form->id, $params['action'] ) ) {
Loading history...
1281
				self::show_form_after_submit( $pass_args );
1282
			}
1283
		} elseif ( ! empty( $errors ) ) {
1284
			self::show_form_after_submit( $pass_args );
1285
1286
		} else {
1287
1288
			do_action( 'frm_validate_form_creation', $params, $fields, $form, $title, $description );
1289
1290
			if ( apply_filters( 'frm_continue_to_create', true, $form->id ) ) {
1291
				$entry_id = self::just_created_entry( $form->id );
1292
				$pass_args['entry_id'] = $entry_id;
1293
				$pass_args['reset'] = true;
1294
				$pass_args['conf_method'] = self::get_confirmation_method( compact( 'form', 'entry_id' ) );
1295
1296
				self::run_success_action( $pass_args );
1297
1298
				do_action( 'frm_after_entry_processed', array(
1299
					'entry_id' => $entry_id,
1300
					'form' => $form,
1301
				) );
1302
			}
1303
		}
1304
	}
1305
1306
	/**
1307
	 * If the form was processed earlier (init), get the generated errors
1308
	 * @since 2.05
1309
	 */
1310
	private static function get_saved_errors( $form, $params ) {
1311
		global $frm_vars;
1312
1313
		if ( $params['posted_form_id'] == $form->id && $_POST && isset( $frm_vars['created_entries'][ $form->id ] ) ) {
1314
			$errors = $frm_vars['created_entries'][ $form->id ]['errors'];
1315
		} else {
1316
			$errors = array();
1317
		}
1318
		return $errors;
1319
	}
1320
1321
	/**
1322
	 * @since 2.2.7
1323
	 */
1324
	public static function just_created_entry( $form_id ) {
1325
		global $frm_vars;
1326
		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;
1327
	}
1328
1329
	/**
1330
	 * @since 3.0
1331
	 */
1332
	private static function get_confirmation_method( $atts ) {
1333
		$opt = 'success_action';
1334
		$method = ( isset( $atts['form']->options[ $opt ] ) && ! empty( $atts['form']->options[ $opt ] ) ) ? $atts['form']->options[ $opt ] : 'message';
1335
		$method = apply_filters( 'frm_success_filter', $method, $atts['form'], 'create' );
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1335
		$method = /** @scrutinizer ignore-call */ apply_filters( 'frm_success_filter', $method, $atts['form'], 'create' );
Loading history...
1336
1337
		if ( $method != 'message' && ( ! $atts['entry_id'] || ! is_numeric( $atts['entry_id'] ) ) ) {
1338
			$method = 'message';
1339
		}
1340
1341
		return $method;
1342
	}
1343
1344
	public static function maybe_trigger_redirect( $form, $params, $args ) {
1345
		if ( ! isset( $params['id'] ) ) {
1346
			global $frm_vars;
1347
			$params['id'] = $frm_vars['created_entries'][ $form->id ]['entry_id'];
1348
		}
1349
1350
		$conf_method = self::get_confirmation_method( array(
1351
			'form'     => $form,
1352
			'entry_id' => $params['id'],
1353
		) );
1354
1355
		if ( 'redirect' === $conf_method ) {
1356
			self::trigger_redirect( $form, $params, $args );
1357
		}
1358
	}
1359
1360
	public static function trigger_redirect( $form, $params, $args ) {
1361
		$success_args = array(
1362
			'action'      => $params['action'],
1363
			'conf_method' => 'redirect',
1364
			'form'        => $form,
1365
			'entry_id'    => $params['id'],
1366
		);
1367
1368
		if ( isset( $args['ajax'] ) ) {
1369
			$success_args['ajax'] = $args['ajax'];
1370
		}
1371
1372
		self::run_success_action( $success_args );
1373
	}
1374
1375
	/**
1376
	 * Used when the success action is not 'message'
1377
	 * @since 2.05
1378
	 */
1379
	public static function run_success_action( $args ) {
1380
		$extra_args = $args;
1381
		unset( $extra_args['form'] );
1382
1383
		do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args );
0 ignored issues
show
Bug introduced by
The function do_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1383
		/** @scrutinizer ignore-call */ 
1384
  do_action( 'frm_success_action', $args['conf_method'], $args['form'], $args['form']->options, $args['entry_id'], $extra_args );
Loading history...
1384
1385
		$opt = ( ! isset( $args['action'] ) || $args['action'] == 'create' ) ? 'success' : 'edit';
1386
		$args['success_opt'] = $opt;
1387
		if ( $args['conf_method'] == 'page' && is_numeric( $args['form']->options[ $opt . '_page_id' ] ) ) {
1388
			self::load_page_after_submit( $args );
1389
		} elseif ( $args['conf_method'] == 'redirect' ) {
1390
			self::redirect_after_submit( $args );
1391
		} else {
1392
			self::show_message_after_save( $args );
1393
		}
1394
	}
1395
1396
	/**
1397
	 * @since 3.0
1398
	 */
1399
	private static function load_page_after_submit( $args ) {
1400
		global $post;
1401
		$opt = $args['success_opt'];
1402
		if ( ! $post || $args['form']->options[ $opt . '_page_id' ] != $post->ID ) {
1403
			$page = get_post( $args['form']->options[ $opt . '_page_id' ] );
0 ignored issues
show
Bug introduced by
The function get_post was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1403
			$page = /** @scrutinizer ignore-call */ get_post( $args['form']->options[ $opt . '_page_id' ] );
Loading history...
1404
			$old_post = $post;
1405
			$post = $page;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
1406
			$content = apply_filters( 'frm_content', $page->post_content, $args['form'], $args['entry_id'] );
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1406
			$content = /** @scrutinizer ignore-call */ apply_filters( 'frm_content', $page->post_content, $args['form'], $args['entry_id'] );
Loading history...
1407
			echo apply_filters( 'the_content', $content );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
1408
			$post = $old_post;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
1409
		}
1410
	}
1411
1412
	/**
1413
	 * @since 3.0
1414
	 */
1415
	private static function redirect_after_submit( $args ) {
1416
		global $frm_vars;
1417
1418
		add_filter( 'frm_use_wpautop', '__return_false' );
0 ignored issues
show
Bug introduced by
The function add_filter was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1418
		/** @scrutinizer ignore-call */ 
1419
  add_filter( 'frm_use_wpautop', '__return_false' );
Loading history...
1419
1420
		$opt = $args['success_opt'];
1421
		$success_url = trim( $args['form']->options[ $opt . '_url' ] );
1422
		$success_url = apply_filters( 'frm_content', $success_url, $args['form'], $args['entry_id'] );
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1422
		$success_url = /** @scrutinizer ignore-call */ apply_filters( 'frm_content', $success_url, $args['form'], $args['entry_id'] );
Loading history...
1423
1424
		$success_msg = isset( $args['form']->options[ $opt . '_msg' ] ) ? $args['form']->options[ $opt . '_msg' ] : __( 'Please wait while you are redirected.', 'formidable' );
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1424
		$success_msg = isset( $args['form']->options[ $opt . '_msg' ] ) ? $args['form']->options[ $opt . '_msg' ] : /** @scrutinizer ignore-call */ __( 'Please wait while you are redirected.', 'formidable' );
Loading history...
1425
1426
		$redirect_msg = self::get_redirect_message( $success_url, $success_msg, $args );
1427
1428
		$args['id'] = $args['entry_id'];
1429
		FrmEntriesController::delete_entry_before_redirect( $success_url, $args['form'], $args );
1430
1431
		add_filter( 'frm_redirect_url', 'FrmEntriesController::prepare_redirect_url' );
1432
		$success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args);
1433
1434
		$doing_ajax = FrmAppHelper::doing_ajax();
1435
1436
		if ( isset( $args['ajax'] ) && $args['ajax'] && $doing_ajax ) {
1437
			echo json_encode( array( 'redirect' => $success_url ) );
1438
			wp_die();
0 ignored issues
show
Bug introduced by
The function wp_die was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1438
			/** @scrutinizer ignore-call */ 
1439
   wp_die();
Loading history...
1439
		} elseif ( ! headers_sent() ) {
1440
			wp_redirect( esc_url_raw( $success_url ) );
0 ignored issues
show
Bug introduced by
The function esc_url_raw was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1440
			wp_redirect( /** @scrutinizer ignore-call */ esc_url_raw( $success_url ) );
Loading history...
Bug introduced by
The function wp_redirect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1440
			/** @scrutinizer ignore-call */ 
1441
   wp_redirect( esc_url_raw( $success_url ) );
Loading history...
1441
			die(); // do not use wp_die or redirect fails
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
1442
		} else {
1443
			add_filter( 'frm_use_wpautop', '__return_true' );
1444
1445
			echo $redirect_msg;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$redirect_msg'
Loading history...
1446
			echo "<script type='text/javascript'>window.onload = function(){setTimeout(window.location='" . esc_url_raw( $success_url ) . "', 8000);}</script>";
1447
		}
1448
	}
1449
1450
	/**
1451
	 * @since 3.0
1452
	 * @param string $success_url
1453
	 * @param string $success_msg
1454
	 * @param array $args
1455
	 */
1456
	private static function get_redirect_message( $success_url, $success_msg, $args ) {
1457
		$redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg frm_message">' . $success_msg . '<br/>' .
0 ignored issues
show
Bug introduced by
The function esc_attr was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1457
		$redirect_msg = '<div class="' . /** @scrutinizer ignore-call */ esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg frm_message">' . $success_msg . '<br/>' .
Loading history...
1458
			sprintf( __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), '<a href="' . esc_url( $success_url ) . '">', '</a>') .
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1458
			sprintf( /** @scrutinizer ignore-call */ __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), '<a href="' . esc_url( $success_url ) . '">', '</a>') .
Loading history...
Bug introduced by
The function esc_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1458
			sprintf( __( '%1$sClick here%2$s if you are not automatically redirected.', 'formidable' ), '<a href="' . /** @scrutinizer ignore-call */ esc_url( $success_url ) . '">', '</a>') .
Loading history...
1459
			'</div></div>';
1460
1461
		return apply_filters( 'frm_redirect_msg', $redirect_msg, array(
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1461
		return /** @scrutinizer ignore-call */ apply_filters( 'frm_redirect_msg', $redirect_msg, array(
Loading history...
1462
			'entry_id' => $args['entry_id'],
1463
			'form_id'  => $args['form']->id,
1464
			'form'     => $args['form'],
1465
		) );
1466
	}
1467
1468
	/**
1469
	 * Prepare to show the success message and empty form after submit
1470
	 * @since 2.05
1471
	 */
1472
	public static function show_message_after_save( $atts ) {
1473
		$atts['message'] = self::prepare_submit_message( $atts['form'], $atts['entry_id'] );
1474
1475
		if ( ! isset( $atts['form']->options['show_form'] ) || $atts['form']->options['show_form'] ) {
1476
			self::show_form_after_submit( $atts );
1477
		} else {
1478
			self::show_lone_success_messsage( $atts );
1479
		}
1480
	}
1481
1482
	/**
1483
	 * Show an empty form
1484
	 * @since 2.05
1485
	 */
1486
	private static function show_form_after_submit( $args ) {
1487
		self::fill_atts_for_form_display( $args );
1488
1489
		$errors = $args['errors'];
1490
		$message = $args['message'];
1491
		$form = $args['form'];
1492
		$title = $args['title'];
1493
		$description = $args['description'];
1494
1495
		if ( empty( $args['fields'] ) ) {
1496
			$values = array();
1497
		} else {
1498
			$values = FrmEntriesHelper::setup_new_vars( $args['fields'], $form, $args['reset'] );
1499
		}
1500
		unset( $args );
1501
1502
		$include_form_tag = apply_filters( 'frm_include_form_tag', true, $form );
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1502
		$include_form_tag = /** @scrutinizer ignore-call */ apply_filters( 'frm_include_form_tag', true, $form );
Loading history...
1503
1504
		$frm_settings = FrmAppHelper::get_settings();
1505
		$submit = isset( $form->options['submit_value'] ) ? $form->options['submit_value'] : $frm_settings->submit_value;
1506
1507
		include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php' );
1508
	}
1509
1510
	/**
1511
	 * Get all the values needed on the new.php entry page
1512
	 * @since 2.05
1513
	 */
1514
	private static function fill_atts_for_form_display( &$args ) {
1515
		$defaults = array(
1516
			'errors'  => array(),
1517
			'message' => '',
1518
			'fields'  => array(),
1519
			'form'    => array(),
1520
			'title'   => true,
1521
			'description' => false,
1522
			'reset'   => false,
1523
		);
1524
		$args = wp_parse_args( $args, $defaults );
0 ignored issues
show
Bug introduced by
The function wp_parse_args was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1524
		$args = /** @scrutinizer ignore-call */ wp_parse_args( $args, $defaults );
Loading history...
1525
	}
1526
1527
	/**
1528
	 * Show the success message without the form
1529
	 * @since 2.05
1530
	 */
1531
	private static function show_lone_success_messsage( $atts ) {
1532
		global $frm_vars;
1533
		$values = FrmEntriesHelper::setup_new_vars( $atts['fields'], $atts['form'], true );
1534
		self::maybe_load_css( $atts['form'], $values['custom_style'], $frm_vars['load_css'] );
1535
1536
		$include_extra_container = 'frm_forms' . FrmFormsHelper::get_form_style_class( $values );
1537
		$errors = array();
1538
		$form = $atts['form'];
1539
		$message = $atts['message'];
1540
1541
		include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php' );
1542
	}
1543
1544
	/**
1545
	 * Prepare the success message before it's shown
1546
	 * @since 2.05
1547
	 */
1548
	private static function prepare_submit_message( $form, $entry_id ) {
1549
		$frm_settings = FrmAppHelper::get_settings();
1550
1551
		if ( $entry_id && is_numeric( $entry_id ) ) {
1552
			$message = isset( $form->options['success_msg'] ) ? $form->options['success_msg'] : $frm_settings->success_msg;
1553
			$class = 'frm_message';
1554
		} else {
1555
			$message = $frm_settings->failed_msg;
1556
			$class = FrmFormsHelper::form_error_class();
1557
		}
1558
1559
		$message = FrmFormsHelper::get_success_message( compact( 'message', 'form', 'entry_id', 'class' ) );
1560
		return apply_filters( 'frm_main_feedback', $message, $form, $entry_id );
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1560
		return /** @scrutinizer ignore-call */ apply_filters( 'frm_main_feedback', $message, $form, $entry_id );
Loading history...
1561
	}
1562
1563
	public static function front_head() {
1564
		$version = FrmAppHelper::plugin_version();
1565
		$suffix = FrmAppHelper::js_suffix();
1566
1567
		if ( ! empty( $suffix ) && self::has_combo_js_file() ) {
1568
			wp_register_script( 'formidable', FrmAppHelper::plugin_url() . '/js/frm.min.js', array( 'jquery' ), $version, true );
0 ignored issues
show
Bug introduced by
The function wp_register_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1568
			/** @scrutinizer ignore-call */ 
1569
   wp_register_script( 'formidable', FrmAppHelper::plugin_url() . '/js/frm.min.js', array( 'jquery' ), $version, true );
Loading history...
1569
		} else {
1570
			wp_register_script( 'formidable', FrmAppHelper::plugin_url() . "/js/formidable{$suffix}.js", array( 'jquery' ), $version, true );
1571
		}
1572
1573
		add_filter( 'script_loader_tag', 'FrmFormsController::defer_script_loading', 10, 2 );
0 ignored issues
show
Bug introduced by
The function add_filter was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1573
		/** @scrutinizer ignore-call */ 
1574
  add_filter( 'script_loader_tag', 'FrmFormsController::defer_script_loading', 10, 2 );
Loading history...
1574
1575
		if ( FrmAppHelper::is_admin() ) {
1576
			// don't load this in back-end
1577
			return;
1578
		}
1579
1580
		FrmAppHelper::localize_script( 'front' );
1581
		FrmStylesController::enqueue_css( 'register' );
1582
	}
1583
1584
	/**
1585
	 * @since 3.0
1586
	 */
1587
	public static function has_combo_js_file() {
1588
		return is_readable( FrmAppHelper::plugin_path() . '/js/frm.min.js' );
1589
	}
1590
1591
	public static function maybe_load_css( $form, $this_load, $global_load ) {
1592
		$load_css = FrmForm::is_form_loaded( $form, $this_load, $global_load );
1593
1594
		if ( $load_css ) {
1595
			global $frm_vars;
1596
			self::footer_js( 'header' );
1597
			$frm_vars['css_loaded'] = true;
1598
		}
1599
	}
1600
1601
	public static function defer_script_loading( $tag, $handle ) {
1602
	    if ( 'recaptcha-api' == $handle && ! strpos( $tag, 'defer' ) ) {
1603
	        $tag = str_replace( ' src', ' defer="defer" async="async" src', $tag );
1604
		}
1605
	    return $tag;
1606
	}
1607
1608
	public static function footer_js( $location = 'footer' ) {
1609
		global $frm_vars;
1610
1611
		FrmStylesController::enqueue_css();
1612
1613
		if ( ! FrmAppHelper::is_admin() && $location != 'header' && ! empty( $frm_vars['forms_loaded'] ) ) {
1614
			//load formidable js
1615
			wp_enqueue_script( 'formidable' );
0 ignored issues
show
Bug introduced by
The function wp_enqueue_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1615
			/** @scrutinizer ignore-call */ 
1616
   wp_enqueue_script( 'formidable' );
Loading history...
1616
		}
1617
	}
1618
1619
	/**
1620
	 * @since 2.0.8
1621
	 */
1622
	private static function maybe_minimize_form( $atts, &$content ) {
1623
		// check if minimizing is turned on
1624
		if ( self::is_minification_on( $atts ) ) {
1625
			$content = str_replace( array( "\r\n", "\r", "\n", "\t", '    ' ), '', $content );
1626
		}
1627
	}
1628
1629
	/**
1630
	 * @since 2.0.8
1631
	 * @return boolean
1632
	 */
1633
	private static function is_minification_on( $atts ) {
1634
		return isset( $atts['minimize'] ) && ! empty( $atts['minimize'] );
1635
	}
1636
1637
	public static function bulk_create_template( $ids ) {
1638
		_deprecated_function( __METHOD__, '3.0', 'FrmForm::duplicate( $id, true, true )' );
0 ignored issues
show
Bug introduced by
The function _deprecated_function was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1638
		/** @scrutinizer ignore-call */ 
1639
  _deprecated_function( __METHOD__, '3.0', 'FrmForm::duplicate( $id, true, true )' );
Loading history...
1639
		FrmAppHelper::permission_check( 'frm_edit_forms' );
1640
1641
		foreach ( $ids as $id ) {
1642
			FrmForm::duplicate( $id, true, true );
1643
		}
1644
1645
		return __( 'Form template was Successfully Created', 'formidable' );
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1645
		return /** @scrutinizer ignore-call */ __( 'Form template was Successfully Created', 'formidable' );
Loading history...
1646
	}
1647
}
1648