Completed
Push — master ( 07fdbe...22d5ad )
by Jamie
03:00
created
classes/models/FrmForm.php 2 patches
Indentation   +333 added lines, -333 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 ) {
138
+		foreach ( $values as $value_key => $value ) {
139 139
 			if ( $value_key && 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['item_meta']) && ! isset($values['field_options']) ) {
195
-            return $values;
196
-        }
194
+		if ( ! 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, 'frm_form' );
563
-    	if ( false !== $counts ) {
564
-    	    return $counts;
565
-    	}
562
+		$counts = wp_cache_get( $cache_key, 'frm_form' );
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, 'frm_form' );
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   +101 added lines, -101 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 139
 			if ( $value_key && in_array( $value_key, $form_fields ) ) {
140
-				$new_values[ $value_key ] = $value;
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['item_meta']) && ! isset($values['field_options']) ) {
194
+        if ( ! 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.