Completed
Push — master ( 0841f7...c277a4 )
by Stephanie
03:30
created
classes/helpers/FrmAppHelper.php 3 patches
Doc Comments   +11 added lines, -1 removed lines patch added patch discarded remove patch
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 	 * Sanitize the value, and allow some HTML
357 357
 	 * @since 2.0
358 358
 	 * @param string $value
359
-	 * @param array $allowed
359
+	 * @param string[] $allowed
360 360
 	 * @return string
361 361
 	 */
362 362
 	public static function kses( $value, $allowed = array() ) {
@@ -464,6 +464,7 @@  discard block
 block discarded – undo
464 464
 	/**
465 465
 	 * Keep track of the keys cached in each group so they can be deleted
466 466
 	 * in Redis and Memcache
467
+	 * @param string $group
467 468
 	 */
468 469
 	public static function add_key_to_group_cache( $key, $group ) {
469 470
 		$cached = self::get_group_cached_keys( $group );
@@ -787,6 +788,9 @@  discard block
 block discarded – undo
787 788
 		return FrmFieldsHelper::prepare_other_input( $args, $other_opt, $checked );
788 789
     }
789 790
 
791
+	/**
792
+	 * @param string $function
793
+	 */
790 794
 	public static function recursive_function_map( $value, $function ) {
791 795
 		if ( is_array( $value ) ) {
792 796
 			$original_function = $function;
@@ -1206,6 +1210,9 @@  discard block
 block discarded – undo
1206 1210
         return $sub . (($len < $original_len) ? $continue : '');
1207 1211
     }
1208 1212
 
1213
+	/**
1214
+	 * @param string[] $function_names
1215
+	 */
1209 1216
 	public static function mb_function( $function_names, $args ) {
1210 1217
 		$mb_function_name = $function_names[0];
1211 1218
 		$function_name = $function_names[1];
@@ -1239,6 +1246,9 @@  discard block
 block discarded – undo
1239 1246
         return $formatted;
1240 1247
     }
1241 1248
 
1249
+	/**
1250
+	 * @param string $time_format
1251
+	 */
1242 1252
 	private static function add_time_to_date( $time_format, $date ) {
1243 1253
 		if ( empty( $time_format ) ) {
1244 1254
 			$time_format = get_option('time_format');
Please login to merge, or discard this patch.
Indentation   +1034 added lines, -1034 removed lines patch added patch discarded remove patch
@@ -12,50 +12,50 @@  discard block
 block discarded – undo
12 12
 	 */
13 13
 	public static $plug_version = '2.02.06';
14 14
 
15
-    /**
16
-     * @since 1.07.02
17
-     *
18
-     * @param none
19
-     * @return string The version of this plugin
20
-     */
21
-    public static function plugin_version() {
22
-        return self::$plug_version;
23
-    }
24
-
25
-    public static function plugin_folder() {
26
-        return basename(self::plugin_path());
27
-    }
28
-
29
-    public static function plugin_path() {
30
-        return dirname(dirname(dirname(__FILE__)));
31
-    }
32
-
33
-    public static function plugin_url() {
34
-        //prevously FRM_URL constant
15
+	/**
16
+	 * @since 1.07.02
17
+	 *
18
+	 * @param none
19
+	 * @return string The version of this plugin
20
+	 */
21
+	public static function plugin_version() {
22
+		return self::$plug_version;
23
+	}
24
+
25
+	public static function plugin_folder() {
26
+		return basename(self::plugin_path());
27
+	}
28
+
29
+	public static function plugin_path() {
30
+		return dirname(dirname(dirname(__FILE__)));
31
+	}
32
+
33
+	public static function plugin_url() {
34
+		//prevously FRM_URL constant
35 35
 		return plugins_url( '', self::plugin_path() . '/formidable.php' );
36
-    }
36
+	}
37 37
 
38 38
 	public static function relative_plugin_url() {
39 39
 		return str_replace( array( 'https:', 'http:' ), '', self::plugin_url() );
40 40
 	}
41 41
 
42
-    /**
43
-     * @return string Site URL
44
-     */
45
-    public static function site_url() {
46
-        return site_url();
47
-    }
48
-
49
-    /**
50
-     * Get the name of this site
51
-     * Used for [sitename] shortcode
52
-     *
53
-     * @since 2.0
54
-     * @return string
55
-     */
56
-    public static function site_name() {
57
-        return get_option('blogname');
58
-    }
42
+	/**
43
+	 * @return string Site URL
44
+	 */
45
+	public static function site_url() {
46
+		return site_url();
47
+	}
48
+
49
+	/**
50
+	 * Get the name of this site
51
+	 * Used for [sitename] shortcode
52
+	 *
53
+	 * @since 2.0
54
+	 * @return string
55
+	 */
56
+	public static function site_name() {
57
+		return get_option('blogname');
58
+	}
59 59
 
60 60
 	public static function make_affiliate_url( $url ) {
61 61
 		$affiliate_id = self::get_affiliate();
@@ -76,83 +76,83 @@  discard block
 block discarded – undo
76 76
 		return $affiliate_id;
77 77
 	}
78 78
 
79
-    /**
80
-     * Get the Formidable settings
81
-     *
82
-     * @since 2.0
83
-     *
84
-     * @param None
85
-     * @return FrmSettings $frm_setings
86
-     */
87
-    public static function get_settings() {
88
-        global $frm_settings;
89
-        if ( empty($frm_settings) ) {
90
-            $frm_settings = new FrmSettings();
91
-        }
92
-        return $frm_settings;
93
-    }
79
+	/**
80
+	 * Get the Formidable settings
81
+	 *
82
+	 * @since 2.0
83
+	 *
84
+	 * @param None
85
+	 * @return FrmSettings $frm_setings
86
+	 */
87
+	public static function get_settings() {
88
+		global $frm_settings;
89
+		if ( empty($frm_settings) ) {
90
+			$frm_settings = new FrmSettings();
91
+		}
92
+		return $frm_settings;
93
+	}
94 94
 
95 95
 	public static function get_menu_name() {
96 96
 		$frm_settings = FrmAppHelper::get_settings();
97 97
 		return $frm_settings->menu;
98 98
 	}
99 99
 
100
-    /**
101
-     * Show a message in place of pro features
102
-     *
103
-     * @since 2.0
104
-     */
100
+	/**
101
+	 * Show a message in place of pro features
102
+	 *
103
+	 * @since 2.0
104
+	 */
105 105
 	public static function update_message() {
106 106
 		_deprecated_function( __FUNCTION__, '2.0.19' );
107
-    }
108
-
109
-    public static function pro_is_installed() {
110
-        return apply_filters('frm_pro_installed', false);
111
-    }
112
-
113
-    /**
114
-     * Check for certain page in Formidable settings
115
-     *
116
-     * @since 2.0
117
-     *
118
-     * @param string $page The name of the page to check
119
-     * @return boolean
120
-     */
107
+	}
108
+
109
+	public static function pro_is_installed() {
110
+		return apply_filters('frm_pro_installed', false);
111
+	}
112
+
113
+	/**
114
+	 * Check for certain page in Formidable settings
115
+	 *
116
+	 * @since 2.0
117
+	 *
118
+	 * @param string $page The name of the page to check
119
+	 * @return boolean
120
+	 */
121 121
 	public static function is_admin_page( $page = 'formidable' ) {
122
-        global $pagenow;
122
+		global $pagenow;
123 123
 		$get_page = self::simple_get( 'page', 'sanitize_title' );
124
-        if ( $pagenow ) {
124
+		if ( $pagenow ) {
125 125
 			return $pagenow == 'admin.php' && $get_page == $page;
126
-        }
126
+		}
127 127
 
128 128
 		return is_admin() && $get_page == $page;
129
-    }
130
-
131
-    /**
132
-     * Check for the form preview page
133
-     *
134
-     * @since 2.0
135
-     *
136
-     * @param None
137
-     * @return boolean
138
-     */
139
-    public static function is_preview_page() {
140
-        global $pagenow;
129
+	}
130
+
131
+	/**
132
+	 * Check for the form preview page
133
+	 *
134
+	 * @since 2.0
135
+	 *
136
+	 * @param None
137
+	 * @return boolean
138
+	 */
139
+	public static function is_preview_page() {
140
+		global $pagenow;
141 141
 		$action = FrmAppHelper::simple_get( 'action', 'sanitize_title' );
142 142
 		return $pagenow && $pagenow == 'admin-ajax.php' && $action == 'frm_forms_preview';
143
-    }
143
+	}
144 144
 
145
-    /**
146
-     * Check for ajax except the form preview page
147
-     *
148
-     * @since 2.0
149
-     *
150
-     * @param None
151
-     * @return boolean
152
-     */
153
-    public static function doing_ajax() {
154
-        return defined('DOING_AJAX') && DOING_AJAX && ! self::is_preview_page();
155
-    }
145
+	/**
146
+	 * Check for ajax except the form preview page
147
+	 *
148
+	 * @since 2.0
149
+	 *
150
+	 * @param None
151
+	 * @return boolean
152
+	 */
153
+	public static function doing_ajax() {
154
+		return defined('DOING_AJAX') && DOING_AJAX && ! self::is_preview_page();
155
+	}
156 156
 
157 157
 	/**
158 158
 	 * @since 2.0.8
@@ -162,102 +162,102 @@  discard block
 block discarded – undo
162 162
 		return isset( $frm_vars['prevent_caching'] ) && $frm_vars['prevent_caching'];
163 163
 	}
164 164
 
165
-    /**
166
-     * Check if on an admin page
167
-     *
168
-     * @since 2.0
169
-     *
170
-     * @param None
171
-     * @return boolean
172
-     */
173
-    public static function is_admin() {
174
-        return is_admin() && ( ! defined('DOING_AJAX') || ! DOING_AJAX );
175
-    }
176
-
177
-    /**
178
-     * Check if value contains blank value or empty array
179
-     *
180
-     * @since 2.0
181
-     * @param mixed $value - value to check
165
+	/**
166
+	 * Check if on an admin page
167
+	 *
168
+	 * @since 2.0
169
+	 *
170
+	 * @param None
171
+	 * @return boolean
172
+	 */
173
+	public static function is_admin() {
174
+		return is_admin() && ( ! defined('DOING_AJAX') || ! DOING_AJAX );
175
+	}
176
+
177
+	/**
178
+	 * Check if value contains blank value or empty array
179
+	 *
180
+	 * @since 2.0
181
+	 * @param mixed $value - value to check
182 182
 	 * @param string
183
-     * @return boolean
184
-     */
185
-    public static function is_empty_value( $value, $empty = '' ) {
186
-        return ( is_array( $value ) && empty( $value ) ) || $value == $empty;
187
-    }
188
-
189
-    public static function is_not_empty_value( $value, $empty = '' ) {
190
-        return ! self::is_empty_value( $value, $empty );
191
-    }
192
-
193
-    /**
194
-     * Get any value from the $_SERVER
195
-     *
196
-     * @since 2.0
197
-     * @param string $value
198
-     * @return string
199
-     */
183
+	 * @return boolean
184
+	 */
185
+	public static function is_empty_value( $value, $empty = '' ) {
186
+		return ( is_array( $value ) && empty( $value ) ) || $value == $empty;
187
+	}
188
+
189
+	public static function is_not_empty_value( $value, $empty = '' ) {
190
+		return ! self::is_empty_value( $value, $empty );
191
+	}
192
+
193
+	/**
194
+	 * Get any value from the $_SERVER
195
+	 *
196
+	 * @since 2.0
197
+	 * @param string $value
198
+	 * @return string
199
+	 */
200 200
 	public static function get_server_value( $value ) {
201
-        return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( $_SERVER[ $value ] ) : '';
202
-    }
203
-
204
-    /**
205
-     * Check for the IP address in several places
206
-     * Used by [ip] shortcode
207
-     *
208
-     * @return string The IP address of the current user
209
-     */
210
-    public static function get_ip_address() {
201
+		return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( $_SERVER[ $value ] ) : '';
202
+	}
203
+
204
+	/**
205
+	 * Check for the IP address in several places
206
+	 * Used by [ip] shortcode
207
+	 *
208
+	 * @return string The IP address of the current user
209
+	 */
210
+	public static function get_ip_address() {
211 211
 		$ip = '';
212
-        foreach ( array(
213
-            'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP',
214
-            'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR',
215
-        ) as $key ) {
216
-            if ( ! isset( $_SERVER[ $key ] ) ) {
217
-                continue;
218
-            }
219
-
220
-            foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) {
221
-                $ip = trim($ip); // just to be safe
222
-
223
-                if ( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) {
224
-                    return $ip;
225
-                }
226
-            }
227
-        }
212
+		foreach ( array(
213
+			'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP',
214
+			'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR',
215
+		) as $key ) {
216
+			if ( ! isset( $_SERVER[ $key ] ) ) {
217
+				continue;
218
+			}
219
+
220
+			foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) {
221
+				$ip = trim($ip); // just to be safe
222
+
223
+				if ( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) {
224
+					return $ip;
225
+				}
226
+			}
227
+		}
228 228
 
229 229
 		return sanitize_text_field( $ip );
230
-    }
230
+	}
231 231
 
232
-    public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) {
233
-        if ( strpos($param, '[') ) {
234
-            $params = explode('[', $param);
235
-            $param = $params[0];
236
-        }
232
+	public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) {
233
+		if ( strpos($param, '[') ) {
234
+			$params = explode('[', $param);
235
+			$param = $params[0];
236
+		}
237 237
 
238 238
 		if ( $src == 'get' ) {
239
-            $value = isset( $_POST[ $param ] ) ? stripslashes_deep( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? stripslashes_deep( $_GET[ $param ] ) : $default );
240
-            if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) {
241
-                $value = stripslashes_deep( htmlspecialchars_decode( urldecode( $_GET[ $param ] ) ) );
242
-            }
239
+			$value = isset( $_POST[ $param ] ) ? stripslashes_deep( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? stripslashes_deep( $_GET[ $param ] ) : $default );
240
+			if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) {
241
+				$value = stripslashes_deep( htmlspecialchars_decode( urldecode( $_GET[ $param ] ) ) );
242
+			}
243 243
 			self::sanitize_value( $sanitize, $value );
244 244
 		} else {
245
-            $value = self::get_simple_request( array( 'type' => $src, 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) );
246
-        }
245
+			$value = self::get_simple_request( array( 'type' => $src, 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) );
246
+		}
247 247
 
248 248
 		if ( isset( $params ) && is_array( $value ) && ! empty( $value ) ) {
249
-            foreach ( $params as $k => $p ) {
250
-                if ( ! $k || ! is_array($value) ) {
251
-                    continue;
252
-                }
249
+			foreach ( $params as $k => $p ) {
250
+				if ( ! $k || ! is_array($value) ) {
251
+					continue;
252
+				}
253 253
 
254
-                $p = trim($p, ']');
255
-                $value = isset( $value[ $p ] ) ? $value[ $p ] : $default;
256
-            }
257
-        }
254
+				$p = trim($p, ']');
255
+				$value = isset( $value[ $p ] ) ? $value[ $p ] : $default;
256
+			}
257
+		}
258 258
 
259
-        return $value;
260
-    }
259
+		return $value;
260
+	}
261 261
 
262 262
 	public static function get_post_param( $param, $default = '', $sanitize = '' ) {
263 263
 		return self::get_simple_request( array( 'type' => 'post', 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) );
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 	 */
274 274
 	public static function simple_get( $param, $sanitize = 'sanitize_text_field', $default = '' ) {
275 275
 		return self::get_simple_request( array( 'type' => 'get', 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) );
276
-    }
276
+	}
277 277
 
278 278
 	/**
279 279
 	 * Get a GET/POST/REQUEST value and sanitize it
@@ -309,12 +309,12 @@  discard block
 block discarded – undo
309 309
 	}
310 310
 
311 311
 	/**
312
-	* Preserve backslashes in a value, but make sure value doesn't get compounding slashes
313
-	*
314
-	* @since 2.0.8
315
-	* @param string $value
316
-	* @return string $value
317
-	*/
312
+	 * Preserve backslashes in a value, but make sure value doesn't get compounding slashes
313
+	 *
314
+	 * @since 2.0.8
315
+	 * @param string $value
316
+	 * @return string $value
317
+	 */
318 318
 	public static function preserve_backslashes( $value ) {
319 319
 		// If backslashes have already been added, don't add them again
320 320
 		if ( strpos( $value, '\\\\' ) === false ) {
@@ -336,14 +336,14 @@  discard block
 block discarded – undo
336 336
 		}
337 337
 	}
338 338
 
339
-    public static function sanitize_request( $sanitize_method, &$values ) {
340
-        $temp_values = $values;
341
-        foreach ( $temp_values as $k => $val ) {
342
-            if ( isset( $sanitize_method[ $k ] ) ) {
339
+	public static function sanitize_request( $sanitize_method, &$values ) {
340
+		$temp_values = $values;
341
+		foreach ( $temp_values as $k => $val ) {
342
+			if ( isset( $sanitize_method[ $k ] ) ) {
343 343
 				$values[ $k ] = call_user_func( $sanitize_method[ $k ], $val );
344
-            }
345
-        }
346
-    }
344
+			}
345
+		}
346
+	}
347 347
 
348 348
 	public static function sanitize_array( &$values ) {
349 349
 		$temp_values = $values;
@@ -361,12 +361,12 @@  discard block
 block discarded – undo
361 361
 	 */
362 362
 	public static function kses( $value, $allowed = array() ) {
363 363
 		$html = array(
364
-		    'a' => array(
364
+			'a' => array(
365 365
 				'href'  => array(),
366 366
 				'title' => array(),
367 367
 				'id'    => array(),
368 368
 				'class' => array(),
369
-		    ),
369
+			),
370 370
 		);
371 371
 
372 372
 		$allowed_html = array();
@@ -377,77 +377,77 @@  discard block
 block discarded – undo
377 377
 		return wp_kses( $value, $allowed_html );
378 378
 	}
379 379
 
380
-    /**
381
-     * Used when switching the action for a bulk action
382
-     * @since 2.0
383
-     */
384
-    public static function remove_get_action() {
385
-        if ( ! isset($_GET) ) {
386
-            return;
387
-        }
380
+	/**
381
+	 * Used when switching the action for a bulk action
382
+	 * @since 2.0
383
+	 */
384
+	public static function remove_get_action() {
385
+		if ( ! isset($_GET) ) {
386
+			return;
387
+		}
388 388
 
389
-        $new_action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ( isset( $_GET['action2'] ) ? sanitize_text_field( $_GET['action2'] ) : '' );
390
-        if ( ! empty( $new_action ) ) {
389
+		$new_action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ( isset( $_GET['action2'] ) ? sanitize_text_field( $_GET['action2'] ) : '' );
390
+		if ( ! empty( $new_action ) ) {
391 391
 			$_SERVER['REQUEST_URI'] = str_replace( '&action=' . $new_action, '', FrmAppHelper::get_server_value( 'REQUEST_URI' ) );
392
-        }
393
-    }
394
-
395
-    /**
396
-     * Check the WP query for a parameter
397
-     *
398
-     * @since 2.0
399
-     * @return string|array
400
-     */
401
-    public static function get_query_var( $value, $param ) {
402
-        if ( $value != '' ) {
403
-            return $value;
404
-        }
405
-
406
-        global $wp_query;
407
-        if ( isset( $wp_query->query_vars[ $param ] ) ) {
408
-            $value = $wp_query->query_vars[ $param ];
409
-        }
410
-
411
-        return $value;
412
-    }
413
-
414
-    /**
415
-     * @param string $type
416
-     */
417
-    public static function trigger_hook_load( $type, $object = null ) {
418
-        // only load the form hooks once
392
+		}
393
+	}
394
+
395
+	/**
396
+	 * Check the WP query for a parameter
397
+	 *
398
+	 * @since 2.0
399
+	 * @return string|array
400
+	 */
401
+	public static function get_query_var( $value, $param ) {
402
+		if ( $value != '' ) {
403
+			return $value;
404
+		}
405
+
406
+		global $wp_query;
407
+		if ( isset( $wp_query->query_vars[ $param ] ) ) {
408
+			$value = $wp_query->query_vars[ $param ];
409
+		}
410
+
411
+		return $value;
412
+	}
413
+
414
+	/**
415
+	 * @param string $type
416
+	 */
417
+	public static function trigger_hook_load( $type, $object = null ) {
418
+		// only load the form hooks once
419 419
 		$hooks_loaded = apply_filters( 'frm_' . $type . '_hooks_loaded', false, $object );
420
-        if ( ! $hooks_loaded ) {
420
+		if ( ! $hooks_loaded ) {
421 421
 			do_action( 'frm_load_' . $type . '_hooks' );
422
-        }
423
-    }
424
-
425
-    /**
426
-     * Check cache before fetching values and saving to cache
427
-     *
428
-     * @since 2.0
429
-     *
430
-     * @param string $cache_key The unique name for this cache
431
-     * @param string $group The name of the cache group
432
-     * @param string $query If blank, don't run a db call
433
-     * @param string $type The wpdb function to use with this query
434
-     * @return mixed $results The cache or query results
435
-     */
436
-    public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
437
-        $results = wp_cache_get($cache_key, $group);
438
-        if ( ! self::is_empty_value( $results, false ) || empty($query) ) {
439
-            return $results;
440
-        }
441
-
442
-        if ( 'get_posts' == $type ) {
443
-            $results = get_posts($query);
422
+		}
423
+	}
424
+
425
+	/**
426
+	 * Check cache before fetching values and saving to cache
427
+	 *
428
+	 * @since 2.0
429
+	 *
430
+	 * @param string $cache_key The unique name for this cache
431
+	 * @param string $group The name of the cache group
432
+	 * @param string $query If blank, don't run a db call
433
+	 * @param string $type The wpdb function to use with this query
434
+	 * @return mixed $results The cache or query results
435
+	 */
436
+	public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
437
+		$results = wp_cache_get($cache_key, $group);
438
+		if ( ! self::is_empty_value( $results, false ) || empty($query) ) {
439
+			return $results;
440
+		}
441
+
442
+		if ( 'get_posts' == $type ) {
443
+			$results = get_posts($query);
444 444
 		} else if ( 'get_associative_results' == $type ) {
445 445
 			global $wpdb;
446 446
 			$results = $wpdb->get_results( $query, OBJECT_K );
447
-        } else {
448
-            global $wpdb;
449
-            $results = $wpdb->{$type}($query);
450
-        }
447
+		} else {
448
+			global $wpdb;
449
+			$results = $wpdb->{$type}($query);
450
+		}
451 451
 
452 452
 		self::set_cache( $cache_key, $results, $group, $time );
453 453
 
@@ -479,44 +479,44 @@  discard block
 block discarded – undo
479 479
 		return (array) $cached;
480 480
 	}
481 481
 
482
-    /**
483
-     * Data that should be stored for a long time can be stored in a transient.
484
-     * First check the cache, then check the transient
485
-     * @since 2.0
486
-     * @return mixed The cached value or false
487
-     */
482
+	/**
483
+	 * Data that should be stored for a long time can be stored in a transient.
484
+	 * First check the cache, then check the transient
485
+	 * @since 2.0
486
+	 * @return mixed The cached value or false
487
+	 */
488 488
 	public static function check_cache_and_transient( $cache_key ) {
489
-        // check caching layer first
490
-        $results = self::check_cache( $cache_key );
491
-        if ( $results ) {
492
-            return $results;
493
-        }
494
-
495
-        // then check the transient
496
-        $results = get_transient($cache_key);
497
-        if ( $results ) {
498
-            wp_cache_set($cache_key, $results);
499
-        }
500
-
501
-        return $results;
502
-    }
503
-
504
-    /**
505
-     * @since 2.0
506
-     * @param string $cache_key
507
-     */
489
+		// check caching layer first
490
+		$results = self::check_cache( $cache_key );
491
+		if ( $results ) {
492
+			return $results;
493
+		}
494
+
495
+		// then check the transient
496
+		$results = get_transient($cache_key);
497
+		if ( $results ) {
498
+			wp_cache_set($cache_key, $results);
499
+		}
500
+
501
+		return $results;
502
+	}
503
+
504
+	/**
505
+	 * @since 2.0
506
+	 * @param string $cache_key
507
+	 */
508 508
 	public static function delete_cache_and_transient( $cache_key, $group = 'default' ) {
509 509
 		delete_transient($cache_key);
510 510
 		wp_cache_delete( $cache_key, $group );
511 511
 	}
512 512
 
513
-    /**
514
-     * Delete all caching in a single group
515
-     *
516
-     * @since 2.0
517
-     *
518
-     * @param string $group The name of the cache group
519
-     */
513
+	/**
514
+	 * Delete all caching in a single group
515
+	 *
516
+	 * @since 2.0
517
+	 *
518
+	 * @param string $group The name of the cache group
519
+	 */
520 520
 	public static function cache_delete_group( $group ) {
521 521
 		$cached_keys = self::get_group_cached_keys( $group );
522 522
 
@@ -533,34 +533,34 @@  discard block
 block discarded – undo
533 533
 		}
534 534
 	}
535 535
 
536
-    /**
537
-     * Check a value from a shortcode to see if true or false.
538
-     * True when value is 1, true, 'true', 'yes'
539
-     *
540
-     * @since 1.07.10
541
-     *
542
-     * @param string $value The value to compare
543
-     * @return boolean True or False
544
-     */
536
+	/**
537
+	 * Check a value from a shortcode to see if true or false.
538
+	 * True when value is 1, true, 'true', 'yes'
539
+	 *
540
+	 * @since 1.07.10
541
+	 *
542
+	 * @param string $value The value to compare
543
+	 * @return boolean True or False
544
+	 */
545 545
 	public static function is_true( $value ) {
546
-        return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
547
-    }
546
+		return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
547
+	}
548 548
 
549
-    /**
550
-     * Used to filter shortcode in text widgets
551
-     */
552
-    public static function widget_text_filter_callback( $matches ) {
553
-        return do_shortcode( $matches[0] );
554
-    }
549
+	/**
550
+	 * Used to filter shortcode in text widgets
551
+	 */
552
+	public static function widget_text_filter_callback( $matches ) {
553
+		return do_shortcode( $matches[0] );
554
+	}
555 555
 
556
-    public static function get_pages() {
556
+	public static function get_pages() {
557 557
 		return get_posts( array( 'post_type' => 'page', 'post_status' => array( 'publish', 'private' ), 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC' ) );
558
-    }
558
+	}
559 559
 
560
-    public static function wp_pages_dropdown( $field_name, $page_id, $truncate = false ) {
561
-        $pages = self::get_pages();
560
+	public static function wp_pages_dropdown( $field_name, $page_id, $truncate = false ) {
561
+		$pages = self::get_pages();
562 562
 		$selected = self::get_post_param( $field_name, $page_id, 'absint' );
563
-    ?>
563
+	?>
564 564
         <select name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" class="frm-pages-dropdown">
565 565
             <option value=""> </option>
566 566
             <?php foreach ( $pages as $page ) { ?>
@@ -570,108 +570,108 @@  discard block
 block discarded – undo
570 570
             <?php } ?>
571 571
         </select>
572 572
     <?php
573
-    }
573
+	}
574 574
 
575 575
 	public static function post_edit_link( $post_id ) {
576
-        $post = get_post($post_id);
577
-        if ( $post ) {
576
+		$post = get_post($post_id);
577
+		if ( $post ) {
578 578
 			$post_url = admin_url( 'post.php?post=' . $post_id . '&action=edit' );
579 579
 			return '<a href="' . esc_url( $post_url ) . '">' . self::truncate( $post->post_title, 50 ) . '</a>';
580
-        }
581
-        return '';
582
-    }
580
+		}
581
+		return '';
582
+	}
583 583
 
584 584
 	public static function wp_roles_dropdown( $field_name, $capability, $multiple = 'single' ) {
585
-    ?>
585
+	?>
586 586
         <select name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" <?php
587
-            echo ( 'multiple' == $multiple ) ? 'multiple="multiple"' : '';
588
-            ?> class="frm_multiselect">
587
+			echo ( 'multiple' == $multiple ) ? 'multiple="multiple"' : '';
588
+			?> class="frm_multiselect">
589 589
             <?php self::roles_options($capability); ?>
590 590
         </select>
591 591
     <?php
592
-    }
592
+	}
593 593
 
594 594
 	public static function roles_options( $capability ) {
595
-        global $frm_vars;
596
-        if ( isset($frm_vars['editable_roles']) ) {
597
-            $editable_roles = $frm_vars['editable_roles'];
598
-        } else {
599
-            $editable_roles = get_editable_roles();
600
-            $frm_vars['editable_roles'] = $editable_roles;
601
-        }
602
-
603
-        foreach ( $editable_roles as $role => $details ) {
604
-            $name = translate_user_role($details['name'] ); ?>
595
+		global $frm_vars;
596
+		if ( isset($frm_vars['editable_roles']) ) {
597
+			$editable_roles = $frm_vars['editable_roles'];
598
+		} else {
599
+			$editable_roles = get_editable_roles();
600
+			$frm_vars['editable_roles'] = $editable_roles;
601
+		}
602
+
603
+		foreach ( $editable_roles as $role => $details ) {
604
+			$name = translate_user_role($details['name'] ); ?>
605 605
         <option value="<?php echo esc_attr($role) ?>" <?php echo in_array($role, (array) $capability) ? ' selected="selected"' : ''; ?>><?php echo esc_attr($name) ?> </option>
606 606
 <?php
607
-            unset($role, $details);
608
-        }
609
-    }
607
+			unset($role, $details);
608
+		}
609
+	}
610 610
 
611 611
 	public static function frm_capabilities( $type = 'auto' ) {
612
-        $cap = array(
613
-            'frm_view_forms'        => __( 'View Forms and Templates', 'formidable' ),
614
-            'frm_edit_forms'        => __( 'Add/Edit Forms and Templates', 'formidable' ),
615
-            'frm_delete_forms'      => __( 'Delete Forms and Templates', 'formidable' ),
616
-            'frm_change_settings'   => __( 'Access this Settings Page', 'formidable' ),
617
-            'frm_view_entries'      => __( 'View Entries from Admin Area', 'formidable' ),
618
-            'frm_delete_entries'    => __( 'Delete Entries from Admin Area', 'formidable' ),
619
-        );
612
+		$cap = array(
613
+			'frm_view_forms'        => __( 'View Forms and Templates', 'formidable' ),
614
+			'frm_edit_forms'        => __( 'Add/Edit Forms and Templates', 'formidable' ),
615
+			'frm_delete_forms'      => __( 'Delete Forms and Templates', 'formidable' ),
616
+			'frm_change_settings'   => __( 'Access this Settings Page', 'formidable' ),
617
+			'frm_view_entries'      => __( 'View Entries from Admin Area', 'formidable' ),
618
+			'frm_delete_entries'    => __( 'Delete Entries from Admin Area', 'formidable' ),
619
+		);
620 620
 
621 621
 		if ( ! self::pro_is_installed() && 'pro' != $type ) {
622
-            return $cap;
623
-        }
622
+			return $cap;
623
+		}
624 624
 
625
-        $cap['frm_create_entries'] = __( 'Add Entries from Admin Area', 'formidable' );
626
-        $cap['frm_edit_entries'] = __( 'Edit Entries from Admin Area', 'formidable' );
627
-        $cap['frm_view_reports'] = __( 'View Reports', 'formidable' );
628
-        $cap['frm_edit_displays'] = __( 'Add/Edit Views', 'formidable' );
625
+		$cap['frm_create_entries'] = __( 'Add Entries from Admin Area', 'formidable' );
626
+		$cap['frm_edit_entries'] = __( 'Edit Entries from Admin Area', 'formidable' );
627
+		$cap['frm_view_reports'] = __( 'View Reports', 'formidable' );
628
+		$cap['frm_edit_displays'] = __( 'Add/Edit Views', 'formidable' );
629 629
 
630
-        return $cap;
631
-    }
630
+		return $cap;
631
+	}
632 632
 
633 633
 	public static function user_has_permission( $needed_role ) {
634
-        if ( $needed_role == '-1' ) {
635
-            return false;
634
+		if ( $needed_role == '-1' ) {
635
+			return false;
636 636
 		}
637 637
 
638
-        // $needed_role will be equal to blank if "Logged-in users" is selected
639
-        if ( ( $needed_role == '' && is_user_logged_in() ) || current_user_can( $needed_role ) ) {
640
-            return true;
641
-        }
638
+		// $needed_role will be equal to blank if "Logged-in users" is selected
639
+		if ( ( $needed_role == '' && is_user_logged_in() ) || current_user_can( $needed_role ) ) {
640
+			return true;
641
+		}
642 642
 
643
-        $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
644
-        foreach ( $roles as $role ) {
643
+		$roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
644
+		foreach ( $roles as $role ) {
645 645
 			if ( current_user_can( $role ) ) {
646
-        		return true;
646
+				return true;
647 647
 			}
648
-        	if ( $role == $needed_role ) {
649
-        		break;
648
+			if ( $role == $needed_role ) {
649
+				break;
650 650
 			}
651
-        }
652
-        return false;
653
-    }
654
-
655
-    /**
656
-     * Make sure administrators can see Formidable menu
657
-     *
658
-     * @since 2.0
659
-     */
660
-    public static function maybe_add_permissions() {
651
+		}
652
+		return false;
653
+	}
654
+
655
+	/**
656
+	 * Make sure administrators can see Formidable menu
657
+	 *
658
+	 * @since 2.0
659
+	 */
660
+	public static function maybe_add_permissions() {
661 661
 		self::force_capability( 'frm_view_entries' );
662 662
 
663
-        if ( ! current_user_can('administrator') || current_user_can('frm_view_forms') ) {
664
-            return;
665
-        }
663
+		if ( ! current_user_can('administrator') || current_user_can('frm_view_forms') ) {
664
+			return;
665
+		}
666 666
 
667 667
 		$user_id = get_current_user_id();
668 668
 		$user = new WP_User( $user_id );
669
-        $frm_roles = self::frm_capabilities();
670
-        foreach ( $frm_roles as $frm_role => $frm_role_description ) {
669
+		$frm_roles = self::frm_capabilities();
670
+		foreach ( $frm_roles as $frm_role => $frm_role_description ) {
671 671
 			$user->add_cap( $frm_role );
672
-            unset($frm_role, $frm_role_description);
673
-        }
674
-    }
672
+			unset($frm_role, $frm_role_description);
673
+		}
674
+	}
675 675
 
676 676
 	/**
677 677
 	 * Make sure admins have permission to see the menu items
@@ -687,28 +687,28 @@  discard block
 block discarded – undo
687 687
 		}
688 688
 	}
689 689
 
690
-    /**
691
-     * Check if the user has permision for action.
692
-     * Return permission message and stop the action if no permission
693
-     * @since 2.0
694
-     * @param string $permission
695
-     */
690
+	/**
691
+	 * Check if the user has permision for action.
692
+	 * Return permission message and stop the action if no permission
693
+	 * @since 2.0
694
+	 * @param string $permission
695
+	 */
696 696
 	public static function permission_check( $permission, $show_message = 'show' ) {
697
-        $permission_error = self::permission_nonce_error($permission);
698
-        if ( $permission_error !== false ) {
699
-            if ( 'hide' == $show_message ) {
700
-                $permission_error = '';
701
-            }
702
-            wp_die($permission_error);
703
-        }
704
-    }
705
-
706
-    /**
707
-     * Check user permission and nonce
708
-     * @since 2.0
709
-     * @param string $permission
710
-     * @return false|string The permission message or false if allowed
711
-     */
697
+		$permission_error = self::permission_nonce_error($permission);
698
+		if ( $permission_error !== false ) {
699
+			if ( 'hide' == $show_message ) {
700
+				$permission_error = '';
701
+			}
702
+			wp_die($permission_error);
703
+		}
704
+	}
705
+
706
+	/**
707
+	 * Check user permission and nonce
708
+	 * @since 2.0
709
+	 * @param string $permission
710
+	 * @return false|string The permission message or false if allowed
711
+	 */
712 712
 	public static function permission_nonce_error( $permission, $nonce_name = '', $nonce = '' ) {
713 713
 		if ( ! empty( $permission ) && ! current_user_can( $permission ) && ! current_user_can( 'administrator' ) ) {
714 714
 			$frm_settings = self::get_settings();
@@ -716,23 +716,23 @@  discard block
 block discarded – undo
716 716
 		}
717 717
 
718 718
 		$error = false;
719
-        if ( empty($nonce_name) ) {
720
-            return $error;
721
-        }
719
+		if ( empty($nonce_name) ) {
720
+			return $error;
721
+		}
722 722
 
723
-        if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $_REQUEST[ $nonce_name ], $nonce ) ) ) {
724
-            $frm_settings = self::get_settings();
725
-            $error = $frm_settings->admin_permission;
726
-        }
723
+		if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $_REQUEST[ $nonce_name ], $nonce ) ) ) {
724
+			$frm_settings = self::get_settings();
725
+			$error = $frm_settings->admin_permission;
726
+		}
727 727
 
728
-        return $error;
729
-    }
728
+		return $error;
729
+	}
730 730
 
731
-    public static function checked( $values, $current ) {
731
+	public static function checked( $values, $current ) {
732 732
 		if ( self::check_selected( $values, $current ) ) {
733
-            echo ' checked="checked"';
733
+			echo ' checked="checked"';
734 734
 		}
735
-    }
735
+	}
736 736
 
737 737
 	public static function check_selected( $values, $current ) {
738 738
 		$values = self::recursive_function_map( $values, 'trim' );
@@ -742,50 +742,50 @@  discard block
 block discarded – undo
742 742
 		return ( is_array( $values ) && in_array( $current, $values ) ) || ( ! is_array( $values ) && $values == $current );
743 743
 	}
744 744
 
745
-    /**
746
-    * Check if current field option is an "other" option
747
-    *
748
-    * @since 2.0
749
-    *
750
-    * @param string $opt_key
751
-    * @return boolean Returns true if current field option is an "Other" option
752
-    */
753
-    public static function is_other_opt( $opt_key ) {
754
-        _deprecated_function( __FUNCTION__, '2.0.6', 'FrmFieldsHelper::is_other_opt' );
755
-        return FrmFieldsHelper::is_other_opt( $opt_key );
756
-    }
757
-
758
-    /**
759
-    * Get value that belongs in "Other" text box
760
-    *
761
-    * @since 2.0
762
-    *
763
-    * @param string $opt_key
764
-    * @param array $field
765
-    * @return string $other_val
766
-    */
767
-    public static function get_other_val( $opt_key, $field, $parent = false, $pointer = false ) {
745
+	/**
746
+	 * Check if current field option is an "other" option
747
+	 *
748
+	 * @since 2.0
749
+	 *
750
+	 * @param string $opt_key
751
+	 * @return boolean Returns true if current field option is an "Other" option
752
+	 */
753
+	public static function is_other_opt( $opt_key ) {
754
+		_deprecated_function( __FUNCTION__, '2.0.6', 'FrmFieldsHelper::is_other_opt' );
755
+		return FrmFieldsHelper::is_other_opt( $opt_key );
756
+	}
757
+
758
+	/**
759
+	 * Get value that belongs in "Other" text box
760
+	 *
761
+	 * @since 2.0
762
+	 *
763
+	 * @param string $opt_key
764
+	 * @param array $field
765
+	 * @return string $other_val
766
+	 */
767
+	public static function get_other_val( $opt_key, $field, $parent = false, $pointer = false ) {
768 768
 		_deprecated_function( __FUNCTION__, '2.0.6', 'FrmFieldsHelper::get_other_val' );
769 769
 		return FrmFieldsHelper::get_other_val( compact( 'opt_key', 'field', 'parent', 'pointer' ) );
770
-    }
771
-
772
-    /**
773
-    * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val.
774
-    * Intended for front-end use
775
-    *
776
-    * @since 2.0
777
-    *
778
-    * @param array $field
779
-    * @param boolean $other_opt
780
-    * @param string $checked
781
-    * @param array $args should include opt_key and field name
782
-    * @return string $other_val
783
-    */
784
-    public static function prepare_other_input( $field, &$other_opt, &$checked, $args = array() ) {
770
+	}
771
+
772
+	/**
773
+	 * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val.
774
+	 * Intended for front-end use
775
+	 *
776
+	 * @since 2.0
777
+	 *
778
+	 * @param array $field
779
+	 * @param boolean $other_opt
780
+	 * @param string $checked
781
+	 * @param array $args should include opt_key and field name
782
+	 * @return string $other_val
783
+	 */
784
+	public static function prepare_other_input( $field, &$other_opt, &$checked, $args = array() ) {
785 785
 		_deprecated_function( __FUNCTION__, '2.0.6', 'FrmFieldsHelper::prepare_other_input' );
786 786
 		$args['field'] = $field;
787 787
 		return FrmFieldsHelper::prepare_other_input( $args, $other_opt, $checked );
788
-    }
788
+	}
789 789
 
790 790
 	public static function recursive_function_map( $value, $function ) {
791 791
 		if ( is_array( $value ) ) {
@@ -815,24 +815,24 @@  discard block
 block discarded – undo
815 815
 		return (bool) count( array_filter( array_keys( $array ), 'is_string' ) );
816 816
 	}
817 817
 
818
-    /**
819
-     * Flatten a multi-dimensional array
820
-     */
818
+	/**
819
+	 * Flatten a multi-dimensional array
820
+	 */
821 821
 	public static function array_flatten( $array, $keys = 'keep' ) {
822
-        $return = array();
823
-        foreach ( $array as $key => $value ) {
824
-            if ( is_array($value) ) {
822
+		$return = array();
823
+		foreach ( $array as $key => $value ) {
824
+			if ( is_array($value) ) {
825 825
 				$return = array_merge( $return, self::array_flatten( $value, $keys ) );
826
-            } else {
826
+			} else {
827 827
 				if ( $keys == 'keep' ) {
828 828
 					$return[ $key ] = $value;
829 829
 				} else {
830 830
 					$return[] = $value;
831 831
 				}
832
-            }
833
-        }
834
-        return $return;
835
-    }
832
+			}
833
+		}
834
+		return $return;
835
+	}
836 836
 
837 837
 	public static function esc_textarea( $text, $is_rich_text = false ) {
838 838
 		$safe_text = str_replace( '&quot;', '"', $text );
@@ -843,308 +843,308 @@  discard block
 block discarded – undo
843 843
 		return apply_filters( 'esc_textarea', $safe_text, $text );
844 844
 	}
845 845
 
846
-    /**
847
-     * Add auto paragraphs to text areas
848
-     * @since 2.0
849
-     */
846
+	/**
847
+	 * Add auto paragraphs to text areas
848
+	 * @since 2.0
849
+	 */
850 850
 	public static function use_wpautop( $content ) {
851
-        if ( apply_filters('frm_use_wpautop', true) ) {
852
-            $content = wpautop(str_replace( '<br>', '<br />', $content));
853
-        }
854
-        return $content;
855
-    }
851
+		if ( apply_filters('frm_use_wpautop', true) ) {
852
+			$content = wpautop(str_replace( '<br>', '<br />', $content));
853
+		}
854
+		return $content;
855
+	}
856 856
 
857 857
 	public static function replace_quotes( $val ) {
858
-        //Replace double quotes
858
+		//Replace double quotes
859 859
 		$val = str_replace( array( '&#8220;', '&#8221;', '&#8243;' ), '"', $val );
860
-        //Replace single quotes
861
-        $val = str_replace( array( '&#8216;', '&#8217;', '&#8242;', '&prime;', '&rsquo;', '&lsquo;' ), "'", $val );
862
-        return $val;
863
-    }
864
-
865
-    /**
866
-     * @since 2.0
867
-     * @return string The base Google APIS url for the current version of jQuery UI
868
-     */
869
-    public static function jquery_ui_base_url() {
860
+		//Replace single quotes
861
+		$val = str_replace( array( '&#8216;', '&#8217;', '&#8242;', '&prime;', '&rsquo;', '&lsquo;' ), "'", $val );
862
+		return $val;
863
+	}
864
+
865
+	/**
866
+	 * @since 2.0
867
+	 * @return string The base Google APIS url for the current version of jQuery UI
868
+	 */
869
+	public static function jquery_ui_base_url() {
870 870
 		$url = 'http' . ( is_ssl() ? 's' : '' ) . '://ajax.googleapis.com/ajax/libs/jqueryui/' . self::script_version('jquery-ui-core');
871
-        $url = apply_filters('frm_jquery_ui_base_url', $url);
872
-        return $url;
873
-    }
871
+		$url = apply_filters('frm_jquery_ui_base_url', $url);
872
+		return $url;
873
+	}
874 874
 
875
-    /**
876
-     * @param string $handle
877
-     */
875
+	/**
876
+	 * @param string $handle
877
+	 */
878 878
 	public static function script_version( $handle ) {
879
-        global $wp_scripts;
880
-    	if ( ! $wp_scripts ) {
881
-    	    return false;
882
-    	}
879
+		global $wp_scripts;
880
+		if ( ! $wp_scripts ) {
881
+			return false;
882
+		}
883 883
 
884
-        $ver = 0;
884
+		$ver = 0;
885 885
 
886
-        if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
887
-            return $ver;
888
-        }
886
+		if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
887
+			return $ver;
888
+		}
889 889
 
890
-        $query = $wp_scripts->registered[ $handle ];
891
-    	if ( is_object( $query ) ) {
892
-    	    $ver = $query->ver;
893
-    	}
890
+		$query = $wp_scripts->registered[ $handle ];
891
+		if ( is_object( $query ) ) {
892
+			$ver = $query->ver;
893
+		}
894 894
 
895
-    	return $ver;
896
-    }
895
+		return $ver;
896
+	}
897 897
 
898 898
 	public static function js_redirect( $url ) {
899 899
 		return '<script type="text/javascript">window.location="' . esc_url_raw( $url ) . '"</script>';
900
-    }
900
+	}
901 901
 
902 902
 	public static function get_user_id_param( $user_id ) {
903
-        if ( ! $user_id || empty($user_id) || is_numeric($user_id) ) {
904
-            return $user_id;
905
-        }
903
+		if ( ! $user_id || empty($user_id) || is_numeric($user_id) ) {
904
+			return $user_id;
905
+		}
906 906
 
907 907
 		if ( $user_id == 'current' ) {
908 908
 			$user_id = get_current_user_id();
909 909
 		} else {
910
-            if ( is_email($user_id) ) {
911
-                $user = get_user_by('email', $user_id);
912
-            } else {
913
-                $user = get_user_by('login', $user_id);
914
-            }
910
+			if ( is_email($user_id) ) {
911
+				$user = get_user_by('email', $user_id);
912
+			} else {
913
+				$user = get_user_by('login', $user_id);
914
+			}
915 915
 
916
-            if ( $user ) {
917
-                $user_id = $user->ID;
918
-            }
919
-            unset($user);
920
-        }
916
+			if ( $user ) {
917
+				$user_id = $user->ID;
918
+			}
919
+			unset($user);
920
+		}
921 921
 
922
-        return $user_id;
923
-    }
922
+		return $user_id;
923
+	}
924 924
 
925 925
 	public static function get_file_contents( $filename, $atts = array() ) {
926
-        if ( ! is_file($filename) ) {
927
-            return false;
928
-        }
929
-
930
-        extract($atts);
931
-        ob_start();
932
-        include($filename);
933
-        $contents = ob_get_contents();
934
-        ob_end_clean();
935
-        return $contents;
936
-    }
937
-
938
-    /**
939
-     * @param string $table_name
940
-     * @param string $column
926
+		if ( ! is_file($filename) ) {
927
+			return false;
928
+		}
929
+
930
+		extract($atts);
931
+		ob_start();
932
+		include($filename);
933
+		$contents = ob_get_contents();
934
+		ob_end_clean();
935
+		return $contents;
936
+	}
937
+
938
+	/**
939
+	 * @param string $table_name
940
+	 * @param string $column
941 941
 	 * @param int $id
942 942
 	 * @param int $num_chars
943
-     */
944
-    public static function get_unique_key( $name = '', $table_name, $column, $id = 0, $num_chars = 5 ) {
945
-        $key = '';
943
+	 */
944
+	public static function get_unique_key( $name = '', $table_name, $column, $id = 0, $num_chars = 5 ) {
945
+		$key = '';
946 946
 
947
-        if ( ! empty( $name ) ) {
948
-            $key = sanitize_key($name);
949
-        }
947
+		if ( ! empty( $name ) ) {
948
+			$key = sanitize_key($name);
949
+		}
950 950
 
951 951
 		if ( empty( $key ) ) {
952
-            $max_slug_value = pow(36, $num_chars);
953
-            $min_slug_value = 37; // we want to have at least 2 characters in the slug
954
-            $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
955
-        }
952
+			$max_slug_value = pow(36, $num_chars);
953
+			$min_slug_value = 37; // we want to have at least 2 characters in the slug
954
+			$key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
955
+		}
956 956
 
957 957
 		if ( is_numeric($key) || in_array( $key, array( 'id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd' ) ) ) {
958 958
 			$key = $key . 'a';
959
-        }
959
+		}
960 960
 
961 961
 		$key_check = FrmDb::get_var( $table_name, array( $column => $key, 'ID !' => $id ), $column );
962 962
 
963
-        if ( $key_check || is_numeric($key_check) ) {
964
-            $suffix = 2;
963
+		if ( $key_check || is_numeric($key_check) ) {
964
+			$suffix = 2;
965 965
 			do {
966 966
 				$alt_post_name = substr( $key, 0, 200 - ( strlen( $suffix ) + 1 ) ) . $suffix;
967 967
 				$key_check = FrmDb::get_var( $table_name, array( $column => $alt_post_name, 'ID !' => $id ), $column );
968 968
 				$suffix++;
969 969
 			} while ($key_check || is_numeric($key_check));
970 970
 			$key = $alt_post_name;
971
-        }
972
-        return $key;
973
-    }
974
-
975
-    /**
976
-     * Editing a Form or Entry
977
-     * @param string $table
978
-     * @return bool|array
979
-     */
980
-    public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array(), $args = array() ) {
981
-        if ( ! $record ) {
982
-            return false;
983
-        }
984
-
985
-        if ( empty($post_values) ) {
986
-            $post_values = stripslashes_deep($_POST);
987
-        }
971
+		}
972
+		return $key;
973
+	}
974
+
975
+	/**
976
+	 * Editing a Form or Entry
977
+	 * @param string $table
978
+	 * @return bool|array
979
+	 */
980
+	public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array(), $args = array() ) {
981
+		if ( ! $record ) {
982
+			return false;
983
+		}
984
+
985
+		if ( empty($post_values) ) {
986
+			$post_values = stripslashes_deep($_POST);
987
+		}
988 988
 
989 989
 		$values = array( 'id' => $record->id, 'fields' => array() );
990 990
 
991 991
 		foreach ( array( 'name', 'description' ) as $var ) {
992
-            $default_val = isset($record->{$var}) ? $record->{$var} : '';
992
+			$default_val = isset($record->{$var}) ? $record->{$var} : '';
993 993
 			$values[ $var ] = self::get_param( $var, $default_val, 'get', 'wp_kses_post' );
994
-            unset($var, $default_val);
995
-        }
996
-
997
-        $values['description'] = self::use_wpautop($values['description']);
998
-        $frm_settings = self::get_settings();
999
-        $is_form_builder = self::is_admin_page('formidable' );
1000
-
1001
-        foreach ( (array) $fields as $field ) {
1002
-            // Make sure to filter default values (for placeholder text), but not on the form builder page
1003
-            if ( ! $is_form_builder ) {
1004
-                $field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true );
1005
-            }
994
+			unset($var, $default_val);
995
+		}
996
+
997
+		$values['description'] = self::use_wpautop($values['description']);
998
+		$frm_settings = self::get_settings();
999
+		$is_form_builder = self::is_admin_page('formidable' );
1000
+
1001
+		foreach ( (array) $fields as $field ) {
1002
+			// Make sure to filter default values (for placeholder text), but not on the form builder page
1003
+			if ( ! $is_form_builder ) {
1004
+				$field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true );
1005
+			}
1006 1006
 			$parent_form_id = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id;
1007 1007
 			self::fill_field_defaults($field, $record, $values, compact('default', 'post_values', 'frm_settings', 'parent_form_id' ) );
1008
-        }
1008
+		}
1009 1009
 
1010
-        self::fill_form_opts($record, $table, $post_values, $values);
1010
+		self::fill_form_opts($record, $table, $post_values, $values);
1011 1011
 
1012
-        if ( $table == 'entries' ) {
1013
-            $values = FrmEntriesHelper::setup_edit_vars( $values, $record );
1014
-        } else if ( $table == 'forms' ) {
1015
-            $values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values );
1016
-        }
1012
+		if ( $table == 'entries' ) {
1013
+			$values = FrmEntriesHelper::setup_edit_vars( $values, $record );
1014
+		} else if ( $table == 'forms' ) {
1015
+			$values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values );
1016
+		}
1017 1017
 
1018
-        return $values;
1019
-    }
1018
+		return $values;
1019
+	}
1020 1020
 
1021 1021
 	private static function fill_field_defaults( $field, $record, array &$values, $args ) {
1022
-        $post_values = $args['post_values'];
1023
-
1024
-        if ( $args['default'] ) {
1025
-            $meta_value = $field->default_value;
1026
-        } else {
1027
-            if ( $record->post_id && self::pro_is_installed() && isset($field->field_options['post_field']) && $field->field_options['post_field'] ) {
1028
-                if ( ! isset($field->field_options['custom_field']) ) {
1029
-                    $field->field_options['custom_field'] = '';
1030
-                }
1022
+		$post_values = $args['post_values'];
1023
+
1024
+		if ( $args['default'] ) {
1025
+			$meta_value = $field->default_value;
1026
+		} else {
1027
+			if ( $record->post_id && self::pro_is_installed() && isset($field->field_options['post_field']) && $field->field_options['post_field'] ) {
1028
+				if ( ! isset($field->field_options['custom_field']) ) {
1029
+					$field->field_options['custom_field'] = '';
1030
+				}
1031 1031
 				$meta_value = FrmProEntryMetaHelper::get_post_value( $record->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array( 'truncate' => false, 'type' => $field->type, 'form_id' => $field->form_id, 'field' => $field ) );
1032
-            } else {
1032
+			} else {
1033 1033
 				$meta_value = FrmEntryMeta::get_meta_value( $record, $field->id );
1034
-            }
1035
-        }
1034
+			}
1035
+		}
1036 1036
 
1037 1037
 		$field_type = isset( $post_values['field_options'][ 'type_' . $field->id ] ) ? $post_values['field_options'][ 'type_' . $field->id ] : $field->type;
1038
-        $new_value = isset( $post_values['item_meta'][ $field->id ] ) ? maybe_unserialize( $post_values['item_meta'][ $field->id ] ) : $meta_value;
1039
-
1040
-        $field_array = array(
1041
-            'id'            => $field->id,
1042
-            'value'         => $new_value,
1043
-            'default_value' => $field->default_value,
1044
-            'name'          => $field->name,
1045
-            'description'   => $field->description,
1046
-            'type'          => apply_filters('frm_field_type', $field_type, $field, $new_value),
1047
-            'options'       => $field->options,
1048
-            'required'      => $field->required,
1049
-            'field_key'     => $field->field_key,
1050
-            'field_order'   => $field->field_order,
1051
-            'form_id'       => $field->form_id,
1038
+		$new_value = isset( $post_values['item_meta'][ $field->id ] ) ? maybe_unserialize( $post_values['item_meta'][ $field->id ] ) : $meta_value;
1039
+
1040
+		$field_array = array(
1041
+			'id'            => $field->id,
1042
+			'value'         => $new_value,
1043
+			'default_value' => $field->default_value,
1044
+			'name'          => $field->name,
1045
+			'description'   => $field->description,
1046
+			'type'          => apply_filters('frm_field_type', $field_type, $field, $new_value),
1047
+			'options'       => $field->options,
1048
+			'required'      => $field->required,
1049
+			'field_key'     => $field->field_key,
1050
+			'field_order'   => $field->field_order,
1051
+			'form_id'       => $field->form_id,
1052 1052
 			'parent_form_id' => $args['parent_form_id'],
1053
-        );
1053
+		);
1054 1054
 
1055
-        $args['field_type'] = $field_type;
1056
-        self::fill_field_opts($field, $field_array, $args);
1055
+		$args['field_type'] = $field_type;
1056
+		self::fill_field_opts($field, $field_array, $args);
1057 1057
 		// Track the original field's type
1058 1058
 		$field_array['original_type'] = isset( $field->field_options['original_type'] ) ? $field->field_options['original_type'] : $field->type;
1059 1059
 
1060
-        $field_array = apply_filters( 'frm_setup_edit_fields_vars', $field_array, $field, $values['id'], array() );
1060
+		$field_array = apply_filters( 'frm_setup_edit_fields_vars', $field_array, $field, $values['id'], array() );
1061 1061
 
1062
-        if ( ! isset($field_array['unique']) || ! $field_array['unique'] ) {
1063
-            $field_array['unique_msg'] = '';
1064
-        }
1062
+		if ( ! isset($field_array['unique']) || ! $field_array['unique'] ) {
1063
+			$field_array['unique_msg'] = '';
1064
+		}
1065 1065
 
1066
-        $field_array = array_merge( $field->field_options, $field_array );
1066
+		$field_array = array_merge( $field->field_options, $field_array );
1067 1067
 
1068
-        $values['fields'][ $field->id ] = $field_array;
1069
-    }
1068
+		$values['fields'][ $field->id ] = $field_array;
1069
+	}
1070 1070
 
1071 1071
 	private static function fill_field_opts( $field, array &$field_array, $args ) {
1072
-        $post_values = $args['post_values'];
1073
-        $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
1072
+		$post_values = $args['post_values'];
1073
+		$opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
1074 1074
 
1075
-        foreach ( $opt_defaults as $opt => $default_opt ) {
1075
+		foreach ( $opt_defaults as $opt => $default_opt ) {
1076 1076
 			$field_array[ $opt ] = ( $post_values && isset( $post_values['field_options'][ $opt . '_' . $field->id ] ) ) ? maybe_unserialize( $post_values['field_options'][ $opt . '_' . $field->id ] ) : ( isset( $field->field_options[ $opt ] ) ? $field->field_options[ $opt ] : $default_opt );
1077
-            if ( $opt == 'blank' && $field_array[ $opt ] == '' ) {
1078
-                $field_array[ $opt ] = $args['frm_settings']->blank_msg;
1079
-            } else if ( $opt == 'invalid' && $field_array[ $opt ] == '' ) {
1080
-                if ( $args['field_type'] == 'captcha' ) {
1081
-                    $field_array[ $opt ] = $args['frm_settings']->re_msg;
1082
-                } else {
1083
-                    $field_array[ $opt ] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] );
1084
-                }
1085
-            }
1086
-        }
1087
-
1088
-        if ( $field_array['custom_html'] == '' ) {
1089
-            $field_array['custom_html'] = FrmFieldsHelper::get_default_html($args['field_type']);
1090
-        }
1091
-    }
1092
-
1093
-    /**
1094
-     * @param string $table
1095
-     */
1077
+			if ( $opt == 'blank' && $field_array[ $opt ] == '' ) {
1078
+				$field_array[ $opt ] = $args['frm_settings']->blank_msg;
1079
+			} else if ( $opt == 'invalid' && $field_array[ $opt ] == '' ) {
1080
+				if ( $args['field_type'] == 'captcha' ) {
1081
+					$field_array[ $opt ] = $args['frm_settings']->re_msg;
1082
+				} else {
1083
+					$field_array[ $opt ] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] );
1084
+				}
1085
+			}
1086
+		}
1087
+
1088
+		if ( $field_array['custom_html'] == '' ) {
1089
+			$field_array['custom_html'] = FrmFieldsHelper::get_default_html($args['field_type']);
1090
+		}
1091
+	}
1092
+
1093
+	/**
1094
+	 * @param string $table
1095
+	 */
1096 1096
 	private static function fill_form_opts( $record, $table, $post_values, array &$values ) {
1097
-        if ( $table == 'entries' ) {
1098
-            $form = $record->form_id;
1097
+		if ( $table == 'entries' ) {
1098
+			$form = $record->form_id;
1099 1099
 			FrmForm::maybe_get_form( $form );
1100
-        } else {
1101
-            $form = $record;
1102
-        }
1100
+		} else {
1101
+			$form = $record;
1102
+		}
1103 1103
 
1104
-        if ( ! $form ) {
1105
-            return;
1106
-        }
1104
+		if ( ! $form ) {
1105
+			return;
1106
+		}
1107 1107
 
1108
-        $values['form_name'] = isset($record->form_id) ? $form->name : '';
1108
+		$values['form_name'] = isset($record->form_id) ? $form->name : '';
1109 1109
 		$values['parent_form_id'] = isset( $record->form_id ) ? $form->parent_form_id : 0;
1110 1110
 
1111
-        if ( ! is_array($form->options) ) {
1112
-            return;
1113
-        }
1111
+		if ( ! is_array($form->options) ) {
1112
+			return;
1113
+		}
1114 1114
 
1115
-        foreach ( $form->options as $opt => $value ) {
1116
-            $values[ $opt ] = isset( $post_values[ $opt ] ) ? maybe_unserialize( $post_values[ $opt ] ) : $value;
1117
-        }
1115
+		foreach ( $form->options as $opt => $value ) {
1116
+			$values[ $opt ] = isset( $post_values[ $opt ] ) ? maybe_unserialize( $post_values[ $opt ] ) : $value;
1117
+		}
1118 1118
 
1119
-        self::fill_form_defaults($post_values, $values);
1120
-    }
1119
+		self::fill_form_defaults($post_values, $values);
1120
+	}
1121 1121
 
1122
-    /**
1123
-     * Set to POST value or default
1124
-     */
1122
+	/**
1123
+	 * Set to POST value or default
1124
+	 */
1125 1125
 	private static function fill_form_defaults( $post_values, array &$values ) {
1126
-        $form_defaults = FrmFormsHelper::get_default_opts();
1126
+		$form_defaults = FrmFormsHelper::get_default_opts();
1127 1127
 
1128
-        foreach ( $form_defaults as $opt => $default ) {
1129
-            if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
1128
+		foreach ( $form_defaults as $opt => $default ) {
1129
+			if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
1130 1130
 				$values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default;
1131
-            }
1131
+			}
1132 1132
 
1133
-            unset($opt, $defaut);
1134
-        }
1133
+			unset($opt, $defaut);
1134
+		}
1135 1135
 
1136
-        if ( ! isset($values['custom_style']) ) {
1137
-            $frm_settings = self::get_settings();
1136
+		if ( ! isset($values['custom_style']) ) {
1137
+			$frm_settings = self::get_settings();
1138 1138
 			$values['custom_style'] = ( $post_values && isset( $post_values['options']['custom_style'] ) ) ? absint( $_POST['options']['custom_style'] ) : ( $frm_settings->load_style != 'none' );
1139
-        }
1139
+		}
1140 1140
 
1141 1141
 		foreach ( array( 'before', 'after', 'submit' ) as $h ) {
1142 1142
 			if ( ! isset( $values[ $h . '_html' ] ) ) {
1143 1143
 				$values[ $h . '_html' ] = ( isset( $post_values['options'][ $h . '_html' ] ) ? $post_values['options'][ $h . '_html' ] : FrmFormsHelper::get_default_html( $h ) );
1144
-            }
1145
-            unset($h);
1146
-        }
1147
-    }
1144
+			}
1145
+			unset($h);
1146
+		}
1147
+	}
1148 1148
 
1149 1149
 	public static function get_meta_value( $field_id, $entry ) {
1150 1150
 		_deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntryMeta::get_meta_value' );
@@ -1152,59 +1152,59 @@  discard block
 block discarded – undo
1152 1152
 	}
1153 1153
 
1154 1154
 	public static function insert_opt_html( $args ) {
1155
-        $class = '';
1156
-        if ( in_array( $args['type'], array( 'email', 'user_id', 'hidden', 'select', 'radio', 'checkbox', 'phone', 'text' ) ) ) {
1157
-            $class .= 'show_frm_not_email_to';
1158
-        }
1159
-    ?>
1155
+		$class = '';
1156
+		if ( in_array( $args['type'], array( 'email', 'user_id', 'hidden', 'select', 'radio', 'checkbox', 'phone', 'text' ) ) ) {
1157
+			$class .= 'show_frm_not_email_to';
1158
+		}
1159
+	?>
1160 1160
 <li>
1161 1161
     <a href="javascript:void(0)" class="frmids frm_insert_code alignright <?php echo esc_attr($class) ?>" data-code="<?php echo esc_attr($args['id']) ?>" >[<?php echo esc_attr( $args['id'] ) ?>]</a>
1162 1162
     <a href="javascript:void(0)" class="frmkeys frm_insert_code alignright <?php echo esc_attr($class) ?>" data-code="<?php echo esc_attr($args['key']) ?>" >[<?php echo esc_attr( self::truncate($args['key'], 10) ) ?>]</a>
1163 1163
     <a href="javascript:void(0)" class="frm_insert_code <?php echo esc_attr( $class ) ?>" data-code="<?php echo esc_attr($args['id']) ?>" ><?php echo esc_attr( self::truncate($args['name'], 60) ) ?></a>
1164 1164
 </li>
1165 1165
     <?php
1166
-    }
1166
+	}
1167 1167
 
1168 1168
 	public static function truncate( $str, $length, $minword = 3, $continue = '...' ) {
1169
-        if ( is_array( $str ) ) {
1170
-            return '';
1169
+		if ( is_array( $str ) ) {
1170
+			return '';
1171 1171
 		}
1172 1172
 
1173
-        $length = (int) $length;
1173
+		$length = (int) $length;
1174 1174
 		$str = wp_strip_all_tags( $str );
1175 1175
 		$original_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $str ) );
1176 1176
 
1177 1177
 		if ( $length == 0 ) {
1178
-            return '';
1179
-        } else if ( $length <= 10 ) {
1178
+			return '';
1179
+		} else if ( $length <= 10 ) {
1180 1180
 			$sub = self::mb_function( array( 'mb_substr', 'substr' ), array( $str, 0, $length ) );
1181
-            return $sub . (($length < $original_len) ? $continue : '');
1182
-        }
1181
+			return $sub . (($length < $original_len) ? $continue : '');
1182
+		}
1183 1183
 
1184
-        $sub = '';
1185
-        $len = 0;
1184
+		$sub = '';
1185
+		$len = 0;
1186 1186
 
1187 1187
 		$words = self::mb_function( array( 'mb_split', 'explode' ), array( ' ', $str ) );
1188 1188
 
1189 1189
 		foreach ( $words as $word ) {
1190
-            $part = (($sub != '') ? ' ' : '') . $word;
1190
+			$part = (($sub != '') ? ' ' : '') . $word;
1191 1191
 			$total_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub . $part ) );
1192
-            if ( $total_len > $length && str_word_count($sub) ) {
1193
-                break;
1194
-            }
1192
+			if ( $total_len > $length && str_word_count($sub) ) {
1193
+				break;
1194
+			}
1195 1195
 
1196
-            $sub .= $part;
1196
+			$sub .= $part;
1197 1197
 			$len += self::mb_function( array( 'mb_strlen', 'strlen' ), array( $part ) );
1198 1198
 
1199
-            if ( str_word_count($sub) > $minword && $total_len >= $length ) {
1200
-                break;
1201
-            }
1199
+			if ( str_word_count($sub) > $minword && $total_len >= $length ) {
1200
+				break;
1201
+			}
1202 1202
 
1203
-            unset($total_len, $word);
1204
-        }
1203
+			unset($total_len, $word);
1204
+		}
1205 1205
 
1206
-        return $sub . (($len < $original_len) ? $continue : '');
1207
-    }
1206
+		return $sub . (($len < $original_len) ? $continue : '');
1207
+	}
1208 1208
 
1209 1209
 	public static function mb_function( $function_names, $args ) {
1210 1210
 		$mb_function_name = $function_names[0];
@@ -1216,18 +1216,18 @@  discard block
 block discarded – undo
1216 1216
 	}
1217 1217
 
1218 1218
 	public static function get_formatted_time( $date, $date_format = '', $time_format = '' ) {
1219
-        if ( empty($date) ) {
1220
-            return $date;
1221
-        }
1219
+		if ( empty($date) ) {
1220
+			return $date;
1221
+		}
1222 1222
 
1223
-        if ( empty($date_format) ) {
1224
-            $date_format = get_option('date_format');
1225
-        }
1223
+		if ( empty($date_format) ) {
1224
+			$date_format = get_option('date_format');
1225
+		}
1226 1226
 
1227
-        if ( preg_match('/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date) && self::pro_is_installed() ) {
1228
-            $frmpro_settings = new FrmProSettings();
1229
-            $date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d');
1230
-        }
1227
+		if ( preg_match('/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date) && self::pro_is_installed() ) {
1228
+			$frmpro_settings = new FrmProSettings();
1229
+			$date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d');
1230
+		}
1231 1231
 
1232 1232
 		$formatted = self::get_localized_date( $date_format, $date );
1233 1233
 
@@ -1236,8 +1236,8 @@  discard block
 block discarded – undo
1236 1236
 			$formatted .= self::add_time_to_date( $time_format, $date );
1237 1237
 		}
1238 1238
 
1239
-        return $formatted;
1240
-    }
1239
+		return $formatted;
1240
+	}
1241 1241
 
1242 1242
 	private static function add_time_to_date( $time_format, $date ) {
1243 1243
 		if ( empty( $time_format ) ) {
@@ -1318,61 +1318,61 @@  discard block
 block discarded – undo
1318 1318
 		);
1319 1319
 	}
1320 1320
 
1321
-    /**
1322
-     * Added for < WP 4.0 compatability
1323
-     *
1324
-     * @since 1.07.10
1325
-     *
1326
-     * @param string $term The value to escape
1327
-     * @return string The escaped value
1328
-     */
1321
+	/**
1322
+	 * Added for < WP 4.0 compatability
1323
+	 *
1324
+	 * @since 1.07.10
1325
+	 *
1326
+	 * @param string $term The value to escape
1327
+	 * @return string The escaped value
1328
+	 */
1329 1329
 	public static function esc_like( $term ) {
1330
-        global $wpdb;
1331
-        if ( method_exists($wpdb, 'esc_like') ) {
1330
+		global $wpdb;
1331
+		if ( method_exists($wpdb, 'esc_like') ) {
1332 1332
 			// WP 4.0
1333
-            $term = $wpdb->esc_like( $term );
1334
-        } else {
1335
-            $term = like_escape( $term );
1336
-        }
1333
+			$term = $wpdb->esc_like( $term );
1334
+		} else {
1335
+			$term = like_escape( $term );
1336
+		}
1337 1337
 
1338
-        return $term;
1339
-    }
1338
+		return $term;
1339
+	}
1340 1340
 
1341
-    /**
1342
-     * @param string $order_query
1343
-     */
1341
+	/**
1342
+	 * @param string $order_query
1343
+	 */
1344 1344
 	public static function esc_order( $order_query ) {
1345
-        if ( empty($order_query) ) {
1346
-            return '';
1347
-        }
1348
-
1349
-        // remove ORDER BY before santizing
1350
-        $order_query = strtolower($order_query);
1351
-        if ( strpos($order_query, 'order by') !== false ) {
1352
-            $order_query = str_replace('order by', '', $order_query);
1353
-        }
1354
-
1355
-        $order_query = explode(' ', trim($order_query));
1356
-
1357
-        $order_fields = array(
1358
-            'id', 'form_key', 'name', 'description',
1359
-            'parent_form_id', 'logged_in', 'is_template',
1360
-            'default_template', 'status', 'created_at',
1361
-        );
1362
-
1363
-        $order = trim(trim(reset($order_query), ','));
1364
-        if ( ! in_array($order, $order_fields) ) {
1365
-            return '';
1366
-        }
1367
-
1368
-        $order_by = '';
1369
-        if ( count($order_query) > 1 ) {
1345
+		if ( empty($order_query) ) {
1346
+			return '';
1347
+		}
1348
+
1349
+		// remove ORDER BY before santizing
1350
+		$order_query = strtolower($order_query);
1351
+		if ( strpos($order_query, 'order by') !== false ) {
1352
+			$order_query = str_replace('order by', '', $order_query);
1353
+		}
1354
+
1355
+		$order_query = explode(' ', trim($order_query));
1356
+
1357
+		$order_fields = array(
1358
+			'id', 'form_key', 'name', 'description',
1359
+			'parent_form_id', 'logged_in', 'is_template',
1360
+			'default_template', 'status', 'created_at',
1361
+		);
1362
+
1363
+		$order = trim(trim(reset($order_query), ','));
1364
+		if ( ! in_array($order, $order_fields) ) {
1365
+			return '';
1366
+		}
1367
+
1368
+		$order_by = '';
1369
+		if ( count($order_query) > 1 ) {
1370 1370
 			$order_by = end( $order_query );
1371 1371
 			self::esc_order_by( $order_by );
1372
-        }
1372
+		}
1373 1373
 
1374 1374
 		return ' ORDER BY ' . $order . ' ' . $order_by;
1375
-    }
1375
+	}
1376 1376
 
1377 1377
 	/**
1378 1378
 	 * Make sure this is ordering by either ASC or DESC
@@ -1384,169 +1384,169 @@  discard block
 block discarded – undo
1384 1384
 		}
1385 1385
 	}
1386 1386
 
1387
-    /**
1388
-     * @param string $limit
1389
-     */
1387
+	/**
1388
+	 * @param string $limit
1389
+	 */
1390 1390
 	public static function esc_limit( $limit ) {
1391
-        if ( empty($limit) ) {
1392
-            return '';
1393
-        }
1391
+		if ( empty($limit) ) {
1392
+			return '';
1393
+		}
1394 1394
 
1395
-        $limit = trim(str_replace(' limit', '', strtolower($limit)));
1396
-        if ( is_numeric($limit) ) {
1395
+		$limit = trim(str_replace(' limit', '', strtolower($limit)));
1396
+		if ( is_numeric($limit) ) {
1397 1397
 			return ' LIMIT ' . $limit;
1398
-        }
1398
+		}
1399 1399
 
1400
-        $limit = explode(',', trim($limit));
1401
-        foreach ( $limit as $k => $l ) {
1402
-            if ( is_numeric( $l ) ) {
1403
-                $limit[ $k ] = $l;
1404
-            }
1405
-        }
1400
+		$limit = explode(',', trim($limit));
1401
+		foreach ( $limit as $k => $l ) {
1402
+			if ( is_numeric( $l ) ) {
1403
+				$limit[ $k ] = $l;
1404
+			}
1405
+		}
1406 1406
 
1407
-        $limit = implode(',', $limit);
1407
+		$limit = implode(',', $limit);
1408 1408
 		return ' LIMIT ' . $limit;
1409
-    }
1410
-
1411
-    /**
1412
-     * Get an array of values ready to go through $wpdb->prepare
1413
-     * @since 2.0
1414
-     */
1415
-    public static function prepare_array_values( $array, $type = '%s' ) {
1416
-        $placeholders = array_fill(0, count($array), $type);
1417
-        return implode(', ', $placeholders);
1418
-    }
1419
-
1420
-    public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) {
1421
-        if ( empty($where) ) {
1422
-            return '';
1423
-        }
1409
+	}
1410
+
1411
+	/**
1412
+	 * Get an array of values ready to go through $wpdb->prepare
1413
+	 * @since 2.0
1414
+	 */
1415
+	public static function prepare_array_values( $array, $type = '%s' ) {
1416
+		$placeholders = array_fill(0, count($array), $type);
1417
+		return implode(', ', $placeholders);
1418
+	}
1419
+
1420
+	public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) {
1421
+		if ( empty($where) ) {
1422
+			return '';
1423
+		}
1424 1424
 
1425 1425
 		if ( is_array( $where ) ) {
1426
-            global $wpdb;
1427
-            FrmDb::get_where_clause_and_values( $where, $starts_with );
1426
+			global $wpdb;
1427
+			FrmDb::get_where_clause_and_values( $where, $starts_with );
1428 1428
 			$where = $wpdb->prepare( $where['where'], $where['values'] );
1429 1429
 		} else {
1430
-            $where = $starts_with . $where;
1431
-        }
1430
+			$where = $starts_with . $where;
1431
+		}
1432 1432
 
1433
-        return $where;
1434
-    }
1433
+		return $where;
1434
+	}
1435 1435
 
1436
-    // Pagination Methods
1436
+	// Pagination Methods
1437 1437
 
1438
-    /**
1439
-     * @param integer $current_p
1440
-     */
1438
+	/**
1439
+	 * @param integer $current_p
1440
+	 */
1441 1441
 	public static function get_last_record_num( $r_count, $current_p, $p_size ) {
1442 1442
 		return ( ( $r_count < ( $current_p * $p_size ) ) ? $r_count : ( $current_p * $p_size ) );
1443 1443
 	}
1444 1444
 
1445
-    /**
1446
-     * @param integer $current_p
1447
-     */
1448
-    public static function get_first_record_num( $r_count, $current_p, $p_size ) {
1449
-        if ( $current_p == 1 ) {
1450
-            return 1;
1451
-        } else {
1452
-            return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 );
1453
-        }
1454
-    }
1445
+	/**
1446
+	 * @param integer $current_p
1447
+	 */
1448
+	public static function get_first_record_num( $r_count, $current_p, $p_size ) {
1449
+		if ( $current_p == 1 ) {
1450
+			return 1;
1451
+		} else {
1452
+			return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 );
1453
+		}
1454
+	}
1455 1455
 
1456 1456
 	/**
1457 1457
 	 * @return array
1458 1458
 	 */
1459 1459
 	public static function json_to_array( $json_vars ) {
1460
-        $vars = array();
1461
-        foreach ( $json_vars as $jv ) {
1462
-            $jv_name = explode('[', $jv['name']);
1463
-            $last = count($jv_name) - 1;
1464
-            foreach ( $jv_name as $p => $n ) {
1465
-                $name = trim($n, ']');
1466
-                if ( ! isset($l1) ) {
1467
-                    $l1 = $name;
1468
-                }
1469
-
1470
-                if ( ! isset($l2) ) {
1471
-                    $l2 = $name;
1472
-                }
1473
-
1474
-                if ( ! isset($l3) ) {
1475
-                    $l3 = $name;
1476
-                }
1477
-
1478
-                $this_val = ( $p == $last ) ? $jv['value'] : array();
1479
-
1480
-                switch ( $p ) {
1481
-                    case 0:
1482
-                        $l1 = $name;
1483
-                        self::add_value_to_array( $name, $l1, $this_val, $vars );
1484
-                    break;
1485
-
1486
-                    case 1:
1487
-                        $l2 = $name;
1488
-                        self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] );
1489
-                    break;
1490
-
1491
-                    case 2:
1492
-                        $l3 = $name;
1493
-                        self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] );
1494
-                    break;
1495
-
1496
-                    case 3:
1497
-                        $l4 = $name;
1498
-                        self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] );
1499
-                    break;
1500
-                }
1501
-
1502
-                unset($this_val, $n);
1503
-            }
1504
-
1505
-            unset($last, $jv);
1506
-        }
1507
-
1508
-        return $vars;
1509
-    }
1510
-
1511
-    /**
1512
-     * @param string $name
1513
-     * @param string $l1
1514
-     */
1515
-    public static function add_value_to_array( $name, $l1, $val, &$vars ) {
1516
-        if ( $name == '' ) {
1517
-            $vars[] = $val;
1518
-        } else if ( ! isset( $vars[ $l1 ] ) ) {
1519
-            $vars[ $l1 ] = $val;
1520
-        }
1521
-    }
1460
+		$vars = array();
1461
+		foreach ( $json_vars as $jv ) {
1462
+			$jv_name = explode('[', $jv['name']);
1463
+			$last = count($jv_name) - 1;
1464
+			foreach ( $jv_name as $p => $n ) {
1465
+				$name = trim($n, ']');
1466
+				if ( ! isset($l1) ) {
1467
+					$l1 = $name;
1468
+				}
1469
+
1470
+				if ( ! isset($l2) ) {
1471
+					$l2 = $name;
1472
+				}
1473
+
1474
+				if ( ! isset($l3) ) {
1475
+					$l3 = $name;
1476
+				}
1477
+
1478
+				$this_val = ( $p == $last ) ? $jv['value'] : array();
1479
+
1480
+				switch ( $p ) {
1481
+					case 0:
1482
+						$l1 = $name;
1483
+						self::add_value_to_array( $name, $l1, $this_val, $vars );
1484
+					break;
1485
+
1486
+					case 1:
1487
+						$l2 = $name;
1488
+						self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] );
1489
+					break;
1490
+
1491
+					case 2:
1492
+						$l3 = $name;
1493
+						self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] );
1494
+					break;
1495
+
1496
+					case 3:
1497
+						$l4 = $name;
1498
+						self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] );
1499
+					break;
1500
+				}
1501
+
1502
+				unset($this_val, $n);
1503
+			}
1504
+
1505
+			unset($last, $jv);
1506
+		}
1507
+
1508
+		return $vars;
1509
+	}
1510
+
1511
+	/**
1512
+	 * @param string $name
1513
+	 * @param string $l1
1514
+	 */
1515
+	public static function add_value_to_array( $name, $l1, $val, &$vars ) {
1516
+		if ( $name == '' ) {
1517
+			$vars[] = $val;
1518
+		} else if ( ! isset( $vars[ $l1 ] ) ) {
1519
+			$vars[ $l1 ] = $val;
1520
+		}
1521
+	}
1522 1522
 
1523 1523
 	public static function maybe_add_tooltip( $name, $class = 'closed', $form_name = '' ) {
1524
-        $tooltips = array(
1525
-            'action_title'  => __( 'Give this action a label for easy reference.', 'formidable' ),
1526
-            'email_to'      => __( 'Add one or more recipient addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].  [admin_email] is the address set in WP General Settings.', 'formidable' ),
1527
-            'cc'            => __( 'Add CC addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1528
-            'bcc'           => __( 'Add BCC addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1529
-            'reply_to'      => __( 'If you would like a different reply to address than the "from" address, add a single address here.  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1530
-            'from'          => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <[email protected]> or [email protected].', 'formidable' ),
1531
-            'email_subject' => esc_attr( sprintf( __( 'If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable' ), $form_name, self::site_name() ) ),
1532
-        );
1533
-
1534
-        if ( ! isset( $tooltips[ $name ] ) ) {
1535
-            return;
1536
-        }
1537
-
1538
-        if ( 'open' == $class ) {
1539
-            echo ' frm_help"';
1540
-        } else {
1541
-            echo ' class="frm_help"';
1542
-        }
1524
+		$tooltips = array(
1525
+			'action_title'  => __( 'Give this action a label for easy reference.', 'formidable' ),
1526
+			'email_to'      => __( 'Add one or more recipient addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].  [admin_email] is the address set in WP General Settings.', 'formidable' ),
1527
+			'cc'            => __( 'Add CC addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1528
+			'bcc'           => __( 'Add BCC addresses separated by a ",".  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1529
+			'reply_to'      => __( 'If you would like a different reply to address than the "from" address, add a single address here.  FORMAT: Name <[email protected]> or [email protected].', 'formidable' ),
1530
+			'from'          => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <[email protected]> or [email protected].', 'formidable' ),
1531
+			'email_subject' => esc_attr( sprintf( __( 'If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable' ), $form_name, self::site_name() ) ),
1532
+		);
1533
+
1534
+		if ( ! isset( $tooltips[ $name ] ) ) {
1535
+			return;
1536
+		}
1537
+
1538
+		if ( 'open' == $class ) {
1539
+			echo ' frm_help"';
1540
+		} else {
1541
+			echo ' class="frm_help"';
1542
+		}
1543 1543
 
1544 1544
 		echo ' title="' . esc_attr( $tooltips[ $name ] );
1545 1545
 
1546
-        if ( 'open' != $class ) {
1547
-            echo '"';
1548
-        }
1549
-    }
1546
+		if ( 'open' != $class ) {
1547
+			echo '"';
1548
+		}
1549
+	}
1550 1550
 
1551 1551
 	/**
1552 1552
 	 * Add the current_page class to that page in the form nav
@@ -1562,35 +1562,35 @@  discard block
 block discarded – undo
1562 1562
 		}
1563 1563
 	}
1564 1564
 
1565
-    /**
1566
-     * Prepare and json_encode post content
1567
-     *
1568
-     * @since 2.0
1569
-     *
1570
-     * @param array $post_content
1571
-     * @return string $post_content ( json encoded array )
1572
-     */
1573
-    public static function prepare_and_encode( $post_content ) {
1574
-        //Loop through array to strip slashes and add only the needed ones
1565
+	/**
1566
+	 * Prepare and json_encode post content
1567
+	 *
1568
+	 * @since 2.0
1569
+	 *
1570
+	 * @param array $post_content
1571
+	 * @return string $post_content ( json encoded array )
1572
+	 */
1573
+	public static function prepare_and_encode( $post_content ) {
1574
+		//Loop through array to strip slashes and add only the needed ones
1575 1575
 		foreach ( $post_content as $key => $val ) {
1576 1576
 			// Replace problematic characters (like &quot;)
1577 1577
 			$val = str_replace( '&quot;', '"', $val );
1578 1578
 
1579 1579
 			self::prepare_action_slashes( $val, $key, $post_content );
1580
-            unset( $key, $val );
1581
-        }
1580
+			unset( $key, $val );
1581
+		}
1582 1582
 
1583
-        // json_encode the array
1584
-        $post_content = json_encode( $post_content );
1583
+		// json_encode the array
1584
+		$post_content = json_encode( $post_content );
1585 1585
 
1586
-	    // add extra slashes for \r\n since WP strips them
1586
+		// add extra slashes for \r\n since WP strips them
1587 1587
 		$post_content = str_replace( array( '\\r', '\\n', '\\u', '\\t' ), array( '\\\\r', '\\\\n', '\\\\u', '\\\\t' ), $post_content );
1588 1588
 
1589
-        // allow for &quot
1590
-	    $post_content = str_replace( '&quot;', '\\"', $post_content );
1589
+		// allow for &quot
1590
+		$post_content = str_replace( '&quot;', '\\"', $post_content );
1591 1591
 
1592
-        return $post_content;
1593
-    }
1592
+		return $post_content;
1593
+	}
1594 1594
 
1595 1595
 	private static function prepare_action_slashes( $val, $key, &$post_content ) {
1596 1596
 		if ( ! isset( $post_content[ $key ] ) ) {
@@ -1658,64 +1658,64 @@  discard block
 block discarded – undo
1658 1658
 	}
1659 1659
 
1660 1660
 	public static function maybe_json_decode( $string ) {
1661
-        if ( is_array($string) ) {
1662
-            return $string;
1663
-        }
1661
+		if ( is_array($string) ) {
1662
+			return $string;
1663
+		}
1664 1664
 
1665
-        $new_string = json_decode($string, true);
1666
-        if ( function_exists('json_last_error') ) {
1665
+		$new_string = json_decode($string, true);
1666
+		if ( function_exists('json_last_error') ) {
1667 1667
 			// php 5.3+
1668
-            if ( json_last_error() == JSON_ERROR_NONE ) {
1669
-                $string = $new_string;
1670
-            }
1671
-        } else if ( isset($new_string) ) {
1668
+			if ( json_last_error() == JSON_ERROR_NONE ) {
1669
+				$string = $new_string;
1670
+			}
1671
+		} else if ( isset($new_string) ) {
1672 1672
 			// php < 5.3 fallback
1673
-            $string = $new_string;
1674
-        }
1675
-        return $string;
1676
-    }
1677
-
1678
-    /**
1679
-     * @since 1.07.10
1680
-     *
1681
-     * @param string $post_type The name of the post type that may need to be highlighted
1682
-     * echo The javascript to open and highlight the Formidable menu
1683
-     */
1673
+			$string = $new_string;
1674
+		}
1675
+		return $string;
1676
+	}
1677
+
1678
+	/**
1679
+	 * @since 1.07.10
1680
+	 *
1681
+	 * @param string $post_type The name of the post type that may need to be highlighted
1682
+	 * echo The javascript to open and highlight the Formidable menu
1683
+	 */
1684 1684
 	public static function maybe_highlight_menu( $post_type ) {
1685
-        global $post;
1685
+		global $post;
1686 1686
 
1687
-        if ( isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != $post_type ) {
1688
-            return;
1689
-        }
1687
+		if ( isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != $post_type ) {
1688
+			return;
1689
+		}
1690 1690
 
1691
-        if ( is_object($post) && $post->post_type != $post_type ) {
1692
-            return;
1693
-        }
1691
+		if ( is_object($post) && $post->post_type != $post_type ) {
1692
+			return;
1693
+		}
1694 1694
 
1695
-        self::load_admin_wide_js();
1696
-        echo '<script type="text/javascript">jQuery(document).ready(function(){frmSelectSubnav();});</script>';
1697
-    }
1695
+		self::load_admin_wide_js();
1696
+		echo '<script type="text/javascript">jQuery(document).ready(function(){frmSelectSubnav();});</script>';
1697
+	}
1698 1698
 
1699
-    /**
1700
-     * Load the JS file on non-Formidable pages in the admin area
1701
-     * @since 2.0
1702
-     */
1699
+	/**
1700
+	 * Load the JS file on non-Formidable pages in the admin area
1701
+	 * @since 2.0
1702
+	 */
1703 1703
 	public static function load_admin_wide_js( $load = true ) {
1704
-        $version = FrmAppHelper::plugin_version();
1704
+		$version = FrmAppHelper::plugin_version();
1705 1705
 		wp_register_script( 'formidable_admin_global', FrmAppHelper::plugin_url() . '/js/formidable_admin_global.js', array( 'jquery' ), $version );
1706 1706
 
1707
-        wp_localize_script( 'formidable_admin_global', 'frmGlobal', array(
1707
+		wp_localize_script( 'formidable_admin_global', 'frmGlobal', array(
1708 1708
 			'updating_msg' => __( 'Please wait while your site updates.', 'formidable' ),
1709
-            'deauthorize'  => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ),
1709
+			'deauthorize'  => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ),
1710 1710
 			'url'          => FrmAppHelper::plugin_url(),
1711 1711
 			'loading'      => __( 'Loading&hellip;' ),
1712 1712
 			'nonce'        => wp_create_nonce( 'frm_ajax' ),
1713
-        ) );
1713
+		) );
1714 1714
 
1715 1715
 		if ( $load ) {
1716 1716
 			wp_enqueue_script( 'formidable_admin_global' );
1717 1717
 		}
1718
-    }
1718
+	}
1719 1719
 
1720 1720
 	/**
1721 1721
 	 * @since 2.0.9
@@ -1724,9 +1724,9 @@  discard block
 block discarded – undo
1724 1724
 		wp_enqueue_style( 'frm_fonts', self::plugin_url() . '/css/frm_fonts.css', array(), self::plugin_version() );
1725 1725
 	}
1726 1726
 
1727
-    /**
1728
-     * @param string $location
1729
-     */
1727
+	/**
1728
+	 * @param string $location
1729
+	 */
1730 1730
 	public static function localize_script( $location ) {
1731 1731
 		$ajax_url = admin_url( 'admin-ajax.php', is_ssl() ? 'admin' : 'http' );
1732 1732
 		$ajax_url = apply_filters( 'frm_ajax_url', $ajax_url );
@@ -1779,81 +1779,81 @@  discard block
 block discarded – undo
1779 1779
 		}
1780 1780
 	}
1781 1781
 
1782
-    /**
1782
+	/**
1783 1783
 	 * echo the message on the plugins listing page
1784
-     * @since 1.07.10
1785
-     *
1786
-     * @param float $min_version The version the add-on requires
1787
-     */
1784
+	 * @since 1.07.10
1785
+	 *
1786
+	 * @param float $min_version The version the add-on requires
1787
+	 */
1788 1788
 	public static function min_version_notice( $min_version ) {
1789
-        $frm_version = self::plugin_version();
1789
+		$frm_version = self::plugin_version();
1790 1790
 
1791
-        // check if Formidable meets minimum requirements
1792
-        if ( version_compare($frm_version, $min_version, '>=') ) {
1793
-            return;
1794
-        }
1791
+		// check if Formidable meets minimum requirements
1792
+		if ( version_compare($frm_version, $min_version, '>=') ) {
1793
+			return;
1794
+		}
1795 1795
 
1796
-        $wp_list_table = _get_list_table('WP_Plugins_List_Table');
1796
+		$wp_list_table = _get_list_table('WP_Plugins_List_Table');
1797 1797
 		echo '<tr class="plugin-update-tr active"><th colspan="' . absint( $wp_list_table->get_column_count() ) . '" class="check-column plugin-update colspanchange"><div class="update-message">' .
1798
-        __( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) .
1799
-        '</div></td></tr>';
1800
-    }
1801
-
1802
-    public static function locales( $type = 'date' ) {
1803
-        $locales = array(
1804
-            'en' => __( 'English', 'formidable' ),    '' => __( 'English/Western', 'formidable' ),
1805
-            'af' => __( 'Afrikaans', 'formidable' ),  'sq' => __( 'Albanian', 'formidable' ),
1806
-            'ar' => __( 'Arabic', 'formidable' ),     'hy' => __( 'Armenian', 'formidable' ),
1807
-            'az' => __( 'Azerbaijani', 'formidable' ), 'eu' => __( 'Basque', 'formidable' ),
1808
-            'bs' => __( 'Bosnian', 'formidable' ),    'bg' => __( 'Bulgarian', 'formidable' ),
1809
-            'ca' => __( 'Catalan', 'formidable' ),    'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ),
1810
-            'zh-CN' => __( 'Chinese Simplified', 'formidable' ), 'zh-TW' => __( 'Chinese Traditional', 'formidable' ),
1811
-            'hr' => __( 'Croatian', 'formidable' ),   'cs' => __( 'Czech', 'formidable' ),
1812
-            'da' => __( 'Danish', 'formidable' ),     'nl' => __( 'Dutch', 'formidable' ),
1813
-            'en-GB' => __( 'English/UK', 'formidable' ), 'eo' => __( 'Esperanto', 'formidable' ),
1814
-            'et' => __( 'Estonian', 'formidable' ),   'fo' => __( 'Faroese', 'formidable' ),
1815
-            'fa' => __( 'Farsi/Persian', 'formidable' ), 'fil' => __( 'Filipino', 'formidable' ),
1816
-            'fi' => __( 'Finnish', 'formidable' ),    'fr' => __( 'French', 'formidable' ),
1817
-            'fr-CA' => __( 'French/Canadian', 'formidable' ), 'fr-CH' => __( 'French/Swiss', 'formidable' ),
1818
-            'de' => __( 'German', 'formidable' ),     'de-AT' => __( 'German/Austria', 'formidable' ),
1819
-            'de-CH' => __( 'German/Switzerland', 'formidable' ), 'el' => __( 'Greek', 'formidable' ),
1820
-            'he' => __( 'Hebrew', 'formidable' ),     'iw' => __( 'Hebrew', 'formidable' ),
1821
-            'hi' => __( 'Hindi', 'formidable' ),      'hu' => __( 'Hungarian', 'formidable' ),
1822
-            'is' => __( 'Icelandic', 'formidable' ),  'id' => __( 'Indonesian', 'formidable' ),
1823
-            'it' => __( 'Italian', 'formidable' ),    'ja' => __( 'Japanese', 'formidable' ),
1824
-            'ko' => __( 'Korean', 'formidable' ),     'lv' => __( 'Latvian', 'formidable' ),
1825
-            'lt' => __( 'Lithuanian', 'formidable' ), 'ms' => __( 'Malaysian', 'formidable' ),
1826
-            'no' => __( 'Norwegian', 'formidable' ),  'pl' => __( 'Polish', 'formidable' ),
1827
-            'pt' => __( 'Portuguese', 'formidable' ), 'pt-BR' => __( 'Portuguese/Brazilian', 'formidable' ),
1828
-            'pt-PT' => __( 'Portuguese/Portugal', 'formidable' ), 'ro' => __( 'Romanian', 'formidable' ),
1829
-            'ru' => __( 'Russian', 'formidable' ),    'sr' => __( 'Serbian', 'formidable' ),
1830
-            'sr-SR' => __( 'Serbian', 'formidable' ), 'sk' => __( 'Slovak', 'formidable' ),
1831
-            'sl' => __( 'Slovenian', 'formidable' ),  'es' => __( 'Spanish', 'formidable' ),
1832
-            'es-419' => __( 'Spanish/Latin America', 'formidable' ), 'sv' => __( 'Swedish', 'formidable' ),
1833
-            'ta' => __( 'Tamil', 'formidable' ),      'th' => __( 'Thai', 'formidable' ),
1834
-            'tu' => __( 'Turkish', 'formidable' ),    'tr' => __( 'Turkish', 'formidable' ),
1835
-            'uk' => __( 'Ukranian', 'formidable' ),   'vi' => __( 'Vietnamese', 'formidable' ),
1836
-        );
1837
-
1838
-        if ( $type == 'captcha' ) {
1839
-            // remove the languages unavailable for the captcha
1840
-            $unset = array(
1841
-                '', 'af', 'sq', 'hy', 'az', 'eu', 'bs',
1842
-                'zh-HK', 'eo', 'et', 'fo', 'fr-CH',
1843
-                'he', 'is', 'ms', 'sr-SR', 'ta', 'tu',
1844
-            );
1845
-        } else {
1846
-            // remove the languages unavailable for the datepicker
1847
-            $unset = array(
1848
-                'en', 'fil', 'fr-CA', 'de-AT', 'de-AT',
1849
-                'de-CH', 'iw', 'hi', 'pt', 'pt-PT',
1850
-                'es-419', 'tr',
1851
-            );
1852
-        }
1853
-
1854
-        $locales = array_diff_key($locales, array_flip($unset));
1855
-        $locales = apply_filters('frm_locales', $locales);
1856
-
1857
-        return $locales;
1858
-    }
1798
+		__( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) .
1799
+		'</div></td></tr>';
1800
+	}
1801
+
1802
+	public static function locales( $type = 'date' ) {
1803
+		$locales = array(
1804
+			'en' => __( 'English', 'formidable' ),    '' => __( 'English/Western', 'formidable' ),
1805
+			'af' => __( 'Afrikaans', 'formidable' ),  'sq' => __( 'Albanian', 'formidable' ),
1806
+			'ar' => __( 'Arabic', 'formidable' ),     'hy' => __( 'Armenian', 'formidable' ),
1807
+			'az' => __( 'Azerbaijani', 'formidable' ), 'eu' => __( 'Basque', 'formidable' ),
1808
+			'bs' => __( 'Bosnian', 'formidable' ),    'bg' => __( 'Bulgarian', 'formidable' ),
1809
+			'ca' => __( 'Catalan', 'formidable' ),    'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ),
1810
+			'zh-CN' => __( 'Chinese Simplified', 'formidable' ), 'zh-TW' => __( 'Chinese Traditional', 'formidable' ),
1811
+			'hr' => __( 'Croatian', 'formidable' ),   'cs' => __( 'Czech', 'formidable' ),
1812
+			'da' => __( 'Danish', 'formidable' ),     'nl' => __( 'Dutch', 'formidable' ),
1813
+			'en-GB' => __( 'English/UK', 'formidable' ), 'eo' => __( 'Esperanto', 'formidable' ),
1814
+			'et' => __( 'Estonian', 'formidable' ),   'fo' => __( 'Faroese', 'formidable' ),
1815
+			'fa' => __( 'Farsi/Persian', 'formidable' ), 'fil' => __( 'Filipino', 'formidable' ),
1816
+			'fi' => __( 'Finnish', 'formidable' ),    'fr' => __( 'French', 'formidable' ),
1817
+			'fr-CA' => __( 'French/Canadian', 'formidable' ), 'fr-CH' => __( 'French/Swiss', 'formidable' ),
1818
+			'de' => __( 'German', 'formidable' ),     'de-AT' => __( 'German/Austria', 'formidable' ),
1819
+			'de-CH' => __( 'German/Switzerland', 'formidable' ), 'el' => __( 'Greek', 'formidable' ),
1820
+			'he' => __( 'Hebrew', 'formidable' ),     'iw' => __( 'Hebrew', 'formidable' ),
1821
+			'hi' => __( 'Hindi', 'formidable' ),      'hu' => __( 'Hungarian', 'formidable' ),
1822
+			'is' => __( 'Icelandic', 'formidable' ),  'id' => __( 'Indonesian', 'formidable' ),
1823
+			'it' => __( 'Italian', 'formidable' ),    'ja' => __( 'Japanese', 'formidable' ),
1824
+			'ko' => __( 'Korean', 'formidable' ),     'lv' => __( 'Latvian', 'formidable' ),
1825
+			'lt' => __( 'Lithuanian', 'formidable' ), 'ms' => __( 'Malaysian', 'formidable' ),
1826
+			'no' => __( 'Norwegian', 'formidable' ),  'pl' => __( 'Polish', 'formidable' ),
1827
+			'pt' => __( 'Portuguese', 'formidable' ), 'pt-BR' => __( 'Portuguese/Brazilian', 'formidable' ),
1828
+			'pt-PT' => __( 'Portuguese/Portugal', 'formidable' ), 'ro' => __( 'Romanian', 'formidable' ),
1829
+			'ru' => __( 'Russian', 'formidable' ),    'sr' => __( 'Serbian', 'formidable' ),
1830
+			'sr-SR' => __( 'Serbian', 'formidable' ), 'sk' => __( 'Slovak', 'formidable' ),
1831
+			'sl' => __( 'Slovenian', 'formidable' ),  'es' => __( 'Spanish', 'formidable' ),
1832
+			'es-419' => __( 'Spanish/Latin America', 'formidable' ), 'sv' => __( 'Swedish', 'formidable' ),
1833
+			'ta' => __( 'Tamil', 'formidable' ),      'th' => __( 'Thai', 'formidable' ),
1834
+			'tu' => __( 'Turkish', 'formidable' ),    'tr' => __( 'Turkish', 'formidable' ),
1835
+			'uk' => __( 'Ukranian', 'formidable' ),   'vi' => __( 'Vietnamese', 'formidable' ),
1836
+		);
1837
+
1838
+		if ( $type == 'captcha' ) {
1839
+			// remove the languages unavailable for the captcha
1840
+			$unset = array(
1841
+				'', 'af', 'sq', 'hy', 'az', 'eu', 'bs',
1842
+				'zh-HK', 'eo', 'et', 'fo', 'fr-CH',
1843
+				'he', 'is', 'ms', 'sr-SR', 'ta', 'tu',
1844
+			);
1845
+		} else {
1846
+			// remove the languages unavailable for the datepicker
1847
+			$unset = array(
1848
+				'en', 'fil', 'fr-CA', 'de-AT', 'de-AT',
1849
+				'de-CH', 'iw', 'hi', 'pt', 'pt-PT',
1850
+				'es-419', 'tr',
1851
+			);
1852
+		}
1853
+
1854
+		$locales = array_diff_key($locales, array_flip($unset));
1855
+		$locales = apply_filters('frm_locales', $locales);
1856
+
1857
+		return $locales;
1858
+	}
1859 1859
 }
Please login to merge, or discard this patch.
Spacing   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
2
+if ( ! defined( 'ABSPATH' ) ) {
3 3
 	die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
@@ -23,11 +23,11 @@  discard block
 block discarded – undo
23 23
     }
24 24
 
25 25
     public static function plugin_folder() {
26
-        return basename(self::plugin_path());
26
+        return basename( self::plugin_path() );
27 27
     }
28 28
 
29 29
     public static function plugin_path() {
30
-        return dirname(dirname(dirname(__FILE__)));
30
+        return dirname( dirname( dirname( __FILE__ ) ) );
31 31
     }
32 32
 
33 33
     public static function plugin_url() {
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      * @return string
55 55
      */
56 56
     public static function site_name() {
57
-        return get_option('blogname');
57
+        return get_option( 'blogname' );
58 58
     }
59 59
 
60 60
 	public static function make_affiliate_url( $url ) {
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 
68 68
 	public static function get_affiliate() {
69 69
 		return '';
70
-		$affiliate_id = apply_filters( 'frm_affiliate_link', get_option('frm_aff') );
70
+		$affiliate_id = apply_filters( 'frm_affiliate_link', get_option( 'frm_aff' ) );
71 71
 		$affiliate_id = strtolower( $affiliate_id );
72 72
 		$allowed_affiliates = array();
73 73
 		if ( ! in_array( $affiliate_id, $allowed_affiliates ) ) {
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      */
87 87
     public static function get_settings() {
88 88
         global $frm_settings;
89
-        if ( empty($frm_settings) ) {
89
+        if ( empty( $frm_settings ) ) {
90 90
             $frm_settings = new FrmSettings();
91 91
         }
92 92
         return $frm_settings;
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
     }
108 108
 
109 109
     public static function pro_is_installed() {
110
-        return apply_filters('frm_pro_installed', false);
110
+        return apply_filters( 'frm_pro_installed', false );
111 111
     }
112 112
 
113 113
     /**
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
      * @return boolean
152 152
      */
153 153
     public static function doing_ajax() {
154
-        return defined('DOING_AJAX') && DOING_AJAX && ! self::is_preview_page();
154
+        return defined( 'DOING_AJAX' ) && DOING_AJAX && ! self::is_preview_page();
155 155
     }
156 156
 
157 157
 	/**
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
      * @return boolean
172 172
      */
173 173
     public static function is_admin() {
174
-        return is_admin() && ( ! defined('DOING_AJAX') || ! DOING_AJAX );
174
+        return is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX );
175 175
     }
176 176
 
177 177
     /**
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
      * @return string
199 199
      */
200 200
 	public static function get_server_value( $value ) {
201
-        return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( $_SERVER[ $value ] ) : '';
201
+        return isset( $_SERVER[$value] ) ? wp_strip_all_tags( $_SERVER[$value] ) : '';
202 202
     }
203 203
 
204 204
     /**
@@ -213,14 +213,14 @@  discard block
 block discarded – undo
213 213
             'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP',
214 214
             'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR',
215 215
         ) as $key ) {
216
-            if ( ! isset( $_SERVER[ $key ] ) ) {
216
+            if ( ! isset( $_SERVER[$key] ) ) {
217 217
                 continue;
218 218
             }
219 219
 
220
-            foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) {
221
-                $ip = trim($ip); // just to be safe
220
+            foreach ( explode( ',', $_SERVER[$key] ) as $ip ) {
221
+                $ip = trim( $ip ); // just to be safe
222 222
 
223
-                if ( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) {
223
+                if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) !== false ) {
224 224
                     return $ip;
225 225
                 }
226 226
             }
@@ -230,15 +230,15 @@  discard block
 block discarded – undo
230 230
     }
231 231
 
232 232
     public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) {
233
-        if ( strpos($param, '[') ) {
234
-            $params = explode('[', $param);
233
+        if ( strpos( $param, '[' ) ) {
234
+            $params = explode( '[', $param );
235 235
             $param = $params[0];
236 236
         }
237 237
 
238 238
 		if ( $src == 'get' ) {
239
-            $value = isset( $_POST[ $param ] ) ? stripslashes_deep( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? stripslashes_deep( $_GET[ $param ] ) : $default );
240
-            if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) {
241
-                $value = stripslashes_deep( htmlspecialchars_decode( urldecode( $_GET[ $param ] ) ) );
239
+            $value = isset( $_POST[$param] ) ? stripslashes_deep( $_POST[$param] ) : ( isset( $_GET[$param] ) ? stripslashes_deep( $_GET[$param] ) : $default );
240
+            if ( ! isset( $_POST[$param] ) && isset( $_GET[$param] ) && ! is_array( $value ) ) {
241
+                $value = stripslashes_deep( htmlspecialchars_decode( urldecode( $_GET[$param] ) ) );
242 242
             }
243 243
 			self::sanitize_value( $sanitize, $value );
244 244
 		} else {
@@ -247,12 +247,12 @@  discard block
 block discarded – undo
247 247
 
248 248
 		if ( isset( $params ) && is_array( $value ) && ! empty( $value ) ) {
249 249
             foreach ( $params as $k => $p ) {
250
-                if ( ! $k || ! is_array($value) ) {
250
+                if ( ! $k || ! is_array( $value ) ) {
251 251
                     continue;
252 252
                 }
253 253
 
254
-                $p = trim($p, ']');
255
-                $value = isset( $value[ $p ] ) ? $value[ $p ] : $default;
254
+                $p = trim( $p, ']' );
255
+                $value = isset( $value[$p] ) ? $value[$p] : $default;
256 256
             }
257 257
         }
258 258
 
@@ -291,16 +291,16 @@  discard block
 block discarded – undo
291 291
 
292 292
 		$value = $args['default'];
293 293
 		if ( $args['type'] == 'get' ) {
294
-			if ( $_GET && isset( $_GET[ $args['param'] ] ) ) {
295
-				$value = $_GET[ $args['param'] ];
294
+			if ( $_GET && isset( $_GET[$args['param']] ) ) {
295
+				$value = $_GET[$args['param']];
296 296
 			}
297 297
 		} else if ( $args['type'] == 'post' ) {
298
-			if ( isset( $_POST[ $args['param'] ] ) ) {
299
-				$value = stripslashes_deep( maybe_unserialize( $_POST[ $args['param'] ] ) );
298
+			if ( isset( $_POST[$args['param']] ) ) {
299
+				$value = stripslashes_deep( maybe_unserialize( $_POST[$args['param']] ) );
300 300
 			}
301 301
 		} else {
302
-			if ( isset( $_REQUEST[ $args['param'] ] ) ) {
303
-				$value = $_REQUEST[ $args['param'] ];
302
+			if ( isset( $_REQUEST[$args['param']] ) ) {
303
+				$value = $_REQUEST[$args['param']];
304 304
 			}
305 305
 		}
306 306
 
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 			if ( is_array( $value ) ) {
329 329
 				$temp_values = $value;
330 330
 				foreach ( $temp_values as $k => $v ) {
331
-					FrmAppHelper::sanitize_value( $sanitize, $value[ $k ] );
331
+					FrmAppHelper::sanitize_value( $sanitize, $value[$k] );
332 332
 				}
333 333
 			} else {
334 334
 				$value = call_user_func( $sanitize, $value );
@@ -339,8 +339,8 @@  discard block
 block discarded – undo
339 339
     public static function sanitize_request( $sanitize_method, &$values ) {
340 340
         $temp_values = $values;
341 341
         foreach ( $temp_values as $k => $val ) {
342
-            if ( isset( $sanitize_method[ $k ] ) ) {
343
-				$values[ $k ] = call_user_func( $sanitize_method[ $k ], $val );
342
+            if ( isset( $sanitize_method[$k] ) ) {
343
+				$values[$k] = call_user_func( $sanitize_method[$k], $val );
344 344
             }
345 345
         }
346 346
     }
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 	public static function sanitize_array( &$values ) {
349 349
 		$temp_values = $values;
350 350
 		foreach ( $temp_values as $k => $val ) {
351
-			$values[ $k ] = wp_kses_post( $val );
351
+			$values[$k] = wp_kses_post( $val );
352 352
 		}
353 353
 	}
354 354
 
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
 
372 372
 		$allowed_html = array();
373 373
 		foreach ( $allowed as $a ) {
374
-			$allowed_html[ $a ] = isset( $html[ $a ] ) ? $html[ $a ] : array();
374
+			$allowed_html[$a] = isset( $html[$a] ) ? $html[$a] : array();
375 375
 		}
376 376
 
377 377
 		return wp_kses( $value, $allowed_html );
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
      * @since 2.0
383 383
      */
384 384
     public static function remove_get_action() {
385
-        if ( ! isset($_GET) ) {
385
+        if ( ! isset( $_GET ) ) {
386 386
             return;
387 387
         }
388 388
 
@@ -404,8 +404,8 @@  discard block
 block discarded – undo
404 404
         }
405 405
 
406 406
         global $wp_query;
407
-        if ( isset( $wp_query->query_vars[ $param ] ) ) {
408
-            $value = $wp_query->query_vars[ $param ];
407
+        if ( isset( $wp_query->query_vars[$param] ) ) {
408
+            $value = $wp_query->query_vars[$param];
409 409
         }
410 410
 
411 411
         return $value;
@@ -434,19 +434,19 @@  discard block
 block discarded – undo
434 434
      * @return mixed $results The cache or query results
435 435
      */
436 436
     public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
437
-        $results = wp_cache_get($cache_key, $group);
438
-        if ( ! self::is_empty_value( $results, false ) || empty($query) ) {
437
+        $results = wp_cache_get( $cache_key, $group );
438
+        if ( ! self::is_empty_value( $results, false ) || empty( $query ) ) {
439 439
             return $results;
440 440
         }
441 441
 
442 442
         if ( 'get_posts' == $type ) {
443
-            $results = get_posts($query);
443
+            $results = get_posts( $query );
444 444
 		} else if ( 'get_associative_results' == $type ) {
445 445
 			global $wpdb;
446 446
 			$results = $wpdb->get_results( $query, OBJECT_K );
447 447
         } else {
448 448
             global $wpdb;
449
-            $results = $wpdb->{$type}($query);
449
+            $results = $wpdb->{$type}( $query );
450 450
         }
451 451
 
452 452
 		self::set_cache( $cache_key, $results, $group, $time );
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 	 */
468 468
 	public static function add_key_to_group_cache( $key, $group ) {
469 469
 		$cached = self::get_group_cached_keys( $group );
470
-		$cached[ $key ] = $key;
470
+		$cached[$key] = $key;
471 471
 		wp_cache_set( 'cached_keys', $cached, $group, 300 );
472 472
 	}
473 473
 
@@ -493,9 +493,9 @@  discard block
 block discarded – undo
493 493
         }
494 494
 
495 495
         // then check the transient
496
-        $results = get_transient($cache_key);
496
+        $results = get_transient( $cache_key );
497 497
         if ( $results ) {
498
-            wp_cache_set($cache_key, $results);
498
+            wp_cache_set( $cache_key, $results );
499 499
         }
500 500
 
501 501
         return $results;
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
      * @param string $cache_key
507 507
      */
508 508
 	public static function delete_cache_and_transient( $cache_key, $group = 'default' ) {
509
-		delete_transient($cache_key);
509
+		delete_transient( $cache_key );
510 510
 		wp_cache_delete( $cache_key, $group );
511 511
 	}
512 512
 
@@ -525,8 +525,8 @@  discard block
 block discarded – undo
525 525
 				$group => $cached_keys,
526 526
 			);
527 527
 
528
-			if ( isset( $group_cache[ $group ] ) ) {
529
-				foreach ( $group_cache[ $group ] as $k => $v ) {
528
+			if ( isset( $group_cache[$group] ) ) {
529
+				foreach ( $group_cache[$group] as $k => $v ) {
530 530
 					$d = wp_cache_delete( $k, $group );
531 531
 				}
532 532
 			}
@@ -554,17 +554,17 @@  discard block
 block discarded – undo
554 554
     }
555 555
 
556 556
     public static function get_pages() {
557
-		return get_posts( array( 'post_type' => 'page', 'post_status' => array( 'publish', 'private' ), 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC' ) );
557
+		return get_posts( array( 'post_type' => 'page', 'post_status' => array( 'publish', 'private' ), 'numberposts' => - 1, 'orderby' => 'title', 'order' => 'ASC' ) );
558 558
     }
559 559
 
560 560
     public static function wp_pages_dropdown( $field_name, $page_id, $truncate = false ) {
561 561
         $pages = self::get_pages();
562 562
 		$selected = self::get_post_param( $field_name, $page_id, 'absint' );
563 563
     ?>
564
-        <select name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" class="frm-pages-dropdown">
564
+        <select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $field_name ); ?>" class="frm-pages-dropdown">
565 565
             <option value=""> </option>
566 566
             <?php foreach ( $pages as $page ) { ?>
567
-				<option value="<?php echo esc_attr($page->ID); ?>" <?php selected( $selected, $page->ID ) ?>>
567
+				<option value="<?php echo esc_attr( $page->ID ); ?>" <?php selected( $selected, $page->ID ) ?>>
568 568
 					<?php echo esc_html( $truncate ? self::truncate( $page->post_title, $truncate ) : $page->post_title ); ?>
569 569
 				</option>
570 570
             <?php } ?>
@@ -573,7 +573,7 @@  discard block
 block discarded – undo
573 573
     }
574 574
 
575 575
 	public static function post_edit_link( $post_id ) {
576
-        $post = get_post($post_id);
576
+        $post = get_post( $post_id );
577 577
         if ( $post ) {
578 578
 			$post_url = admin_url( 'post.php?post=' . $post_id . '&action=edit' );
579 579
 			return '<a href="' . esc_url( $post_url ) . '">' . self::truncate( $post->post_title, 50 ) . '</a>';
@@ -583,17 +583,17 @@  discard block
 block discarded – undo
583 583
 
584 584
 	public static function wp_roles_dropdown( $field_name, $capability, $multiple = 'single' ) {
585 585
     ?>
586
-        <select name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" <?php
586
+        <select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $field_name ); ?>" <?php
587 587
             echo ( 'multiple' == $multiple ) ? 'multiple="multiple"' : '';
588 588
             ?> class="frm_multiselect">
589
-            <?php self::roles_options($capability); ?>
589
+            <?php self::roles_options( $capability ); ?>
590 590
         </select>
591 591
     <?php
592 592
     }
593 593
 
594 594
 	public static function roles_options( $capability ) {
595 595
         global $frm_vars;
596
-        if ( isset($frm_vars['editable_roles']) ) {
596
+        if ( isset( $frm_vars['editable_roles'] ) ) {
597 597
             $editable_roles = $frm_vars['editable_roles'];
598 598
         } else {
599 599
             $editable_roles = get_editable_roles();
@@ -601,10 +601,10 @@  discard block
 block discarded – undo
601 601
         }
602 602
 
603 603
         foreach ( $editable_roles as $role => $details ) {
604
-            $name = translate_user_role($details['name'] ); ?>
605
-        <option value="<?php echo esc_attr($role) ?>" <?php echo in_array($role, (array) $capability) ? ' selected="selected"' : ''; ?>><?php echo esc_attr($name) ?> </option>
604
+            $name = translate_user_role( $details['name'] ); ?>
605
+        <option value="<?php echo esc_attr( $role ) ?>" <?php echo in_array( $role, (array) $capability ) ? ' selected="selected"' : ''; ?>><?php echo esc_attr( $name ) ?> </option>
606 606
 <?php
607
-            unset($role, $details);
607
+            unset( $role, $details );
608 608
         }
609 609
     }
610 610
 
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
     public static function maybe_add_permissions() {
661 661
 		self::force_capability( 'frm_view_entries' );
662 662
 
663
-        if ( ! current_user_can('administrator') || current_user_can('frm_view_forms') ) {
663
+        if ( ! current_user_can( 'administrator' ) || current_user_can( 'frm_view_forms' ) ) {
664 664
             return;
665 665
         }
666 666
 
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
         $frm_roles = self::frm_capabilities();
670 670
         foreach ( $frm_roles as $frm_role => $frm_role_description ) {
671 671
 			$user->add_cap( $frm_role );
672
-            unset($frm_role, $frm_role_description);
672
+            unset( $frm_role, $frm_role_description );
673 673
         }
674 674
     }
675 675
 
@@ -694,12 +694,12 @@  discard block
 block discarded – undo
694 694
      * @param string $permission
695 695
      */
696 696
 	public static function permission_check( $permission, $show_message = 'show' ) {
697
-        $permission_error = self::permission_nonce_error($permission);
697
+        $permission_error = self::permission_nonce_error( $permission );
698 698
         if ( $permission_error !== false ) {
699 699
             if ( 'hide' == $show_message ) {
700 700
                 $permission_error = '';
701 701
             }
702
-            wp_die($permission_error);
702
+            wp_die( $permission_error );
703 703
         }
704 704
     }
705 705
 
@@ -716,11 +716,11 @@  discard block
 block discarded – undo
716 716
 		}
717 717
 
718 718
 		$error = false;
719
-        if ( empty($nonce_name) ) {
719
+        if ( empty( $nonce_name ) ) {
720 720
             return $error;
721 721
         }
722 722
 
723
-        if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $_REQUEST[ $nonce_name ], $nonce ) ) ) {
723
+        if ( $_REQUEST && ( ! isset( $_REQUEST[$nonce_name] ) || ! wp_verify_nonce( $_REQUEST[$nonce_name], $nonce ) ) ) {
724 724
             $frm_settings = self::get_settings();
725 725
             $error = $frm_settings->admin_permission;
726 726
         }
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
 			} else {
801 801
 				foreach ( $value as $k => $v ) {
802 802
 					if ( ! is_array( $v ) ) {
803
-						$value[ $k ] = call_user_func( $original_function, $v );
803
+						$value[$k] = call_user_func( $original_function, $v );
804 804
 					}
805 805
 				}
806 806
 			}
@@ -821,11 +821,11 @@  discard block
 block discarded – undo
821 821
 	public static function array_flatten( $array, $keys = 'keep' ) {
822 822
         $return = array();
823 823
         foreach ( $array as $key => $value ) {
824
-            if ( is_array($value) ) {
824
+            if ( is_array( $value ) ) {
825 825
 				$return = array_merge( $return, self::array_flatten( $value, $keys ) );
826 826
             } else {
827 827
 				if ( $keys == 'keep' ) {
828
-					$return[ $key ] = $value;
828
+					$return[$key] = $value;
829 829
 				} else {
830 830
 					$return[] = $value;
831 831
 				}
@@ -848,8 +848,8 @@  discard block
 block discarded – undo
848 848
      * @since 2.0
849 849
      */
850 850
 	public static function use_wpautop( $content ) {
851
-        if ( apply_filters('frm_use_wpautop', true) ) {
852
-            $content = wpautop(str_replace( '<br>', '<br />', $content));
851
+        if ( apply_filters( 'frm_use_wpautop', true ) ) {
852
+            $content = wpautop( str_replace( '<br>', '<br />', $content ) );
853 853
         }
854 854
         return $content;
855 855
     }
@@ -867,8 +867,8 @@  discard block
 block discarded – undo
867 867
      * @return string The base Google APIS url for the current version of jQuery UI
868 868
      */
869 869
     public static function jquery_ui_base_url() {
870
-		$url = 'http' . ( is_ssl() ? 's' : '' ) . '://ajax.googleapis.com/ajax/libs/jqueryui/' . self::script_version('jquery-ui-core');
871
-        $url = apply_filters('frm_jquery_ui_base_url', $url);
870
+		$url = 'http' . ( is_ssl() ? 's' : '' ) . '://ajax.googleapis.com/ajax/libs/jqueryui/' . self::script_version( 'jquery-ui-core' );
871
+        $url = apply_filters( 'frm_jquery_ui_base_url', $url );
872 872
         return $url;
873 873
     }
874 874
 
@@ -883,11 +883,11 @@  discard block
 block discarded – undo
883 883
 
884 884
         $ver = 0;
885 885
 
886
-        if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
886
+        if ( ! isset( $wp_scripts->registered[$handle] ) ) {
887 887
             return $ver;
888 888
         }
889 889
 
890
-        $query = $wp_scripts->registered[ $handle ];
890
+        $query = $wp_scripts->registered[$handle];
891 891
     	if ( is_object( $query ) ) {
892 892
     	    $ver = $query->ver;
893 893
     	}
@@ -900,36 +900,36 @@  discard block
 block discarded – undo
900 900
     }
901 901
 
902 902
 	public static function get_user_id_param( $user_id ) {
903
-        if ( ! $user_id || empty($user_id) || is_numeric($user_id) ) {
903
+        if ( ! $user_id || empty( $user_id ) || is_numeric( $user_id ) ) {
904 904
             return $user_id;
905 905
         }
906 906
 
907 907
 		if ( $user_id == 'current' ) {
908 908
 			$user_id = get_current_user_id();
909 909
 		} else {
910
-            if ( is_email($user_id) ) {
911
-                $user = get_user_by('email', $user_id);
910
+            if ( is_email( $user_id ) ) {
911
+                $user = get_user_by( 'email', $user_id );
912 912
             } else {
913
-                $user = get_user_by('login', $user_id);
913
+                $user = get_user_by( 'login', $user_id );
914 914
             }
915 915
 
916 916
             if ( $user ) {
917 917
                 $user_id = $user->ID;
918 918
             }
919
-            unset($user);
919
+            unset( $user );
920 920
         }
921 921
 
922 922
         return $user_id;
923 923
     }
924 924
 
925 925
 	public static function get_file_contents( $filename, $atts = array() ) {
926
-        if ( ! is_file($filename) ) {
926
+        if ( ! is_file( $filename ) ) {
927 927
             return false;
928 928
         }
929 929
 
930
-        extract($atts);
930
+        extract( $atts );
931 931
         ob_start();
932
-        include($filename);
932
+        include( $filename );
933 933
         $contents = ob_get_contents();
934 934
         ob_end_clean();
935 935
         return $contents;
@@ -945,28 +945,28 @@  discard block
 block discarded – undo
945 945
         $key = '';
946 946
 
947 947
         if ( ! empty( $name ) ) {
948
-            $key = sanitize_key($name);
948
+            $key = sanitize_key( $name );
949 949
         }
950 950
 
951 951
 		if ( empty( $key ) ) {
952
-            $max_slug_value = pow(36, $num_chars);
952
+            $max_slug_value = pow( 36, $num_chars );
953 953
             $min_slug_value = 37; // we want to have at least 2 characters in the slug
954
-            $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
954
+            $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
955 955
         }
956 956
 
957
-		if ( is_numeric($key) || in_array( $key, array( 'id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd' ) ) ) {
957
+		if ( is_numeric( $key ) || in_array( $key, array( 'id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd' ) ) ) {
958 958
 			$key = $key . 'a';
959 959
         }
960 960
 
961 961
 		$key_check = FrmDb::get_var( $table_name, array( $column => $key, 'ID !' => $id ), $column );
962 962
 
963
-        if ( $key_check || is_numeric($key_check) ) {
963
+        if ( $key_check || is_numeric( $key_check ) ) {
964 964
             $suffix = 2;
965 965
 			do {
966 966
 				$alt_post_name = substr( $key, 0, 200 - ( strlen( $suffix ) + 1 ) ) . $suffix;
967 967
 				$key_check = FrmDb::get_var( $table_name, array( $column => $alt_post_name, 'ID !' => $id ), $column );
968
-				$suffix++;
969
-			} while ($key_check || is_numeric($key_check));
968
+				$suffix ++;
969
+			} while ( $key_check || is_numeric( $key_check ) );
970 970
 			$key = $alt_post_name;
971 971
         }
972 972
         return $key;
@@ -982,32 +982,32 @@  discard block
 block discarded – undo
982 982
             return false;
983 983
         }
984 984
 
985
-        if ( empty($post_values) ) {
986
-            $post_values = stripslashes_deep($_POST);
985
+        if ( empty( $post_values ) ) {
986
+            $post_values = stripslashes_deep( $_POST );
987 987
         }
988 988
 
989 989
 		$values = array( 'id' => $record->id, 'fields' => array() );
990 990
 
991 991
 		foreach ( array( 'name', 'description' ) as $var ) {
992
-            $default_val = isset($record->{$var}) ? $record->{$var} : '';
993
-			$values[ $var ] = self::get_param( $var, $default_val, 'get', 'wp_kses_post' );
994
-            unset($var, $default_val);
992
+            $default_val = isset( $record->{$var}) ? $record->{$var} : '';
993
+			$values[$var] = self::get_param( $var, $default_val, 'get', 'wp_kses_post' );
994
+            unset( $var, $default_val );
995 995
         }
996 996
 
997
-        $values['description'] = self::use_wpautop($values['description']);
997
+        $values['description'] = self::use_wpautop( $values['description'] );
998 998
         $frm_settings = self::get_settings();
999
-        $is_form_builder = self::is_admin_page('formidable' );
999
+        $is_form_builder = self::is_admin_page( 'formidable' );
1000 1000
 
1001 1001
         foreach ( (array) $fields as $field ) {
1002 1002
             // Make sure to filter default values (for placeholder text), but not on the form builder page
1003 1003
             if ( ! $is_form_builder ) {
1004
-                $field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true );
1004
+                $field->default_value = apply_filters( 'frm_get_default_value', $field->default_value, $field, true );
1005 1005
             }
1006 1006
 			$parent_form_id = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id;
1007
-			self::fill_field_defaults($field, $record, $values, compact('default', 'post_values', 'frm_settings', 'parent_form_id' ) );
1007
+			self::fill_field_defaults( $field, $record, $values, compact( 'default', 'post_values', 'frm_settings', 'parent_form_id' ) );
1008 1008
         }
1009 1009
 
1010
-        self::fill_form_opts($record, $table, $post_values, $values);
1010
+        self::fill_form_opts( $record, $table, $post_values, $values );
1011 1011
 
1012 1012
         if ( $table == 'entries' ) {
1013 1013
             $values = FrmEntriesHelper::setup_edit_vars( $values, $record );
@@ -1024,8 +1024,8 @@  discard block
 block discarded – undo
1024 1024
         if ( $args['default'] ) {
1025 1025
             $meta_value = $field->default_value;
1026 1026
         } else {
1027
-            if ( $record->post_id && self::pro_is_installed() && isset($field->field_options['post_field']) && $field->field_options['post_field'] ) {
1028
-                if ( ! isset($field->field_options['custom_field']) ) {
1027
+            if ( $record->post_id && self::pro_is_installed() && isset( $field->field_options['post_field'] ) && $field->field_options['post_field'] ) {
1028
+                if ( ! isset( $field->field_options['custom_field'] ) ) {
1029 1029
                     $field->field_options['custom_field'] = '';
1030 1030
                 }
1031 1031
 				$meta_value = FrmProEntryMetaHelper::get_post_value( $record->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array( 'truncate' => false, 'type' => $field->type, 'form_id' => $field->form_id, 'field' => $field ) );
@@ -1034,8 +1034,8 @@  discard block
 block discarded – undo
1034 1034
             }
1035 1035
         }
1036 1036
 
1037
-		$field_type = isset( $post_values['field_options'][ 'type_' . $field->id ] ) ? $post_values['field_options'][ 'type_' . $field->id ] : $field->type;
1038
-        $new_value = isset( $post_values['item_meta'][ $field->id ] ) ? maybe_unserialize( $post_values['item_meta'][ $field->id ] ) : $meta_value;
1037
+		$field_type = isset( $post_values['field_options']['type_' . $field->id] ) ? $post_values['field_options']['type_' . $field->id] : $field->type;
1038
+        $new_value = isset( $post_values['item_meta'][$field->id] ) ? maybe_unserialize( $post_values['item_meta'][$field->id] ) : $meta_value;
1039 1039
 
1040 1040
         $field_array = array(
1041 1041
             'id'            => $field->id,
@@ -1043,7 +1043,7 @@  discard block
 block discarded – undo
1043 1043
             'default_value' => $field->default_value,
1044 1044
             'name'          => $field->name,
1045 1045
             'description'   => $field->description,
1046
-            'type'          => apply_filters('frm_field_type', $field_type, $field, $new_value),
1046
+            'type'          => apply_filters( 'frm_field_type', $field_type, $field, $new_value ),
1047 1047
             'options'       => $field->options,
1048 1048
             'required'      => $field->required,
1049 1049
             'field_key'     => $field->field_key,
@@ -1053,40 +1053,40 @@  discard block
 block discarded – undo
1053 1053
         );
1054 1054
 
1055 1055
         $args['field_type'] = $field_type;
1056
-        self::fill_field_opts($field, $field_array, $args);
1056
+        self::fill_field_opts( $field, $field_array, $args );
1057 1057
 		// Track the original field's type
1058 1058
 		$field_array['original_type'] = isset( $field->field_options['original_type'] ) ? $field->field_options['original_type'] : $field->type;
1059 1059
 
1060 1060
         $field_array = apply_filters( 'frm_setup_edit_fields_vars', $field_array, $field, $values['id'], array() );
1061 1061
 
1062
-        if ( ! isset($field_array['unique']) || ! $field_array['unique'] ) {
1062
+        if ( ! isset( $field_array['unique'] ) || ! $field_array['unique'] ) {
1063 1063
             $field_array['unique_msg'] = '';
1064 1064
         }
1065 1065
 
1066 1066
         $field_array = array_merge( $field->field_options, $field_array );
1067 1067
 
1068
-        $values['fields'][ $field->id ] = $field_array;
1068
+        $values['fields'][$field->id] = $field_array;
1069 1069
     }
1070 1070
 
1071 1071
 	private static function fill_field_opts( $field, array &$field_array, $args ) {
1072 1072
         $post_values = $args['post_values'];
1073
-        $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
1073
+        $opt_defaults = FrmFieldsHelper::get_default_field_opts( $field_array['type'], $field, true );
1074 1074
 
1075 1075
         foreach ( $opt_defaults as $opt => $default_opt ) {
1076
-			$field_array[ $opt ] = ( $post_values && isset( $post_values['field_options'][ $opt . '_' . $field->id ] ) ) ? maybe_unserialize( $post_values['field_options'][ $opt . '_' . $field->id ] ) : ( isset( $field->field_options[ $opt ] ) ? $field->field_options[ $opt ] : $default_opt );
1077
-            if ( $opt == 'blank' && $field_array[ $opt ] == '' ) {
1078
-                $field_array[ $opt ] = $args['frm_settings']->blank_msg;
1079
-            } else if ( $opt == 'invalid' && $field_array[ $opt ] == '' ) {
1076
+			$field_array[$opt] = ( $post_values && isset( $post_values['field_options'][$opt . '_' . $field->id] ) ) ? maybe_unserialize( $post_values['field_options'][$opt . '_' . $field->id] ) : ( isset( $field->field_options[$opt] ) ? $field->field_options[$opt] : $default_opt );
1077
+            if ( $opt == 'blank' && $field_array[$opt] == '' ) {
1078
+                $field_array[$opt] = $args['frm_settings']->blank_msg;
1079
+            } else if ( $opt == 'invalid' && $field_array[$opt] == '' ) {
1080 1080
                 if ( $args['field_type'] == 'captcha' ) {
1081
-                    $field_array[ $opt ] = $args['frm_settings']->re_msg;
1081
+                    $field_array[$opt] = $args['frm_settings']->re_msg;
1082 1082
                 } else {
1083
-                    $field_array[ $opt ] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] );
1083
+                    $field_array[$opt] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] );
1084 1084
                 }
1085 1085
             }
1086 1086
         }
1087 1087
 
1088 1088
         if ( $field_array['custom_html'] == '' ) {
1089
-            $field_array['custom_html'] = FrmFieldsHelper::get_default_html($args['field_type']);
1089
+            $field_array['custom_html'] = FrmFieldsHelper::get_default_html( $args['field_type'] );
1090 1090
         }
1091 1091
     }
1092 1092
 
@@ -1105,18 +1105,18 @@  discard block
 block discarded – undo
1105 1105
             return;
1106 1106
         }
1107 1107
 
1108
-        $values['form_name'] = isset($record->form_id) ? $form->name : '';
1108
+        $values['form_name'] = isset( $record->form_id ) ? $form->name : '';
1109 1109
 		$values['parent_form_id'] = isset( $record->form_id ) ? $form->parent_form_id : 0;
1110 1110
 
1111
-        if ( ! is_array($form->options) ) {
1111
+        if ( ! is_array( $form->options ) ) {
1112 1112
             return;
1113 1113
         }
1114 1114
 
1115 1115
         foreach ( $form->options as $opt => $value ) {
1116
-            $values[ $opt ] = isset( $post_values[ $opt ] ) ? maybe_unserialize( $post_values[ $opt ] ) : $value;
1116
+            $values[$opt] = isset( $post_values[$opt] ) ? maybe_unserialize( $post_values[$opt] ) : $value;
1117 1117
         }
1118 1118
 
1119
-        self::fill_form_defaults($post_values, $values);
1119
+        self::fill_form_defaults( $post_values, $values );
1120 1120
     }
1121 1121
 
1122 1122
     /**
@@ -1126,23 +1126,23 @@  discard block
 block discarded – undo
1126 1126
         $form_defaults = FrmFormsHelper::get_default_opts();
1127 1127
 
1128 1128
         foreach ( $form_defaults as $opt => $default ) {
1129
-            if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
1130
-				$values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default;
1129
+            if ( ! isset( $values[$opt] ) || $values[$opt] == '' ) {
1130
+				$values[$opt] = ( $post_values && isset( $post_values['options'][$opt] ) ) ? $post_values['options'][$opt] : $default;
1131 1131
             }
1132 1132
 
1133
-            unset($opt, $defaut);
1133
+            unset( $opt, $defaut );
1134 1134
         }
1135 1135
 
1136
-        if ( ! isset($values['custom_style']) ) {
1136
+        if ( ! isset( $values['custom_style'] ) ) {
1137 1137
             $frm_settings = self::get_settings();
1138 1138
 			$values['custom_style'] = ( $post_values && isset( $post_values['options']['custom_style'] ) ) ? absint( $_POST['options']['custom_style'] ) : ( $frm_settings->load_style != 'none' );
1139 1139
         }
1140 1140
 
1141 1141
 		foreach ( array( 'before', 'after', 'submit' ) as $h ) {
1142
-			if ( ! isset( $values[ $h . '_html' ] ) ) {
1143
-				$values[ $h . '_html' ] = ( isset( $post_values['options'][ $h . '_html' ] ) ? $post_values['options'][ $h . '_html' ] : FrmFormsHelper::get_default_html( $h ) );
1142
+			if ( ! isset( $values[$h . '_html'] ) ) {
1143
+				$values[$h . '_html'] = ( isset( $post_values['options'][$h . '_html'] ) ? $post_values['options'][$h . '_html'] : FrmFormsHelper::get_default_html( $h ) );
1144 1144
             }
1145
-            unset($h);
1145
+            unset( $h );
1146 1146
         }
1147 1147
     }
1148 1148
 
@@ -1158,9 +1158,9 @@  discard block
 block discarded – undo
1158 1158
         }
1159 1159
     ?>
1160 1160
 <li>
1161
-    <a href="javascript:void(0)" class="frmids frm_insert_code alignright <?php echo esc_attr($class) ?>" data-code="<?php echo esc_attr($args['id']) ?>" >[<?php echo esc_attr( $args['id'] ) ?>]</a>
1162
-    <a href="javascript:void(0)" class="frmkeys frm_insert_code alignright <?php echo esc_attr($class) ?>" data-code="<?php echo esc_attr($args['key']) ?>" >[<?php echo esc_attr( self::truncate($args['key'], 10) ) ?>]</a>
1163
-    <a href="javascript:void(0)" class="frm_insert_code <?php echo esc_attr( $class ) ?>" data-code="<?php echo esc_attr($args['id']) ?>" ><?php echo esc_attr( self::truncate($args['name'], 60) ) ?></a>
1161
+    <a href="javascript:void(0)" class="frmids frm_insert_code alignright <?php echo esc_attr( $class ) ?>" data-code="<?php echo esc_attr( $args['id'] ) ?>" >[<?php echo esc_attr( $args['id'] ) ?>]</a>
1162
+    <a href="javascript:void(0)" class="frmkeys frm_insert_code alignright <?php echo esc_attr( $class ) ?>" data-code="<?php echo esc_attr( $args['key'] ) ?>" >[<?php echo esc_attr( self::truncate( $args['key'], 10 ) ) ?>]</a>
1163
+    <a href="javascript:void(0)" class="frm_insert_code <?php echo esc_attr( $class ) ?>" data-code="<?php echo esc_attr( $args['id'] ) ?>" ><?php echo esc_attr( self::truncate( $args['name'], 60 ) ) ?></a>
1164 1164
 </li>
1165 1165
     <?php
1166 1166
     }
@@ -1178,7 +1178,7 @@  discard block
 block discarded – undo
1178 1178
             return '';
1179 1179
         } else if ( $length <= 10 ) {
1180 1180
 			$sub = self::mb_function( array( 'mb_substr', 'substr' ), array( $str, 0, $length ) );
1181
-            return $sub . (($length < $original_len) ? $continue : '');
1181
+            return $sub . ( ( $length < $original_len ) ? $continue : '' );
1182 1182
         }
1183 1183
 
1184 1184
         $sub = '';
@@ -1187,23 +1187,23 @@  discard block
 block discarded – undo
1187 1187
 		$words = self::mb_function( array( 'mb_split', 'explode' ), array( ' ', $str ) );
1188 1188
 
1189 1189
 		foreach ( $words as $word ) {
1190
-            $part = (($sub != '') ? ' ' : '') . $word;
1190
+            $part = ( ( $sub != '' ) ? ' ' : '' ) . $word;
1191 1191
 			$total_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub . $part ) );
1192
-            if ( $total_len > $length && str_word_count($sub) ) {
1192
+            if ( $total_len > $length && str_word_count( $sub ) ) {
1193 1193
                 break;
1194 1194
             }
1195 1195
 
1196 1196
             $sub .= $part;
1197 1197
 			$len += self::mb_function( array( 'mb_strlen', 'strlen' ), array( $part ) );
1198 1198
 
1199
-            if ( str_word_count($sub) > $minword && $total_len >= $length ) {
1199
+            if ( str_word_count( $sub ) > $minword && $total_len >= $length ) {
1200 1200
                 break;
1201 1201
             }
1202 1202
 
1203
-            unset($total_len, $word);
1203
+            unset( $total_len, $word );
1204 1204
         }
1205 1205
 
1206
-        return $sub . (($len < $original_len) ? $continue : '');
1206
+        return $sub . ( ( $len < $original_len ) ? $continue : '' );
1207 1207
     }
1208 1208
 
1209 1209
 	public static function mb_function( $function_names, $args ) {
@@ -1216,17 +1216,17 @@  discard block
 block discarded – undo
1216 1216
 	}
1217 1217
 
1218 1218
 	public static function get_formatted_time( $date, $date_format = '', $time_format = '' ) {
1219
-        if ( empty($date) ) {
1219
+        if ( empty( $date ) ) {
1220 1220
             return $date;
1221 1221
         }
1222 1222
 
1223
-        if ( empty($date_format) ) {
1224
-            $date_format = get_option('date_format');
1223
+        if ( empty( $date_format ) ) {
1224
+            $date_format = get_option( 'date_format' );
1225 1225
         }
1226 1226
 
1227
-        if ( preg_match('/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date) && self::pro_is_installed() ) {
1227
+        if ( preg_match( '/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date ) && self::pro_is_installed() ) {
1228 1228
             $frmpro_settings = new FrmProSettings();
1229
-            $date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d');
1229
+            $date = FrmProAppHelper::convert_date( $date, $frmpro_settings->date_format, 'Y-m-d' );
1230 1230
         }
1231 1231
 
1232 1232
 		$formatted = self::get_localized_date( $date_format, $date );
@@ -1241,7 +1241,7 @@  discard block
 block discarded – undo
1241 1241
 
1242 1242
 	private static function add_time_to_date( $time_format, $date ) {
1243 1243
 		if ( empty( $time_format ) ) {
1244
-			$time_format = get_option('time_format');
1244
+			$time_format = get_option( 'time_format' );
1245 1245
 		}
1246 1246
 
1247 1247
 		$trimmed_format = trim( $time_format );
@@ -1287,10 +1287,10 @@  discard block
 block discarded – undo
1287 1287
 		$time_strings = self::get_time_strings();
1288 1288
 
1289 1289
 		foreach ( $time_strings as $k => $v ) {
1290
-			if ( $diff[ $k ] ) {
1291
-				$time_strings[ $k ] = $diff[ $k ] . ' ' . ( $diff[ $k ] > 1 ? $v[1] : $v[0] );
1290
+			if ( $diff[$k] ) {
1291
+				$time_strings[$k] = $diff[$k] . ' ' . ( $diff[$k] > 1 ? $v[1] : $v[0] );
1292 1292
 			} else {
1293
-				unset( $time_strings[ $k ] );
1293
+				unset( $time_strings[$k] );
1294 1294
 			}
1295 1295
 		}
1296 1296
 
@@ -1328,7 +1328,7 @@  discard block
 block discarded – undo
1328 1328
      */
1329 1329
 	public static function esc_like( $term ) {
1330 1330
         global $wpdb;
1331
-        if ( method_exists($wpdb, 'esc_like') ) {
1331
+        if ( method_exists( $wpdb, 'esc_like' ) ) {
1332 1332
 			// WP 4.0
1333 1333
             $term = $wpdb->esc_like( $term );
1334 1334
         } else {
@@ -1342,17 +1342,17 @@  discard block
 block discarded – undo
1342 1342
      * @param string $order_query
1343 1343
      */
1344 1344
 	public static function esc_order( $order_query ) {
1345
-        if ( empty($order_query) ) {
1345
+        if ( empty( $order_query ) ) {
1346 1346
             return '';
1347 1347
         }
1348 1348
 
1349 1349
         // remove ORDER BY before santizing
1350
-        $order_query = strtolower($order_query);
1351
-        if ( strpos($order_query, 'order by') !== false ) {
1352
-            $order_query = str_replace('order by', '', $order_query);
1350
+        $order_query = strtolower( $order_query );
1351
+        if ( strpos( $order_query, 'order by' ) !== false ) {
1352
+            $order_query = str_replace( 'order by', '', $order_query );
1353 1353
         }
1354 1354
 
1355
-        $order_query = explode(' ', trim($order_query));
1355
+        $order_query = explode( ' ', trim( $order_query ) );
1356 1356
 
1357 1357
         $order_fields = array(
1358 1358
             'id', 'form_key', 'name', 'description',
@@ -1360,13 +1360,13 @@  discard block
 block discarded – undo
1360 1360
             'default_template', 'status', 'created_at',
1361 1361
         );
1362 1362
 
1363
-        $order = trim(trim(reset($order_query), ','));
1364
-        if ( ! in_array($order, $order_fields) ) {
1363
+        $order = trim( trim( reset( $order_query ), ',' ) );
1364
+        if ( ! in_array( $order, $order_fields ) ) {
1365 1365
             return '';
1366 1366
         }
1367 1367
 
1368 1368
         $order_by = '';
1369
-        if ( count($order_query) > 1 ) {
1369
+        if ( count( $order_query ) > 1 ) {
1370 1370
 			$order_by = end( $order_query );
1371 1371
 			self::esc_order_by( $order_by );
1372 1372
         }
@@ -1388,23 +1388,23 @@  discard block
 block discarded – undo
1388 1388
      * @param string $limit
1389 1389
      */
1390 1390
 	public static function esc_limit( $limit ) {
1391
-        if ( empty($limit) ) {
1391
+        if ( empty( $limit ) ) {
1392 1392
             return '';
1393 1393
         }
1394 1394
 
1395
-        $limit = trim(str_replace(' limit', '', strtolower($limit)));
1396
-        if ( is_numeric($limit) ) {
1395
+        $limit = trim( str_replace( ' limit', '', strtolower( $limit ) ) );
1396
+        if ( is_numeric( $limit ) ) {
1397 1397
 			return ' LIMIT ' . $limit;
1398 1398
         }
1399 1399
 
1400
-        $limit = explode(',', trim($limit));
1400
+        $limit = explode( ',', trim( $limit ) );
1401 1401
         foreach ( $limit as $k => $l ) {
1402 1402
             if ( is_numeric( $l ) ) {
1403
-                $limit[ $k ] = $l;
1403
+                $limit[$k] = $l;
1404 1404
             }
1405 1405
         }
1406 1406
 
1407
-        $limit = implode(',', $limit);
1407
+        $limit = implode( ',', $limit );
1408 1408
 		return ' LIMIT ' . $limit;
1409 1409
     }
1410 1410
 
@@ -1413,12 +1413,12 @@  discard block
 block discarded – undo
1413 1413
      * @since 2.0
1414 1414
      */
1415 1415
     public static function prepare_array_values( $array, $type = '%s' ) {
1416
-        $placeholders = array_fill(0, count($array), $type);
1417
-        return implode(', ', $placeholders);
1416
+        $placeholders = array_fill( 0, count( $array ), $type );
1417
+        return implode( ', ', $placeholders );
1418 1418
     }
1419 1419
 
1420 1420
     public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) {
1421
-        if ( empty($where) ) {
1421
+        if ( empty( $where ) ) {
1422 1422
             return '';
1423 1423
         }
1424 1424
 
@@ -1459,19 +1459,19 @@  discard block
 block discarded – undo
1459 1459
 	public static function json_to_array( $json_vars ) {
1460 1460
         $vars = array();
1461 1461
         foreach ( $json_vars as $jv ) {
1462
-            $jv_name = explode('[', $jv['name']);
1463
-            $last = count($jv_name) - 1;
1462
+            $jv_name = explode( '[', $jv['name'] );
1463
+            $last = count( $jv_name ) - 1;
1464 1464
             foreach ( $jv_name as $p => $n ) {
1465
-                $name = trim($n, ']');
1466
-                if ( ! isset($l1) ) {
1465
+                $name = trim( $n, ']' );
1466
+                if ( ! isset( $l1 ) ) {
1467 1467
                     $l1 = $name;
1468 1468
                 }
1469 1469
 
1470
-                if ( ! isset($l2) ) {
1470
+                if ( ! isset( $l2 ) ) {
1471 1471
                     $l2 = $name;
1472 1472
                 }
1473 1473
 
1474
-                if ( ! isset($l3) ) {
1474
+                if ( ! isset( $l3 ) ) {
1475 1475
                     $l3 = $name;
1476 1476
                 }
1477 1477
 
@@ -1485,24 +1485,24 @@  discard block
 block discarded – undo
1485 1485
 
1486 1486
                     case 1:
1487 1487
                         $l2 = $name;
1488
-                        self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] );
1488
+                        self::add_value_to_array( $name, $l2, $this_val, $vars[$l1] );
1489 1489
                     break;
1490 1490
 
1491 1491
                     case 2:
1492 1492
                         $l3 = $name;
1493
-                        self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] );
1493
+                        self::add_value_to_array( $name, $l3, $this_val, $vars[$l1][$l2] );
1494 1494
                     break;
1495 1495
 
1496 1496
                     case 3:
1497 1497
                         $l4 = $name;
1498
-                        self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] );
1498
+                        self::add_value_to_array( $name, $l4, $this_val, $vars[$l1][$l2][$l3] );
1499 1499
                     break;
1500 1500
                 }
1501 1501
 
1502
-                unset($this_val, $n);
1502
+                unset( $this_val, $n );
1503 1503
             }
1504 1504
 
1505
-            unset($last, $jv);
1505
+            unset( $last, $jv );
1506 1506
         }
1507 1507
 
1508 1508
         return $vars;
@@ -1515,8 +1515,8 @@  discard block
 block discarded – undo
1515 1515
     public static function add_value_to_array( $name, $l1, $val, &$vars ) {
1516 1516
         if ( $name == '' ) {
1517 1517
             $vars[] = $val;
1518
-        } else if ( ! isset( $vars[ $l1 ] ) ) {
1519
-            $vars[ $l1 ] = $val;
1518
+        } else if ( ! isset( $vars[$l1] ) ) {
1519
+            $vars[$l1] = $val;
1520 1520
         }
1521 1521
     }
1522 1522
 
@@ -1531,7 +1531,7 @@  discard block
 block discarded – undo
1531 1531
             'email_subject' => esc_attr( sprintf( __( 'If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable' ), $form_name, self::site_name() ) ),
1532 1532
         );
1533 1533
 
1534
-        if ( ! isset( $tooltips[ $name ] ) ) {
1534
+        if ( ! isset( $tooltips[$name] ) ) {
1535 1535
             return;
1536 1536
         }
1537 1537
 
@@ -1541,7 +1541,7 @@  discard block
 block discarded – undo
1541 1541
             echo ' class="frm_help"';
1542 1542
         }
1543 1543
 
1544
-		echo ' title="' . esc_attr( $tooltips[ $name ] );
1544
+		echo ' title="' . esc_attr( $tooltips[$name] );
1545 1545
 
1546 1546
         if ( 'open' != $class ) {
1547 1547
             echo '"';
@@ -1593,13 +1593,13 @@  discard block
 block discarded – undo
1593 1593
     }
1594 1594
 
1595 1595
 	private static function prepare_action_slashes( $val, $key, &$post_content ) {
1596
-		if ( ! isset( $post_content[ $key ] ) ) {
1596
+		if ( ! isset( $post_content[$key] ) ) {
1597 1597
 			return;
1598 1598
 		}
1599 1599
 
1600 1600
 		if ( is_array( $val ) ) {
1601 1601
 			foreach ( $val as $k1 => $v1 ) {
1602
-				self::prepare_action_slashes( $v1, $k1, $post_content[ $key ] );
1602
+				self::prepare_action_slashes( $v1, $k1, $post_content[$key] );
1603 1603
 				unset( $k1, $v1 );
1604 1604
 			}
1605 1605
 		} else {
@@ -1607,7 +1607,7 @@  discard block
 block discarded – undo
1607 1607
 			$val = stripslashes( $val );
1608 1608
 
1609 1609
 			// Add backslashes before double quotes and forward slashes only
1610
-			$post_content[ $key ] = addcslashes( $val, '"\\/' );
1610
+			$post_content[$key] = addcslashes( $val, '"\\/' );
1611 1611
 		}
1612 1612
 	}
1613 1613
 
@@ -1624,7 +1624,7 @@  discard block
 block discarded – undo
1624 1624
 		$settings['post_content'] = FrmAppHelper::prepare_and_encode( $settings['post_content'] );
1625 1625
 
1626 1626
 		if ( empty( $settings['ID'] ) ) {
1627
-			unset( $settings['ID']);
1627
+			unset( $settings['ID'] );
1628 1628
 		}
1629 1629
 
1630 1630
 		// delete all caches for this group
@@ -1658,17 +1658,17 @@  discard block
 block discarded – undo
1658 1658
 	}
1659 1659
 
1660 1660
 	public static function maybe_json_decode( $string ) {
1661
-        if ( is_array($string) ) {
1661
+        if ( is_array( $string ) ) {
1662 1662
             return $string;
1663 1663
         }
1664 1664
 
1665
-        $new_string = json_decode($string, true);
1666
-        if ( function_exists('json_last_error') ) {
1665
+        $new_string = json_decode( $string, true );
1666
+        if ( function_exists( 'json_last_error' ) ) {
1667 1667
 			// php 5.3+
1668 1668
             if ( json_last_error() == JSON_ERROR_NONE ) {
1669 1669
                 $string = $new_string;
1670 1670
             }
1671
-        } else if ( isset($new_string) ) {
1671
+        } else if ( isset( $new_string ) ) {
1672 1672
 			// php < 5.3 fallback
1673 1673
             $string = $new_string;
1674 1674
         }
@@ -1684,11 +1684,11 @@  discard block
 block discarded – undo
1684 1684
 	public static function maybe_highlight_menu( $post_type ) {
1685 1685
         global $post;
1686 1686
 
1687
-        if ( isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != $post_type ) {
1687
+        if ( isset( $_REQUEST['post_type'] ) && $_REQUEST['post_type'] != $post_type ) {
1688 1688
             return;
1689 1689
         }
1690 1690
 
1691
-        if ( is_object($post) && $post->post_type != $post_type ) {
1691
+        if ( is_object( $post ) && $post->post_type != $post_type ) {
1692 1692
             return;
1693 1693
         }
1694 1694
 
@@ -1789,11 +1789,11 @@  discard block
 block discarded – undo
1789 1789
         $frm_version = self::plugin_version();
1790 1790
 
1791 1791
         // check if Formidable meets minimum requirements
1792
-        if ( version_compare($frm_version, $min_version, '>=') ) {
1792
+        if ( version_compare( $frm_version, $min_version, '>=' ) ) {
1793 1793
             return;
1794 1794
         }
1795 1795
 
1796
-        $wp_list_table = _get_list_table('WP_Plugins_List_Table');
1796
+        $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
1797 1797
 		echo '<tr class="plugin-update-tr active"><th colspan="' . absint( $wp_list_table->get_column_count() ) . '" class="check-column plugin-update colspanchange"><div class="update-message">' .
1798 1798
         __( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) .
1799 1799
         '</div></td></tr>';
@@ -1801,38 +1801,38 @@  discard block
 block discarded – undo
1801 1801
 
1802 1802
     public static function locales( $type = 'date' ) {
1803 1803
         $locales = array(
1804
-            'en' => __( 'English', 'formidable' ),    '' => __( 'English/Western', 'formidable' ),
1805
-            'af' => __( 'Afrikaans', 'formidable' ),  'sq' => __( 'Albanian', 'formidable' ),
1806
-            'ar' => __( 'Arabic', 'formidable' ),     'hy' => __( 'Armenian', 'formidable' ),
1804
+            'en' => __( 'English', 'formidable' ), '' => __( 'English/Western', 'formidable' ),
1805
+            'af' => __( 'Afrikaans', 'formidable' ), 'sq' => __( 'Albanian', 'formidable' ),
1806
+            'ar' => __( 'Arabic', 'formidable' ), 'hy' => __( 'Armenian', 'formidable' ),
1807 1807
             'az' => __( 'Azerbaijani', 'formidable' ), 'eu' => __( 'Basque', 'formidable' ),
1808
-            'bs' => __( 'Bosnian', 'formidable' ),    'bg' => __( 'Bulgarian', 'formidable' ),
1809
-            'ca' => __( 'Catalan', 'formidable' ),    'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ),
1808
+            'bs' => __( 'Bosnian', 'formidable' ), 'bg' => __( 'Bulgarian', 'formidable' ),
1809
+            'ca' => __( 'Catalan', 'formidable' ), 'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ),
1810 1810
             'zh-CN' => __( 'Chinese Simplified', 'formidable' ), 'zh-TW' => __( 'Chinese Traditional', 'formidable' ),
1811
-            'hr' => __( 'Croatian', 'formidable' ),   'cs' => __( 'Czech', 'formidable' ),
1812
-            'da' => __( 'Danish', 'formidable' ),     'nl' => __( 'Dutch', 'formidable' ),
1811
+            'hr' => __( 'Croatian', 'formidable' ), 'cs' => __( 'Czech', 'formidable' ),
1812
+            'da' => __( 'Danish', 'formidable' ), 'nl' => __( 'Dutch', 'formidable' ),
1813 1813
             'en-GB' => __( 'English/UK', 'formidable' ), 'eo' => __( 'Esperanto', 'formidable' ),
1814
-            'et' => __( 'Estonian', 'formidable' ),   'fo' => __( 'Faroese', 'formidable' ),
1814
+            'et' => __( 'Estonian', 'formidable' ), 'fo' => __( 'Faroese', 'formidable' ),
1815 1815
             'fa' => __( 'Farsi/Persian', 'formidable' ), 'fil' => __( 'Filipino', 'formidable' ),
1816
-            'fi' => __( 'Finnish', 'formidable' ),    'fr' => __( 'French', 'formidable' ),
1816
+            'fi' => __( 'Finnish', 'formidable' ), 'fr' => __( 'French', 'formidable' ),
1817 1817
             'fr-CA' => __( 'French/Canadian', 'formidable' ), 'fr-CH' => __( 'French/Swiss', 'formidable' ),
1818
-            'de' => __( 'German', 'formidable' ),     'de-AT' => __( 'German/Austria', 'formidable' ),
1818
+            'de' => __( 'German', 'formidable' ), 'de-AT' => __( 'German/Austria', 'formidable' ),
1819 1819
             'de-CH' => __( 'German/Switzerland', 'formidable' ), 'el' => __( 'Greek', 'formidable' ),
1820
-            'he' => __( 'Hebrew', 'formidable' ),     'iw' => __( 'Hebrew', 'formidable' ),
1821
-            'hi' => __( 'Hindi', 'formidable' ),      'hu' => __( 'Hungarian', 'formidable' ),
1822
-            'is' => __( 'Icelandic', 'formidable' ),  'id' => __( 'Indonesian', 'formidable' ),
1823
-            'it' => __( 'Italian', 'formidable' ),    'ja' => __( 'Japanese', 'formidable' ),
1824
-            'ko' => __( 'Korean', 'formidable' ),     'lv' => __( 'Latvian', 'formidable' ),
1820
+            'he' => __( 'Hebrew', 'formidable' ), 'iw' => __( 'Hebrew', 'formidable' ),
1821
+            'hi' => __( 'Hindi', 'formidable' ), 'hu' => __( 'Hungarian', 'formidable' ),
1822
+            'is' => __( 'Icelandic', 'formidable' ), 'id' => __( 'Indonesian', 'formidable' ),
1823
+            'it' => __( 'Italian', 'formidable' ), 'ja' => __( 'Japanese', 'formidable' ),
1824
+            'ko' => __( 'Korean', 'formidable' ), 'lv' => __( 'Latvian', 'formidable' ),
1825 1825
             'lt' => __( 'Lithuanian', 'formidable' ), 'ms' => __( 'Malaysian', 'formidable' ),
1826
-            'no' => __( 'Norwegian', 'formidable' ),  'pl' => __( 'Polish', 'formidable' ),
1826
+            'no' => __( 'Norwegian', 'formidable' ), 'pl' => __( 'Polish', 'formidable' ),
1827 1827
             'pt' => __( 'Portuguese', 'formidable' ), 'pt-BR' => __( 'Portuguese/Brazilian', 'formidable' ),
1828 1828
             'pt-PT' => __( 'Portuguese/Portugal', 'formidable' ), 'ro' => __( 'Romanian', 'formidable' ),
1829
-            'ru' => __( 'Russian', 'formidable' ),    'sr' => __( 'Serbian', 'formidable' ),
1829
+            'ru' => __( 'Russian', 'formidable' ), 'sr' => __( 'Serbian', 'formidable' ),
1830 1830
             'sr-SR' => __( 'Serbian', 'formidable' ), 'sk' => __( 'Slovak', 'formidable' ),
1831
-            'sl' => __( 'Slovenian', 'formidable' ),  'es' => __( 'Spanish', 'formidable' ),
1831
+            'sl' => __( 'Slovenian', 'formidable' ), 'es' => __( 'Spanish', 'formidable' ),
1832 1832
             'es-419' => __( 'Spanish/Latin America', 'formidable' ), 'sv' => __( 'Swedish', 'formidable' ),
1833
-            'ta' => __( 'Tamil', 'formidable' ),      'th' => __( 'Thai', 'formidable' ),
1834
-            'tu' => __( 'Turkish', 'formidable' ),    'tr' => __( 'Turkish', 'formidable' ),
1835
-            'uk' => __( 'Ukranian', 'formidable' ),   'vi' => __( 'Vietnamese', 'formidable' ),
1833
+            'ta' => __( 'Tamil', 'formidable' ), 'th' => __( 'Thai', 'formidable' ),
1834
+            'tu' => __( 'Turkish', 'formidable' ), 'tr' => __( 'Turkish', 'formidable' ),
1835
+            'uk' => __( 'Ukranian', 'formidable' ), 'vi' => __( 'Vietnamese', 'formidable' ),
1836 1836
         );
1837 1837
 
1838 1838
         if ( $type == 'captcha' ) {
@@ -1851,8 +1851,8 @@  discard block
 block discarded – undo
1851 1851
             );
1852 1852
         }
1853 1853
 
1854
-        $locales = array_diff_key($locales, array_flip($unset));
1855
-        $locales = apply_filters('frm_locales', $locales);
1854
+        $locales = array_diff_key( $locales, array_flip( $unset ) );
1855
+        $locales = apply_filters( 'frm_locales', $locales );
1856 1856
 
1857 1857
         return $locales;
1858 1858
     }
Please login to merge, or discard this patch.
classes/models/FrmForm.php 2 patches
Indentation   +334 added lines, -334 removed lines patch added patch discarded remove patch
@@ -1,387 +1,387 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('ABSPATH') ) {
3
-    die('You are not allowed to call this page directly.');
3
+	die('You are not allowed to call this page directly.');
4 4
 }
5 5
 
6 6
 class FrmForm {
7 7
 
8
-    /**
9
-     * @return int|boolean id on success or false on failure
10
-     */
11
-    public static function create( $values ) {
12
-        global $wpdb;
8
+	/**
9
+	 * @return int|boolean id on success or false on failure
10
+	 */
11
+	public static function create( $values ) {
12
+		global $wpdb;
13 13
 
14
-        $new_values = array(
14
+		$new_values = array(
15 15
 			'form_key'      => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ),
16
-            'name'          => $values['name'],
17
-            'description'   => $values['description'],
18
-            'status'        => isset($values['status']) ? $values['status'] : 'draft',
19
-            'logged_in'     => isset($values['logged_in']) ? $values['logged_in'] : 0,
20
-            'is_template'   => isset($values['is_template']) ? (int) $values['is_template'] : 0,
16
+			'name'          => $values['name'],
17
+			'description'   => $values['description'],
18
+			'status'        => isset($values['status']) ? $values['status'] : 'draft',
19
+			'logged_in'     => isset($values['logged_in']) ? $values['logged_in'] : 0,
20
+			'is_template'   => isset($values['is_template']) ? (int) $values['is_template'] : 0,
21 21
 			'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0,
22
-            'editable'      => isset($values['editable']) ? (int) $values['editable'] : 0,
23
-            'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
24
-            'created_at'    => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
25
-        );
22
+			'editable'      => isset($values['editable']) ? (int) $values['editable'] : 0,
23
+			'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
24
+			'created_at'    => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
25
+		);
26 26
 
27 27
 		$options = isset( $values['options'] ) ? (array) $values['options'] : array();
28 28
 		FrmFormsHelper::fill_form_options( $options, $values );
29 29
 
30
-        $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
31
-        $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
32
-        $options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
30
+		$options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
31
+		$options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
32
+		$options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
33 33
 
34
-        $options = apply_filters('frm_form_options_before_update', $options, $values);
35
-        $new_values['options'] = serialize($options);
34
+		$options = apply_filters('frm_form_options_before_update', $options, $values);
35
+		$new_values['options'] = serialize($options);
36 36
 
37
-        //if(isset($values['id']) && is_numeric($values['id']))
38
-        //    $new_values['id'] = $values['id'];
37
+		//if(isset($values['id']) && is_numeric($values['id']))
38
+		//    $new_values['id'] = $values['id'];
39 39
 
40 40
 		$wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
41 41
 
42
-        $id = $wpdb->insert_id;
42
+		$id = $wpdb->insert_id;
43 43
 
44 44
 		// Clear form caching
45 45
 		self::clear_form_cache();
46 46
 
47
-        return $id;
48
-    }
47
+		return $id;
48
+	}
49 49
 
50
-    /**
51
-     * @return int|boolean ID on success or false on failure
52
-     */
53
-    public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
54
-        global $wpdb;
50
+	/**
51
+	 * @return int|boolean ID on success or false on failure
52
+	 */
53
+	public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) {
54
+		global $wpdb;
55 55
 
56
-        $values = self::getOne( $id, $blog_id );
57
-        if ( ! $values ) {
58
-            return false;
59
-        }
56
+		$values = self::getOne( $id, $blog_id );
57
+		if ( ! $values ) {
58
+			return false;
59
+		}
60 60
 
61
-        $new_key = $copy_keys ? $values->form_key : '';
61
+		$new_key = $copy_keys ? $values->form_key : '';
62 62
 
63
-        $new_values = array(
63
+		$new_values = array(
64 64
 			'form_key'      => FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_forms', 'form_key' ),
65
-            'name'          => $values->name,
66
-            'description'   => $values->description,
67
-            'status'        => $template ? 'published' : 'draft',
68
-            'logged_in'     => $values->logged_in ? $values->logged_in : 0,
69
-            'editable'      => $values->editable ? $values->editable : 0,
70
-            'created_at'    => current_time('mysql', 1),
71
-            'is_template'   => $template ? 1 : 0,
72
-        );
73
-
74
-        if ( $blog_id ) {
75
-            $new_values['status'] = 'published';
76
-            $new_options = maybe_unserialize($values->options);
77
-            $new_options['email_to'] = get_option('admin_email');
78
-            $new_options['copy'] = false;
79
-            $new_values['options'] = $new_options;
80
-        } else {
81
-            $new_values['options'] = $values->options;
82
-        }
83
-
84
-        if ( is_array($new_values['options']) ) {
85
-            $new_values['options'] = serialize($new_values['options']);
86
-        }
65
+			'name'          => $values->name,
66
+			'description'   => $values->description,
67
+			'status'        => $template ? 'published' : 'draft',
68
+			'logged_in'     => $values->logged_in ? $values->logged_in : 0,
69
+			'editable'      => $values->editable ? $values->editable : 0,
70
+			'created_at'    => current_time('mysql', 1),
71
+			'is_template'   => $template ? 1 : 0,
72
+		);
73
+
74
+		if ( $blog_id ) {
75
+			$new_values['status'] = 'published';
76
+			$new_options = maybe_unserialize($values->options);
77
+			$new_options['email_to'] = get_option('admin_email');
78
+			$new_options['copy'] = false;
79
+			$new_values['options'] = $new_options;
80
+		} else {
81
+			$new_values['options'] = $values->options;
82
+		}
83
+
84
+		if ( is_array($new_values['options']) ) {
85
+			$new_values['options'] = serialize($new_values['options']);
86
+		}
87 87
 
88 88
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
89 89
 
90
-        if ( $query_results ) {
90
+		if ( $query_results ) {
91 91
 			// Clear form caching
92 92
 			self::clear_form_cache();
93 93
 
94
-            $form_id = $wpdb->insert_id;
95
-            FrmField::duplicate($id, $form_id, $copy_keys, $blog_id);
94
+			$form_id = $wpdb->insert_id;
95
+			FrmField::duplicate($id, $form_id, $copy_keys, $blog_id);
96 96
 
97
-            // update form settings after fields are created
97
+			// update form settings after fields are created
98 98
 			do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) );
99
-            return $form_id;
100
-        }
99
+			return $form_id;
100
+		}
101 101
 
102
-        return false;
103
-    }
102
+		return false;
103
+	}
104 104
 
105 105
 	public static function after_duplicate( $form_id, $values ) {
106
-        $new_opts = $values['options'] = maybe_unserialize($values['options']);
106
+		$new_opts = $values['options'] = maybe_unserialize($values['options']);
107 107
 
108
-        if ( isset($new_opts['success_msg']) ) {
109
-            $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
110
-        }
108
+		if ( isset($new_opts['success_msg']) ) {
109
+			$new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
110
+		}
111 111
 
112
-        $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
112
+		$new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
113 113
 
114
-        if ( $new_opts != $values['options'] ) {
115
-            global $wpdb;
114
+		if ( $new_opts != $values['options'] ) {
115
+			global $wpdb;
116 116
 			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $new_opts ) ), array( 'id' => $form_id ) );
117
-        }
118
-    }
117
+		}
118
+	}
119 119
 
120
-    /**
121
-     * @return int|boolean
122
-     */
123
-    public static function update( $id, $values, $create_link = false ) {
124
-        global $wpdb;
120
+	/**
121
+	 * @return int|boolean
122
+	 */
123
+	public static function update( $id, $values, $create_link = false ) {
124
+		global $wpdb;
125 125
 
126
-        if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) {
127
-            $values['status'] = 'published';
128
-        }
126
+		if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) {
127
+			$values['status'] = 'published';
128
+		}
129 129
 
130
-        if ( isset($values['form_key']) ) {
130
+		if ( isset($values['form_key']) ) {
131 131
 			$values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id );
132
-        }
132
+		}
133 133
 
134
-        $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' );
134
+		$form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' );
135 135
 
136
-        $new_values = self::set_update_options( array(), $values);
136
+		$new_values = self::set_update_options( array(), $values);
137 137
 
138
-        foreach ( $values as $value_key => $value ) {
139
-            if ( in_array($value_key, $form_fields) ) {
138
+		foreach ( $values as $value_key => $value ) {
139
+			if ( in_array($value_key, $form_fields) ) {
140 140
 				$new_values[ $value_key ] = $value;
141
-            }
142
-        }
141
+			}
142
+		}
143 143
 
144
-        if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
145
-            $new_values['status'] = $values['new_status'];
146
-        }
144
+		if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) {
145
+			$new_values['status'] = $values['new_status'];
146
+		}
147 147
 
148
-        if ( ! empty( $new_values ) ) {
148
+		if ( ! empty( $new_values ) ) {
149 149
 			$query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $id ) );
150
-            if ( $query_results ) {
150
+			if ( $query_results ) {
151 151
 				self::clear_form_cache();
152
-            }
153
-        } else {
154
-            $query_results = true;
155
-        }
156
-        unset($new_values);
152
+			}
153
+		} else {
154
+			$query_results = true;
155
+		}
156
+		unset($new_values);
157 157
 
158
-        $values = self::update_fields($id, $values);
158
+		$values = self::update_fields($id, $values);
159 159
 
160 160
 		do_action( 'frm_update_form', $id, $values );
161 161
 		do_action( 'frm_update_form_' . $id, $values );
162 162
 
163
-        return $query_results;
164
-    }
163
+		return $query_results;
164
+	}
165 165
 
166
-    /**
167
-     * @return array
168
-     */
166
+	/**
167
+	 * @return array
168
+	 */
169 169
 	public static function set_update_options( $new_values, $values ) {
170
-        if ( ! isset($values['options']) ) {
171
-            return $new_values;
172
-        }
170
+		if ( ! isset($values['options']) ) {
171
+			return $new_values;
172
+		}
173 173
 
174 174
 		$options = isset( $values['options'] ) ? (array) $values['options'] : array();
175 175
 		FrmFormsHelper::fill_form_options( $options, $values );
176 176
 
177
-        $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0;
178
-        $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
179
-        $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
180
-        $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
177
+		$options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0;
178
+		$options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
179
+		$options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
180
+		$options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
181 181
 
182
-        $options = apply_filters('frm_form_options_before_update', $options, $values);
183
-        $new_values['options'] = serialize($options);
182
+		$options = apply_filters('frm_form_options_before_update', $options, $values);
183
+		$new_values['options'] = serialize($options);
184 184
 
185
-        return $new_values;
186
-    }
185
+		return $new_values;
186
+	}
187 187
 
188 188
 
189
-    /**
190
-     * @return array
191
-     */
189
+	/**
190
+	 * @return array
191
+	 */
192 192
 	public static function update_fields( $id, $values ) {
193 193
 
194
-        if ( ! isset($values['options']) && ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
195
-            return $values;
196
-        }
194
+		if ( ! isset($values['options']) && ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
195
+			return $values;
196
+		}
197 197
 
198
-        $all_fields = FrmField::get_all_for_form($id);
199
-        if ( empty($all_fields) ) {
200
-            return $values;
201
-        }
198
+		$all_fields = FrmField::get_all_for_form($id);
199
+		if ( empty($all_fields) ) {
200
+			return $values;
201
+		}
202 202
 
203
-        if ( ! isset($values['item_meta']) ) {
204
-            $values['item_meta'] = array();
205
-        }
203
+		if ( ! isset($values['item_meta']) ) {
204
+			$values['item_meta'] = array();
205
+		}
206 206
 
207
-        $field_array = array();
208
-        $existing_keys = array_keys($values['item_meta']);
209
-        foreach ( $all_fields as $fid ) {
210
-            if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
207
+		$field_array = array();
208
+		$existing_keys = array_keys($values['item_meta']);
209
+		foreach ( $all_fields as $fid ) {
210
+			if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
211 211
 				$values['item_meta'][ $fid->id ] = '';
212
-            }
212
+			}
213 213
 			$field_array[ $fid->id ] = $fid;
214
-        }
215
-        unset($all_fields);
214
+		}
215
+		unset($all_fields);
216 216
 
217
-        foreach ( $values['item_meta'] as $field_id => $default_value ) {
217
+		foreach ( $values['item_meta'] as $field_id => $default_value ) {
218 218
 			if ( isset( $field_array[ $field_id ] ) ) {
219 219
 				$field = $field_array[ $field_id ];
220
-            } else {
221
-                $field = FrmField::getOne($field_id);
222
-            }
220
+			} else {
221
+				$field = FrmField::getOne($field_id);
222
+			}
223 223
 
224
-            if ( ! $field ) {
225
-                continue;
226
-            }
224
+			if ( ! $field ) {
225
+				continue;
226
+			}
227 227
 
228 228
 			$is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) );
229 229
 			if ( $is_settings_page ) {
230
-                //updating the settings page
230
+				//updating the settings page
231 231
 				if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) {
232 232
 					$field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ? $values['field_options'][ 'custom_html_' . $field_id ] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) );
233
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
233
+					$field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
234 234
 					FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
235
-                } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
236
-                    $prev_opts = $field->field_options;
237
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
238
-                    if ( $prev_opts != $field->field_options ) {
235
+				} else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
236
+					$prev_opts = $field->field_options;
237
+					$field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
238
+					if ( $prev_opts != $field->field_options ) {
239 239
 						FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
240
-                    }
241
-                    unset($prev_opts);
242
-                }
243
-            }
240
+					}
241
+					unset($prev_opts);
242
+				}
243
+			}
244 244
 
245 245
 			if ( $is_settings_page && ! defined( 'WP_IMPORTING' ) ) {
246
-                continue;
247
-            }
246
+				continue;
247
+			}
248 248
 
249
-            //updating the form
249
+			//updating the form
250 250
 			$update_options = FrmFieldsHelper::get_default_field_opts( $field->type, $field, true );
251 251
 			unset( $update_options['custom_html'] ); // don't check for POST html
252 252
 			$update_options = apply_filters( 'frm_field_options_to_update', $update_options );
253 253
 
254 254
 			foreach ( $update_options as $opt => $default ) {
255 255
 				$field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( sanitize_text_field( $values['field_options'][ $opt . '_' . $field_id ] ) ) : $default;
256
-            }
256
+			}
257 257
 
258
-            $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
258
+			$field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
259 259
 			$default_value = maybe_serialize( $values['item_meta'][ $field_id ] );
260 260
 			$field_key = isset( $values['field_options'][ 'field_key_' . $field_id ] ) ? $values['field_options'][ 'field_key_' . $field_id ] : $field->field_key;
261 261
 			$required = isset( $values['field_options'][ 'required_' . $field_id ] ) ? $values['field_options'][ 'required_' . $field_id ] : false;
262 262
 			$field_type = isset( $values['field_options'][ 'type_' . $field_id ] ) ? $values['field_options'][ 'type_' . $field_id ] : $field->type;
263 263
 			$field_description = isset( $values['field_options'][ 'description_' . $field_id ] ) ? $values['field_options'][ 'description_' . $field_id ] : $field->description;
264 264
 
265
-            FrmField::update($field_id, array(
266
-                'field_key' => $field_key, 'type' => $field_type,
267
-                'default_value' => $default_value, 'field_options' => $field->field_options,
268
-                'description' => $field_description, 'required' => $required,
269
-            ) );
265
+			FrmField::update($field_id, array(
266
+				'field_key' => $field_key, 'type' => $field_type,
267
+				'default_value' => $default_value, 'field_options' => $field->field_options,
268
+				'description' => $field_description, 'required' => $required,
269
+			) );
270 270
 
271
-            FrmField::delete_form_transient($field->form_id);
272
-        }
271
+			FrmField::delete_form_transient($field->form_id);
272
+		}
273 273
 		self::clear_form_cache();
274 274
 
275
-        return $values;
276
-    }
275
+		return $values;
276
+	}
277 277
 
278
-    /**
279
-     * @param string $status
280
-     * @return int|boolean
281
-     */
278
+	/**
279
+	 * @param string $status
280
+	 * @return int|boolean
281
+	 */
282 282
 	public static function set_status( $id, $status ) {
283
-        if ( 'trash' == $status ) {
284
-            return self::trash($id);
285
-        }
283
+		if ( 'trash' == $status ) {
284
+			return self::trash($id);
285
+		}
286 286
 
287 287
 		$statuses  = array( 'published', 'draft', 'trash' );
288
-        if ( ! in_array( $status, $statuses ) ) {
289
-            return false;
290
-        }
288
+		if ( ! in_array( $status, $statuses ) ) {
289
+			return false;
290
+		}
291 291
 
292
-        global $wpdb;
292
+		global $wpdb;
293 293
 
294
-        if ( is_array($id) ) {
294
+		if ( is_array($id) ) {
295 295
 			$where = array( 'id' => $id, 'parent_form_id' => $id, 'or' => 1 );
296 296
 			FrmDb::get_where_clause_and_values( $where );
297 297
 			array_unshift( $where['values'], $status );
298 298
 
299 299
 			$query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) );
300
-        } else {
300
+		} else {
301 301
 			$query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) );
302 302
 			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'parent_form_id' => $id ) );
303
-        }
303
+		}
304 304
 
305
-        if ( $query_results ) {
305
+		if ( $query_results ) {
306 306
 			self::clear_form_cache();
307
-        }
307
+		}
308 308
 
309
-        return $query_results;
310
-    }
309
+		return $query_results;
310
+	}
311 311
 
312
-    /**
313
-     * @return int|boolean
314
-     */
312
+	/**
313
+	 * @return int|boolean
314
+	 */
315 315
 	public static function trash( $id ) {
316
-        if ( ! EMPTY_TRASH_DAYS ) {
317
-            return self::destroy( $id );
318
-        }
316
+		if ( ! EMPTY_TRASH_DAYS ) {
317
+			return self::destroy( $id );
318
+		}
319 319
 
320
-        $form = self::getOne($id);
321
-        if ( ! $form ) {
322
-            return false;
323
-        }
320
+		$form = self::getOne($id);
321
+		if ( ! $form ) {
322
+			return false;
323
+		}
324 324
 
325
-        $options = $form->options;
326
-        $options['trash_time'] = time();
325
+		$options = $form->options;
326
+		$options['trash_time'] = time();
327 327
 
328
-        global $wpdb;
329
-        $query_results = $wpdb->update(
328
+		global $wpdb;
329
+		$query_results = $wpdb->update(
330 330
 			$wpdb->prefix . 'frm_forms',
331 331
 			array( 'status' => 'trash', 'options' => serialize( $options ) ),
332 332
 			array( 'id' => $id )
333
-        );
333
+		);
334 334
 
335
-        $wpdb->update(
335
+		$wpdb->update(
336 336
 			$wpdb->prefix . 'frm_forms',
337 337
 			array( 'status' => 'trash', 'options' => serialize( $options ) ),
338 338
 			array( 'parent_form_id' => $id )
339
-        );
339
+		);
340 340
 
341
-        if ( $query_results ) {
341
+		if ( $query_results ) {
342 342
 			self::clear_form_cache();
343
-        }
343
+		}
344 344
 
345
-        return $query_results;
346
-    }
345
+		return $query_results;
346
+	}
347 347
 
348
-    /**
349
-     * @return int|boolean
350
-     */
348
+	/**
349
+	 * @return int|boolean
350
+	 */
351 351
 	public static function destroy( $id ) {
352
-        global $wpdb;
352
+		global $wpdb;
353 353
 
354
-        $form = self::getOne($id);
355
-        if ( ! $form ) {
356
-            return false;
357
-        }
354
+		$form = self::getOne($id);
355
+		if ( ! $form ) {
356
+			return false;
357
+		}
358 358
 		$id = $form->id;
359 359
 
360
-        // Disconnect the entries from this form
360
+		// Disconnect the entries from this form
361 361
 		$entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) );
362
-        foreach ( $entries as $entry_id ) {
363
-            FrmEntry::destroy($entry_id);
364
-            unset($entry_id);
365
-        }
362
+		foreach ( $entries as $entry_id ) {
363
+			FrmEntry::destroy($entry_id);
364
+			unset($entry_id);
365
+		}
366 366
 
367
-        // Disconnect the fields from this form
367
+		// Disconnect the fields from this form
368 368
 		$wpdb->query( $wpdb->prepare( 'DELETE fi FROM ' . $wpdb->prefix . 'frm_fields AS fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id) WHERE fi.form_id=%d OR parent_form_id=%d', $id, $id ) );
369 369
 
370 370
 		$query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) );
371
-        if ( $query_results ) {
372
-            // Delete all form actions linked to this form
373
-            $action_control = FrmFormActionsController::get_form_actions( 'email' );
374
-            $action_control->destroy($id, 'all');
371
+		if ( $query_results ) {
372
+			// Delete all form actions linked to this form
373
+			$action_control = FrmFormActionsController::get_form_actions( 'email' );
374
+			$action_control->destroy($id, 'all');
375 375
 
376 376
 			// Clear form caching
377 377
 			self::clear_form_cache();
378 378
 
379 379
 			do_action( 'frm_destroy_form', $id );
380 380
 			do_action( 'frm_destroy_form_' . $id );
381
-        }
381
+		}
382 382
 
383
-        return $query_results;
384
-    }
383
+		return $query_results;
384
+	}
385 385
 
386 386
 	/**
387 387
 	 * Delete trashed forms based on how long they have been trashed
@@ -413,49 +413,49 @@  discard block
 block discarded – undo
413 413
 		return $count;
414 414
 	}
415 415
 
416
-    /**
417
-     * @return string form name
418
-     */
419
-    public static function &getName( $id ) {
420
-        global $wpdb;
421
-
422
-        $form = FrmAppHelper::check_cache($id, 'frm_form');
423
-        if ( $form ) {
424
-            $r = stripslashes($form->name);
425
-            return $r;
426
-        }
427
-
428
-        $query_key = is_numeric( $id ) ? 'id' : 'form_key';
429
-        $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
430
-        $r = stripslashes($r);
431
-
432
-        return $r;
433
-    }
434
-
435
-    /**
436
-     * @param string $key
437
-     * @return int form id
438
-     */
416
+	/**
417
+	 * @return string form name
418
+	 */
419
+	public static function &getName( $id ) {
420
+		global $wpdb;
421
+
422
+		$form = FrmAppHelper::check_cache($id, 'frm_form');
423
+		if ( $form ) {
424
+			$r = stripslashes($form->name);
425
+			return $r;
426
+		}
427
+
428
+		$query_key = is_numeric( $id ) ? 'id' : 'form_key';
429
+		$r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
430
+		$r = stripslashes($r);
431
+
432
+		return $r;
433
+	}
434
+
435
+	/**
436
+	 * @param string $key
437
+	 * @return int form id
438
+	 */
439 439
 	public static function &getIdByKey( $key ) {
440
-        $id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) );
441
-        return $id;
442
-    }
443
-
444
-    /**
445
-     * @param int $id
446
-     * @return string form key
447
-     */
440
+		$id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) );
441
+		return $id;
442
+	}
443
+
444
+	/**
445
+	 * @param int $id
446
+	 * @return string form key
447
+	 */
448 448
 	public static function &getKeyById( $id ) {
449
-        $id = (int) $id;
450
-        $cache = FrmAppHelper::check_cache($id, 'frm_form');
451
-        if ( $cache ) {
452
-            return $cache->form_key;
453
-        }
449
+		$id = (int) $id;
450
+		$cache = FrmAppHelper::check_cache($id, 'frm_form');
451
+		if ( $cache ) {
452
+			return $cache->form_key;
453
+		}
454 454
 
455
-        $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
455
+		$key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' );
456 456
 
457
-        return $key;
458
-    }
457
+		return $key;
458
+	}
459 459
 
460 460
 	/**
461 461
 	 * If $form is numeric, get the form object
@@ -468,47 +468,47 @@  discard block
 block discarded – undo
468 468
 		}
469 469
 	}
470 470
 
471
-    /**
472
-     * @return object form
473
-     */
474
-    public static function getOne( $id, $blog_id = false ) {
475
-        global $wpdb;
471
+	/**
472
+	 * @return object form
473
+	 */
474
+	public static function getOne( $id, $blog_id = false ) {
475
+		global $wpdb;
476 476
 
477
-        if ( $blog_id && is_multisite() ) {
478
-            global $wpmuBaseTablePrefix;
477
+		if ( $blog_id && is_multisite() ) {
478
+			global $wpmuBaseTablePrefix;
479 479
 			$prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix( $blog_id );
480 480
 
481 481
 			$table_name = $prefix . 'frm_forms';
482
-        } else {
482
+		} else {
483 483
 			$table_name = $wpdb->prefix . 'frm_forms';
484
-            $cache = wp_cache_get($id, 'frm_form');
485
-            if ( $cache ) {
486
-                if ( isset($cache->options) ) {
487
-                    $cache->options = maybe_unserialize($cache->options);
488
-                }
484
+			$cache = wp_cache_get($id, 'frm_form');
485
+			if ( $cache ) {
486
+				if ( isset($cache->options) ) {
487
+					$cache->options = maybe_unserialize($cache->options);
488
+				}
489 489
 
490
-                return stripslashes_deep($cache);
491
-            }
492
-        }
490
+				return stripslashes_deep($cache);
491
+			}
492
+		}
493 493
 
494
-        if ( is_numeric($id) ) {
495
-            $where = array( 'id' => $id );
496
-        } else {
497
-            $where = array( 'form_key' => $id );
498
-        }
494
+		if ( is_numeric($id) ) {
495
+			$where = array( 'id' => $id );
496
+		} else {
497
+			$where = array( 'form_key' => $id );
498
+		}
499 499
 
500
-        $results = FrmDb::get_row( $table_name, $where );
500
+		$results = FrmDb::get_row( $table_name, $where );
501 501
 
502
-        if ( isset($results->options) ) {
502
+		if ( isset($results->options) ) {
503 503
 			FrmAppHelper::set_cache( $results->id, $results, 'frm_form' );
504
-            $results->options = maybe_unserialize($results->options);
505
-        }
506
-        return stripslashes_deep($results);
507
-    }
508
-
509
-    /**
510
-     * @return object|array of objects
511
-     */
504
+			$results->options = maybe_unserialize($results->options);
505
+		}
506
+		return stripslashes_deep($results);
507
+	}
508
+
509
+	/**
510
+	 * @return object|array of objects
511
+	 */
512 512
 	public static function getAll( $where = array(), $order_by = '', $limit = '' ) {
513 513
 		if ( is_array( $where ) && ! empty( $where ) ) {
514 514
 			$results = FrmDb::get_results( 'frm_forms', $where, '*', array( 'order_by' => $order_by, 'limit' => $limit ) );
@@ -532,8 +532,8 @@  discard block
 block discarded – undo
532 532
 			$results = reset( $results );
533 533
 		}
534 534
 
535
-        return stripslashes_deep($results);
536
-    }
535
+		return stripslashes_deep($results);
536
+	}
537 537
 
538 538
 	/**
539 539
 	 * Get all published forms
@@ -551,47 +551,47 @@  discard block
 block discarded – undo
551 551
 		return $forms;
552 552
 	}
553 553
 
554
-    /**
555
-     * @return int count of forms
556
-     */
557
-    public static function &get_count() {
558
-    	global $wpdb;
554
+	/**
555
+	 * @return int count of forms
556
+	 */
557
+	public static function &get_count() {
558
+		global $wpdb;
559 559
 
560
-    	$cache_key = 'frm_form_counts';
560
+		$cache_key = 'frm_form_counts';
561 561
 
562
-    	$counts = wp_cache_get( $cache_key, 'counts' );
563
-    	if ( false !== $counts ) {
564
-    	    return $counts;
565
-    	}
562
+		$counts = wp_cache_get( $cache_key, 'counts' );
563
+		if ( false !== $counts ) {
564
+			return $counts;
565
+		}
566 566
 
567
-        $results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' );
567
+		$results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' );
568 568
 
569 569
 		$statuses = array( 'published', 'draft', 'template', 'trash' );
570
-    	$counts = array_fill_keys( $statuses, 0 );
570
+		$counts = array_fill_keys( $statuses, 0 );
571 571
 
572
-    	foreach ( $results as $row ) {
573
-            if ( 'trash' != $row->status ) {
574
-    	        if ( $row->is_template ) {
572
+		foreach ( $results as $row ) {
573
+			if ( 'trash' != $row->status ) {
574
+				if ( $row->is_template ) {
575 575
 					$counts['template']++;
576
-    	        } else {
576
+				} else {
577 577
 					$counts['published']++;
578
-    	        }
579
-    	    } else {
578
+				}
579
+			} else {
580 580
 				$counts['trash']++;
581
-        	}
581
+			}
582 582
 
583
-    	    if ( 'draft' == $row->status ) {
583
+			if ( 'draft' == $row->status ) {
584 584
 				$counts['draft']++;
585
-    	    }
585
+			}
586 586
 
587
-    		unset($row);
588
-    	}
587
+			unset($row);
588
+		}
589 589
 
590
-    	$counts = (object) $counts;
590
+		$counts = (object) $counts;
591 591
 		FrmAppHelper::set_cache( $cache_key, $counts, 'counts' );
592 592
 
593
-    	return $counts;
594
-    }
593
+		return $counts;
594
+	}
595 595
 
596 596
 	/**
597 597
 	 * Clear form caching
@@ -604,14 +604,14 @@  discard block
 block discarded – undo
604 604
 		FrmAppHelper::cache_delete_group( 'frm_form' );
605 605
 	}
606 606
 
607
-    /**
608
-     * @return array of errors
609
-     */
607
+	/**
608
+	 * @return array of errors
609
+	 */
610 610
 	public static function validate( $values ) {
611
-        $errors = array();
611
+		$errors = array();
612 612
 
613
-        return apply_filters('frm_validate_form', $errors, $values);
614
-    }
613
+		return apply_filters('frm_validate_form', $errors, $values);
614
+	}
615 615
 
616 616
 	public static function get_params( $form = null ) {
617 617
 		global $frm_vars;
Please login to merge, or discard this patch.
Spacing   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
3
-    die('You are not allowed to call this page directly.');
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+    die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
6 6
 class FrmForm {
@@ -15,24 +15,24 @@  discard block
 block discarded – undo
15 15
 			'form_key'      => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ),
16 16
             'name'          => $values['name'],
17 17
             'description'   => $values['description'],
18
-            'status'        => isset($values['status']) ? $values['status'] : 'draft',
19
-            'logged_in'     => isset($values['logged_in']) ? $values['logged_in'] : 0,
20
-            'is_template'   => isset($values['is_template']) ? (int) $values['is_template'] : 0,
18
+            'status'        => isset( $values['status'] ) ? $values['status'] : 'draft',
19
+            'logged_in'     => isset( $values['logged_in'] ) ? $values['logged_in'] : 0,
20
+            'is_template'   => isset( $values['is_template'] ) ? (int) $values['is_template'] : 0,
21 21
 			'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0,
22
-            'editable'      => isset($values['editable']) ? (int) $values['editable'] : 0,
23
-            'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0,
24
-            'created_at'    => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1),
22
+            'editable'      => isset( $values['editable'] ) ? (int) $values['editable'] : 0,
23
+            'default_template' => isset( $values['default_template'] ) ? (int) $values['default_template'] : 0,
24
+            'created_at'    => isset( $values['created_at'] ) ? $values['created_at'] : current_time( 'mysql', 1 ),
25 25
         );
26 26
 
27 27
 		$options = isset( $values['options'] ) ? (array) $values['options'] : array();
28 28
 		FrmFormsHelper::fill_form_options( $options, $values );
29 29
 
30
-        $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
31
-        $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
32
-        $options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
30
+        $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
31
+        $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' );
32
+        $options['submit_html'] = isset( $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' );
33 33
 
34
-        $options = apply_filters('frm_form_options_before_update', $options, $values);
35
-        $new_values['options'] = serialize($options);
34
+        $options = apply_filters( 'frm_form_options_before_update', $options, $values );
35
+        $new_values['options'] = serialize( $options );
36 36
 
37 37
         //if(isset($values['id']) && is_numeric($values['id']))
38 38
         //    $new_values['id'] = $values['id'];
@@ -67,22 +67,22 @@  discard block
 block discarded – undo
67 67
             'status'        => $template ? 'published' : 'draft',
68 68
             'logged_in'     => $values->logged_in ? $values->logged_in : 0,
69 69
             'editable'      => $values->editable ? $values->editable : 0,
70
-            'created_at'    => current_time('mysql', 1),
70
+            'created_at'    => current_time( 'mysql', 1 ),
71 71
             'is_template'   => $template ? 1 : 0,
72 72
         );
73 73
 
74 74
         if ( $blog_id ) {
75 75
             $new_values['status'] = 'published';
76
-            $new_options = maybe_unserialize($values->options);
77
-            $new_options['email_to'] = get_option('admin_email');
76
+            $new_options = maybe_unserialize( $values->options );
77
+            $new_options['email_to'] = get_option( 'admin_email' );
78 78
             $new_options['copy'] = false;
79 79
             $new_values['options'] = $new_options;
80 80
         } else {
81 81
             $new_values['options'] = $values->options;
82 82
         }
83 83
 
84
-        if ( is_array($new_values['options']) ) {
85
-            $new_values['options'] = serialize($new_values['options']);
84
+        if ( is_array( $new_values['options'] ) ) {
85
+            $new_values['options'] = serialize( $new_values['options'] );
86 86
         }
87 87
 
88 88
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values );
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 			self::clear_form_cache();
93 93
 
94 94
             $form_id = $wpdb->insert_id;
95
-            FrmField::duplicate($id, $form_id, $copy_keys, $blog_id);
95
+            FrmField::duplicate( $id, $form_id, $copy_keys, $blog_id );
96 96
 
97 97
             // update form settings after fields are created
98 98
 			do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) );
@@ -103,13 +103,13 @@  discard block
 block discarded – undo
103 103
     }
104 104
 
105 105
 	public static function after_duplicate( $form_id, $values ) {
106
-        $new_opts = $values['options'] = maybe_unserialize($values['options']);
106
+        $new_opts = $values['options'] = maybe_unserialize( $values['options'] );
107 107
 
108
-        if ( isset($new_opts['success_msg']) ) {
109
-            $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']);
108
+        if ( isset( $new_opts['success_msg'] ) ) {
109
+            $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids( $new_opts['success_msg'] );
110 110
         }
111 111
 
112
-        $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id);
112
+        $new_opts = apply_filters( 'frm_after_duplicate_form_values', $new_opts, $form_id );
113 113
 
114 114
         if ( $new_opts != $values['options'] ) {
115 115
             global $wpdb;
@@ -127,17 +127,17 @@  discard block
 block discarded – undo
127 127
             $values['status'] = 'published';
128 128
         }
129 129
 
130
-        if ( isset($values['form_key']) ) {
130
+        if ( isset( $values['form_key'] ) ) {
131 131
 			$values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id );
132 132
         }
133 133
 
134 134
         $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' );
135 135
 
136
-        $new_values = self::set_update_options( array(), $values);
136
+        $new_values = self::set_update_options( array(), $values );
137 137
 
138 138
         foreach ( $values as $value_key => $value ) {
139
-            if ( in_array($value_key, $form_fields) ) {
140
-				$new_values[ $value_key ] = $value;
139
+            if ( in_array( $value_key, $form_fields ) ) {
140
+				$new_values[$value_key] = $value;
141 141
             }
142 142
         }
143 143
 
@@ -153,9 +153,9 @@  discard block
 block discarded – undo
153 153
         } else {
154 154
             $query_results = true;
155 155
         }
156
-        unset($new_values);
156
+        unset( $new_values );
157 157
 
158
-        $values = self::update_fields($id, $values);
158
+        $values = self::update_fields( $id, $values );
159 159
 
160 160
 		do_action( 'frm_update_form', $id, $values );
161 161
 		do_action( 'frm_update_form_' . $id, $values );
@@ -167,20 +167,20 @@  discard block
 block discarded – undo
167 167
      * @return array
168 168
      */
169 169
 	public static function set_update_options( $new_values, $values ) {
170
-        if ( ! isset($values['options']) ) {
170
+        if ( ! isset( $values['options'] ) ) {
171 171
             return $new_values;
172 172
         }
173 173
 
174 174
 		$options = isset( $values['options'] ) ? (array) $values['options'] : array();
175 175
 		FrmFormsHelper::fill_form_options( $options, $values );
176 176
 
177
-        $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0;
178
-        $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before');
179
-        $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after');
180
-        $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit');
177
+        $options['custom_style'] = isset( $values['options']['custom_style'] ) ? $values['options']['custom_style'] : 0;
178
+        $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' );
179
+        $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' );
180
+        $options['submit_html'] = ( isset( $values['options']['submit_html'] ) && $values['options']['submit_html'] != '' ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' );
181 181
 
182
-        $options = apply_filters('frm_form_options_before_update', $options, $values);
183
-        $new_values['options'] = serialize($options);
182
+        $options = apply_filters( 'frm_form_options_before_update', $options, $values );
183
+        $new_values['options'] = serialize( $options );
184 184
 
185 185
         return $new_values;
186 186
     }
@@ -191,54 +191,54 @@  discard block
 block discarded – undo
191 191
      */
192 192
 	public static function update_fields( $id, $values ) {
193 193
 
194
-        if ( ! isset($values['options']) && ! isset($values['item_meta']) && ! isset($values['field_options']) ) {
194
+        if ( ! isset( $values['options'] ) && ! isset( $values['item_meta'] ) && ! isset( $values['field_options'] ) ) {
195 195
             return $values;
196 196
         }
197 197
 
198
-        $all_fields = FrmField::get_all_for_form($id);
199
-        if ( empty($all_fields) ) {
198
+        $all_fields = FrmField::get_all_for_form( $id );
199
+        if ( empty( $all_fields ) ) {
200 200
             return $values;
201 201
         }
202 202
 
203
-        if ( ! isset($values['item_meta']) ) {
203
+        if ( ! isset( $values['item_meta'] ) ) {
204 204
             $values['item_meta'] = array();
205 205
         }
206 206
 
207 207
         $field_array = array();
208
-        $existing_keys = array_keys($values['item_meta']);
208
+        $existing_keys = array_keys( $values['item_meta'] );
209 209
         foreach ( $all_fields as $fid ) {
210
-            if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) {
211
-				$values['item_meta'][ $fid->id ] = '';
210
+            if ( ! in_array( $fid->id, $existing_keys ) && ( isset( $values['frm_fields_submitted'] ) && in_array( $fid->id, $values['frm_fields_submitted'] ) ) || isset( $values['options'] ) ) {
211
+				$values['item_meta'][$fid->id] = '';
212 212
             }
213
-			$field_array[ $fid->id ] = $fid;
213
+			$field_array[$fid->id] = $fid;
214 214
         }
215
-        unset($all_fields);
215
+        unset( $all_fields );
216 216
 
217 217
         foreach ( $values['item_meta'] as $field_id => $default_value ) {
218
-			if ( isset( $field_array[ $field_id ] ) ) {
219
-				$field = $field_array[ $field_id ];
218
+			if ( isset( $field_array[$field_id] ) ) {
219
+				$field = $field_array[$field_id];
220 220
             } else {
221
-                $field = FrmField::getOne($field_id);
221
+                $field = FrmField::getOne( $field_id );
222 222
             }
223 223
 
224 224
             if ( ! $field ) {
225 225
                 continue;
226 226
             }
227 227
 
228
-			$is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) );
228
+			$is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options']['custom_html_' . $field_id] ) );
229 229
 			if ( $is_settings_page ) {
230 230
                 //updating the settings page
231
-				if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) {
232
-					$field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ? $values['field_options'][ 'custom_html_' . $field_id ] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) );
233
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
231
+				if ( isset( $values['field_options']['custom_html_' . $field_id] ) ) {
232
+					$field->field_options['custom_html'] = isset( $values['field_options']['custom_html_' . $field_id] ) ? $values['field_options']['custom_html_' . $field_id] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) );
233
+                    $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values );
234 234
 					FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
235 235
                 } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) {
236 236
                     $prev_opts = $field->field_options;
237
-                    $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values);
237
+                    $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values );
238 238
                     if ( $prev_opts != $field->field_options ) {
239 239
 						FrmField::update( $field_id, array( 'field_options' => $field->field_options ) );
240 240
                     }
241
-                    unset($prev_opts);
241
+                    unset( $prev_opts );
242 242
                 }
243 243
             }
244 244
 
@@ -252,23 +252,23 @@  discard block
 block discarded – undo
252 252
 			$update_options = apply_filters( 'frm_field_options_to_update', $update_options );
253 253
 
254 254
 			foreach ( $update_options as $opt => $default ) {
255
-				$field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( sanitize_text_field( $values['field_options'][ $opt . '_' . $field_id ] ) ) : $default;
255
+				$field->field_options[$opt] = isset( $values['field_options'][$opt . '_' . $field_id] ) ? trim( sanitize_text_field( $values['field_options'][$opt . '_' . $field_id] ) ) : $default;
256 256
             }
257 257
 
258
-            $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values);
259
-			$default_value = maybe_serialize( $values['item_meta'][ $field_id ] );
260
-			$field_key = isset( $values['field_options'][ 'field_key_' . $field_id ] ) ? $values['field_options'][ 'field_key_' . $field_id ] : $field->field_key;
261
-			$required = isset( $values['field_options'][ 'required_' . $field_id ] ) ? $values['field_options'][ 'required_' . $field_id ] : false;
262
-			$field_type = isset( $values['field_options'][ 'type_' . $field_id ] ) ? $values['field_options'][ 'type_' . $field_id ] : $field->type;
263
-			$field_description = isset( $values['field_options'][ 'description_' . $field_id ] ) ? $values['field_options'][ 'description_' . $field_id ] : $field->description;
258
+            $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values );
259
+			$default_value = maybe_serialize( $values['item_meta'][$field_id] );
260
+			$field_key = isset( $values['field_options']['field_key_' . $field_id] ) ? $values['field_options']['field_key_' . $field_id] : $field->field_key;
261
+			$required = isset( $values['field_options']['required_' . $field_id] ) ? $values['field_options']['required_' . $field_id] : false;
262
+			$field_type = isset( $values['field_options']['type_' . $field_id] ) ? $values['field_options']['type_' . $field_id] : $field->type;
263
+			$field_description = isset( $values['field_options']['description_' . $field_id] ) ? $values['field_options']['description_' . $field_id] : $field->description;
264 264
 
265
-            FrmField::update($field_id, array(
265
+            FrmField::update( $field_id, array(
266 266
                 'field_key' => $field_key, 'type' => $field_type,
267 267
                 'default_value' => $default_value, 'field_options' => $field->field_options,
268 268
                 'description' => $field_description, 'required' => $required,
269 269
             ) );
270 270
 
271
-            FrmField::delete_form_transient($field->form_id);
271
+            FrmField::delete_form_transient( $field->form_id );
272 272
         }
273 273
 		self::clear_form_cache();
274 274
 
@@ -281,17 +281,17 @@  discard block
 block discarded – undo
281 281
      */
282 282
 	public static function set_status( $id, $status ) {
283 283
         if ( 'trash' == $status ) {
284
-            return self::trash($id);
284
+            return self::trash( $id );
285 285
         }
286 286
 
287
-		$statuses  = array( 'published', 'draft', 'trash' );
287
+		$statuses = array( 'published', 'draft', 'trash' );
288 288
         if ( ! in_array( $status, $statuses ) ) {
289 289
             return false;
290 290
         }
291 291
 
292 292
         global $wpdb;
293 293
 
294
-        if ( is_array($id) ) {
294
+        if ( is_array( $id ) ) {
295 295
 			$where = array( 'id' => $id, 'parent_form_id' => $id, 'or' => 1 );
296 296
 			FrmDb::get_where_clause_and_values( $where );
297 297
 			array_unshift( $where['values'], $status );
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
             return self::destroy( $id );
318 318
         }
319 319
 
320
-        $form = self::getOne($id);
320
+        $form = self::getOne( $id );
321 321
         if ( ! $form ) {
322 322
             return false;
323 323
         }
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 	public static function destroy( $id ) {
352 352
         global $wpdb;
353 353
 
354
-        $form = self::getOne($id);
354
+        $form = self::getOne( $id );
355 355
         if ( ! $form ) {
356 356
             return false;
357 357
         }
@@ -360,8 +360,8 @@  discard block
 block discarded – undo
360 360
         // Disconnect the entries from this form
361 361
 		$entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) );
362 362
         foreach ( $entries as $entry_id ) {
363
-            FrmEntry::destroy($entry_id);
364
-            unset($entry_id);
363
+            FrmEntry::destroy( $entry_id );
364
+            unset( $entry_id );
365 365
         }
366 366
 
367 367
         // Disconnect the fields from this form
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
         if ( $query_results ) {
372 372
             // Delete all form actions linked to this form
373 373
             $action_control = FrmFormActionsController::get_form_actions( 'email' );
374
-            $action_control->destroy($id, 'all');
374
+            $action_control->destroy( $id, 'all' );
375 375
 
376 376
 			// Clear form caching
377 377
 			self::clear_form_cache();
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
 			$form->options = maybe_unserialize( $form->options );
406 406
 			if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) {
407 407
 				self::destroy( $form->id );
408
-				$count++;
408
+				$count ++;
409 409
 			}
410 410
 
411 411
 			unset( $form );
@@ -419,15 +419,15 @@  discard block
 block discarded – undo
419 419
     public static function &getName( $id ) {
420 420
         global $wpdb;
421 421
 
422
-        $form = FrmAppHelper::check_cache($id, 'frm_form');
422
+        $form = FrmAppHelper::check_cache( $id, 'frm_form' );
423 423
         if ( $form ) {
424
-            $r = stripslashes($form->name);
424
+            $r = stripslashes( $form->name );
425 425
             return $r;
426 426
         }
427 427
 
428 428
         $query_key = is_numeric( $id ) ? 'id' : 'form_key';
429 429
         $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' );
430
-        $r = stripslashes($r);
430
+        $r = stripslashes( $r );
431 431
 
432 432
         return $r;
433 433
     }
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
      */
448 448
 	public static function &getKeyById( $id ) {
449 449
         $id = (int) $id;
450
-        $cache = FrmAppHelper::check_cache($id, 'frm_form');
450
+        $cache = FrmAppHelper::check_cache( $id, 'frm_form' );
451 451
         if ( $cache ) {
452 452
             return $cache->form_key;
453 453
         }
@@ -481,17 +481,17 @@  discard block
 block discarded – undo
481 481
 			$table_name = $prefix . 'frm_forms';
482 482
         } else {
483 483
 			$table_name = $wpdb->prefix . 'frm_forms';
484
-            $cache = wp_cache_get($id, 'frm_form');
484
+            $cache = wp_cache_get( $id, 'frm_form' );
485 485
             if ( $cache ) {
486
-                if ( isset($cache->options) ) {
487
-                    $cache->options = maybe_unserialize($cache->options);
486
+                if ( isset( $cache->options ) ) {
487
+                    $cache->options = maybe_unserialize( $cache->options );
488 488
                 }
489 489
 
490
-                return stripslashes_deep($cache);
490
+                return stripslashes_deep( $cache );
491 491
             }
492 492
         }
493 493
 
494
-        if ( is_numeric($id) ) {
494
+        if ( is_numeric( $id ) ) {
495 495
             $where = array( 'id' => $id );
496 496
         } else {
497 497
             $where = array( 'form_key' => $id );
@@ -499,11 +499,11 @@  discard block
 block discarded – undo
499 499
 
500 500
         $results = FrmDb::get_row( $table_name, $where );
501 501
 
502
-        if ( isset($results->options) ) {
502
+        if ( isset( $results->options ) ) {
503 503
 			FrmAppHelper::set_cache( $results->id, $results, 'frm_form' );
504
-            $results->options = maybe_unserialize($results->options);
504
+            $results->options = maybe_unserialize( $results->options );
505 505
         }
506
-        return stripslashes_deep($results);
506
+        return stripslashes_deep( $results );
507 507
     }
508 508
 
509 509
     /**
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
 			$results = reset( $results );
533 533
 		}
534 534
 
535
-        return stripslashes_deep($results);
535
+        return stripslashes_deep( $results );
536 536
     }
537 537
 
538 538
 	/**
@@ -572,19 +572,19 @@  discard block
 block discarded – undo
572 572
     	foreach ( $results as $row ) {
573 573
             if ( 'trash' != $row->status ) {
574 574
     	        if ( $row->is_template ) {
575
-					$counts['template']++;
575
+					$counts['template'] ++;
576 576
     	        } else {
577
-					$counts['published']++;
577
+					$counts['published'] ++;
578 578
     	        }
579 579
     	    } else {
580
-				$counts['trash']++;
580
+				$counts['trash'] ++;
581 581
         	}
582 582
 
583 583
     	    if ( 'draft' == $row->status ) {
584
-				$counts['draft']++;
584
+				$counts['draft'] ++;
585 585
     	    }
586 586
 
587
-    		unset($row);
587
+    		unset( $row );
588 588
     	}
589 589
 
590 590
     	$counts = (object) $counts;
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
 	public static function validate( $values ) {
611 611
         $errors = array();
612 612
 
613
-        return apply_filters('frm_validate_form', $errors, $values);
613
+        return apply_filters( 'frm_validate_form', $errors, $values );
614 614
     }
615 615
 
616 616
 	public static function get_params( $form = null ) {
@@ -622,11 +622,11 @@  discard block
 block discarded – undo
622 622
 			self::maybe_get_form( $form );
623 623
 		}
624 624
 
625
-		if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) {
626
-			return $frm_vars['form_params'][ $form->id ];
625
+		if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][$form->id] ) ) {
626
+			return $frm_vars['form_params'][$form->id];
627 627
 		}
628 628
 
629
-		$action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
629
+		$action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
630 630
 		$action = apply_filters( 'frm_show_new_entry_page', FrmAppHelper::get_param( $action_var, 'new', 'get', 'sanitize_title' ), $form );
631 631
 
632 632
 		$default_values = array(
@@ -644,15 +644,15 @@  discard block
 block discarded – undo
644 644
 			//if there are two forms on the same page, make sure not to submit both
645 645
 			foreach ( $default_values as $var => $default ) {
646 646
 				if ( $var == 'action' ) {
647
-					$values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' );
647
+					$values[$var] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' );
648 648
 				} else {
649
-					$values[ $var ] = FrmAppHelper::get_param( $var, $default );
649
+					$values[$var] = FrmAppHelper::get_param( $var, $default );
650 650
 				}
651 651
 				unset( $var, $default );
652 652
 			}
653 653
 		} else {
654 654
 			foreach ( $default_values as $var => $default ) {
655
-				$values[ $var ] = $default;
655
+				$values[$var] = $default;
656 656
 				unset( $var, $default );
657 657
 			}
658 658
 		}
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
 	public static function list_page_params() {
668 668
 		$values = array();
669 669
 		foreach ( array( 'template' => 0, 'id' => '', 'paged' => 1, 'form' => '', 'search' => '', 'sort' => '', 'sdir' => '' ) as $var => $default ) {
670
-			$values[ $var ] = FrmAppHelper::get_param( $var, $default );
670
+			$values[$var] = FrmAppHelper::get_param( $var, $default );
671 671
 		}
672 672
 
673 673
 		return $values;
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
 			'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'fid' => '',
688 688
 			'keep_post' => '',
689 689
 		) as $var => $default ) {
690
-			$values[ $var ] = FrmAppHelper::get_param( $var, $default );
690
+			$values[$var] = FrmAppHelper::get_param( $var, $default );
691 691
 		}
692 692
 
693 693
 		return $values;
@@ -729,16 +729,16 @@  discard block
 block discarded – undo
729 729
 		$small_form = new stdClass();
730 730
 		foreach ( array( 'id', 'form_key', 'name' ) as $var ) {
731 731
 			$small_form->{$var} = $form->{$var};
732
-			unset($var);
732
+			unset( $var );
733 733
 		}
734 734
 
735 735
 		$frm_vars['forms_loaded'][] = $small_form;
736 736
 
737
-		if ( $this_load && empty($global_load) ) {
737
+		if ( $this_load && empty( $global_load ) ) {
738 738
 			$global_load = $frm_vars['load_css'] = true;
739 739
 		}
740 740
 
741
-		return ( ( ! isset($frm_vars['css_loaded']) || ! $frm_vars['css_loaded'] ) && $global_load );
741
+		return ( ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) && $global_load );
742 742
 	}
743 743
 
744 744
 	public static function show_submit( $form ) {
Please login to merge, or discard this patch.
classes/models/FrmField.php 2 patches
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 }
5 5
 
6 6
 class FrmField {
7
-    static $use_cache = true;
7
+	static $use_cache = true;
8 8
 	static $transient_size = 200;
9 9
 
10 10
 	public static function field_selection() {
@@ -51,39 +51,39 @@  discard block
 block discarded – undo
51 51
 		));
52 52
 	}
53 53
 
54
-    public static function create( $values, $return = true ) {
55
-        global $wpdb, $frm_duplicate_ids;
54
+	public static function create( $values, $return = true ) {
55
+		global $wpdb, $frm_duplicate_ids;
56 56
 
57
-        $new_values = array();
58
-        $key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
57
+		$new_values = array();
58
+		$key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
59 59
 		$new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' );
60 60
 
61 61
 		foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) {
62 62
 			$new_values[ $col ] = $values[ $col ];
63
-        }
63
+		}
64 64
 
65
-        $new_values['options'] = $values['options'];
65
+		$new_values['options'] = $values['options'];
66 66
 
67
-        $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null;
68
-        $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0;
69
-        $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null;
70
-        $new_values['field_options'] = $values['field_options'];
71
-        $new_values['created_at'] = current_time('mysql', 1);
67
+		$new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null;
68
+		$new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0;
69
+		$new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null;
70
+		$new_values['field_options'] = $values['field_options'];
71
+		$new_values['created_at'] = current_time('mysql', 1);
72 72
 
73 73
 		if ( isset( $values['id'] ) ) {
74 74
 			$frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key'];
75
-            $new_values = apply_filters('frm_duplicated_field', $new_values);
76
-        }
75
+			$new_values = apply_filters('frm_duplicated_field', $new_values);
76
+		}
77 77
 
78 78
 		foreach ( $new_values as $k => $v ) {
79
-            if ( is_array( $v ) ) {
79
+			if ( is_array( $v ) ) {
80 80
 				$new_values[ $k ] = serialize( $v );
81 81
 			}
82
-            unset( $k, $v );
83
-        }
82
+			unset( $k, $v );
83
+		}
84 84
 
85
-        //if(isset($values['id']) and is_numeric($values['id']))
86
-        //    $new_values['id'] = $values['id'];
85
+		//if(isset($values['id']) and is_numeric($values['id']))
86
+		//    $new_values['id'] = $values['id'];
87 87
 
88 88
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_fields', $new_values );
89 89
 		$new_id = 0;
@@ -104,22 +104,22 @@  discard block
 block discarded – undo
104 104
 		} else {
105 105
 			return false;
106 106
 		}
107
-    }
107
+	}
108 108
 
109
-    public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) {
110
-        global $frm_duplicate_ids;
109
+	public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) {
110
+		global $frm_duplicate_ids;
111 111
 
112 112
 		$where = array( array( 'or' => 1, 'fi.form_id' => $old_form_id, 'fr.parent_form_id' => $old_form_id ) );
113 113
 		$fields = self::getAll( $where, 'field_order', '', $blog_id );
114 114
 
115
-        foreach ( (array) $fields as $field ) {
116
-            $new_key = ($copy_keys) ? $field->field_key : '';
117
-            if ( $copy_keys && substr($field->field_key, -1) == 2 ) {
118
-                $new_key = rtrim($new_key, 2);
119
-            }
115
+		foreach ( (array) $fields as $field ) {
116
+			$new_key = ($copy_keys) ? $field->field_key : '';
117
+			if ( $copy_keys && substr($field->field_key, -1) == 2 ) {
118
+				$new_key = rtrim($new_key, 2);
119
+			}
120 120
 
121
-            $values = array();
122
-            FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key );
121
+			$values = array();
122
+			FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key );
123 123
 
124 124
 			// If this is a repeating section, create new form
125 125
 			if ( self::is_repeating_field( $field ) ) {
@@ -138,16 +138,16 @@  discard block
 block discarded – undo
138 138
 				$values['form_id'] = $new_repeat_form_id;
139 139
 			}
140 140
 
141
-            $values = apply_filters('frm_duplicated_field', $values);
142
-            $new_id = self::create($values);
143
-            $frm_duplicate_ids[ $field->id ] = $new_id;
144
-            $frm_duplicate_ids[ $field->field_key ] = $new_id;
145
-            unset($field);
146
-        }
147
-    }
141
+			$values = apply_filters('frm_duplicated_field', $values);
142
+			$new_id = self::create($values);
143
+			$frm_duplicate_ids[ $field->id ] = $new_id;
144
+			$frm_duplicate_ids[ $field->field_key ] = $new_id;
145
+			unset($field);
146
+		}
147
+	}
148 148
 
149 149
 	public static function update( $id, $values ) {
150
-        global $wpdb;
150
+		global $wpdb;
151 151
 
152 152
 		$id = absint( $id );
153 153
 
@@ -155,9 +155,9 @@  discard block
 block discarded – undo
155 155
 			$values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id );
156 156
 		}
157 157
 
158
-        if ( isset($values['required']) ) {
159
-            $values['required'] = (int) $values['required'];
160
-        }
158
+		if ( isset($values['required']) ) {
159
+			$values['required'] = (int) $values['required'];
160
+		}
161 161
 
162 162
 		self::preserve_format_option_backslashes( $values );
163 163
 
@@ -174,41 +174,41 @@  discard block
 block discarded – undo
174 174
 
175 175
 		$query_results = $wpdb->update( $wpdb->prefix . 'frm_fields', $values, array( 'id' => $id ) );
176 176
 
177
-        $form_id = 0;
177
+		$form_id = 0;
178 178
 		if ( isset( $values['form_id'] ) ) {
179
-            $form_id = absint( $values['form_id'] );
179
+			$form_id = absint( $values['form_id'] );
180 180
 		} else {
181
-            $field = self::getOne($id);
182
-            if ( $field ) {
183
-                $form_id = $field->form_id;
184
-            }
185
-            unset($field);
186
-        }
187
-        unset($values);
181
+			$field = self::getOne($id);
182
+			if ( $field ) {
183
+				$form_id = $field->form_id;
184
+			}
185
+			unset($field);
186
+		}
187
+		unset($values);
188 188
 
189 189
 		if ( $query_results ) {
190
-            wp_cache_delete( $id, 'frm_field' );
191
-            if ( $form_id ) {
192
-                self::delete_form_transient( $form_id );
193
-            }
194
-        }
190
+			wp_cache_delete( $id, 'frm_field' );
191
+			if ( $form_id ) {
192
+				self::delete_form_transient( $form_id );
193
+			}
194
+		}
195 195
 
196
-        return $query_results;
197
-    }
196
+		return $query_results;
197
+	}
198 198
 
199 199
 	/**
200
-	* Keep backslashes in the phone format option
201
-	*
202
-	* @since 2.0.8
203
-	* @param $values array - pass by reference
204
-	*/
200
+	 * Keep backslashes in the phone format option
201
+	 *
202
+	 * @since 2.0.8
203
+	 * @param $values array - pass by reference
204
+	 */
205 205
 	private static function preserve_format_option_backslashes( &$values ) {
206 206
 		if ( isset( $values['field_options']['format'] ) ) {
207 207
 			$values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] );
208 208
 		}
209 209
 	}
210 210
 
211
-    public static function destroy( $id ) {
211
+	public static function destroy( $id ) {
212 212
 		global $wpdb;
213 213
 
214 214
 		do_action( 'frm_before_destroy_field', $id );
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 
224 224
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $id ) );
225 225
 		return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_fields WHERE id=%d', $id ) );
226
-    }
226
+	}
227 227
 
228 228
 	public static function delete_form_transient( $form_id ) {
229 229
 		$form_id = absint( $form_id );
@@ -237,11 +237,11 @@  discard block
 block discarded – undo
237 237
 
238 238
 		FrmAppHelper::cache_delete_group( 'frm_field' );
239 239
 
240
-        $form = FrmForm::getOne($form_id);
241
-        if ( $form && $form->parent_form_id ) {
242
-            self::delete_form_transient( $form->parent_form_id );
243
-        }
244
-    }
240
+		$form = FrmForm::getOne($form_id);
241
+		if ( $form && $form->parent_form_id ) {
242
+			self::delete_form_transient( $form->parent_form_id );
243
+		}
244
+	}
245 245
 
246 246
 	/**
247 247
 	 * If $field is numeric, get the field object
@@ -257,131 +257,131 @@  discard block
 block discarded – undo
257 257
 			return;
258 258
 		}
259 259
 
260
-        global $wpdb;
260
+		global $wpdb;
261 261
 
262
-        $where = is_numeric($id) ? 'id=%d' : 'field_key=%s';
262
+		$where = is_numeric($id) ? 'id=%d' : 'field_key=%s';
263 263
 		$query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id );
264 264
 
265
-        $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
265
+		$results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
266 266
 
267
-        if ( empty($results) ) {
268
-            return $results;
269
-        }
267
+		if ( empty($results) ) {
268
+			return $results;
269
+		}
270 270
 
271
-        if ( is_numeric($id) ) {
271
+		if ( is_numeric($id) ) {
272 272
 			FrmAppHelper::set_cache( $results->field_key, $results, 'frm_field' );
273
-        } else if ( $results ) {
273
+		} else if ( $results ) {
274 274
 			FrmAppHelper::set_cache( $results->id, $results, 'frm_field' );
275
-        }
275
+		}
276 276
 
277 277
 		self::prepare_options( $results );
278 278
 
279
-        return stripslashes_deep($results);
280
-    }
279
+		return stripslashes_deep($results);
280
+	}
281 281
 
282
-    /**
283
-     * Get the field type by key or id
284
-     * @param int|string The field id or key
282
+	/**
283
+	 * Get the field type by key or id
284
+	 * @param int|string The field id or key
285 285
 	 * @param mixed $col The name of the column in the fields database table
286
-     */
287
-    public static function &get_type( $id, $col = 'type' ) {
288
-        $field = FrmAppHelper::check_cache( $id, 'frm_field' );
289
-        if ( $field ) {
290
-            $type = $field->{$col};
291
-        } else {
292
-            $type = FrmDb::get_var( 'frm_fields', array( 'or' => 1, 'id' => $id, 'field_key' => $id ), $col );
293
-        }
294
-
295
-        return $type;
296
-    }
286
+	 */
287
+	public static function &get_type( $id, $col = 'type' ) {
288
+		$field = FrmAppHelper::check_cache( $id, 'frm_field' );
289
+		if ( $field ) {
290
+			$type = $field->{$col};
291
+		} else {
292
+			$type = FrmDb::get_var( 'frm_fields', array( 'or' => 1, 'id' => $id, 'field_key' => $id ), $col );
293
+		}
294
+
295
+		return $type;
296
+	}
297 297
 
298 298
 	public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) {
299
-        if ( ! $form_id ) {
300
-            return array();
301
-        }
299
+		if ( ! $form_id ) {
300
+			return array();
301
+		}
302 302
 
303 303
 		$results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_sub, 'inc_repeat' => $inc_sub ) );
304 304
 		if ( ! empty( $results ) ) {
305
-            $fields = array();
306
-            $count = 0;
307
-            foreach ( $results as $result ) {
308
-                if ( $type != $result->type ) {
309
-                    continue;
310
-                }
305
+			$fields = array();
306
+			$count = 0;
307
+			foreach ( $results as $result ) {
308
+				if ( $type != $result->type ) {
309
+					continue;
310
+				}
311 311
 
312 312
 				$fields[ $result->id ] = $result;
313
-                $count++;
314
-                if ( $limit == 1 ) {
315
-                    $fields = $result;
316
-                    break;
317
-                }
313
+				$count++;
314
+				if ( $limit == 1 ) {
315
+					$fields = $result;
316
+					break;
317
+				}
318 318
 
319
-                if ( ! empty($limit) && $count >= $limit ) {
320
-                    break;
321
-                }
319
+				if ( ! empty($limit) && $count >= $limit ) {
320
+					break;
321
+				}
322 322
 
323
-                unset($result);
324
-            }
325
-            return stripslashes_deep($fields);
326
-        }
323
+				unset($result);
324
+			}
325
+			return stripslashes_deep($fields);
326
+		}
327 327
 
328
-        self::$use_cache = false;
328
+		self::$use_cache = false;
329 329
 
330 330
 		$where = array( 'fi.form_id' => (int) $form_id, 'fi.type' => $type );
331 331
 		self::maybe_include_repeating_fields( $inc_sub, $where );
332 332
 		$results = self::getAll( $where, 'field_order', $limit );
333
-        self::$use_cache = true;
334
-        self::include_sub_fields($results, $inc_sub, $type);
333
+		self::$use_cache = true;
334
+		self::include_sub_fields($results, $inc_sub, $type);
335 335
 
336
-        return $results;
337
-    }
336
+		return $results;
337
+	}
338 338
 
339 339
 	public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) {
340
-        if ( ! (int) $form_id ) {
341
-            return array();
342
-        }
340
+		if ( ! (int) $form_id ) {
341
+			return array();
342
+		}
343 343
 
344 344
 		$results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) );
345 345
 		if ( ! empty( $results ) ) {
346
-            if ( empty($limit) ) {
346
+			if ( empty($limit) ) {
347 347
 				return $results;
348
-            }
348
+			}
349 349
 
350
-            $fields = array();
351
-            $count = 0;
352
-            foreach ( $results as $result ) {
350
+			$fields = array();
351
+			$count = 0;
352
+			foreach ( $results as $result ) {
353 353
 				$fields[ $result->id ] = $result;
354
-                if ( ! empty($limit) && $count >= $limit ) {
355
-                    break;
356
-                }
357
-            }
354
+				if ( ! empty($limit) && $count >= $limit ) {
355
+					break;
356
+				}
357
+			}
358 358
 
359 359
 			return $fields;
360
-        }
360
+		}
361 361
 
362
-        self::$use_cache = false;
362
+		self::$use_cache = false;
363 363
 
364 364
 		$where = array( 'fi.form_id' => absint( $form_id ) );
365 365
 		self::maybe_include_repeating_fields( $inc_repeat, $where );
366 366
 		$results = self::getAll( $where, 'field_order', $limit );
367 367
 
368
-        self::$use_cache = true;
368
+		self::$use_cache = true;
369 369
 
370 370
 		self::include_sub_fields( $results, $inc_embed, 'all' );
371 371
 
372
-        if ( empty($limit) ) {
372
+		if ( empty($limit) ) {
373 373
 			self::set_field_transient( $results, $form_id, 0, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) );
374
-        }
374
+		}
375 375
 
376 376
 		return $results;
377
-    }
377
+	}
378 378
 
379 379
 	/**
380
-	* If repeating fields should be included, adjust $where accordingly
381
-	*
382
-	* @param string $inc_repeat
383
-	* @param array $where - pass by reference
384
-	*/
380
+	 * If repeating fields should be included, adjust $where accordingly
381
+	 *
382
+	 * @param string $inc_repeat
383
+	 * @param array $where - pass by reference
384
+	 */
385 385
 	private static function maybe_include_repeating_fields( $inc_repeat, &$where ) {
386 386
 		if ( $inc_repeat == 'include' ) {
387 387
 			$form_id = $where['fi.form_id'];
@@ -392,77 +392,77 @@  discard block
 block discarded – undo
392 392
 
393 393
 	public static function include_sub_fields( &$results, $inc_embed, $type = 'all' ) {
394 394
 		if ( 'include' != $inc_embed || empty( $results ) ) {
395
-            return;
396
-        }
395
+			return;
396
+		}
397 397
 
398
-        $form_fields = $results;
398
+		$form_fields = $results;
399 399
 		$index_offset = 1;
400
-        foreach ( $form_fields as $k => $field ) {
401
-            if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) {
402
-                continue;
403
-            }
404
-
405
-            if ( $type == 'all' ) {
406
-                $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
407
-            } else {
408
-                $sub_fields = self::get_all_types_in_form($field->form_id, $type);
409
-            }
410
-
411
-            if ( ! empty($sub_fields) ) {
400
+		foreach ( $form_fields as $k => $field ) {
401
+			if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) {
402
+				continue;
403
+			}
404
+
405
+			if ( $type == 'all' ) {
406
+				$sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
407
+			} else {
408
+				$sub_fields = self::get_all_types_in_form($field->form_id, $type);
409
+			}
410
+
411
+			if ( ! empty($sub_fields) ) {
412 412
 				$index = $k + $index_offset;
413 413
 				$index_offset += count( $sub_fields );
414 414
 				array_splice($results, $index, 0, $sub_fields);
415
-            }
416
-            unset($field, $sub_fields);
417
-        }
418
-    }
415
+			}
416
+			unset($field, $sub_fields);
417
+		}
418
+	}
419 419
 
420 420
 	public static function getAll( $where = array(), $order_by = '', $limit = '', $blog_id = false ) {
421 421
 		$cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id;
422
-        if ( self::$use_cache ) {
423
-            // make sure old cache doesn't get saved as a transient
424
-            $results = wp_cache_get($cache_key, 'frm_field');
425
-            if ( false !== $results ) {
426
-                return stripslashes_deep($results);
427
-            }
428
-        }
429
-
430
-        global $wpdb;
431
-
432
-        if ( $blog_id && is_multisite() ) {
433
-            global $wpmuBaseTablePrefix;
434
-            if ( $wpmuBaseTablePrefix ) {
422
+		if ( self::$use_cache ) {
423
+			// make sure old cache doesn't get saved as a transient
424
+			$results = wp_cache_get($cache_key, 'frm_field');
425
+			if ( false !== $results ) {
426
+				return stripslashes_deep($results);
427
+			}
428
+		}
429
+
430
+		global $wpdb;
431
+
432
+		if ( $blog_id && is_multisite() ) {
433
+			global $wpmuBaseTablePrefix;
434
+			if ( $wpmuBaseTablePrefix ) {
435 435
 				$prefix = $wpmuBaseTablePrefix . $blog_id . '_';
436
-            } else {
437
-                $prefix = $wpdb->get_blog_prefix( $blog_id );
438
-            }
436
+			} else {
437
+				$prefix = $wpdb->get_blog_prefix( $blog_id );
438
+			}
439 439
 
440 440
 			$table_name = $prefix . 'frm_fields';
441 441
 			$form_table_name = $prefix . 'frm_forms';
442 442
 		} else {
443 443
 			$table_name = $wpdb->prefix . 'frm_fields';
444 444
 			$form_table_name = $wpdb->prefix . 'frm_forms';
445
-        }
445
+		}
446 446
 
447 447
 		if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) {
448 448
 			$order_by = ' ORDER BY ' . $order_by;
449 449
 		}
450 450
 
451
-        $limit = FrmAppHelper::esc_limit($limit);
451
+		$limit = FrmAppHelper::esc_limit($limit);
452 452
 
453
-        $query = "SELECT fi.*, fr.name as form_name  FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
454
-        $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
453
+		$query = "SELECT fi.*, fr.name as form_name  FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
454
+		$query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
455 455
 
456
-        if ( is_array($where) ) {
457
-            $results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type );
456
+		if ( is_array($where) ) {
457
+			$results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type );
458 458
 		} else {
459 459
 			// if the query is not an array, then it has already been prepared
460
-            $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
460
+			$query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
461 461
 
462 462
 			$function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
463 463
 			$results = $wpdb->$function_name( $query );
464
-        }
465
-        unset( $where );
464
+		}
465
+		unset( $where );
466 466
 
467 467
 		self::format_field_results( $results );
468 468
 
@@ -561,21 +561,21 @@  discard block
 block discarded – undo
561 561
 
562 562
 	public static function getIds( $where = '', $order_by = '', $limit = '' ) {
563 563
 		_deprecated_function( __FUNCTION__, '2.0' );
564
-        global $wpdb;
565
-        if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) {
564
+		global $wpdb;
565
+		if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) {
566 566
 			$order_by = ' ORDER BY ' . $order_by;
567
-        }
567
+		}
568 568
 
569 569
 		$query = 'SELECT fi.id  FROM ' . $wpdb->prefix . 'frm_fields fi ' .
570 570
 			'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON fi.form_id=fr.id' .
571 571
 			FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
572 572
 
573
-        $method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col';
573
+		$method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col';
574 574
 		$cache_key = 'getIds_' . maybe_serialize( $where ) . $order_by . $limit;
575
-        $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method);
575
+		$results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method);
576 576
 
577
-        return $results;
578
-    }
577
+		return $results;
578
+	}
579 579
 
580 580
 	public static function is_no_save_field( $type ) {
581 581
 		return in_array( $type, self::no_save_fields() );
@@ -718,8 +718,8 @@  discard block
 block discarded – undo
718 718
 	}
719 719
 
720 720
 	/**
721
-	* @since 2.0.09
722
-	*/
721
+	 * @since 2.0.09
722
+	 */
723 723
 	public static function is_repeating_field( $field ) {
724 724
 		if ( is_array( $field ) ) {
725 725
 			$is_repeating_field = ( 'divider' == $field['type'] );
@@ -729,14 +729,14 @@  discard block
 block discarded – undo
729 729
 		return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) );
730 730
 	}
731 731
 
732
-    /**
733
-     * @param string $key
734
-     * @return int field id
735
-     */
732
+	/**
733
+	 * @param string $key
734
+	 * @return int field id
735
+	 */
736 736
 	public static function get_id_by_key( $key ) {
737
-        $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) );
738
-        return $id;
739
-    }
737
+		$id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) );
738
+		return $id;
739
+	}
740 740
 
741 741
 	/**
742 742
 	 * @param string $id
Please login to merge, or discard this patch.
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
2
+if ( ! defined( 'ABSPATH' ) ) {
3 3
 	die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 	static $transient_size = 200;
9 9
 
10 10
 	public static function field_selection() {
11
-		$fields = apply_filters('frm_available_fields', array(
11
+		$fields = apply_filters( 'frm_available_fields', array(
12 12
 			'text'      => __( 'Single Line Text', 'formidable' ),
13 13
 			'textarea'  => __( 'Paragraph Text', 'formidable' ),
14 14
 			'checkbox'  => __( 'Checkboxes', 'formidable' ),
@@ -17,13 +17,13 @@  discard block
 block discarded – undo
17 17
 			'email'     => __( 'Email Address', 'formidable' ),
18 18
 			'url'       => __( 'Website/URL', 'formidable' ),
19 19
 			'captcha'   => __( 'reCAPTCHA', 'formidable' ),
20
-		));
20
+		) );
21 21
 
22 22
 		return $fields;
23 23
 	}
24 24
 
25 25
 	public static function pro_field_selection() {
26
-		return apply_filters('frm_pro_available_fields', array(
26
+		return apply_filters( 'frm_pro_available_fields', array(
27 27
 			'end_divider' => array(
28 28
 				'name'  => __( 'End Section', 'formidable' ),
29 29
 				'switch_from' => 'divider',
@@ -48,36 +48,36 @@  discard block
 block discarded – undo
48 48
 			'tag'       => __( 'Tags', 'formidable' ),
49 49
 			'credit_card' => __( 'Credit Card', 'formidable' ),
50 50
 			'address'   => __( 'Address', 'formidable' ),
51
-		));
51
+		) );
52 52
 	}
53 53
 
54 54
     public static function create( $values, $return = true ) {
55 55
         global $wpdb, $frm_duplicate_ids;
56 56
 
57 57
         $new_values = array();
58
-        $key = isset($values['field_key']) ? $values['field_key'] : $values['name'];
58
+        $key = isset( $values['field_key'] ) ? $values['field_key'] : $values['name'];
59 59
 		$new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' );
60 60
 
61 61
 		foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) {
62
-			$new_values[ $col ] = $values[ $col ];
62
+			$new_values[$col] = $values[$col];
63 63
         }
64 64
 
65 65
         $new_values['options'] = $values['options'];
66 66
 
67
-        $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null;
68
-        $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0;
69
-        $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null;
67
+        $new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null;
68
+        $new_values['required'] = isset( $values['required'] ) ? (int) $values['required'] : 0;
69
+        $new_values['form_id'] = isset( $values['form_id'] ) ? (int) $values['form_id'] : null;
70 70
         $new_values['field_options'] = $values['field_options'];
71
-        $new_values['created_at'] = current_time('mysql', 1);
71
+        $new_values['created_at'] = current_time( 'mysql', 1 );
72 72
 
73 73
 		if ( isset( $values['id'] ) ) {
74
-			$frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key'];
75
-            $new_values = apply_filters('frm_duplicated_field', $new_values);
74
+			$frm_duplicate_ids[$values['field_key']] = $new_values['field_key'];
75
+            $new_values = apply_filters( 'frm_duplicated_field', $new_values );
76 76
         }
77 77
 
78 78
 		foreach ( $new_values as $k => $v ) {
79 79
             if ( is_array( $v ) ) {
80
-				$new_values[ $k ] = serialize( $v );
80
+				$new_values[$k] = serialize( $v );
81 81
 			}
82 82
             unset( $k, $v );
83 83
         }
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 
99 99
 		if ( $query_results ) {
100 100
 			if ( isset( $values['id'] ) ) {
101
-				$frm_duplicate_ids[ $values['id'] ] = $new_id;
101
+				$frm_duplicate_ids[$values['id']] = $new_id;
102 102
 			}
103 103
 			return $new_id;
104 104
 		} else {
@@ -113,9 +113,9 @@  discard block
 block discarded – undo
113 113
 		$fields = self::getAll( $where, 'field_order', '', $blog_id );
114 114
 
115 115
         foreach ( (array) $fields as $field ) {
116
-            $new_key = ($copy_keys) ? $field->field_key : '';
117
-            if ( $copy_keys && substr($field->field_key, -1) == 2 ) {
118
-                $new_key = rtrim($new_key, 2);
116
+            $new_key = ( $copy_keys ) ? $field->field_key : '';
117
+            if ( $copy_keys && substr( $field->field_key, -1 ) == 2 ) {
118
+                $new_key = rtrim( $new_key, 2 );
119 119
             }
120 120
 
121 121
             $values = array();
@@ -138,11 +138,11 @@  discard block
 block discarded – undo
138 138
 				$values['form_id'] = $new_repeat_form_id;
139 139
 			}
140 140
 
141
-            $values = apply_filters('frm_duplicated_field', $values);
142
-            $new_id = self::create($values);
143
-            $frm_duplicate_ids[ $field->id ] = $new_id;
144
-            $frm_duplicate_ids[ $field->field_key ] = $new_id;
145
-            unset($field);
141
+            $values = apply_filters( 'frm_duplicated_field', $values );
142
+            $new_id = self::create( $values );
143
+            $frm_duplicate_ids[$field->id] = $new_id;
144
+            $frm_duplicate_ids[$field->field_key] = $new_id;
145
+            unset( $field );
146 146
         }
147 147
     }
148 148
 
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 			$values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id );
156 156
 		}
157 157
 
158
-        if ( isset($values['required']) ) {
158
+        if ( isset( $values['required'] ) ) {
159 159
             $values['required'] = (int) $values['required'];
160 160
         }
161 161
 
@@ -167,8 +167,8 @@  discard block
 block discarded – undo
167 167
 
168 168
 		// serialize array values
169 169
 		foreach ( array( 'default_value', 'field_options', 'options' ) as $opt ) {
170
-			if ( isset( $values[ $opt ] ) && is_array( $values[ $opt ] ) ) {
171
-				$values[ $opt ] = serialize( $values[ $opt ] );
170
+			if ( isset( $values[$opt] ) && is_array( $values[$opt] ) ) {
171
+				$values[$opt] = serialize( $values[$opt] );
172 172
 			}
173 173
 		}
174 174
 
@@ -178,13 +178,13 @@  discard block
 block discarded – undo
178 178
 		if ( isset( $values['form_id'] ) ) {
179 179
             $form_id = absint( $values['form_id'] );
180 180
 		} else {
181
-            $field = self::getOne($id);
181
+            $field = self::getOne( $id );
182 182
             if ( $field ) {
183 183
                 $form_id = $field->form_id;
184 184
             }
185
-            unset($field);
185
+            unset( $field );
186 186
         }
187
-        unset($values);
187
+        unset( $values );
188 188
 
189 189
 		if ( $query_results ) {
190 190
             wp_cache_delete( $id, 'frm_field' );
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 
238 238
 		FrmAppHelper::cache_delete_group( 'frm_field' );
239 239
 
240
-        $form = FrmForm::getOne($form_id);
240
+        $form = FrmForm::getOne( $form_id );
241 241
         if ( $form && $form->parent_form_id ) {
242 242
             self::delete_form_transient( $form->parent_form_id );
243 243
         }
@@ -259,16 +259,16 @@  discard block
 block discarded – undo
259 259
 
260 260
         global $wpdb;
261 261
 
262
-        $where = is_numeric($id) ? 'id=%d' : 'field_key=%s';
262
+        $where = is_numeric( $id ) ? 'id=%d' : 'field_key=%s';
263 263
 		$query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id );
264 264
 
265 265
         $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
266 266
 
267
-        if ( empty($results) ) {
267
+        if ( empty( $results ) ) {
268 268
             return $results;
269 269
         }
270 270
 
271
-        if ( is_numeric($id) ) {
271
+        if ( is_numeric( $id ) ) {
272 272
 			FrmAppHelper::set_cache( $results->field_key, $results, 'frm_field' );
273 273
         } else if ( $results ) {
274 274
 			FrmAppHelper::set_cache( $results->id, $results, 'frm_field' );
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 
277 277
 		self::prepare_options( $results );
278 278
 
279
-        return stripslashes_deep($results);
279
+        return stripslashes_deep( $results );
280 280
     }
281 281
 
282 282
     /**
@@ -309,20 +309,20 @@  discard block
 block discarded – undo
309 309
                     continue;
310 310
                 }
311 311
 
312
-				$fields[ $result->id ] = $result;
313
-                $count++;
312
+				$fields[$result->id] = $result;
313
+                $count ++;
314 314
                 if ( $limit == 1 ) {
315 315
                     $fields = $result;
316 316
                     break;
317 317
                 }
318 318
 
319
-                if ( ! empty($limit) && $count >= $limit ) {
319
+                if ( ! empty( $limit ) && $count >= $limit ) {
320 320
                     break;
321 321
                 }
322 322
 
323
-                unset($result);
323
+                unset( $result );
324 324
             }
325
-            return stripslashes_deep($fields);
325
+            return stripslashes_deep( $fields );
326 326
         }
327 327
 
328 328
         self::$use_cache = false;
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 		self::maybe_include_repeating_fields( $inc_sub, $where );
332 332
 		$results = self::getAll( $where, 'field_order', $limit );
333 333
         self::$use_cache = true;
334
-        self::include_sub_fields($results, $inc_sub, $type);
334
+        self::include_sub_fields( $results, $inc_sub, $type );
335 335
 
336 336
         return $results;
337 337
     }
@@ -343,15 +343,15 @@  discard block
 block discarded – undo
343 343
 
344 344
 		$results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) );
345 345
 		if ( ! empty( $results ) ) {
346
-            if ( empty($limit) ) {
346
+            if ( empty( $limit ) ) {
347 347
 				return $results;
348 348
             }
349 349
 
350 350
             $fields = array();
351 351
             $count = 0;
352 352
             foreach ( $results as $result ) {
353
-				$fields[ $result->id ] = $result;
354
-                if ( ! empty($limit) && $count >= $limit ) {
353
+				$fields[$result->id] = $result;
354
+                if ( ! empty( $limit ) && $count >= $limit ) {
355 355
                     break;
356 356
                 }
357 357
             }
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
 
370 370
 		self::include_sub_fields( $results, $inc_embed, 'all' );
371 371
 
372
-        if ( empty($limit) ) {
372
+        if ( empty( $limit ) ) {
373 373
 			self::set_field_transient( $results, $form_id, 0, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) );
374 374
         }
375 375
 
@@ -398,22 +398,22 @@  discard block
 block discarded – undo
398 398
         $form_fields = $results;
399 399
 		$index_offset = 1;
400 400
         foreach ( $form_fields as $k => $field ) {
401
-            if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) {
401
+            if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) {
402 402
                 continue;
403 403
             }
404 404
 
405 405
             if ( $type == 'all' ) {
406 406
                 $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
407 407
             } else {
408
-                $sub_fields = self::get_all_types_in_form($field->form_id, $type);
408
+                $sub_fields = self::get_all_types_in_form( $field->form_id, $type );
409 409
             }
410 410
 
411
-            if ( ! empty($sub_fields) ) {
411
+            if ( ! empty( $sub_fields ) ) {
412 412
 				$index = $k + $index_offset;
413 413
 				$index_offset += count( $sub_fields );
414
-				array_splice($results, $index, 0, $sub_fields);
414
+				array_splice( $results, $index, 0, $sub_fields );
415 415
             }
416
-            unset($field, $sub_fields);
416
+            unset( $field, $sub_fields );
417 417
         }
418 418
     }
419 419
 
@@ -421,9 +421,9 @@  discard block
 block discarded – undo
421 421
 		$cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id;
422 422
         if ( self::$use_cache ) {
423 423
             // make sure old cache doesn't get saved as a transient
424
-            $results = wp_cache_get($cache_key, 'frm_field');
424
+            $results = wp_cache_get( $cache_key, 'frm_field' );
425 425
             if ( false !== $results ) {
426
-                return stripslashes_deep($results);
426
+                return stripslashes_deep( $results );
427 427
             }
428 428
         }
429 429
 
@@ -448,16 +448,16 @@  discard block
 block discarded – undo
448 448
 			$order_by = ' ORDER BY ' . $order_by;
449 449
 		}
450 450
 
451
-        $limit = FrmAppHelper::esc_limit($limit);
451
+        $limit = FrmAppHelper::esc_limit( $limit );
452 452
 
453 453
         $query = "SELECT fi.*, fr.name as form_name  FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
454 454
         $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
455 455
 
456
-        if ( is_array($where) ) {
456
+        if ( is_array( $where ) ) {
457 457
             $results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type );
458 458
 		} else {
459 459
 			// if the query is not an array, then it has already been prepared
460
-            $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
460
+            $query .= FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
461 461
 
462 462
 			$function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
463 463
 			$results = $wpdb->$function_name( $query );
@@ -480,9 +480,9 @@  discard block
 block discarded – undo
480 480
 				FrmAppHelper::set_cache( $result->id, $result, 'frm_field' );
481 481
 				FrmAppHelper::set_cache( $result->field_key, $result, 'frm_field' );
482 482
 
483
-				$results[ $r_key ]->field_options = maybe_unserialize( $result->field_options );
484
-				$results[ $r_key ]->options = maybe_unserialize( $result->options );
485
-				$results[ $r_key ]->default_value = maybe_unserialize( $result->default_value );
483
+				$results[$r_key]->field_options = maybe_unserialize( $result->field_options );
484
+				$results[$r_key]->options = maybe_unserialize( $result->options );
485
+				$results[$r_key]->default_value = maybe_unserialize( $result->default_value );
486 486
 
487 487
 				unset( $r_key, $result );
488 488
 			}
@@ -501,8 +501,8 @@  discard block
 block discarded – undo
501 501
 	private static function prepare_options( &$results ) {
502 502
 		$results->field_options = maybe_unserialize( $results->field_options );
503 503
 
504
-		$results->options = maybe_unserialize($results->options);
505
-		$results->default_value = maybe_unserialize($results->default_value);
504
+		$results->options = maybe_unserialize( $results->options );
505
+		$results->default_value = maybe_unserialize( $results->default_value );
506 506
 	}
507 507
 
508 508
 	/**
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
 
530 530
 			if ( count( $next_fields ) >= self::$transient_size ) {
531 531
 				// if this transient is full, check for another
532
-				$next++;
532
+				$next ++;
533 533
 				self::get_next_transient( $fields, $base_name, $next );
534 534
 			}
535 535
 		}
@@ -555,14 +555,14 @@  discard block
 block discarded – undo
555 555
 				return;
556 556
 			}
557 557
 
558
-			$next++;
558
+			$next ++;
559 559
 		}
560 560
 	}
561 561
 
562 562
 	public static function getIds( $where = '', $order_by = '', $limit = '' ) {
563 563
 		_deprecated_function( __FUNCTION__, '2.0' );
564 564
         global $wpdb;
565
-        if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) {
565
+        if ( ! empty( $order_by ) && ! strpos( $order_by, 'ORDER BY' ) !== false ) {
566 566
 			$order_by = ' ORDER BY ' . $order_by;
567 567
         }
568 568
 
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
 
573 573
         $method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col';
574 574
 		$cache_key = 'getIds_' . maybe_serialize( $where ) . $order_by . $limit;
575
-        $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method);
575
+        $results = FrmAppHelper::check_cache( $cache_key, 'frm_field', $query, $method );
576 576
 
577 577
         return $results;
578 578
     }
@@ -603,8 +603,8 @@  discard block
 block discarded – undo
603 603
 			$is_multi_value_field = (
604 604
 				$field['type'] == 'checkbox' ||
605 605
 				$field['type'] == 'address' ||
606
-				( $field['type'] == 'data' && isset($field['data_type']) && $field['data_type'] == 'checkbox' ) ||
607
-				( $field['type'] == 'lookup' && isset($field['data_type']) && $field['data_type'] == 'checkbox' ) ||
606
+				( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'checkbox' ) ||
607
+				( $field['type'] == 'lookup' && isset( $field['data_type'] ) && $field['data_type'] == 'checkbox' ) ||
608 608
 				self::is_multiple_select( $field )
609 609
 			);
610 610
 
@@ -629,9 +629,9 @@  discard block
 block discarded – undo
629 629
 	 */
630 630
 	public static function is_multiple_select( $field ) {
631 631
 		if ( is_array( $field ) ) {
632
-			return self::is_option_true( $field, 'multiple' ) && ( ( $field['type'] == 'select' || ( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'select') ) );
632
+			return self::is_option_true( $field, 'multiple' ) && ( ( $field['type'] == 'select' || ( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'select' ) ) );
633 633
 		} else {
634
-			return self::is_option_true( $field, 'multiple' ) && ( ( $field->type == 'select' || ( $field->type == 'data' && isset($field->field_options['data_type'] ) && $field->field_options['data_type'] == 'select') ) );
634
+			return self::is_option_true( $field, 'multiple' ) && ( ( $field->type == 'select' || ( $field->type == 'data' && isset( $field->field_options['data_type'] ) && $field->field_options['data_type'] == 'select' ) ) );
635 635
 		}
636 636
 	}
637 637
 
@@ -678,23 +678,23 @@  discard block
 block discarded – undo
678 678
 	}
679 679
 
680 680
 	public static function is_option_true_in_array( $field, $option ) {
681
-		return isset( $field[ $option ] ) && $field[ $option ];
681
+		return isset( $field[$option] ) && $field[$option];
682 682
 	}
683 683
 
684 684
 	public static function is_option_true_in_object( $field, $option ) {
685
-		return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ];
685
+		return isset( $field->field_options[$option] ) && $field->field_options[$option];
686 686
 	}
687 687
 
688 688
 	public static function is_option_empty_in_array( $field, $option ) {
689
-		return ! isset( $field[ $option ] ) || empty( $field[ $option ] );
689
+		return ! isset( $field[$option] ) || empty( $field[$option] );
690 690
 	}
691 691
 
692 692
 	public static function is_option_empty_in_object( $field, $option ) {
693
-		return ! isset( $field->field_options[ $option ] ) || empty( $field->field_options[ $option ] );
693
+		return ! isset( $field->field_options[$option] ) || empty( $field->field_options[$option] );
694 694
 	}
695 695
 
696 696
 	public static function is_option_value_in_object( $field, $option ) {
697
-		return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != '';
697
+		return isset( $field->field_options[$option] ) && $field->field_options[$option] != '';
698 698
 	}
699 699
 
700 700
 	/**
@@ -710,11 +710,11 @@  discard block
 block discarded – undo
710 710
 	}
711 711
 
712 712
 	public static function get_option_in_array( $field, $option ) {
713
-		return $field[ $option ];
713
+		return $field[$option];
714 714
 	}
715 715
 
716 716
 	public static function get_option_in_object( $field, $option ) {
717
-		return isset( $field->field_options[ $option ] ) ? $field->field_options[ $option ] : '';
717
+		return isset( $field->field_options[$option] ) ? $field->field_options[$option] : '';
718 718
 	}
719 719
 
720 720
 	/**
Please login to merge, or discard this patch.
classes/models/FrmEntry.php 2 patches
Indentation   +376 added lines, -376 removed lines patch added patch discarded remove patch
@@ -6,11 +6,11 @@  discard block
 block discarded – undo
6 6
 class FrmEntry {
7 7
 
8 8
 	/**
9
-	* Create a new entry
10
-	*
11
-	* @param array $values
12
-	* @return int | boolean $entry_id
13
-	*/
9
+	 * Create a new entry
10
+	 *
11
+	 * @param array $values
12
+	 * @return int | boolean $entry_id
13
+	 */
14 14
 	public static function create( $values ) {
15 15
 		$entry_id = self::create_entry( $values, 'standard' );
16 16
 
@@ -18,12 +18,12 @@  discard block
 block discarded – undo
18 18
 	}
19 19
 
20 20
 	/**
21
-	* Create a new entry with some differences depending on type
22
-	*
23
-	* @param array $values
24
-	* @param string $type
25
-	* @return int | boolean $entry_id
26
-	*/
21
+	 * Create a new entry with some differences depending on type
22
+	 *
23
+	 * @param array $values
24
+	 * @param string $type
25
+	 * @return int | boolean $entry_id
26
+	 */
27 27
 	private static function create_entry( $values, $type ) {
28 28
 		$new_values = self::before_insert_entry_in_database( $values, $type );
29 29
 
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
 		return $entry_id;
38 38
 	}
39 39
 
40
-    /**
41
-     * check for duplicate entries created in the last minute
42
-     * @return boolean
43
-     */
40
+	/**
41
+	 * check for duplicate entries created in the last minute
42
+	 * @return boolean
43
+	 */
44 44
 	public static function is_duplicate( $new_values, $values ) {
45 45
 		$duplicate_entry_time = apply_filters( 'frm_time_to_check_duplicates', 60, $new_values );
46 46
 
@@ -48,55 +48,55 @@  discard block
 block discarded – undo
48 48
 			return false;
49 49
 		}
50 50
 
51
-        $check_val = $new_values;
51
+		$check_val = $new_values;
52 52
 		$check_val['created_at >'] = date( 'Y-m-d H:i:s', ( strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) ) );
53 53
 
54 54
 		unset( $check_val['created_at'], $check_val['updated_at'] );
55 55
 		unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] );
56 56
 
57
-        if ( $new_values['item_key'] == $new_values['name'] ) {
58
-            unset($check_val['name']);
59
-        }
57
+		if ( $new_values['item_key'] == $new_values['name'] ) {
58
+			unset($check_val['name']);
59
+		}
60 60
 
61
-        global $wpdb;
61
+		global $wpdb;
62 62
 		$entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) );
63 63
 
64
-        if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) {
65
-            return false;
66
-        }
64
+		if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) {
65
+			return false;
66
+		}
67 67
 
68
-        $is_duplicate = false;
69
-        foreach ( $entry_exists as $entry_exist ) {
70
-            $is_duplicate = true;
68
+		$is_duplicate = false;
69
+		foreach ( $entry_exists as $entry_exist ) {
70
+			$is_duplicate = true;
71 71
 
72
-            //add more checks here to make sure it's a duplicate
73
-            $metas = FrmEntryMeta::get_entry_meta_info($entry_exist);
74
-            $field_metas = array();
75
-            foreach ( $metas as $meta ) {
72
+			//add more checks here to make sure it's a duplicate
73
+			$metas = FrmEntryMeta::get_entry_meta_info($entry_exist);
74
+			$field_metas = array();
75
+			foreach ( $metas as $meta ) {
76 76
 				$field_metas[ $meta->field_id ] = $meta->meta_value;
77
-            }
78
-
79
-            // If prev entry is empty and current entry is not, they are not duplicates
80
-            $filtered_vals = array_filter( $values['item_meta'] );
81
-            if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) {
82
-                return false;
83
-            }
84
-
85
-            $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta']));
86
-            foreach ( $diff as $field_id => $meta_value ) {
87
-                if ( ! empty($meta_value) ) {
88
-                    $is_duplicate = false;
89
-                    continue;
90
-                }
91
-            }
92
-
93
-            if ( $is_duplicate ) {
77
+			}
78
+
79
+			// If prev entry is empty and current entry is not, they are not duplicates
80
+			$filtered_vals = array_filter( $values['item_meta'] );
81
+			if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) {
82
+				return false;
83
+			}
84
+
85
+			$diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta']));
86
+			foreach ( $diff as $field_id => $meta_value ) {
87
+				if ( ! empty($meta_value) ) {
88
+					$is_duplicate = false;
89
+					continue;
90
+				}
91
+			}
92
+
93
+			if ( $is_duplicate ) {
94 94
 				break;
95
-            }
96
-        }
95
+			}
96
+		}
97 97
 
98
-        return $is_duplicate;
99
-    }
98
+		return $is_duplicate;
99
+	}
100 100
 
101 101
 	/**
102 102
 	 * Determine if an entry needs to be checked as a possible duplicate
@@ -125,46 +125,46 @@  discard block
 block discarded – undo
125 125
 		return true;
126 126
 	}
127 127
 
128
-    public static function duplicate( $id ) {
129
-        global $wpdb;
128
+	public static function duplicate( $id ) {
129
+		global $wpdb;
130 130
 
131
-        $values = self::getOne( $id );
131
+		$values = self::getOne( $id );
132 132
 
133
-        $new_values = array();
133
+		$new_values = array();
134 134
 		$new_values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' );
135
-        $new_values['name'] = $values->name;
136
-        $new_values['is_draft'] = $values->is_draft;
137
-        $new_values['user_id'] = $new_values['updated_by'] = (int) $values->user_id;
138
-        $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null;
139
-        $new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1);
135
+		$new_values['name'] = $values->name;
136
+		$new_values['is_draft'] = $values->is_draft;
137
+		$new_values['user_id'] = $new_values['updated_by'] = (int) $values->user_id;
138
+		$new_values['form_id'] = $values->form_id ? (int) $values->form_id: null;
139
+		$new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1);
140 140
 
141 141
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values );
142
-        if ( ! $query_results ) {
143
-            return false;
144
-        }
142
+		if ( ! $query_results ) {
143
+			return false;
144
+		}
145 145
 
146
-        $entry_id = $wpdb->insert_id;
146
+		$entry_id = $wpdb->insert_id;
147 147
 
148
-        global $frm_vars;
149
-        if ( ! isset($frm_vars['saved_entries']) ) {
150
-            $frm_vars['saved_entries'] = array();
151
-        }
152
-        $frm_vars['saved_entries'][] = (int) $entry_id;
148
+		global $frm_vars;
149
+		if ( ! isset($frm_vars['saved_entries']) ) {
150
+			$frm_vars['saved_entries'] = array();
151
+		}
152
+		$frm_vars['saved_entries'][] = (int) $entry_id;
153 153
 
154
-        FrmEntryMeta::duplicate_entry_metas($id, $entry_id);
154
+		FrmEntryMeta::duplicate_entry_metas($id, $entry_id);
155 155
 		self::clear_cache();
156 156
 
157 157
 		do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) );
158
-        return $entry_id;
159
-    }
158
+		return $entry_id;
159
+	}
160 160
 
161 161
 	/**
162
-	* Update an entry (not via XML)
163
-	*
164
-	* @param int $id
165
-	* @param array $values
166
-	* @return boolean|int $update_results
167
-	*/
162
+	 * Update an entry (not via XML)
163
+	 *
164
+	 * @param int $id
165
+	 * @param array $values
166
+	 * @return boolean|int $update_results
167
+	 */
168 168
 	public static function update( $id, $values ) {
169 169
 		$update_results = self::update_entry( $id, $values, 'standard' );
170 170
 
@@ -172,14 +172,14 @@  discard block
 block discarded – undo
172 172
 	}
173 173
 
174 174
 	/**
175
-	* Update an entry with some differences depending on the update type
176
-	*
177
-	* @since 2.0.16
178
-	*
179
-	* @param int $id
180
-	* @param array $values
181
-	* @return boolean|int $query_results
182
-	*/
175
+	 * Update an entry with some differences depending on the update type
176
+	 *
177
+	 * @since 2.0.16
178
+	 *
179
+	 * @param int $id
180
+	 * @param array $values
181
+	 * @return boolean|int $query_results
182
+	 */
183 183
 	private static function update_entry( $id, $values, $update_type ) {
184 184
 		global $wpdb;
185 185
 
@@ -198,34 +198,34 @@  discard block
 block discarded – undo
198 198
 	}
199 199
 
200 200
 	public static function &destroy( $id ) {
201
-        global $wpdb;
202
-        $id = (int) $id;
201
+		global $wpdb;
202
+		$id = (int) $id;
203 203
 
204 204
 		$entry = self::getOne( $id );
205
-        if ( ! $entry ) {
206
-            $result = false;
207
-            return $result;
208
-        }
205
+		if ( ! $entry ) {
206
+			$result = false;
207
+			return $result;
208
+		}
209 209
 
210
-        do_action('frm_before_destroy_entry', $id, $entry);
210
+		do_action('frm_before_destroy_entry', $id, $entry);
211 211
 
212 212
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE item_id=%d', $id ) );
213 213
 		$result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) );
214 214
 
215 215
 		self::clear_cache();
216 216
 
217
-        return $result;
218
-    }
217
+		return $result;
218
+	}
219 219
 
220 220
 	public static function &update_form( $id, $value, $form_id ) {
221
-        global $wpdb;
222
-        $form_id = isset($value) ? $form_id : null;
221
+		global $wpdb;
222
+		$form_id = isset($value) ? $form_id : null;
223 223
 		$result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) );
224 224
 		if ( $result ) {
225 225
 			self::clear_cache();
226 226
 		}
227
-        return $result;
228
-    }
227
+		return $result;
228
+	}
229 229
 
230 230
 	/**
231 231
 	 * Clear entry caching
@@ -261,159 +261,159 @@  discard block
 block discarded – undo
261 261
 	}
262 262
 
263 263
 	public static function getOne( $id, $meta = false ) {
264
-        global $wpdb;
264
+		global $wpdb;
265 265
 
266
-        $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
266
+		$query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
267 267
                   LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
268 268
 
269
-        $query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s';
270
-        $query_args = array( $id );
271
-        $query = $wpdb->prepare( $query, $query_args );
269
+		$query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s';
270
+		$query_args = array( $id );
271
+		$query = $wpdb->prepare( $query, $query_args );
272 272
 
273
-        if ( ! $meta ) {
273
+		if ( ! $meta ) {
274 274
 			$entry = FrmAppHelper::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' );
275
-            return stripslashes_deep($entry);
276
-        }
275
+			return stripslashes_deep($entry);
276
+		}
277 277
 
278
-        $entry = FrmAppHelper::check_cache( $id, 'frm_entry' );
279
-        if ( $entry !== false ) {
280
-            return stripslashes_deep($entry);
281
-        }
278
+		$entry = FrmAppHelper::check_cache( $id, 'frm_entry' );
279
+		if ( $entry !== false ) {
280
+			return stripslashes_deep($entry);
281
+		}
282 282
 
283
-        $entry = $wpdb->get_row( $query );
284
-        $entry = self::get_meta($entry);
283
+		$entry = $wpdb->get_row( $query );
284
+		$entry = self::get_meta($entry);
285 285
 
286
-        return stripslashes_deep($entry);
287
-    }
286
+		return stripslashes_deep($entry);
287
+	}
288 288
 
289 289
 	public static function get_meta( $entry ) {
290
-        if ( ! $entry ) {
291
-            return $entry;
292
-        }
290
+		if ( ! $entry ) {
291
+			return $entry;
292
+		}
293 293
 
294
-        global $wpdb;
294
+		global $wpdb;
295 295
 		$metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_fields f ON m.field_id=f.id', array( 'item_id' => $entry->id, 'field_id !' => 0 ), 'field_id, meta_value, field_key, item_id' );
296 296
 
297
-        $entry->metas = array();
297
+		$entry->metas = array();
298 298
 
299 299
 		$include_key = apply_filters( 'frm_include_meta_keys', false, array( 'form_id' => $entry->form_id ) );
300
-        foreach ( $metas as $meta_val ) {
301
-            if ( $meta_val->item_id == $entry->id ) {
300
+		foreach ( $metas as $meta_val ) {
301
+			if ( $meta_val->item_id == $entry->id ) {
302 302
 				$entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
303 303
 				if ( $include_key ) {
304 304
 					$entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ];
305 305
 				}
306
-                 continue;
307
-            }
306
+				 continue;
307
+			}
308 308
 
309
-            // include sub entries in an array
309
+			// include sub entries in an array
310 310
 			if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) {
311 311
 				$entry->metas[ $meta_val->field_id ] = array();
312
-            }
312
+			}
313 313
 
314 314
 			$entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value );
315 315
 
316
-            unset($meta_val);
317
-        }
318
-        unset($metas);
316
+			unset($meta_val);
317
+		}
318
+		unset($metas);
319 319
 
320 320
 		FrmAppHelper::set_cache( $entry->id, $entry, 'frm_entry' );
321 321
 
322
-        return $entry;
323
-    }
322
+		return $entry;
323
+	}
324 324
 
325
-    /**
326
-     * @param string $id
327
-     */
325
+	/**
326
+	 * @param string $id
327
+	 */
328 328
 	public static function &exists( $id ) {
329
-        global $wpdb;
330
-
331
-        if ( FrmAppHelper::check_cache( $id, 'frm_entry' ) ) {
332
-            $exists = true;
333
-            return $exists;
334
-        }
335
-
336
-        if ( is_numeric($id) ) {
337
-            $where = array( 'id' => $id );
338
-        } else {
339
-            $where = array( 'item_key' => $id );
340
-        }
329
+		global $wpdb;
330
+
331
+		if ( FrmAppHelper::check_cache( $id, 'frm_entry' ) ) {
332
+			$exists = true;
333
+			return $exists;
334
+		}
335
+
336
+		if ( is_numeric($id) ) {
337
+			$where = array( 'id' => $id );
338
+		} else {
339
+			$where = array( 'item_key' => $id );
340
+		}
341 341
 		$id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where );
342 342
 
343
-        $exists = ($id && $id > 0) ? true : false;
344
-        return $exists;
345
-    }
343
+		$exists = ($id && $id > 0) ? true : false;
344
+		return $exists;
345
+	}
346 346
 
347
-    public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
347
+	public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
348 348
 		global $wpdb;
349 349
 
350
-        $limit = FrmAppHelper::esc_limit($limit);
350
+		$limit = FrmAppHelper::esc_limit($limit);
351 351
 
352
-        $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form;
353
-        $entries = wp_cache_get($cache_key, 'frm_entry');
352
+		$cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form;
353
+		$entries = wp_cache_get($cache_key, 'frm_entry');
354 354
 
355
-        if ( false === $entries ) {
356
-            $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft';
355
+		if ( false === $entries ) {
356
+			$fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft';
357 357
 			$table = $wpdb->prefix . 'frm_items it ';
358 358
 
359
-            if ( $inc_form ) {
360
-                $fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
361
-                $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
362
-            }
359
+			if ( $inc_form ) {
360
+				$fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
361
+				$table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
362
+			}
363 363
 
364
-            if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
365
-    		    // sort by a requested field
366
-                $field_id = (int) $order_matches[1];
364
+			if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
365
+				// sort by a requested field
366
+				$field_id = (int) $order_matches[1];
367 367
 				$fields .= ', (SELECT meta_value FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id = ' . $field_id . ' AND item_id = it.id) as meta_' . $field_id;
368 368
 				unset( $order_matches, $field_id );
369
-		    }
369
+			}
370 370
 
371 371
 			// prepare the query
372 372
 			$query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
373 373
 
374
-            $entries = $wpdb->get_results($query, OBJECT_K);
375
-            unset($query);
374
+			$entries = $wpdb->get_results($query, OBJECT_K);
375
+			unset($query);
376 376
 
377 377
 			FrmAppHelper::set_cache( $cache_key, $entries, 'frm_entry' );
378
-        }
378
+		}
379 379
 
380
-        if ( ! $meta || ! $entries ) {
381
-            return stripslashes_deep($entries);
382
-        }
383
-        unset($meta);
380
+		if ( ! $meta || ! $entries ) {
381
+			return stripslashes_deep($entries);
382
+		}
383
+		unset($meta);
384 384
 
385
-        if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) {
385
+		if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) {
386 386
 			$where = array( 'it.form_id' => substr( $where, 11 ) );
387
-        }
387
+		}
388 388
 
389
-        $meta_where = array( 'field_id !' => 0 );
390
-        if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) {
391
-            $meta_where['fi.form_id'] = $where['it.form_id'];
392
-        } else {
393
-            $meta_where['item_id'] = array_keys( $entries );
394
-        }
389
+		$meta_where = array( 'field_id !' => 0 );
390
+		if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) {
391
+			$meta_where['fi.form_id'] = $where['it.form_id'];
392
+		} else {
393
+			$meta_where['item_id'] = array_keys( $entries );
394
+		}
395 395
 
396
-        $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' );
396
+		$metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' );
397 397
 
398
-        unset( $meta_where );
398
+		unset( $meta_where );
399 399
 
400
-        if ( ! $metas ) {
401
-            return stripslashes_deep($entries);
402
-        }
400
+		if ( ! $metas ) {
401
+			return stripslashes_deep($entries);
402
+		}
403 403
 
404
-        foreach ( $metas as $m_key => $meta_val ) {
405
-            if ( ! isset( $entries[ $meta_val->item_id ] ) ) {
406
-                continue;
407
-            }
404
+		foreach ( $metas as $m_key => $meta_val ) {
405
+			if ( ! isset( $entries[ $meta_val->item_id ] ) ) {
406
+				continue;
407
+			}
408 408
 
409
-            if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
409
+			if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
410 410
 				$entries[ $meta_val->item_id ]->metas = array();
411
-            }
411
+			}
412 412
 
413 413
 			$entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
414 414
 
415
-            unset($m_key, $meta_val);
416
-        }
415
+			unset($m_key, $meta_val);
416
+		}
417 417
 
418 418
 		if ( ! FrmAppHelper::prevent_caching() ) {
419 419
 			foreach ( $entries as $entry ) {
@@ -422,31 +422,31 @@  discard block
 block discarded – undo
422 422
 			}
423 423
 		}
424 424
 
425
-        return stripslashes_deep($entries);
426
-    }
425
+		return stripslashes_deep($entries);
426
+	}
427 427
 
428
-    // Pagination Methods
429
-    public static function getRecordCount( $where = '' ) {
430
-        global $wpdb;
428
+	// Pagination Methods
429
+	public static function getRecordCount( $where = '' ) {
430
+		global $wpdb;
431 431
 		$table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
432 432
 
433
-        if ( is_numeric($where) ) {
434
-            $table_join = 'frm_items';
435
-            $where = array( 'form_id' => $where );
436
-        }
433
+		if ( is_numeric($where) ) {
434
+			$table_join = 'frm_items';
435
+			$where = array( 'form_id' => $where );
436
+		}
437 437
 
438
-        if ( is_array( $where ) ) {
439
-            $count = FrmDb::get_count( $table_join, $where );
440
-        } else {
438
+		if ( is_array( $where ) ) {
439
+			$count = FrmDb::get_count( $table_join, $where );
440
+		} else {
441 441
 			$cache_key = 'count_' . maybe_serialize( $where );
442 442
 			$query = 'SELECT COUNT(*) FROM ' . $table_join . FrmAppHelper::prepend_and_or_where( ' WHERE ', $where );
443 443
 			$count = FrmAppHelper::check_cache( $cache_key, 'frm_entry', $query, 'get_var' );
444
-        }
444
+		}
445 445
 
446
-        return $count;
447
-    }
446
+		return $count;
447
+	}
448 448
 
449
-    public static function getPageCount( $p_size, $where = '' ) {
449
+	public static function getPageCount( $p_size, $where = '' ) {
450 450
 		$p_size = (int) $p_size;
451 451
 		$count = 1;
452 452
 		if ( $p_size ) {
@@ -457,16 +457,16 @@  discard block
 block discarded – undo
457 457
 		}
458 458
 
459 459
 		return $count;
460
-    }
460
+	}
461 461
 
462 462
 	/**
463
-	* Prepare the data before inserting it into the database
464
-	*
465
-	* @since 2.0.16
466
-	* @param array $values
467
-	* @param string $type
468
-	* @return array $new_values
469
-	*/
463
+	 * Prepare the data before inserting it into the database
464
+	 *
465
+	 * @since 2.0.16
466
+	 * @param array $values
467
+	 * @param string $type
468
+	 * @return array $new_values
469
+	 */
470 470
 	private static function before_insert_entry_in_database( &$values, $type ) {
471 471
 
472 472
 		self::sanitize_entry_post( $values );
@@ -481,13 +481,13 @@  discard block
 block discarded – undo
481 481
 	}
482 482
 
483 483
 	/**
484
-	* Create an entry and perform after create actions
485
-	*
486
-	* @since 2.0.16
487
-	* @param array $values
488
-	* @param array $new_values
489
-	* @return boolean|int $entry_id
490
-	*/
484
+	 * Create an entry and perform after create actions
485
+	 *
486
+	 * @since 2.0.16
487
+	 * @param array $values
488
+	 * @param array $new_values
489
+	 * @return boolean|int $entry_id
490
+	 */
491 491
 	private static function continue_to_create_entry( $values, $new_values ) {
492 492
 		$entry_id = self::insert_entry_into_database( $new_values );
493 493
 		if ( ! $entry_id ) {
@@ -499,37 +499,37 @@  discard block
 block discarded – undo
499 499
 		return $entry_id;
500 500
 	}
501 501
 
502
-    /**
503
-     * Sanitize the POST values before we use them
504
-     *
505
-     * @since 2.0
506
-     * @param array $values The POST values by reference
507
-     */
508
-    public static function sanitize_entry_post( &$values ) {
509
-        $sanitize_method = array(
510
-            'form_id'       => 'absint',
511
-            'frm_action'    => 'sanitize_title',
512
-            'form_key'      => 'sanitize_title',
513
-            'item_key'      => 'sanitize_title',
514
-            'item_name'     => 'sanitize_text_field',
515
-            'frm_saving_draft' => 'absint',
516
-            'is_draft'      => 'absint',
517
-            'post_id'       => 'absint',
518
-            'parent_item_id' => 'absint',
519
-            'created_at'    => 'sanitize_text_field',
520
-            'updated_at'    => 'sanitize_text_field',
521
-        );
522
-
523
-        FrmAppHelper::sanitize_request( $sanitize_method, $values );
524
-    }
525
-
526
-	/**
527
-	* Prepare the new values for inserting into the database
528
-	*
529
-	* @since 2.0.16
530
-	* @param array $values
531
-	* @return array $new_values
532
-	*/
502
+	/**
503
+	 * Sanitize the POST values before we use them
504
+	 *
505
+	 * @since 2.0
506
+	 * @param array $values The POST values by reference
507
+	 */
508
+	public static function sanitize_entry_post( &$values ) {
509
+		$sanitize_method = array(
510
+			'form_id'       => 'absint',
511
+			'frm_action'    => 'sanitize_title',
512
+			'form_key'      => 'sanitize_title',
513
+			'item_key'      => 'sanitize_title',
514
+			'item_name'     => 'sanitize_text_field',
515
+			'frm_saving_draft' => 'absint',
516
+			'is_draft'      => 'absint',
517
+			'post_id'       => 'absint',
518
+			'parent_item_id' => 'absint',
519
+			'created_at'    => 'sanitize_text_field',
520
+			'updated_at'    => 'sanitize_text_field',
521
+		);
522
+
523
+		FrmAppHelper::sanitize_request( $sanitize_method, $values );
524
+	}
525
+
526
+	/**
527
+	 * Prepare the new values for inserting into the database
528
+	 *
529
+	 * @since 2.0.16
530
+	 * @param array $values
531
+	 * @return array $new_values
532
+	 */
533 533
 	private static function package_entry_data( &$values ) {
534 534
 		global $wpdb;
535 535
 
@@ -562,67 +562,67 @@  discard block
 block discarded – undo
562 562
 	}
563 563
 
564 564
 	/**
565
-	* Get the is_draft value for a new entry
566
-	*
567
-	* @since 2.0.16
568
-	* @param array $values
569
-	* @return int
570
-	*/
565
+	 * Get the is_draft value for a new entry
566
+	 *
567
+	 * @since 2.0.16
568
+	 * @param array $values
569
+	 * @return int
570
+	 */
571 571
 	private static function get_is_draft_value( $values ) {
572 572
 		return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) ||  ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0;
573 573
 	}
574 574
 
575 575
 	/**
576
-	* Get the form_id value for a new entry
577
-	*
578
-	* @since 2.0.16
579
-	* @param array $values
580
-	* @return int|null
581
-	*/
576
+	 * Get the form_id value for a new entry
577
+	 *
578
+	 * @since 2.0.16
579
+	 * @param array $values
580
+	 * @return int|null
581
+	 */
582 582
 	private static function get_form_id( $values ) {
583 583
 		return isset( $values['form_id'] ) ? (int) $values['form_id'] : null;
584 584
 	}
585 585
 
586 586
 	/**
587
-	* Get the post_id value for a new entry
588
-	*
589
-	* @since 2.0.16
590
-	* @param array $values
591
-	* @return int
592
-	*/
587
+	 * Get the post_id value for a new entry
588
+	 *
589
+	 * @since 2.0.16
590
+	 * @param array $values
591
+	 * @return int
592
+	 */
593 593
 	private static function get_post_id( $values ) {
594 594
 		return isset( $values['post_id'] ) ? (int) $values['post_id']: 0;
595 595
 	}
596 596
 
597 597
 	/**
598
-	* Get the parent_item_id value for a new entry
599
-	*
600
-	* @since 2.0.16
601
-	* @param array $values
602
-	* @return int
603
-	*/
598
+	 * Get the parent_item_id value for a new entry
599
+	 *
600
+	 * @since 2.0.16
601
+	 * @param array $values
602
+	 * @return int
603
+	 */
604 604
 	private static function get_parent_item_id( $values ) {
605 605
 		return isset( $values['parent_item_id'] ) ? (int) $values['parent_item_id']: 0;
606 606
 	}
607 607
 
608 608
 	/**
609
-	* Get the created_at value for a new entry
610
-	*
611
-	* @since 2.0.16
612
-	* @param array $values
613
-	* @return string
614
-	*/
609
+	 * Get the created_at value for a new entry
610
+	 *
611
+	 * @since 2.0.16
612
+	 * @param array $values
613
+	 * @return string
614
+	 */
615 615
 	private static function get_created_at( $values ) {
616 616
 		return isset( $values['created_at'] ) ? $values['created_at']: current_time('mysql', 1);
617 617
 	}
618 618
 
619 619
 	/**
620
-	* Get the updated_at value for a new entry
621
-	*
622
-	* @since 2.0.16
623
-	* @param array $values
624
-	* @return string
625
-	*/
620
+	 * Get the updated_at value for a new entry
621
+	 *
622
+	 * @since 2.0.16
623
+	 * @param array $values
624
+	 * @return string
625
+	 */
626 626
 	private static function get_updated_at( $values ) {
627 627
 		if ( isset( $values['updated_at'] ) ) {
628 628
 			$updated_at = $values['updated_at'];
@@ -634,12 +634,12 @@  discard block
 block discarded – undo
634 634
 	}
635 635
 
636 636
 	/**
637
-	* Get the description value for a new entry
638
-	*
639
-	* @since 2.0.16
640
-	* @param array $values
641
-	* @return string
642
-	*/
637
+	 * Get the description value for a new entry
638
+	 *
639
+	 * @since 2.0.16
640
+	 * @param array $values
641
+	 * @return string
642
+	 */
643 643
 	private static function get_entry_description( $values ) {
644 644
 		if ( isset( $values['description'] ) && ! empty( $values['description'] ) ) {
645 645
 			$description = maybe_serialize( $values['description'] );
@@ -654,12 +654,12 @@  discard block
 block discarded – undo
654 654
 	}
655 655
 
656 656
 	/**
657
-	* Get the user_id value for a new entry
658
-	*
659
-	* @since 2.0.16
660
-	* @param array $values
661
-	* @return int
662
-	*/
657
+	 * Get the user_id value for a new entry
658
+	 *
659
+	 * @since 2.0.16
660
+	 * @param array $values
661
+	 * @return int
662
+	 */
663 663
 	private static function get_entry_user_id( $values ) {
664 664
 		if ( isset( $values['frm_user_id'] ) && ( is_numeric( $values['frm_user_id'] ) || FrmAppHelper::is_admin() ) ) {
665 665
 			$user_id = $values['frm_user_id'];
@@ -672,12 +672,12 @@  discard block
 block discarded – undo
672 672
 	}
673 673
 
674 674
 	/**
675
-	* Insert new entry into the database
676
-	*
677
-	* @since 2.0.16
678
-	* @param array $new_values
679
-	* @return int | boolean $entry_id
680
-	*/
675
+	 * Insert new entry into the database
676
+	 *
677
+	 * @since 2.0.16
678
+	 * @param array $new_values
679
+	 * @return int | boolean $entry_id
680
+	 */
681 681
 	private static function insert_entry_into_database( $new_values ) {
682 682
 		global $wpdb;
683 683
 
@@ -693,11 +693,11 @@  discard block
 block discarded – undo
693 693
 	}
694 694
 
695 695
 	/**
696
-	* Add the new entry to global $frm_vars
697
-	*
698
-	* @since 2.0.16
699
-	* @param int $entry_id
700
-	*/
696
+	 * Add the new entry to global $frm_vars
697
+	 *
698
+	 * @since 2.0.16
699
+	 * @param int $entry_id
700
+	 */
701 701
 	private static function add_new_entry_to_frm_vars( $entry_id ) {
702 702
 		global $frm_vars;
703 703
 
@@ -709,12 +709,12 @@  discard block
 block discarded – undo
709 709
 	}
710 710
 
711 711
 	/**
712
-	* Add entry metas, if there are any
713
-	*
714
-	* @since 2.0.16
715
-	* @param array $values
716
-	* @param int $entry_id
717
-	*/
712
+	 * Add entry metas, if there are any
713
+	 *
714
+	 * @since 2.0.16
715
+	 * @param array $values
716
+	 * @param int $entry_id
717
+	 */
718 718
 	private static function maybe_add_entry_metas( $values, $entry_id ) {
719 719
 		if ( isset($values['item_meta']) ) {
720 720
 			FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] );
@@ -722,12 +722,12 @@  discard block
 block discarded – undo
722 722
 	}
723 723
 
724 724
 	/**
725
-	* Trigger frm_after_create_entry hooks
726
-	*
727
-	* @since 2.0.16
728
-	* @param int $entry_id
729
-	* @param array $new_values
730
-	*/
725
+	 * Trigger frm_after_create_entry hooks
726
+	 *
727
+	 * @since 2.0.16
728
+	 * @param int $entry_id
729
+	 * @param array $new_values
730
+	 */
731 731
 	private static function after_entry_created_actions( $entry_id, $values, $new_values ) {
732 732
 		// this is a child entry
733 733
 		$is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
@@ -737,13 +737,13 @@  discard block
 block discarded – undo
737 737
 	}
738 738
 
739 739
 	/**
740
-	* Actions to perform immediately after an entry is inserted in the frm_items database
741
-	*
742
-	* @since 2.0.16
743
-	* @param array $values
744
-	* @param array $new_values
745
-	* @param int $entry_id
746
-	*/
740
+	 * Actions to perform immediately after an entry is inserted in the frm_items database
741
+	 *
742
+	 * @since 2.0.16
743
+	 * @param array $values
744
+	 * @param array $new_values
745
+	 * @param int $entry_id
746
+	 */
747 747
 	private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) {
748 748
 
749 749
 		self::add_new_entry_to_frm_vars( $entry_id );
@@ -756,14 +756,14 @@  discard block
 block discarded – undo
756 756
 	}
757 757
 
758 758
 	/**
759
-	* Perform some actions right before updating an entry
760
-	*
761
-	* @since 2.0.16
762
-	* @param int $id
763
-	* @param array $values
764
-	* @param string $update_type
765
-	* @return boolean $update
766
-	*/
759
+	 * Perform some actions right before updating an entry
760
+	 *
761
+	 * @since 2.0.16
762
+	 * @param int $id
763
+	 * @param array $values
764
+	 * @param string $update_type
765
+	 * @return boolean $update
766
+	 */
767 767
 	private static function before_update_entry( $id, &$values, $update_type ) {
768 768
 		$update = true;
769 769
 
@@ -781,13 +781,13 @@  discard block
 block discarded – undo
781 781
 	}
782 782
 
783 783
 	/**
784
-	* Package the entry data for updating
785
-	*
786
-	* @since 2.0.16
787
-	* @param int $id
788
-	* @param array $values
789
-	* @return array $new_values
790
-	*/
784
+	 * Package the entry data for updating
785
+	 *
786
+	 * @since 2.0.16
787
+	 * @param int $id
788
+	 * @param array $values
789
+	 * @return array $new_values
790
+	 */
791 791
 	private static function package_entry_to_update( $id, $values ) {
792 792
 		global $wpdb;
793 793
 
@@ -821,14 +821,14 @@  discard block
 block discarded – undo
821 821
 	}
822 822
 
823 823
 	/**
824
-	* Perform some actions right after updating an entry
825
-	*
826
-	* @since 2.0.16
827
-	* @param boolean|int $query_results
828
-	* @param int $id
829
-	* @param array $values
830
-	* @param array $new_values
831
-	*/
824
+	 * Perform some actions right after updating an entry
825
+	 *
826
+	 * @since 2.0.16
827
+	 * @param boolean|int $query_results
828
+	 * @param int $id
829
+	 * @param array $values
830
+	 * @param array $new_values
831
+	 */
832 832
 	private static function after_update_entry( $query_results, $id, $values, $new_values ) {
833 833
 		if ( $query_results ) {
834 834
 			self::clear_cache();
@@ -850,13 +850,13 @@  discard block
 block discarded – undo
850 850
 	}
851 851
 
852 852
 	/**
853
-	* Create entry from an XML import
854
-	* Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.)
855
-	*
856
-	* @since 2.0.16
857
-	* @param array $values
858
-	* @return int | boolean $entry_id
859
-	*/
853
+	 * Create entry from an XML import
854
+	 * Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.)
855
+	 *
856
+	 * @since 2.0.16
857
+	 * @param array $values
858
+	 * @return int | boolean $entry_id
859
+	 */
860 860
 	public static function create_entry_from_xml( $values ) {
861 861
 		$entry_id = self::create_entry( $values, 'xml' );
862 862
 
@@ -864,28 +864,28 @@  discard block
 block discarded – undo
864 864
 	}
865 865
 
866 866
 	/**
867
-	* Update entry from an XML import
868
-	* Certain actions aren't necessary when importing (like saving sub entries and modifying other vals)
869
-	*
870
-	* @since 2.0.16
871
-	* @param int $id
872
-	* @param array $values
873
-	* @return int | boolean $updated
874
-	*/
867
+	 * Update entry from an XML import
868
+	 * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals)
869
+	 *
870
+	 * @since 2.0.16
871
+	 * @param int $id
872
+	 * @param array $values
873
+	 * @return int | boolean $updated
874
+	 */
875 875
 	public static function update_entry_from_xml( $id, $values ) {
876 876
 		$updated = self::update_entry( $id, $values, 'xml' );
877 877
 
878 878
 		return $updated;
879 879
 	}
880 880
 
881
-    /**
882
-     * @param string $key
883
-     * @return int entry_id
884
-     */
881
+	/**
882
+	 * @param string $key
883
+	 * @return int entry_id
884
+	 */
885 885
 	public static function get_id_by_key( $key ) {
886
-        $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) );
887
-        return $entry_id;
888
-    }
886
+		$entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) );
887
+		return $entry_id;
888
+	}
889 889
 
890 890
 	public static function validate( $values, $exclude = false ) {
891 891
 		_deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntryValidate::validate' );
Please login to merge, or discard this patch.
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
2
+if ( ! defined( 'ABSPATH' ) ) {
3 3
 	die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
@@ -55,13 +55,13 @@  discard block
 block discarded – undo
55 55
 		unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] );
56 56
 
57 57
         if ( $new_values['item_key'] == $new_values['name'] ) {
58
-            unset($check_val['name']);
58
+            unset( $check_val['name'] );
59 59
         }
60 60
 
61 61
         global $wpdb;
62 62
 		$entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) );
63 63
 
64
-        if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) {
64
+        if ( ! $entry_exists || empty( $entry_exists ) || ! isset( $values['item_meta'] ) ) {
65 65
             return false;
66 66
         }
67 67
 
@@ -70,10 +70,10 @@  discard block
 block discarded – undo
70 70
             $is_duplicate = true;
71 71
 
72 72
             //add more checks here to make sure it's a duplicate
73
-            $metas = FrmEntryMeta::get_entry_meta_info($entry_exist);
73
+            $metas = FrmEntryMeta::get_entry_meta_info( $entry_exist );
74 74
             $field_metas = array();
75 75
             foreach ( $metas as $meta ) {
76
-				$field_metas[ $meta->field_id ] = $meta->meta_value;
76
+				$field_metas[$meta->field_id] = $meta->meta_value;
77 77
             }
78 78
 
79 79
             // If prev entry is empty and current entry is not, they are not duplicates
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
                 return false;
83 83
             }
84 84
 
85
-            $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta']));
85
+            $diff = array_diff_assoc( $field_metas, array_map( 'maybe_serialize', $values['item_meta'] ) );
86 86
             foreach ( $diff as $field_id => $meta_value ) {
87
-                if ( ! empty($meta_value) ) {
87
+                if ( ! empty( $meta_value ) ) {
88 88
                     $is_duplicate = false;
89 89
                     continue;
90 90
                 }
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 		}
114 114
 
115 115
 		// If CSV is importing, don't check for duplicates
116
-		if ( defined('WP_IMPORTING') && WP_IMPORTING ) {
116
+		if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
117 117
 			return false;
118 118
 		}
119 119
 
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
         $new_values['name'] = $values->name;
136 136
         $new_values['is_draft'] = $values->is_draft;
137 137
         $new_values['user_id'] = $new_values['updated_by'] = (int) $values->user_id;
138
-        $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null;
139
-        $new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1);
138
+        $new_values['form_id'] = $values->form_id ? (int) $values->form_id : null;
139
+        $new_values['created_at'] = $new_values['updated_at'] = current_time( 'mysql', 1 );
140 140
 
141 141
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values );
142 142
         if ( ! $query_results ) {
@@ -146,12 +146,12 @@  discard block
 block discarded – undo
146 146
         $entry_id = $wpdb->insert_id;
147 147
 
148 148
         global $frm_vars;
149
-        if ( ! isset($frm_vars['saved_entries']) ) {
149
+        if ( ! isset( $frm_vars['saved_entries'] ) ) {
150 150
             $frm_vars['saved_entries'] = array();
151 151
         }
152 152
         $frm_vars['saved_entries'][] = (int) $entry_id;
153 153
 
154
-        FrmEntryMeta::duplicate_entry_metas($id, $entry_id);
154
+        FrmEntryMeta::duplicate_entry_metas( $id, $entry_id );
155 155
 		self::clear_cache();
156 156
 
157 157
 		do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) );
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 
191 191
 		$new_values = self::package_entry_to_update( $id, $values );
192 192
 
193
-		$query_results = $wpdb->update( $wpdb->prefix . 'frm_items', $new_values, compact('id') );
193
+		$query_results = $wpdb->update( $wpdb->prefix . 'frm_items', $new_values, compact( 'id' ) );
194 194
 
195 195
 		self::after_update_entry( $query_results, $id, $values, $new_values );
196 196
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
             return $result;
208 208
         }
209 209
 
210
-        do_action('frm_before_destroy_entry', $id, $entry);
210
+        do_action( 'frm_before_destroy_entry', $id, $entry );
211 211
 
212 212
 		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE item_id=%d', $id ) );
213 213
 		$result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) );
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 
220 220
 	public static function &update_form( $id, $value, $form_id ) {
221 221
         global $wpdb;
222
-        $form_id = isset($value) ? $form_id : null;
222
+        $form_id = isset( $value ) ? $form_id : null;
223 223
 		$result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) );
224 224
 		if ( $result ) {
225 225
 			self::clear_cache();
@@ -266,24 +266,24 @@  discard block
 block discarded – undo
266 266
         $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
267 267
                   LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
268 268
 
269
-        $query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s';
269
+        $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s';
270 270
         $query_args = array( $id );
271 271
         $query = $wpdb->prepare( $query, $query_args );
272 272
 
273 273
         if ( ! $meta ) {
274 274
 			$entry = FrmAppHelper::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' );
275
-            return stripslashes_deep($entry);
275
+            return stripslashes_deep( $entry );
276 276
         }
277 277
 
278 278
         $entry = FrmAppHelper::check_cache( $id, 'frm_entry' );
279 279
         if ( $entry !== false ) {
280
-            return stripslashes_deep($entry);
280
+            return stripslashes_deep( $entry );
281 281
         }
282 282
 
283 283
         $entry = $wpdb->get_row( $query );
284
-        $entry = self::get_meta($entry);
284
+        $entry = self::get_meta( $entry );
285 285
 
286
-        return stripslashes_deep($entry);
286
+        return stripslashes_deep( $entry );
287 287
     }
288 288
 
289 289
 	public static function get_meta( $entry ) {
@@ -299,23 +299,23 @@  discard block
 block discarded – undo
299 299
 		$include_key = apply_filters( 'frm_include_meta_keys', false, array( 'form_id' => $entry->form_id ) );
300 300
         foreach ( $metas as $meta_val ) {
301 301
             if ( $meta_val->item_id == $entry->id ) {
302
-				$entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
302
+				$entry->metas[$meta_val->field_id] = maybe_unserialize( $meta_val->meta_value );
303 303
 				if ( $include_key ) {
304
-					$entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ];
304
+					$entry->metas[$meta_val->field_key] = $entry->metas[$meta_val->field_id];
305 305
 				}
306 306
                  continue;
307 307
             }
308 308
 
309 309
             // include sub entries in an array
310
-			if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) {
311
-				$entry->metas[ $meta_val->field_id ] = array();
310
+			if ( ! isset( $entry_metas[$meta_val->field_id] ) ) {
311
+				$entry->metas[$meta_val->field_id] = array();
312 312
             }
313 313
 
314
-			$entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value );
314
+			$entry->metas[$meta_val->field_id][] = maybe_unserialize( $meta_val->meta_value );
315 315
 
316
-            unset($meta_val);
316
+            unset( $meta_val );
317 317
         }
318
-        unset($metas);
318
+        unset( $metas );
319 319
 
320 320
 		FrmAppHelper::set_cache( $entry->id, $entry, 'frm_entry' );
321 321
 
@@ -333,24 +333,24 @@  discard block
 block discarded – undo
333 333
             return $exists;
334 334
         }
335 335
 
336
-        if ( is_numeric($id) ) {
336
+        if ( is_numeric( $id ) ) {
337 337
             $where = array( 'id' => $id );
338 338
         } else {
339 339
             $where = array( 'item_key' => $id );
340 340
         }
341 341
 		$id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where );
342 342
 
343
-        $exists = ($id && $id > 0) ? true : false;
343
+        $exists = ( $id && $id > 0 ) ? true : false;
344 344
         return $exists;
345 345
     }
346 346
 
347 347
     public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
348 348
 		global $wpdb;
349 349
 
350
-        $limit = FrmAppHelper::esc_limit($limit);
350
+        $limit = FrmAppHelper::esc_limit( $limit );
351 351
 
352
-        $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form;
353
-        $entries = wp_cache_get($cache_key, 'frm_entry');
352
+        $cache_key = maybe_serialize( $where ) . $order_by . $limit . $inc_form;
353
+        $entries = wp_cache_get( $cache_key, 'frm_entry' );
354 354
 
355 355
         if ( false === $entries ) {
356 356
             $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft';
@@ -369,25 +369,25 @@  discard block
 block discarded – undo
369 369
 		    }
370 370
 
371 371
 			// prepare the query
372
-			$query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
372
+			$query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
373 373
 
374
-            $entries = $wpdb->get_results($query, OBJECT_K);
375
-            unset($query);
374
+            $entries = $wpdb->get_results( $query, OBJECT_K );
375
+            unset( $query );
376 376
 
377 377
 			FrmAppHelper::set_cache( $cache_key, $entries, 'frm_entry' );
378 378
         }
379 379
 
380 380
         if ( ! $meta || ! $entries ) {
381
-            return stripslashes_deep($entries);
381
+            return stripslashes_deep( $entries );
382 382
         }
383
-        unset($meta);
383
+        unset( $meta );
384 384
 
385
-        if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) {
385
+        if ( ! is_array( $where ) && preg_match( '/^it\.form_id=\d+$/', $where ) ) {
386 386
 			$where = array( 'it.form_id' => substr( $where, 11 ) );
387 387
         }
388 388
 
389 389
         $meta_where = array( 'field_id !' => 0 );
390
-        if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) {
390
+        if ( $limit == '' && is_array( $where ) && count( $where ) == 1 && isset( $where['it.form_id'] ) ) {
391 391
             $meta_where['fi.form_id'] = $where['it.form_id'];
392 392
         } else {
393 393
             $meta_where['item_id'] = array_keys( $entries );
@@ -398,21 +398,21 @@  discard block
 block discarded – undo
398 398
         unset( $meta_where );
399 399
 
400 400
         if ( ! $metas ) {
401
-            return stripslashes_deep($entries);
401
+            return stripslashes_deep( $entries );
402 402
         }
403 403
 
404 404
         foreach ( $metas as $m_key => $meta_val ) {
405
-            if ( ! isset( $entries[ $meta_val->item_id ] ) ) {
405
+            if ( ! isset( $entries[$meta_val->item_id] ) ) {
406 406
                 continue;
407 407
             }
408 408
 
409
-            if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
410
-				$entries[ $meta_val->item_id ]->metas = array();
409
+            if ( ! isset( $entries[$meta_val->item_id]->metas ) ) {
410
+				$entries[$meta_val->item_id]->metas = array();
411 411
             }
412 412
 
413
-			$entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value );
413
+			$entries[$meta_val->item_id]->metas[$meta_val->field_id] = maybe_unserialize( $meta_val->meta_value );
414 414
 
415
-            unset($m_key, $meta_val);
415
+            unset( $m_key, $meta_val );
416 416
         }
417 417
 
418 418
 		if ( ! FrmAppHelper::prevent_caching() ) {
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
 			}
423 423
 		}
424 424
 
425
-        return stripslashes_deep($entries);
425
+        return stripslashes_deep( $entries );
426 426
     }
427 427
 
428 428
     // Pagination Methods
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
         global $wpdb;
431 431
 		$table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
432 432
 
433
-        if ( is_numeric($where) ) {
433
+        if ( is_numeric( $where ) ) {
434 434
             $table_join = 'frm_items';
435 435
             $where = array( 'form_id' => $where );
436 436
         }
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
 		self::sanitize_entry_post( $values );
473 473
 
474 474
 		if ( $type != 'xml' ) {
475
-			$values = apply_filters('frm_pre_create_entry', $values);
475
+			$values = apply_filters( 'frm_pre_create_entry', $values );
476 476
 		}
477 477
 
478 478
 		$new_values = self::package_entry_data( $values );
@@ -552,11 +552,11 @@  discard block
 block discarded – undo
552 552
 			'user_id' => self::get_entry_user_id( $values ),
553 553
 		);
554 554
 
555
-		if ( is_array($new_values['name']) ) {
556
-			$new_values['name'] = reset($new_values['name']);
555
+		if ( is_array( $new_values['name'] ) ) {
556
+			$new_values['name'] = reset( $new_values['name'] );
557 557
 		}
558 558
 
559
-		$new_values['updated_by'] = isset($values['updated_by']) ? $values['updated_by'] : $new_values['user_id'];
559
+		$new_values['updated_by'] = isset( $values['updated_by'] ) ? $values['updated_by'] : $new_values['user_id'];
560 560
 
561 561
 		return $new_values;
562 562
 	}
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
 	* @return int
570 570
 	*/
571 571
 	private static function get_is_draft_value( $values ) {
572
-		return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) ||  ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0;
572
+		return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0;
573 573
 	}
574 574
 
575 575
 	/**
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
 	* @return int
592 592
 	*/
593 593
 	private static function get_post_id( $values ) {
594
-		return isset( $values['post_id'] ) ? (int) $values['post_id']: 0;
594
+		return isset( $values['post_id'] ) ? (int) $values['post_id'] : 0;
595 595
 	}
596 596
 
597 597
 	/**
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
 	* @return int
603 603
 	*/
604 604
 	private static function get_parent_item_id( $values ) {
605
-		return isset( $values['parent_item_id'] ) ? (int) $values['parent_item_id']: 0;
605
+		return isset( $values['parent_item_id'] ) ? (int) $values['parent_item_id'] : 0;
606 606
 	}
607 607
 
608 608
 	/**
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
 	* @return string
614 614
 	*/
615 615
 	private static function get_created_at( $values ) {
616
-		return isset( $values['created_at'] ) ? $values['created_at']: current_time('mysql', 1);
616
+		return isset( $values['created_at'] ) ? $values['created_at'] : current_time( 'mysql', 1 );
617 617
 	}
618 618
 
619 619
 	/**
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
 	private static function add_new_entry_to_frm_vars( $entry_id ) {
702 702
 		global $frm_vars;
703 703
 
704
-		if ( ! isset($frm_vars['saved_entries']) ) {
704
+		if ( ! isset( $frm_vars['saved_entries'] ) ) {
705 705
 			$frm_vars['saved_entries'] = array();
706 706
 		}
707 707
 
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
 	* @param int $entry_id
717 717
 	*/
718 718
 	private static function maybe_add_entry_metas( $values, $entry_id ) {
719
-		if ( isset($values['item_meta']) ) {
719
+		if ( isset( $values['item_meta'] ) ) {
720 720
 			FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] );
721 721
 		}
722 722
 	}
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
 		$is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
734 734
 
735 735
 		do_action( 'frm_after_create_entry', $entry_id, $new_values['form_id'], compact( 'is_child' ) );
736
-		do_action( 'frm_after_create_entry_' . $new_values['form_id'], $entry_id , compact( 'is_child' ) );
736
+		do_action( 'frm_after_create_entry_' . $new_values['form_id'], $entry_id, compact( 'is_child' ) );
737 737
 	}
738 738
 
739 739
 	/**
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
 		}
775 775
 
776 776
 		if ( $update && $update_type != 'xml' ) {
777
-			$values = apply_filters('frm_pre_update_entry', $values, $id);
777
+			$values = apply_filters( 'frm_pre_update_entry', $values, $id );
778 778
 		}
779 779
 
780 780
 		return $update;
@@ -795,27 +795,27 @@  discard block
 block discarded – undo
795 795
 			'name'      => self::get_new_entry_name( $values ),
796 796
 			'form_id'   => self::get_form_id( $values ),
797 797
 			'is_draft'  => self::get_is_draft_value( $values ),
798
-			'updated_at' => current_time('mysql', 1),
799
-			'updated_by' => isset($values['updated_by']) ? $values['updated_by'] : get_current_user_id(),
798
+			'updated_at' => current_time( 'mysql', 1 ),
799
+			'updated_by' => isset( $values['updated_by'] ) ? $values['updated_by'] : get_current_user_id(),
800 800
 		);
801 801
 
802
-		if ( isset($values['post_id']) ) {
802
+		if ( isset( $values['post_id'] ) ) {
803 803
 			$new_values['post_id'] = (int) $values['post_id'];
804 804
 		}
805 805
 
806
-		if ( isset($values['item_key']) ) {
806
+		if ( isset( $values['item_key'] ) ) {
807 807
 			$new_values['item_key'] = FrmAppHelper::get_unique_key( $values['item_key'], $wpdb->prefix . 'frm_items', 'item_key', $id );
808 808
 		}
809 809
 
810
-		if ( isset($values['parent_item_id']) ) {
810
+		if ( isset( $values['parent_item_id'] ) ) {
811 811
 			$new_values['parent_item_id'] = (int) $values['parent_item_id'];
812 812
 		}
813 813
 
814
-		if ( isset($values['frm_user_id']) && is_numeric($values['frm_user_id']) ) {
814
+		if ( isset( $values['frm_user_id'] ) && is_numeric( $values['frm_user_id'] ) ) {
815 815
 			$new_values['user_id'] = $values['frm_user_id'];
816 816
 		}
817 817
 
818
-		$new_values = apply_filters('frm_update_entry', $new_values, $id);
818
+		$new_values = apply_filters( 'frm_update_entry', $new_values, $id );
819 819
 
820 820
 		return $new_values;
821 821
 	}
Please login to merge, or discard this patch.
classes/models/FrmEntryMeta.php 2 patches
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -5,25 +5,25 @@  discard block
 block discarded – undo
5 5
 
6 6
 class FrmEntryMeta {
7 7
 
8
-    /**
9
-     * @param string $meta_key
10
-     */
8
+	/**
9
+	 * @param string $meta_key
10
+	 */
11 11
 	public static function add_entry_meta( $entry_id, $field_id, $meta_key = null, $meta_value ) {
12
-        global $wpdb;
12
+		global $wpdb;
13 13
 
14
-        if ( FrmAppHelper::is_empty_value( $meta_value ) ) {
15
-            // don't save blank fields
16
-            return 0;
17
-        }
14
+		if ( FrmAppHelper::is_empty_value( $meta_value ) ) {
15
+			// don't save blank fields
16
+			return 0;
17
+		}
18 18
 
19
-        $new_values = array(
19
+		$new_values = array(
20 20
 			'meta_value'    => is_array( $meta_value ) ? serialize( array_filter( $meta_value, 'FrmAppHelper::is_not_empty_value' ) ) : trim( $meta_value ),
21
-            'item_id'       => $entry_id,
22
-            'field_id'      => $field_id,
23
-            'created_at'    => current_time('mysql', 1),
24
-        );
21
+			'item_id'       => $entry_id,
22
+			'field_id'      => $field_id,
23
+			'created_at'    => current_time('mysql', 1),
24
+		);
25 25
 
26
-        $new_values = apply_filters('frm_add_entry_meta', $new_values);
26
+		$new_values = apply_filters('frm_add_entry_meta', $new_values);
27 27
 
28 28
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_item_metas', $new_values );
29 29
 
@@ -34,40 +34,40 @@  discard block
 block discarded – undo
34 34
 			$id = 0;
35 35
 		}
36 36
 
37
-        return $id;
38
-    }
37
+		return $id;
38
+	}
39 39
 
40
-    /**
41
-     * @param string $meta_key
42
-     */
40
+	/**
41
+	 * @param string $meta_key
42
+	 */
43 43
 	public static function update_entry_meta( $entry_id, $field_id, $meta_key = null, $meta_value ) {
44
-        if ( ! $field_id ) {
45
-            return false;
46
-        }
44
+		if ( ! $field_id ) {
45
+			return false;
46
+		}
47 47
 
48
-        global $wpdb;
48
+		global $wpdb;
49 49
 
50
-        $values = $where_values = array( 'item_id' => $entry_id, 'field_id' => $field_id );
51
-        $values['meta_value'] = $meta_value;
52
-        $values = apply_filters('frm_update_entry_meta', $values);
50
+		$values = $where_values = array( 'item_id' => $entry_id, 'field_id' => $field_id );
51
+		$values['meta_value'] = $meta_value;
52
+		$values = apply_filters('frm_update_entry_meta', $values);
53 53
 		if ( is_array($values['meta_value']) ) {
54 54
 			$values['meta_value'] = array_filter( $values['meta_value'], 'FrmAppHelper::is_not_empty_value' );
55 55
 		}
56
-        $meta_value = maybe_serialize($values['meta_value']);
56
+		$meta_value = maybe_serialize($values['meta_value']);
57 57
 
58
-        wp_cache_delete( $entry_id, 'frm_entry');
58
+		wp_cache_delete( $entry_id, 'frm_entry');
59 59
 		self::clear_cache();
60 60
 
61 61
 		return $wpdb->update( $wpdb->prefix . 'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values );
62
-    }
62
+	}
63 63
 
64 64
 	public static function update_entry_metas( $entry_id, $values ) {
65
-        global $wpdb;
65
+		global $wpdb;
66 66
 
67 67
 		$prev_values = FrmDb::get_col( $wpdb->prefix . 'frm_item_metas', array( 'item_id' => $entry_id, 'field_id !' => 0 ), 'field_id' );
68 68
 
69
-        foreach ( $values as $field_id => $meta_value ) {
70
-            // set the value for the file upload field and add new tags (in Pro version)
69
+		foreach ( $values as $field_id => $meta_value ) {
70
+			// set the value for the file upload field and add new tags (in Pro version)
71 71
 			$meta_value = apply_filters( 'frm_prepare_data_before_db', $meta_value, $field_id, $entry_id );
72 72
 
73 73
 			if ( $prev_values && in_array($field_id, $prev_values) ) {
@@ -85,39 +85,39 @@  discard block
 block discarded – undo
85 85
 			}
86 86
 		}
87 87
 
88
-        if ( empty($prev_values) ) {
89
-            return;
90
-        }
88
+		if ( empty($prev_values) ) {
89
+			return;
90
+		}
91 91
 
92
-        $prev_values = array_diff($prev_values, array_keys($values));
92
+		$prev_values = array_diff($prev_values, array_keys($values));
93 93
 
94
-        if ( empty($prev_values) ) {
95
-            return;
96
-        }
94
+		if ( empty($prev_values) ) {
95
+			return;
96
+		}
97 97
 
98 98
 		// prepare the query
99 99
 		$where = array( 'item_id' => $entry_id, 'field_id' => $prev_values );
100 100
 		FrmDb::get_where_clause_and_values( $where );
101 101
 
102
-        // Delete any leftovers
103
-        $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas ' . $where['where'], $where['values'] ) );
102
+		// Delete any leftovers
103
+		$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas ' . $where['where'], $where['values'] ) );
104 104
 		self::clear_cache();
105
-    }
105
+	}
106 106
 
107 107
 	public static function duplicate_entry_metas( $old_id, $new_id ) {
108
-        $metas = self::get_entry_meta_info($old_id);
109
-        foreach ( $metas as $meta ) {
110
-            self::add_entry_meta($new_id, $meta->field_id, null, $meta->meta_value);
111
-            unset($meta);
112
-        }
108
+		$metas = self::get_entry_meta_info($old_id);
109
+		foreach ( $metas as $meta ) {
110
+			self::add_entry_meta($new_id, $meta->field_id, null, $meta->meta_value);
111
+			unset($meta);
112
+		}
113 113
 		self::clear_cache();
114
-    }
114
+	}
115 115
 
116 116
 	public static function delete_entry_meta( $entry_id, $field_id ) {
117
-        global $wpdb;
117
+		global $wpdb;
118 118
 		self::clear_cache();
119
-        return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id));
120
-    }
119
+		return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id));
120
+	}
121 121
 
122 122
 	/**
123 123
 	 * Clear entry meta caching
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	}
143 143
 
144 144
 	public static function get_entry_meta_by_field( $entry_id, $field_id ) {
145
-        global $wpdb;
145
+		global $wpdb;
146 146
 
147 147
 		if ( is_object( $entry_id ) ) {
148 148
 			$entry = $entry_id;
@@ -155,137 +155,137 @@  discard block
 block discarded – undo
155 155
 
156 156
 		if ( $cached && isset( $cached->metas ) && isset( $cached->metas[ $field_id ] ) ) {
157 157
 			$result = $cached->metas[ $field_id ];
158
-            return stripslashes_deep($result);
159
-        }
158
+			return stripslashes_deep($result);
159
+		}
160 160
 
161 161
 		$get_table = $wpdb->prefix . 'frm_item_metas';
162 162
 		$query = array( 'item_id' => $entry_id );
163
-        if ( is_numeric($field_id) ) {
163
+		if ( is_numeric($field_id) ) {
164 164
 			$query['field_id'] = $field_id;
165
-        } else {
165
+		} else {
166 166
 			$get_table .= ' it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id';
167 167
 			$query['fi.field_key'] = $field_id;
168
-        }
168
+		}
169 169
 
170 170
 		$result = FrmDb::get_var( $get_table, $query, 'meta_value' );
171
-        $result = maybe_unserialize($result);
172
-        $result = stripslashes_deep($result);
171
+		$result = maybe_unserialize($result);
172
+		$result = stripslashes_deep($result);
173 173
 
174
-        return $result;
175
-    }
174
+		return $result;
175
+	}
176 176
 
177 177
 	public static function get_entry_metas( $entry_id ) {
178
-        _deprecated_function( __FUNCTION__, '1.07.10');
178
+		_deprecated_function( __FUNCTION__, '1.07.10');
179 179
 
180
-        global $wpdb;
180
+		global $wpdb;
181 181
 		return FrmDb::get_col( $wpdb->prefix . 'frm_item_metas', array( 'item_id' => $entry_id ), 'meta_value' );
182
-    }
182
+	}
183 183
 
184
-    public static function get_entry_metas_for_field( $field_id, $order = '', $limit = '', $args = array() ) {
184
+	public static function get_entry_metas_for_field( $field_id, $order = '', $limit = '', $args = array() ) {
185 185
 		$defaults = array( 'value' => false, 'unique' => false, 'stripslashes' => true, 'is_draft' => false );
186
-        $args = wp_parse_args( $args, $defaults );
186
+		$args = wp_parse_args( $args, $defaults );
187 187
 
188
-        $query = array();
189
-        self::meta_field_query($field_id, $order, $limit, $args, $query);
190
-        $query = implode(' ', $query);
188
+		$query = array();
189
+		self::meta_field_query($field_id, $order, $limit, $args, $query);
190
+		$query = implode(' ', $query);
191 191
 
192 192
 		$cache_key = 'entry_metas_for_field_' . $field_id . $order . $limit . maybe_serialize( $args );
193
-        $values = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_col');
193
+		$values = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_col');
194 194
 
195
-        if ( ! $args['stripslashes'] ) {
196
-            return $values;
197
-        }
195
+		if ( ! $args['stripslashes'] ) {
196
+			return $values;
197
+		}
198 198
 
199 199
 		foreach ( $values as $k => $v ) {
200 200
 			$values[ $k ] = maybe_unserialize( $v );
201
-            unset($k, $v);
202
-        }
201
+			unset($k, $v);
202
+		}
203 203
 
204
-        return stripslashes_deep($values);
205
-    }
204
+		return stripslashes_deep($values);
205
+	}
206 206
 
207
-    /**
208
-     * @param string $order
209
-     * @param string $limit
210
-     */
207
+	/**
208
+	 * @param string $order
209
+	 * @param string $limit
210
+	 */
211 211
 	private static function meta_field_query( $field_id, $order, $limit, $args, array &$query ) {
212
-        global $wpdb;
213
-        $query[] = 'SELECT';
214
-        $query[] = $args['unique'] ? 'DISTINCT(em.meta_value)' : 'em.meta_value';
212
+		global $wpdb;
213
+		$query[] = 'SELECT';
214
+		$query[] = $args['unique'] ? 'DISTINCT(em.meta_value)' : 'em.meta_value';
215 215
 		$query[] = 'FROM ' . $wpdb->prefix . 'frm_item_metas em ';
216 216
 
217
-        if ( ! $args['is_draft'] ) {
217
+		if ( ! $args['is_draft'] ) {
218 218
 			$query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=em.item_id)';
219
-        }
219
+		}
220 220
 
221
-        if ( is_numeric($field_id) ) {
222
-            $query[] = $wpdb->prepare('WHERE em.field_id=%d', $field_id);
223
-        } else {
221
+		if ( is_numeric($field_id) ) {
222
+			$query[] = $wpdb->prepare('WHERE em.field_id=%d', $field_id);
223
+		} else {
224 224
 			$query[] = $wpdb->prepare( 'LEFT JOIN ' . $wpdb->prefix . 'frm_fields fi ON (em.field_id = fi.id) WHERE fi.field_key=%s', $field_id );
225
-        }
225
+		}
226 226
 
227
-        if ( ! $args['is_draft'] ) {
228
-            $query[] = 'AND e.is_draft=0';
229
-        }
227
+		if ( ! $args['is_draft'] ) {
228
+			$query[] = 'AND e.is_draft=0';
229
+		}
230 230
 
231
-        if ( $args['value'] ) {
232
-            $query[] = $wpdb->prepare(' AND meta_value=%s', $args['value']);
233
-        }
234
-        $query[] = $order . $limit;
235
-    }
231
+		if ( $args['value'] ) {
232
+			$query[] = $wpdb->prepare(' AND meta_value=%s', $args['value']);
233
+		}
234
+		$query[] = $order . $limit;
235
+	}
236 236
 
237 237
 	public static function get_entry_meta_info( $entry_id ) {
238 238
 		return FrmDb::get_results( 'frm_item_metas', array( 'item_id' => $entry_id ) );
239
-    }
239
+	}
240 240
 
241 241
 	public static function getAll( $where = array(), $order_by = '', $limit = '', $stripslashes = false ) {
242
-        global $wpdb;
243
-        $query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key,
242
+		global $wpdb;
243
+		$query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key,
244 244
             fi.required as required, fi.form_id as field_form_id, fi.name as field_name, fi.options as fi_options
245 245
 			FROM ' . $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id' .
246
-            FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
246
+			FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
247 247
 
248 248
 		$cache_key = 'all_' . maybe_serialize( $where ) . $order_by . $limit;
249
-        $results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_row' : 'get_results'));
249
+		$results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_row' : 'get_results'));
250 250
 
251
-        if ( ! $results || ! $stripslashes ) {
252
-            return $results;
253
-        }
251
+		if ( ! $results || ! $stripslashes ) {
252
+			return $results;
253
+		}
254 254
 
255
-        foreach ( $results as $k => $result ) {
255
+		foreach ( $results as $k => $result ) {
256 256
 			$results[ $k ]->meta_value = stripslashes_deep( maybe_unserialize( $result->meta_value ) );
257
-            unset($k, $result);
258
-        }
257
+			unset($k, $result);
258
+		}
259 259
 
260
-        return $results;
261
-    }
260
+		return $results;
261
+	}
262 262
 
263
-    public static function getEntryIds( $where = array(), $order_by = '', $limit = '', $unique = true, $args = array() ) {
263
+	public static function getEntryIds( $where = array(), $order_by = '', $limit = '', $unique = true, $args = array() ) {
264 264
 		$defaults = array(
265 265
 			'is_draft' => false,
266 266
 			'user_id'  => '',
267 267
 			'group_by' => '',
268 268
 		);
269
-        $args = wp_parse_args($args, $defaults);
269
+		$args = wp_parse_args($args, $defaults);
270 270
 
271
-        $query = array();
272
-        self::get_ids_query($where, $order_by, $limit, $unique, $args, $query );
273
-        $query = implode(' ', $query);
271
+		$query = array();
272
+		self::get_ids_query($where, $order_by, $limit, $unique, $args, $query );
273
+		$query = implode(' ', $query);
274 274
 
275 275
 		$cache_key = 'ids_' . maybe_serialize( $where ) . $order_by . 'l' . $limit . 'u' . $unique . maybe_serialize( $args );
276
-        $results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_var' : 'get_col'));
276
+		$results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_var' : 'get_col'));
277 277
 
278
-        return $results;
279
-    }
278
+		return $results;
279
+	}
280 280
 
281
-    /**
282
-     * @param string|array $where
283
-     * @param string $order_by
284
-     * @param string $limit
285
-     */
281
+	/**
282
+	 * @param string|array $where
283
+	 * @param string $order_by
284
+	 * @param string $limit
285
+	 */
286 286
 	private static function get_ids_query( $where, $order_by, $limit, $unique, $args, array &$query ) {
287
-        global $wpdb;
288
-        $query[] = 'SELECT';
287
+		global $wpdb;
288
+		$query[] = 'SELECT';
289 289
 
290 290
 		$defaults = array( 'return_parent_id' => false );
291 291
 		$args = array_merge( $defaults, $args );
@@ -299,88 +299,88 @@  discard block
 block discarded – undo
299 299
 		$query[] = 'FROM ' . $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id';
300 300
 
301 301
 		$query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=it.item_id)';
302
-        if ( is_array($where) ) {
303
-            if ( ! $args['is_draft'] ) {
304
-                $where['e.is_draft'] = 0;
305
-            } else if ( $args['is_draft'] == 1 ) {
306
-                $where['e.is_draft'] = 1;
307
-            }
308
-
309
-            if ( ! empty($args['user_id']) ) {
310
-                $where['e.user_id'] = $args['user_id'];
311
-            }
312
-            $query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
302
+		if ( is_array($where) ) {
303
+			if ( ! $args['is_draft'] ) {
304
+				$where['e.is_draft'] = 0;
305
+			} else if ( $args['is_draft'] == 1 ) {
306
+				$where['e.is_draft'] = 1;
307
+			}
308
+
309
+			if ( ! empty($args['user_id']) ) {
310
+				$where['e.user_id'] = $args['user_id'];
311
+			}
312
+			$query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
313 313
 
314 314
 			if ( $args['group_by'] ) {
315 315
 				$query[] = ' GROUP BY ' . sanitize_text_field( $args['group_by'] );
316 316
 			}
317
-            return;
318
-        }
317
+			return;
318
+		}
319 319
 
320 320
 		$draft_where = $user_where = '';
321
-        if ( ! $args['is_draft'] ) {
321
+		if ( ! $args['is_draft'] ) {
322 322
 			$draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 0 );
323
-        } else if ( $args['is_draft'] == 1 ) {
323
+		} else if ( $args['is_draft'] == 1 ) {
324 324
 			$draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 1 );
325
-        }
325
+		}
326 326
 
327
-        if ( ! empty($args['user_id']) ) {
328
-            $user_where = $wpdb->prepare(' AND e.user_id=%d', $args['user_id']);
329
-        }
327
+		if ( ! empty($args['user_id']) ) {
328
+			$user_where = $wpdb->prepare(' AND e.user_id=%d', $args['user_id']);
329
+		}
330 330
 
331
-        if ( strpos($where, ' GROUP BY ') ) {
332
-            // don't inject WHERE filtering after GROUP BY
333
-            $parts = explode(' GROUP BY ', $where);
334
-            $where = $parts[0];
335
-            $where .= $draft_where . $user_where;
331
+		if ( strpos($where, ' GROUP BY ') ) {
332
+			// don't inject WHERE filtering after GROUP BY
333
+			$parts = explode(' GROUP BY ', $where);
334
+			$where = $parts[0];
335
+			$where .= $draft_where . $user_where;
336 336
 			$where .= ' GROUP BY ' . $parts[1];
337
-        } else {
338
-            $where .= $draft_where . $user_where;
339
-        }
337
+		} else {
338
+			$where .= $draft_where . $user_where;
339
+		}
340 340
 
341 341
 		// The query has already been prepared
342 342
 		$query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
343
-    }
343
+	}
344 344
 
345
-    public static function search_entry_metas( $search, $field_id = '', $operator ) {
345
+	public static function search_entry_metas( $search, $field_id = '', $operator ) {
346 346
 		$cache_key = 'search_' . maybe_serialize( $search ) . $field_id . $operator;
347
-        $results = wp_cache_get($cache_key, 'frm_entry');
348
-        if ( false !== $results ) {
349
-            return $results;
350
-        }
347
+		$results = wp_cache_get($cache_key, 'frm_entry');
348
+		if ( false !== $results ) {
349
+			return $results;
350
+		}
351 351
 
352
-        global $wpdb;
352
+		global $wpdb;
353 353
 		if ( is_array( $search ) ) {
354
-            $where = '';
354
+			$where = '';
355 355
 			foreach ( $search as $field => $value ) {
356 356
 				if ( $value <= 0 || ! in_array( $field, array( 'year', 'month', 'day' ) ) ) {
357
-                    continue;
358
-                }
357
+					continue;
358
+				}
359 359
 
360
-                switch ( $field ) {
361
-                    case 'year':
360
+				switch ( $field ) {
361
+					case 'year':
362 362
 						$value = '%' . $value;
363
-                    break;
364
-                    case 'month':
365
-                        $value .= '%';
366
-                    break;
367
-                    case 'day':
363
+					break;
364
+					case 'month':
365
+						$value .= '%';
366
+					break;
367
+					case 'day':
368 368
 						$value = '%' . $value . '%';
369
-                }
369
+				}
370 370
 				$where .= $wpdb->prepare(' meta_value ' . $operator . ' %s and', $value );
371
-            }
372
-            $where .= $wpdb->prepare(' field_id=%d', $field_id);
371
+			}
372
+			$where .= $wpdb->prepare(' field_id=%d', $field_id);
373 373
 			$query = 'SELECT DISTINCT item_id FROM ' . $wpdb->prefix . 'frm_item_metas' . FrmAppHelper::prepend_and_or_where( ' WHERE ', $where );
374
-        } else {
374
+		} else {
375 375
 			if ( $operator == 'LIKE' ) {
376
-                $search = '%' . $search . '%';
376
+				$search = '%' . $search . '%';
377 377
 			}
378
-            $query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id);
379
-        }
378
+			$query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id);
379
+		}
380 380
 
381
-        $results = $wpdb->get_col($query, 0);
381
+		$results = $wpdb->get_col($query, 0);
382 382
 		FrmAppHelper::set_cache( $cache_key, $results, 'frm_entry' );
383 383
 
384
-        return $results;
385
-    }
384
+		return $results;
385
+	}
386 386
 }
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
2
+if ( ! defined( 'ABSPATH' ) ) {
3 3
 	die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
@@ -20,10 +20,10 @@  discard block
 block discarded – undo
20 20
 			'meta_value'    => is_array( $meta_value ) ? serialize( array_filter( $meta_value, 'FrmAppHelper::is_not_empty_value' ) ) : trim( $meta_value ),
21 21
             'item_id'       => $entry_id,
22 22
             'field_id'      => $field_id,
23
-            'created_at'    => current_time('mysql', 1),
23
+            'created_at'    => current_time( 'mysql', 1 ),
24 24
         );
25 25
 
26
-        $new_values = apply_filters('frm_add_entry_meta', $new_values);
26
+        $new_values = apply_filters( 'frm_add_entry_meta', $new_values );
27 27
 
28 28
 		$query_results = $wpdb->insert( $wpdb->prefix . 'frm_item_metas', $new_values );
29 29
 
@@ -49,13 +49,13 @@  discard block
 block discarded – undo
49 49
 
50 50
         $values = $where_values = array( 'item_id' => $entry_id, 'field_id' => $field_id );
51 51
         $values['meta_value'] = $meta_value;
52
-        $values = apply_filters('frm_update_entry_meta', $values);
53
-		if ( is_array($values['meta_value']) ) {
52
+        $values = apply_filters( 'frm_update_entry_meta', $values );
53
+		if ( is_array( $values['meta_value'] ) ) {
54 54
 			$values['meta_value'] = array_filter( $values['meta_value'], 'FrmAppHelper::is_not_empty_value' );
55 55
 		}
56
-        $meta_value = maybe_serialize($values['meta_value']);
56
+        $meta_value = maybe_serialize( $values['meta_value'] );
57 57
 
58
-        wp_cache_delete( $entry_id, 'frm_entry');
58
+        wp_cache_delete( $entry_id, 'frm_entry' );
59 59
 		self::clear_cache();
60 60
 
61 61
 		return $wpdb->update( $wpdb->prefix . 'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values );
@@ -70,11 +70,11 @@  discard block
 block discarded – undo
70 70
             // set the value for the file upload field and add new tags (in Pro version)
71 71
 			$meta_value = apply_filters( 'frm_prepare_data_before_db', $meta_value, $field_id, $entry_id );
72 72
 
73
-			if ( $prev_values && in_array($field_id, $prev_values) ) {
73
+			if ( $prev_values && in_array( $field_id, $prev_values ) ) {
74 74
 
75 75
 				if ( ( is_array( $meta_value ) && empty( $meta_value ) ) || ( ! is_array( $meta_value ) && trim( $meta_value ) == '' ) ) {
76 76
 					// remove blank fields
77
-					unset( $values[ $field_id ] );
77
+					unset( $values[$field_id] );
78 78
 				} else {
79 79
 					// if value exists, then update it
80 80
 					self::update_entry_meta( $entry_id, $field_id, '', $meta_value );
@@ -85,13 +85,13 @@  discard block
 block discarded – undo
85 85
 			}
86 86
 		}
87 87
 
88
-        if ( empty($prev_values) ) {
88
+        if ( empty( $prev_values ) ) {
89 89
             return;
90 90
         }
91 91
 
92
-        $prev_values = array_diff($prev_values, array_keys($values));
92
+        $prev_values = array_diff( $prev_values, array_keys( $values ) );
93 93
 
94
-        if ( empty($prev_values) ) {
94
+        if ( empty( $prev_values ) ) {
95 95
             return;
96 96
         }
97 97
 
@@ -105,10 +105,10 @@  discard block
 block discarded – undo
105 105
     }
106 106
 
107 107
 	public static function duplicate_entry_metas( $old_id, $new_id ) {
108
-        $metas = self::get_entry_meta_info($old_id);
108
+        $metas = self::get_entry_meta_info( $old_id );
109 109
         foreach ( $metas as $meta ) {
110
-            self::add_entry_meta($new_id, $meta->field_id, null, $meta->meta_value);
111
-            unset($meta);
110
+            self::add_entry_meta( $new_id, $meta->field_id, null, $meta->meta_value );
111
+            unset( $meta );
112 112
         }
113 113
 		self::clear_cache();
114 114
     }
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	public static function delete_entry_meta( $entry_id, $field_id ) {
117 117
         global $wpdb;
118 118
 		self::clear_cache();
119
-        return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id));
119
+        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id ) );
120 120
     }
121 121
 
122 122
 	/**
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 	 */
136 136
 	public static function get_meta_value( $entry, $field_id ) {
137 137
 		if ( isset( $entry->metas ) ) {
138
-			return isset( $entry->metas[ $field_id ] ) ? $entry->metas[ $field_id ] : false;
138
+			return isset( $entry->metas[$field_id] ) ? $entry->metas[$field_id] : false;
139 139
 		} else {
140 140
 			return self::get_entry_meta_by_field( $entry->id, $field_id );
141 141
 		}
@@ -153,14 +153,14 @@  discard block
 block discarded – undo
153 153
 			$cached = FrmAppHelper::check_cache( $entry_id, 'frm_entry' );
154 154
 		}
155 155
 
156
-		if ( $cached && isset( $cached->metas ) && isset( $cached->metas[ $field_id ] ) ) {
157
-			$result = $cached->metas[ $field_id ];
158
-            return stripslashes_deep($result);
156
+		if ( $cached && isset( $cached->metas ) && isset( $cached->metas[$field_id] ) ) {
157
+			$result = $cached->metas[$field_id];
158
+            return stripslashes_deep( $result );
159 159
         }
160 160
 
161 161
 		$get_table = $wpdb->prefix . 'frm_item_metas';
162 162
 		$query = array( 'item_id' => $entry_id );
163
-        if ( is_numeric($field_id) ) {
163
+        if ( is_numeric( $field_id ) ) {
164 164
 			$query['field_id'] = $field_id;
165 165
         } else {
166 166
 			$get_table .= ' it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id';
@@ -168,14 +168,14 @@  discard block
 block discarded – undo
168 168
         }
169 169
 
170 170
 		$result = FrmDb::get_var( $get_table, $query, 'meta_value' );
171
-        $result = maybe_unserialize($result);
172
-        $result = stripslashes_deep($result);
171
+        $result = maybe_unserialize( $result );
172
+        $result = stripslashes_deep( $result );
173 173
 
174 174
         return $result;
175 175
     }
176 176
 
177 177
 	public static function get_entry_metas( $entry_id ) {
178
-        _deprecated_function( __FUNCTION__, '1.07.10');
178
+        _deprecated_function( __FUNCTION__, '1.07.10' );
179 179
 
180 180
         global $wpdb;
181 181
 		return FrmDb::get_col( $wpdb->prefix . 'frm_item_metas', array( 'item_id' => $entry_id ), 'meta_value' );
@@ -186,22 +186,22 @@  discard block
 block discarded – undo
186 186
         $args = wp_parse_args( $args, $defaults );
187 187
 
188 188
         $query = array();
189
-        self::meta_field_query($field_id, $order, $limit, $args, $query);
190
-        $query = implode(' ', $query);
189
+        self::meta_field_query( $field_id, $order, $limit, $args, $query );
190
+        $query = implode( ' ', $query );
191 191
 
192 192
 		$cache_key = 'entry_metas_for_field_' . $field_id . $order . $limit . maybe_serialize( $args );
193
-        $values = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_col');
193
+        $values = FrmAppHelper::check_cache( $cache_key, 'frm_entry', $query, 'get_col' );
194 194
 
195 195
         if ( ! $args['stripslashes'] ) {
196 196
             return $values;
197 197
         }
198 198
 
199 199
 		foreach ( $values as $k => $v ) {
200
-			$values[ $k ] = maybe_unserialize( $v );
201
-            unset($k, $v);
200
+			$values[$k] = maybe_unserialize( $v );
201
+            unset( $k, $v );
202 202
         }
203 203
 
204
-        return stripslashes_deep($values);
204
+        return stripslashes_deep( $values );
205 205
     }
206 206
 
207 207
     /**
@@ -218,8 +218,8 @@  discard block
 block discarded – undo
218 218
 			$query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=em.item_id)';
219 219
         }
220 220
 
221
-        if ( is_numeric($field_id) ) {
222
-            $query[] = $wpdb->prepare('WHERE em.field_id=%d', $field_id);
221
+        if ( is_numeric( $field_id ) ) {
222
+            $query[] = $wpdb->prepare( 'WHERE em.field_id=%d', $field_id );
223 223
         } else {
224 224
 			$query[] = $wpdb->prepare( 'LEFT JOIN ' . $wpdb->prefix . 'frm_fields fi ON (em.field_id = fi.id) WHERE fi.field_key=%s', $field_id );
225 225
         }
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
         }
230 230
 
231 231
         if ( $args['value'] ) {
232
-            $query[] = $wpdb->prepare(' AND meta_value=%s', $args['value']);
232
+            $query[] = $wpdb->prepare( ' AND meta_value=%s', $args['value'] );
233 233
         }
234 234
         $query[] = $order . $limit;
235 235
     }
@@ -243,18 +243,18 @@  discard block
 block discarded – undo
243 243
         $query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key,
244 244
             fi.required as required, fi.form_id as field_form_id, fi.name as field_name, fi.options as fi_options
245 245
 			FROM ' . $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id' .
246
-            FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
246
+            FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
247 247
 
248 248
 		$cache_key = 'all_' . maybe_serialize( $where ) . $order_by . $limit;
249
-        $results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_row' : 'get_results'));
249
+        $results = FrmAppHelper::check_cache( $cache_key, 'frm_entry', $query, ( $limit == ' LIMIT 1' ? 'get_row' : 'get_results' ) );
250 250
 
251 251
         if ( ! $results || ! $stripslashes ) {
252 252
             return $results;
253 253
         }
254 254
 
255 255
         foreach ( $results as $k => $result ) {
256
-			$results[ $k ]->meta_value = stripslashes_deep( maybe_unserialize( $result->meta_value ) );
257
-            unset($k, $result);
256
+			$results[$k]->meta_value = stripslashes_deep( maybe_unserialize( $result->meta_value ) );
257
+            unset( $k, $result );
258 258
         }
259 259
 
260 260
         return $results;
@@ -266,14 +266,14 @@  discard block
 block discarded – undo
266 266
 			'user_id'  => '',
267 267
 			'group_by' => '',
268 268
 		);
269
-        $args = wp_parse_args($args, $defaults);
269
+        $args = wp_parse_args( $args, $defaults );
270 270
 
271 271
         $query = array();
272
-        self::get_ids_query($where, $order_by, $limit, $unique, $args, $query );
273
-        $query = implode(' ', $query);
272
+        self::get_ids_query( $where, $order_by, $limit, $unique, $args, $query );
273
+        $query = implode( ' ', $query );
274 274
 
275 275
 		$cache_key = 'ids_' . maybe_serialize( $where ) . $order_by . 'l' . $limit . 'u' . $unique . maybe_serialize( $args );
276
-        $results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_var' : 'get_col'));
276
+        $results = FrmAppHelper::check_cache( $cache_key, 'frm_entry', $query, ( $limit == ' LIMIT 1' ? 'get_var' : 'get_col' ) );
277 277
 
278 278
         return $results;
279 279
     }
@@ -299,17 +299,17 @@  discard block
 block discarded – undo
299 299
 		$query[] = 'FROM ' . $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id';
300 300
 
301 301
 		$query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=it.item_id)';
302
-        if ( is_array($where) ) {
302
+        if ( is_array( $where ) ) {
303 303
             if ( ! $args['is_draft'] ) {
304 304
                 $where['e.is_draft'] = 0;
305 305
             } else if ( $args['is_draft'] == 1 ) {
306 306
                 $where['e.is_draft'] = 1;
307 307
             }
308 308
 
309
-            if ( ! empty($args['user_id']) ) {
309
+            if ( ! empty( $args['user_id'] ) ) {
310 310
                 $where['e.user_id'] = $args['user_id'];
311 311
             }
312
-            $query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
312
+            $query[] = FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
313 313
 
314 314
 			if ( $args['group_by'] ) {
315 315
 				$query[] = ' GROUP BY ' . sanitize_text_field( $args['group_by'] );
@@ -324,13 +324,13 @@  discard block
 block discarded – undo
324 324
 			$draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 1 );
325 325
         }
326 326
 
327
-        if ( ! empty($args['user_id']) ) {
328
-            $user_where = $wpdb->prepare(' AND e.user_id=%d', $args['user_id']);
327
+        if ( ! empty( $args['user_id'] ) ) {
328
+            $user_where = $wpdb->prepare( ' AND e.user_id=%d', $args['user_id'] );
329 329
         }
330 330
 
331
-        if ( strpos($where, ' GROUP BY ') ) {
331
+        if ( strpos( $where, ' GROUP BY ' ) ) {
332 332
             // don't inject WHERE filtering after GROUP BY
333
-            $parts = explode(' GROUP BY ', $where);
333
+            $parts = explode( ' GROUP BY ', $where );
334 334
             $where = $parts[0];
335 335
             $where .= $draft_where . $user_where;
336 336
 			$where .= ' GROUP BY ' . $parts[1];
@@ -339,12 +339,12 @@  discard block
 block discarded – undo
339 339
         }
340 340
 
341 341
 		// The query has already been prepared
342
-		$query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
342
+		$query[] = FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
343 343
     }
344 344
 
345 345
     public static function search_entry_metas( $search, $field_id = '', $operator ) {
346 346
 		$cache_key = 'search_' . maybe_serialize( $search ) . $field_id . $operator;
347
-        $results = wp_cache_get($cache_key, 'frm_entry');
347
+        $results = wp_cache_get( $cache_key, 'frm_entry' );
348 348
         if ( false !== $results ) {
349 349
             return $results;
350 350
         }
@@ -367,18 +367,18 @@  discard block
 block discarded – undo
367 367
                     case 'day':
368 368
 						$value = '%' . $value . '%';
369 369
                 }
370
-				$where .= $wpdb->prepare(' meta_value ' . $operator . ' %s and', $value );
370
+				$where .= $wpdb->prepare( ' meta_value ' . $operator . ' %s and', $value );
371 371
             }
372
-            $where .= $wpdb->prepare(' field_id=%d', $field_id);
372
+            $where .= $wpdb->prepare( ' field_id=%d', $field_id );
373 373
 			$query = 'SELECT DISTINCT item_id FROM ' . $wpdb->prefix . 'frm_item_metas' . FrmAppHelper::prepend_and_or_where( ' WHERE ', $where );
374 374
         } else {
375 375
 			if ( $operator == 'LIKE' ) {
376 376
                 $search = '%' . $search . '%';
377 377
 			}
378
-            $query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id);
378
+            $query = $wpdb->prepare( "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id );
379 379
         }
380 380
 
381
-        $results = $wpdb->get_col($query, 0);
381
+        $results = $wpdb->get_col( $query, 0 );
382 382
 		FrmAppHelper::set_cache( $cache_key, $results, 'frm_entry' );
383 383
 
384 384
         return $results;
Please login to merge, or discard this patch.