@@ -126,19 +126,19 @@ |
||
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
129 | - * Flatten multi-dimensional array for multi-file upload fields |
|
130 | - * @since 2.0.9 |
|
131 | - */ |
|
129 | + * Flatten multi-dimensional array for multi-file upload fields |
|
130 | + * @since 2.0.9 |
|
131 | + */ |
|
132 | 132 | public static function flatten_multi_file_upload( $field, &$val ) { |
133 | 133 | if ( $field->type == 'file' && FrmField::is_option_true( $field, 'multiple' ) ) { |
134 | 134 | $val = FrmAppHelper::array_flatten( $val ); |
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
138 | - /** |
|
139 | - * Replace returns with HTML line breaks for display |
|
140 | - * @since 2.0.9 |
|
141 | - */ |
|
138 | + /** |
|
139 | + * Replace returns with HTML line breaks for display |
|
140 | + * @since 2.0.9 |
|
141 | + */ |
|
142 | 142 | public static function textarea_display_value( $type, $plain_text, &$value ) { |
143 | 143 | if ( $type == 'textarea' && ! $plain_text ) { |
144 | 144 | $value = str_replace( array( "\r\n", "\r", "\n" ), ' <br/>', $value ); |
@@ -37,20 +37,20 @@ discard block |
||
37 | 37 | $atts['id'] = $atts['entry']->id; |
38 | 38 | } |
39 | 39 | |
40 | - if ( ! $atts['fields'] || ! is_array($atts['fields']) ) { |
|
40 | + if ( ! $atts['fields'] || ! is_array( $atts['fields'] ) ) { |
|
41 | 41 | $atts['fields'] = FrmField::get_all_for_form( $atts['form_id'], '', 'include' ); |
42 | 42 | } |
43 | 43 | |
44 | 44 | $values = array(); |
45 | 45 | foreach ( $atts['fields'] as $f ) { |
46 | 46 | self::fill_entry_values( $atts, $f, $values ); |
47 | - unset($f); |
|
47 | + unset( $f ); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | self::fill_entry_user_info( $atts, $values ); |
51 | 51 | |
52 | 52 | if ( $atts['format'] == 'json' ) { |
53 | - return json_encode($values); |
|
53 | + return json_encode( $values ); |
|
54 | 54 | } else if ( $atts['format'] == 'array' ) { |
55 | 55 | return $values; |
56 | 56 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | self::convert_entry_to_content( $values, $atts, $content ); |
60 | 60 | |
61 | 61 | if ( 'text' == $atts['format'] ) { |
62 | - $content = implode('', $content); |
|
62 | + $content = implode( '', $content ); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | if ( $atts['clickable'] ) { |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | } |
84 | 84 | |
85 | 85 | $field_id_string = reset( $f->field_options['hide_field'] ) . ' show=' . $f->field_options['form_select']; |
86 | - $values[ $f->id ] = array( 'label' => '[' . $f->id . ' show=field_label]', 'val' => '[' . $field_id_string . ']' ); |
|
86 | + $values[$f->id] = array( 'label' => '[' . $f->id . ' show=field_label]', 'val' => '[' . $field_id_string . ']' ); |
|
87 | 87 | } else { |
88 | - $values[ $f->id ] = array( 'label' => '[' . $f->id . ' show=field_label]', 'val' => '[' . $f->id . ']' ); |
|
88 | + $values[$f->id] = array( 'label' => '[' . $f->id . ' show=field_label]', 'val' => '[' . $f->id . ']' ); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | return; |
100 | 100 | } |
101 | 101 | |
102 | - if ( $atts['entry'] && ! isset( $atts['entry']->metas[ $f->id ] ) ) { |
|
102 | + if ( $atts['entry'] && ! isset( $atts['entry']->metas[$f->id] ) ) { |
|
103 | 103 | // In case include_blank is set |
104 | - $atts['entry']->metas[ $f->id ] = ''; |
|
104 | + $atts['entry']->metas[$f->id] = ''; |
|
105 | 105 | |
106 | 106 | if ( FrmAppHelper::pro_is_installed() ) { |
107 | 107 | FrmProEntryMeta::add_post_value_to_entry( $f, $atts['entry'] ); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | |
112 | 112 | $val = ''; |
113 | 113 | if ( $atts['entry'] ) { |
114 | - $prev_val = maybe_unserialize( $atts['entry']->metas[ $f->id ] ); |
|
114 | + $prev_val = maybe_unserialize( $atts['entry']->metas[$f->id] ); |
|
115 | 115 | $meta = array( 'item_id' => $atts['id'], 'field_id' => $f->id, 'meta_value' => $prev_val, 'field_type' => $f->type ); |
116 | 116 | |
117 | 117 | //This filter applies to the default-message shortcode and frm-show-entry shortcode only |
@@ -136,12 +136,12 @@ discard block |
||
136 | 136 | self::maybe_strip_html( $atts['plain_text'], $val ); |
137 | 137 | |
138 | 138 | if ( $atts['format'] != 'text' ) { |
139 | - $values[ $f->field_key ] = $val; |
|
139 | + $values[$f->field_key] = $val; |
|
140 | 140 | if ( isset( $prev_val ) && $prev_val != $val && $f->type != 'textarea' ) { |
141 | - $values[ $f->field_key .'-value' ] = $prev_val; |
|
141 | + $values[$f->field_key . '-value'] = $prev_val; |
|
142 | 142 | } |
143 | 143 | } else { |
144 | - $values[ $f->id ] = array( 'label' => $f->name, 'val' => $val ); |
|
144 | + $values[$f->id] = array( 'label' => $f->name, 'val' => $val ); |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | return; |
188 | 188 | } |
189 | 189 | |
190 | - $data = self::get_entry_description_data( $atts ); |
|
190 | + $data = self::get_entry_description_data( $atts ); |
|
191 | 191 | |
192 | 192 | if ( $atts['default_email'] ) { |
193 | 193 | $atts['entry']->ip = '[ip]'; |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | preg_match_all( $pattern, $u_agent, $matches ); // get the matching numbers |
275 | 275 | |
276 | 276 | // see how many we have |
277 | - $i = count($matches['browser']); |
|
277 | + $i = count( $matches['browser'] ); |
|
278 | 278 | if ( $i != 1 ) { |
279 | 279 | //we will have two since we are not using 'other' argument yet |
280 | 280 | //see if version is before or after the name |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | $version = '?'; |
293 | 293 | } |
294 | 294 | |
295 | - return $bname .' '. $version .' / '. $platform; |
|
295 | + return $bname . ' ' . $version . ' / ' . $platform; |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | public static function convert_entry_to_content( $values, $atts, array &$content ) { |
@@ -311,23 +311,23 @@ discard block |
||
311 | 311 | |
312 | 312 | // merge defaults, global settings, and shortcode options |
313 | 313 | foreach ( $default_settings as $key => $setting ) { |
314 | - if ( $atts[ $key ] != '' ) { |
|
314 | + if ( $atts[$key] != '' ) { |
|
315 | 315 | continue; |
316 | 316 | } |
317 | 317 | |
318 | - $atts[ $key ] = $setting; |
|
318 | + $atts[$key] = $setting; |
|
319 | 319 | unset( $key, $setting ); |
320 | 320 | } |
321 | 321 | |
322 | - unset($default_settings); |
|
322 | + unset( $default_settings ); |
|
323 | 323 | |
324 | - $content[] = '<table cellspacing="0" style="font-size:'. $atts['font_size'] .';line-height:135%; border-bottom:'. $atts['border_width'] . ' solid #' . $atts['border_color'] . ';"><tbody>' . "\r\n"; |
|
325 | - $atts['bg_color'] = ' style="background-color:#'. $atts['bg_color'] .';"'; |
|
326 | - $bg_color_alt = ' style="background-color:#'. $atts['alt_bg_color'] .';"'; |
|
324 | + $content[] = '<table cellspacing="0" style="font-size:' . $atts['font_size'] . ';line-height:135%; border-bottom:' . $atts['border_width'] . ' solid #' . $atts['border_color'] . ';"><tbody>' . "\r\n"; |
|
325 | + $atts['bg_color'] = ' style="background-color:#' . $atts['bg_color'] . ';"'; |
|
326 | + $bg_color_alt = ' style="background-color:#' . $atts['alt_bg_color'] . ';"'; |
|
327 | 327 | |
328 | - $row_style_attributes = 'text-align:' . ( $atts['direction'] == 'rtl' ? 'right' : 'left' ) .';'; |
|
329 | - $row_style_attributes .= 'color:#'. $atts['text_color'] . ';padding:7px 9px;vertical-align:top;'; |
|
330 | - $row_style_attributes .= 'border-top:' . $atts['border_width'] .' solid #' . $atts['border_color'] . ';'; |
|
328 | + $row_style_attributes = 'text-align:' . ( $atts['direction'] == 'rtl' ? 'right' : 'left' ) . ';'; |
|
329 | + $row_style_attributes .= 'color:#' . $atts['text_color'] . ';padding:7px 9px;vertical-align:top;'; |
|
330 | + $row_style_attributes .= 'border-top:' . $atts['border_width'] . ' solid #' . $atts['border_color'] . ';'; |
|
331 | 331 | $row_style = 'style="' . $row_style_attributes . '"'; |
332 | 332 | } |
333 | 333 | |
@@ -335,14 +335,14 @@ discard block |
||
335 | 335 | foreach ( $values as $id => $value ) { |
336 | 336 | if ( $atts['plain_text'] ) { |
337 | 337 | if ( 'rtl' == $atts['direction'] ) { |
338 | - $content[] = $value['val'] . ' :'. $value['label'] ."\r\n"; |
|
338 | + $content[] = $value['val'] . ' :' . $value['label'] . "\r\n"; |
|
339 | 339 | } else { |
340 | - $content[] = $value['label'] . ': '. $value['val'] ."\r\n"; |
|
340 | + $content[] = $value['label'] . ': ' . $value['val'] . "\r\n"; |
|
341 | 341 | } |
342 | 342 | continue; |
343 | 343 | } |
344 | 344 | |
345 | - if ( $atts['default_email'] && is_numeric($id) ) { |
|
345 | + if ( $atts['default_email'] && is_numeric( $id ) ) { |
|
346 | 346 | $content[] = '[if ' . $id . ']<tr style="[frm-alt-color]">'; |
347 | 347 | } else { |
348 | 348 | $content[] = '<tr' . ( $odd ? $atts['bg_color'] : $bg_color_alt ) . '>'; |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | if ( 'rtl' == $atts['direction'] ) { |
353 | 353 | $content[] = '<td ' . $row_style . '>' . $value['val'] . '</td><th ' . $row_style . '>' . $value['label'] . '</th>'; |
354 | 354 | } else { |
355 | - $content[] = '<th ' . $row_style . '>' . $value['label'] . '</th><td '. $row_style . '>' . $value['val'] . '</td>'; |
|
355 | + $content[] = '<th ' . $row_style . '>' . $value['label'] . '</th><td ' . $row_style . '>' . $value['val'] . '</td>'; |
|
356 | 356 | } |
357 | 357 | $content[] = '</tr>' . "\r\n"; |
358 | 358 |
@@ -4,7 +4,7 @@ discard block |
||
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() { |
@@ -52,41 +52,41 @@ discard block |
||
52 | 52 | )); |
53 | 53 | } |
54 | 54 | |
55 | - public static function create( $values, $return = true ) { |
|
56 | - global $wpdb, $frm_duplicate_ids; |
|
55 | + public static function create( $values, $return = true ) { |
|
56 | + global $wpdb, $frm_duplicate_ids; |
|
57 | 57 | |
58 | - $new_values = array(); |
|
59 | - $key = isset($values['field_key']) ? $values['field_key'] : $values['name']; |
|
60 | - $new_values['field_key'] = FrmAppHelper::get_unique_key($key, $wpdb->prefix .'frm_fields', 'field_key'); |
|
58 | + $new_values = array(); |
|
59 | + $key = isset($values['field_key']) ? $values['field_key'] : $values['name']; |
|
60 | + $new_values['field_key'] = FrmAppHelper::get_unique_key($key, $wpdb->prefix .'frm_fields', 'field_key'); |
|
61 | 61 | |
62 | 62 | foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) { |
63 | 63 | $new_values[ $col ] = $values[ $col ]; |
64 | - } |
|
64 | + } |
|
65 | 65 | |
66 | - $new_values['options'] = $values['options']; |
|
66 | + $new_values['options'] = $values['options']; |
|
67 | 67 | |
68 | - $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null; |
|
69 | - $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0; |
|
70 | - $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null; |
|
71 | - $new_values['field_options'] = $values['field_options']; |
|
72 | - $new_values['created_at'] = current_time('mysql', 1); |
|
68 | + $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null; |
|
69 | + $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0; |
|
70 | + $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null; |
|
71 | + $new_values['field_options'] = $values['field_options']; |
|
72 | + $new_values['created_at'] = current_time('mysql', 1); |
|
73 | 73 | |
74 | 74 | if ( isset( $values['id'] ) ) { |
75 | 75 | $frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key']; |
76 | - $new_values = apply_filters('frm_duplicated_field', $new_values); |
|
77 | - } |
|
76 | + $new_values = apply_filters('frm_duplicated_field', $new_values); |
|
77 | + } |
|
78 | 78 | |
79 | 79 | foreach ( $new_values as $k => $v ) { |
80 | - if ( is_array( $v ) ) { |
|
80 | + if ( is_array( $v ) ) { |
|
81 | 81 | $new_values[ $k ] = serialize( $v ); |
82 | 82 | } |
83 | - unset( $k, $v ); |
|
84 | - } |
|
83 | + unset( $k, $v ); |
|
84 | + } |
|
85 | 85 | |
86 | - //if(isset($values['id']) and is_numeric($values['id'])) |
|
87 | - // $new_values['id'] = $values['id']; |
|
86 | + //if(isset($values['id']) and is_numeric($values['id'])) |
|
87 | + // $new_values['id'] = $values['id']; |
|
88 | 88 | |
89 | - $query_results = $wpdb->insert( $wpdb->prefix .'frm_fields', $new_values ); |
|
89 | + $query_results = $wpdb->insert( $wpdb->prefix .'frm_fields', $new_values ); |
|
90 | 90 | $new_id = 0; |
91 | 91 | if ( $query_results ) { |
92 | 92 | self::delete_form_transient( $new_values['form_id'] ); |
@@ -105,22 +105,22 @@ discard block |
||
105 | 105 | } else { |
106 | 106 | return false; |
107 | 107 | } |
108 | - } |
|
108 | + } |
|
109 | 109 | |
110 | - public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) { |
|
111 | - global $frm_duplicate_ids; |
|
110 | + public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) { |
|
111 | + global $frm_duplicate_ids; |
|
112 | 112 | |
113 | 113 | $where = array( array( 'or' => 1, 'fi.form_id' => $old_form_id, 'fr.parent_form_id' => $old_form_id ) ); |
114 | 114 | $fields = self::getAll( $where, 'field_order', '', $blog_id ); |
115 | 115 | |
116 | - foreach ( (array) $fields as $field ) { |
|
117 | - $new_key = ($copy_keys) ? $field->field_key : ''; |
|
118 | - if ( $copy_keys && substr($field->field_key, -1) == 2 ) { |
|
119 | - $new_key = rtrim($new_key, 2); |
|
120 | - } |
|
116 | + foreach ( (array) $fields as $field ) { |
|
117 | + $new_key = ($copy_keys) ? $field->field_key : ''; |
|
118 | + if ( $copy_keys && substr($field->field_key, -1) == 2 ) { |
|
119 | + $new_key = rtrim($new_key, 2); |
|
120 | + } |
|
121 | 121 | |
122 | - $values = array(); |
|
123 | - FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key ); |
|
122 | + $values = array(); |
|
123 | + FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key ); |
|
124 | 124 | |
125 | 125 | // If this is a repeating section, create new form |
126 | 126 | if ( self::is_repeating_field( $field ) ) { |
@@ -139,26 +139,26 @@ discard block |
||
139 | 139 | $values['form_id'] = $new_repeat_form_id; |
140 | 140 | } |
141 | 141 | |
142 | - $values = apply_filters('frm_duplicated_field', $values); |
|
143 | - $new_id = self::create($values); |
|
144 | - $frm_duplicate_ids[ $field->id ] = $new_id; |
|
145 | - $frm_duplicate_ids[ $field->field_key ] = $new_id; |
|
146 | - unset($field); |
|
147 | - } |
|
148 | - } |
|
142 | + $values = apply_filters('frm_duplicated_field', $values); |
|
143 | + $new_id = self::create($values); |
|
144 | + $frm_duplicate_ids[ $field->id ] = $new_id; |
|
145 | + $frm_duplicate_ids[ $field->field_key ] = $new_id; |
|
146 | + unset($field); |
|
147 | + } |
|
148 | + } |
|
149 | 149 | |
150 | 150 | public static function update( $id, $values ) { |
151 | - global $wpdb; |
|
151 | + global $wpdb; |
|
152 | 152 | |
153 | 153 | $id = absint( $id ); |
154 | 154 | |
155 | 155 | if ( isset( $values['field_key'] ) ) { |
156 | - $values['field_key'] = FrmAppHelper::get_unique_key($values['field_key'], $wpdb->prefix .'frm_fields', 'field_key', $id); |
|
156 | + $values['field_key'] = FrmAppHelper::get_unique_key($values['field_key'], $wpdb->prefix .'frm_fields', 'field_key', $id); |
|
157 | 157 | } |
158 | 158 | |
159 | - if ( isset($values['required']) ) { |
|
160 | - $values['required'] = (int) $values['required']; |
|
161 | - } |
|
159 | + if ( isset($values['required']) ) { |
|
160 | + $values['required'] = (int) $values['required']; |
|
161 | + } |
|
162 | 162 | |
163 | 163 | self::preserve_phone_format_backslashes( $values ); |
164 | 164 | |
@@ -169,43 +169,43 @@ discard block |
||
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | - $query_results = $wpdb->update( $wpdb->prefix .'frm_fields', $values, array( 'id' => $id ) ); |
|
172 | + $query_results = $wpdb->update( $wpdb->prefix .'frm_fields', $values, array( 'id' => $id ) ); |
|
173 | 173 | |
174 | - $form_id = 0; |
|
174 | + $form_id = 0; |
|
175 | 175 | if ( isset( $values['form_id'] ) ) { |
176 | - $form_id = absint( $values['form_id'] ); |
|
176 | + $form_id = absint( $values['form_id'] ); |
|
177 | 177 | } else { |
178 | - $field = self::getOne($id); |
|
179 | - if ( $field ) { |
|
180 | - $form_id = $field->form_id; |
|
181 | - } |
|
182 | - unset($field); |
|
183 | - } |
|
184 | - unset($values); |
|
178 | + $field = self::getOne($id); |
|
179 | + if ( $field ) { |
|
180 | + $form_id = $field->form_id; |
|
181 | + } |
|
182 | + unset($field); |
|
183 | + } |
|
184 | + unset($values); |
|
185 | 185 | |
186 | 186 | if ( $query_results ) { |
187 | - wp_cache_delete( $id, 'frm_field' ); |
|
188 | - if ( $form_id ) { |
|
189 | - self::delete_form_transient($form_id); |
|
190 | - } |
|
191 | - } |
|
187 | + wp_cache_delete( $id, 'frm_field' ); |
|
188 | + if ( $form_id ) { |
|
189 | + self::delete_form_transient($form_id); |
|
190 | + } |
|
191 | + } |
|
192 | 192 | |
193 | - return $query_results; |
|
194 | - } |
|
193 | + return $query_results; |
|
194 | + } |
|
195 | 195 | |
196 | 196 | /** |
197 | - * Keep backslashes in the phone format option |
|
198 | - * |
|
199 | - * @since 2.0.8 |
|
200 | - * @param $values array - pass by reference |
|
201 | - */ |
|
197 | + * Keep backslashes in the phone format option |
|
198 | + * |
|
199 | + * @since 2.0.8 |
|
200 | + * @param $values array - pass by reference |
|
201 | + */ |
|
202 | 202 | private static function preserve_phone_format_backslashes( &$values ) { |
203 | 203 | if ( isset( $values['field_options']['format'] ) ) { |
204 | 204 | $values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] ); |
205 | 205 | } |
206 | 206 | } |
207 | 207 | |
208 | - public static function destroy( $id ) { |
|
208 | + public static function destroy( $id ) { |
|
209 | 209 | global $wpdb; |
210 | 210 | |
211 | 211 | do_action( 'frm_before_destroy_field', $id ); |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | |
221 | 221 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $id ) ); |
222 | 222 | return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_fields WHERE id=%d', $id ) ); |
223 | - } |
|
223 | + } |
|
224 | 224 | |
225 | 225 | public static function delete_form_transient( $form_id ) { |
226 | 226 | $form_id = absint( $form_id ); |
@@ -233,16 +233,16 @@ discard block |
||
233 | 233 | $wpdb->query( $wpdb->prepare( 'DELETE FROM '. $wpdb->options .' WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_' . $form_id .'ex%', '_transient_frm_form_fields_' . $form_id .'ex%', '_transient_timeout_frm_form_fields_' . $form_id .'in%', '_transient_frm_form_fields_' . $form_id .'in%' ) ); |
234 | 234 | |
235 | 235 | $cache_key = serialize( array( 'fi.form_id' => $form_id ) ) . 'field_orderlb'; |
236 | - wp_cache_delete($cache_key, 'frm_field'); |
|
236 | + wp_cache_delete($cache_key, 'frm_field'); |
|
237 | 237 | |
238 | 238 | // this cache key is autogenerated in FrmDb::get_var |
239 | 239 | wp_cache_delete( '(__fi.form_id=%d_OR_fr.parent_form_id=%d_)__' . $form_id . '_' . $form_id . '_ORDER_BY_field_orderfi.*__fr.name_as_form_name_results', 'frm_field' ); |
240 | 240 | |
241 | - $form = FrmForm::getOne($form_id); |
|
242 | - if ( $form && $form->parent_form_id ) { |
|
243 | - self::delete_form_transient( $form->parent_form_id ); |
|
244 | - } |
|
245 | - } |
|
241 | + $form = FrmForm::getOne($form_id); |
|
242 | + if ( $form && $form->parent_form_id ) { |
|
243 | + self::delete_form_transient( $form->parent_form_id ); |
|
244 | + } |
|
245 | + } |
|
246 | 246 | |
247 | 247 | /** |
248 | 248 | * If $field is numeric, get the field object |
@@ -258,131 +258,131 @@ discard block |
||
258 | 258 | return; |
259 | 259 | } |
260 | 260 | |
261 | - global $wpdb; |
|
261 | + global $wpdb; |
|
262 | 262 | |
263 | - $where = is_numeric($id) ? 'id=%d' : 'field_key=%s'; |
|
264 | - $query = $wpdb->prepare('SELECT * FROM '. $wpdb->prefix .'frm_fields WHERE '. $where, $id); |
|
263 | + $where = is_numeric($id) ? 'id=%d' : 'field_key=%s'; |
|
264 | + $query = $wpdb->prepare('SELECT * FROM '. $wpdb->prefix .'frm_fields WHERE '. $where, $id); |
|
265 | 265 | |
266 | - $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 ); |
|
266 | + $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 ); |
|
267 | 267 | |
268 | - if ( empty($results) ) { |
|
269 | - return $results; |
|
270 | - } |
|
268 | + if ( empty($results) ) { |
|
269 | + return $results; |
|
270 | + } |
|
271 | 271 | |
272 | - if ( is_numeric($id) ) { |
|
273 | - wp_cache_set( $results->field_key, $results, 'frm_field' ); |
|
274 | - } else if ( $results ) { |
|
275 | - wp_cache_set( $results->id, $results, 'frm_field' ); |
|
276 | - } |
|
272 | + if ( is_numeric($id) ) { |
|
273 | + wp_cache_set( $results->field_key, $results, 'frm_field' ); |
|
274 | + } else if ( $results ) { |
|
275 | + wp_cache_set( $results->id, $results, 'frm_field' ); |
|
276 | + } |
|
277 | 277 | |
278 | 278 | self::prepare_options( $results ); |
279 | 279 | |
280 | - return stripslashes_deep($results); |
|
281 | - } |
|
280 | + return stripslashes_deep($results); |
|
281 | + } |
|
282 | 282 | |
283 | - /** |
|
284 | - * Get the field type by key or id |
|
285 | - * @param int|string The field id or key |
|
283 | + /** |
|
284 | + * Get the field type by key or id |
|
285 | + * @param int|string The field id or key |
|
286 | 286 | * @param mixed $col The name of the column in the fields database table |
287 | - */ |
|
288 | - public static function &get_type( $id, $col = 'type' ) { |
|
289 | - $field = FrmAppHelper::check_cache( $id, 'frm_field' ); |
|
290 | - if ( $field ) { |
|
291 | - $type = $field->{$col}; |
|
292 | - } else { |
|
293 | - $type = FrmDb::get_var( 'frm_fields', array( 'or' => 1, 'id' => $id, 'field_key' => $id ), $col ); |
|
294 | - } |
|
295 | - |
|
296 | - return $type; |
|
297 | - } |
|
287 | + */ |
|
288 | + public static function &get_type( $id, $col = 'type' ) { |
|
289 | + $field = FrmAppHelper::check_cache( $id, 'frm_field' ); |
|
290 | + if ( $field ) { |
|
291 | + $type = $field->{$col}; |
|
292 | + } else { |
|
293 | + $type = FrmDb::get_var( 'frm_fields', array( 'or' => 1, 'id' => $id, 'field_key' => $id ), $col ); |
|
294 | + } |
|
295 | + |
|
296 | + return $type; |
|
297 | + } |
|
298 | 298 | |
299 | 299 | public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) { |
300 | - if ( ! $form_id ) { |
|
301 | - return array(); |
|
302 | - } |
|
300 | + if ( ! $form_id ) { |
|
301 | + return array(); |
|
302 | + } |
|
303 | 303 | |
304 | 304 | $results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_sub, 'inc_repeat' => $inc_sub ) ); |
305 | 305 | if ( ! empty( $results ) ) { |
306 | - $fields = array(); |
|
307 | - $count = 0; |
|
308 | - foreach ( $results as $result ) { |
|
309 | - if ( $type != $result->type ) { |
|
310 | - continue; |
|
311 | - } |
|
306 | + $fields = array(); |
|
307 | + $count = 0; |
|
308 | + foreach ( $results as $result ) { |
|
309 | + if ( $type != $result->type ) { |
|
310 | + continue; |
|
311 | + } |
|
312 | 312 | |
313 | 313 | $fields[ $result->id ] = $result; |
314 | - $count++; |
|
315 | - if ( $limit == 1 ) { |
|
316 | - $fields = $result; |
|
317 | - break; |
|
318 | - } |
|
314 | + $count++; |
|
315 | + if ( $limit == 1 ) { |
|
316 | + $fields = $result; |
|
317 | + break; |
|
318 | + } |
|
319 | 319 | |
320 | - if ( ! empty($limit) && $count >= $limit ) { |
|
321 | - break; |
|
322 | - } |
|
320 | + if ( ! empty($limit) && $count >= $limit ) { |
|
321 | + break; |
|
322 | + } |
|
323 | 323 | |
324 | - unset($result); |
|
325 | - } |
|
326 | - return stripslashes_deep($fields); |
|
327 | - } |
|
324 | + unset($result); |
|
325 | + } |
|
326 | + return stripslashes_deep($fields); |
|
327 | + } |
|
328 | 328 | |
329 | - self::$use_cache = false; |
|
329 | + self::$use_cache = false; |
|
330 | 330 | |
331 | 331 | $where = array( 'fi.form_id' => (int) $form_id, 'fi.type' => $type ); |
332 | 332 | self::maybe_include_repeating_fields( $inc_sub, $where ); |
333 | 333 | $results = self::getAll( $where, 'field_order', $limit ); |
334 | - self::$use_cache = true; |
|
335 | - self::include_sub_fields($results, $inc_sub, $type); |
|
334 | + self::$use_cache = true; |
|
335 | + self::include_sub_fields($results, $inc_sub, $type); |
|
336 | 336 | |
337 | - return $results; |
|
338 | - } |
|
337 | + return $results; |
|
338 | + } |
|
339 | 339 | |
340 | 340 | public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) { |
341 | - if ( ! (int) $form_id ) { |
|
342 | - return array(); |
|
343 | - } |
|
341 | + if ( ! (int) $form_id ) { |
|
342 | + return array(); |
|
343 | + } |
|
344 | 344 | |
345 | 345 | $results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
346 | 346 | if ( ! empty( $results ) ) { |
347 | - if ( empty($limit) ) { |
|
347 | + if ( empty($limit) ) { |
|
348 | 348 | return $results; |
349 | - } |
|
349 | + } |
|
350 | 350 | |
351 | - $fields = array(); |
|
352 | - $count = 0; |
|
353 | - foreach ( $results as $result ) { |
|
351 | + $fields = array(); |
|
352 | + $count = 0; |
|
353 | + foreach ( $results as $result ) { |
|
354 | 354 | $fields[ $result->id ] = $result; |
355 | - if ( ! empty($limit) && $count >= $limit ) { |
|
356 | - break; |
|
357 | - } |
|
358 | - } |
|
355 | + if ( ! empty($limit) && $count >= $limit ) { |
|
356 | + break; |
|
357 | + } |
|
358 | + } |
|
359 | 359 | |
360 | 360 | return $fields; |
361 | - } |
|
361 | + } |
|
362 | 362 | |
363 | - self::$use_cache = false; |
|
363 | + self::$use_cache = false; |
|
364 | 364 | |
365 | 365 | $where = array( 'fi.form_id' => absint( $form_id ) ); |
366 | 366 | self::maybe_include_repeating_fields( $inc_repeat, $where ); |
367 | 367 | $results = self::getAll( $where, 'field_order', $limit ); |
368 | 368 | |
369 | - self::$use_cache = true; |
|
369 | + self::$use_cache = true; |
|
370 | 370 | |
371 | 371 | self::include_sub_fields( $results, $inc_embed, 'all' ); |
372 | 372 | |
373 | - if ( empty($limit) ) { |
|
373 | + if ( empty($limit) ) { |
|
374 | 374 | self::set_field_transient( $results, $form_id, 0, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
375 | - } |
|
375 | + } |
|
376 | 376 | |
377 | 377 | return $results; |
378 | - } |
|
378 | + } |
|
379 | 379 | |
380 | 380 | /** |
381 | - * If repeating fields should be included, adjust $where accordingly |
|
382 | - * |
|
383 | - * @param string $inc_repeat |
|
384 | - * @param array $where - pass by reference |
|
385 | - */ |
|
381 | + * If repeating fields should be included, adjust $where accordingly |
|
382 | + * |
|
383 | + * @param string $inc_repeat |
|
384 | + * @param array $where - pass by reference |
|
385 | + */ |
|
386 | 386 | private static function maybe_include_repeating_fields( $inc_repeat, &$where ) { |
387 | 387 | if ( $inc_repeat == 'include' ) { |
388 | 388 | $form_id = $where['fi.form_id']; |
@@ -393,77 +393,77 @@ discard block |
||
393 | 393 | |
394 | 394 | public static function include_sub_fields( &$results, $inc_embed, $type = 'all' ) { |
395 | 395 | if ( 'include' != $inc_embed ) { |
396 | - return; |
|
397 | - } |
|
396 | + return; |
|
397 | + } |
|
398 | 398 | |
399 | - $form_fields = $results; |
|
399 | + $form_fields = $results; |
|
400 | 400 | $index_offset = 1; |
401 | - foreach ( $form_fields as $k => $field ) { |
|
402 | - if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) { |
|
403 | - continue; |
|
404 | - } |
|
405 | - |
|
406 | - if ( $type == 'all' ) { |
|
407 | - $sub_fields = self::get_all_for_form( $field->field_options['form_select'] ); |
|
408 | - } else { |
|
409 | - $sub_fields = self::get_all_types_in_form($field->form_id, $type); |
|
410 | - } |
|
411 | - |
|
412 | - if ( ! empty($sub_fields) ) { |
|
401 | + foreach ( $form_fields as $k => $field ) { |
|
402 | + if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) { |
|
403 | + continue; |
|
404 | + } |
|
405 | + |
|
406 | + if ( $type == 'all' ) { |
|
407 | + $sub_fields = self::get_all_for_form( $field->field_options['form_select'] ); |
|
408 | + } else { |
|
409 | + $sub_fields = self::get_all_types_in_form($field->form_id, $type); |
|
410 | + } |
|
411 | + |
|
412 | + if ( ! empty($sub_fields) ) { |
|
413 | 413 | $index = $k + $index_offset; |
414 | 414 | $index_offset += count( $sub_fields ); |
415 | 415 | array_splice($results, $index, 0, $sub_fields); |
416 | - } |
|
417 | - unset($field, $sub_fields); |
|
418 | - } |
|
419 | - } |
|
416 | + } |
|
417 | + unset($field, $sub_fields); |
|
418 | + } |
|
419 | + } |
|
420 | 420 | |
421 | 421 | public static function getAll( $where = array(), $order_by = '', $limit = '', $blog_id = false ) { |
422 | - $cache_key = maybe_serialize($where) . $order_by .'l'. $limit .'b'. $blog_id; |
|
423 | - if ( self::$use_cache ) { |
|
424 | - // make sure old cache doesn't get saved as a transient |
|
425 | - $results = wp_cache_get($cache_key, 'frm_field'); |
|
426 | - if ( false !== $results ) { |
|
427 | - return stripslashes_deep($results); |
|
428 | - } |
|
429 | - } |
|
430 | - |
|
431 | - global $wpdb; |
|
432 | - |
|
433 | - if ( $blog_id && is_multisite() ) { |
|
434 | - global $wpmuBaseTablePrefix; |
|
435 | - if ( $wpmuBaseTablePrefix ) { |
|
436 | - $prefix = $wpmuBaseTablePrefix . $blog_id .'_'; |
|
437 | - } else { |
|
438 | - $prefix = $wpdb->get_blog_prefix( $blog_id ); |
|
439 | - } |
|
440 | - |
|
441 | - $table_name = $prefix .'frm_fields'; |
|
442 | - $form_table_name = $prefix .'frm_forms'; |
|
422 | + $cache_key = maybe_serialize($where) . $order_by .'l'. $limit .'b'. $blog_id; |
|
423 | + if ( self::$use_cache ) { |
|
424 | + // make sure old cache doesn't get saved as a transient |
|
425 | + $results = wp_cache_get($cache_key, 'frm_field'); |
|
426 | + if ( false !== $results ) { |
|
427 | + return stripslashes_deep($results); |
|
428 | + } |
|
429 | + } |
|
430 | + |
|
431 | + global $wpdb; |
|
432 | + |
|
433 | + if ( $blog_id && is_multisite() ) { |
|
434 | + global $wpmuBaseTablePrefix; |
|
435 | + if ( $wpmuBaseTablePrefix ) { |
|
436 | + $prefix = $wpmuBaseTablePrefix . $blog_id .'_'; |
|
437 | + } else { |
|
438 | + $prefix = $wpdb->get_blog_prefix( $blog_id ); |
|
439 | + } |
|
440 | + |
|
441 | + $table_name = $prefix .'frm_fields'; |
|
442 | + $form_table_name = $prefix .'frm_forms'; |
|
443 | 443 | } else { |
444 | - $table_name = $wpdb->prefix .'frm_fields'; |
|
445 | - $form_table_name = $wpdb->prefix .'frm_forms'; |
|
446 | - } |
|
444 | + $table_name = $wpdb->prefix .'frm_fields'; |
|
445 | + $form_table_name = $wpdb->prefix .'frm_forms'; |
|
446 | + } |
|
447 | 447 | |
448 | 448 | if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) { |
449 | - $order_by = ' ORDER BY '. $order_by; |
|
449 | + $order_by = ' ORDER BY '. $order_by; |
|
450 | 450 | } |
451 | 451 | |
452 | - $limit = FrmAppHelper::esc_limit($limit); |
|
452 | + $limit = FrmAppHelper::esc_limit($limit); |
|
453 | 453 | |
454 | - $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"; |
|
455 | - $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results'; |
|
454 | + $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"; |
|
455 | + $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results'; |
|
456 | 456 | |
457 | - if ( is_array($where) ) { |
|
458 | - $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 ); |
|
457 | + if ( is_array($where) ) { |
|
458 | + $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 ); |
|
459 | 459 | } else { |
460 | 460 | // if the query is not an array, then it has already been prepared |
461 | - $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
461 | + $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
462 | 462 | |
463 | 463 | $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results'; |
464 | 464 | $results = $wpdb->$function_name( $query ); |
465 | - } |
|
466 | - unset( $where ); |
|
465 | + } |
|
466 | + unset( $where ); |
|
467 | 467 | |
468 | 468 | self::format_field_results( $results ); |
469 | 469 | |
@@ -562,21 +562,21 @@ discard block |
||
562 | 562 | |
563 | 563 | public static function getIds( $where = '', $order_by = '', $limit = '' ) { |
564 | 564 | _deprecated_function( __FUNCTION__, '2.0' ); |
565 | - global $wpdb; |
|
566 | - if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) { |
|
567 | - $order_by = ' ORDER BY '. $order_by; |
|
568 | - } |
|
565 | + global $wpdb; |
|
566 | + if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) { |
|
567 | + $order_by = ' ORDER BY '. $order_by; |
|
568 | + } |
|
569 | 569 | |
570 | - $query = 'SELECT fi.id FROM '. $wpdb->prefix .'frm_fields fi ' . |
|
571 | - 'LEFT OUTER JOIN '. $wpdb->prefix .'frm_forms fr ON fi.form_id=fr.id' . |
|
572 | - FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
570 | + $query = 'SELECT fi.id FROM '. $wpdb->prefix .'frm_fields fi ' . |
|
571 | + 'LEFT OUTER JOIN '. $wpdb->prefix .'frm_forms fr ON fi.form_id=fr.id' . |
|
572 | + FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
573 | 573 | |
574 | - $method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col'; |
|
575 | - $cache_key = 'getIds_'. maybe_serialize($where) . $order_by . $limit; |
|
576 | - $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method); |
|
574 | + $method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col'; |
|
575 | + $cache_key = 'getIds_'. maybe_serialize($where) . $order_by . $limit; |
|
576 | + $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method); |
|
577 | 577 | |
578 | - return $results; |
|
579 | - } |
|
578 | + return $results; |
|
579 | + } |
|
580 | 580 | |
581 | 581 | public static function is_no_save_field( $type ) { |
582 | 582 | return in_array( $type, self::no_save_fields() ); |
@@ -681,8 +681,8 @@ discard block |
||
681 | 681 | } |
682 | 682 | |
683 | 683 | /** |
684 | - * @since 2.0.09 |
|
685 | - */ |
|
684 | + * @since 2.0.09 |
|
685 | + */ |
|
686 | 686 | public static function is_repeating_field( $field ) { |
687 | 687 | if ( is_array( $field ) ) { |
688 | 688 | $is_repeating_field = ( 'divider' == $field['type'] ); |
@@ -692,12 +692,12 @@ discard block |
||
692 | 692 | return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) ); |
693 | 693 | } |
694 | 694 | |
695 | - /** |
|
696 | - * @param string $key |
|
697 | - * @return int field id |
|
698 | - */ |
|
695 | + /** |
|
696 | + * @param string $key |
|
697 | + * @return int field id |
|
698 | + */ |
|
699 | 699 | public static function get_id_by_key( $key ) { |
700 | - $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) ); |
|
701 | - return $id; |
|
702 | - } |
|
700 | + $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) ); |
|
701 | + return $id; |
|
702 | + } |
|
703 | 703 | } |
@@ -1,5 +1,5 @@ discard block |
||
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 |
||
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 |
||
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', |
@@ -49,36 +49,36 @@ discard block |
||
49 | 49 | //'city_selector' => 'US State/County/City selector', |
50 | 50 | //'full_name' => 'First and Last Name', |
51 | 51 | //'quiz' => 'Question and Answer' // for captcha alternative |
52 | - )); |
|
52 | + ) ); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | public static function create( $values, $return = true ) { |
56 | 56 | global $wpdb, $frm_duplicate_ids; |
57 | 57 | |
58 | 58 | $new_values = array(); |
59 | - $key = isset($values['field_key']) ? $values['field_key'] : $values['name']; |
|
60 | - $new_values['field_key'] = FrmAppHelper::get_unique_key($key, $wpdb->prefix .'frm_fields', 'field_key'); |
|
59 | + $key = isset( $values['field_key'] ) ? $values['field_key'] : $values['name']; |
|
60 | + $new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' ); |
|
61 | 61 | |
62 | 62 | foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) { |
63 | - $new_values[ $col ] = $values[ $col ]; |
|
63 | + $new_values[$col] = $values[$col]; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | $new_values['options'] = $values['options']; |
67 | 67 | |
68 | - $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null; |
|
69 | - $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0; |
|
70 | - $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null; |
|
68 | + $new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null; |
|
69 | + $new_values['required'] = isset( $values['required'] ) ? (int) $values['required'] : 0; |
|
70 | + $new_values['form_id'] = isset( $values['form_id'] ) ? (int) $values['form_id'] : null; |
|
71 | 71 | $new_values['field_options'] = $values['field_options']; |
72 | - $new_values['created_at'] = current_time('mysql', 1); |
|
72 | + $new_values['created_at'] = current_time( 'mysql', 1 ); |
|
73 | 73 | |
74 | 74 | if ( isset( $values['id'] ) ) { |
75 | - $frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key']; |
|
76 | - $new_values = apply_filters('frm_duplicated_field', $new_values); |
|
75 | + $frm_duplicate_ids[$values['field_key']] = $new_values['field_key']; |
|
76 | + $new_values = apply_filters( 'frm_duplicated_field', $new_values ); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | foreach ( $new_values as $k => $v ) { |
80 | 80 | if ( is_array( $v ) ) { |
81 | - $new_values[ $k ] = serialize( $v ); |
|
81 | + $new_values[$k] = serialize( $v ); |
|
82 | 82 | } |
83 | 83 | unset( $k, $v ); |
84 | 84 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | //if(isset($values['id']) and is_numeric($values['id'])) |
87 | 87 | // $new_values['id'] = $values['id']; |
88 | 88 | |
89 | - $query_results = $wpdb->insert( $wpdb->prefix .'frm_fields', $new_values ); |
|
89 | + $query_results = $wpdb->insert( $wpdb->prefix . 'frm_fields', $new_values ); |
|
90 | 90 | $new_id = 0; |
91 | 91 | if ( $query_results ) { |
92 | 92 | self::delete_form_transient( $new_values['form_id'] ); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | |
100 | 100 | if ( $query_results ) { |
101 | 101 | if ( isset( $values['id'] ) ) { |
102 | - $frm_duplicate_ids[ $values['id'] ] = $new_id; |
|
102 | + $frm_duplicate_ids[$values['id']] = $new_id; |
|
103 | 103 | } |
104 | 104 | return $new_id; |
105 | 105 | } else { |
@@ -114,9 +114,9 @@ discard block |
||
114 | 114 | $fields = self::getAll( $where, 'field_order', '', $blog_id ); |
115 | 115 | |
116 | 116 | foreach ( (array) $fields as $field ) { |
117 | - $new_key = ($copy_keys) ? $field->field_key : ''; |
|
118 | - if ( $copy_keys && substr($field->field_key, -1) == 2 ) { |
|
119 | - $new_key = rtrim($new_key, 2); |
|
117 | + $new_key = ( $copy_keys ) ? $field->field_key : ''; |
|
118 | + if ( $copy_keys && substr( $field->field_key, -1 ) == 2 ) { |
|
119 | + $new_key = rtrim( $new_key, 2 ); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | $values = array(); |
@@ -139,11 +139,11 @@ discard block |
||
139 | 139 | $values['form_id'] = $new_repeat_form_id; |
140 | 140 | } |
141 | 141 | |
142 | - $values = apply_filters('frm_duplicated_field', $values); |
|
143 | - $new_id = self::create($values); |
|
144 | - $frm_duplicate_ids[ $field->id ] = $new_id; |
|
145 | - $frm_duplicate_ids[ $field->field_key ] = $new_id; |
|
146 | - unset($field); |
|
142 | + $values = apply_filters( 'frm_duplicated_field', $values ); |
|
143 | + $new_id = self::create( $values ); |
|
144 | + $frm_duplicate_ids[$field->id] = $new_id; |
|
145 | + $frm_duplicate_ids[$field->field_key] = $new_id; |
|
146 | + unset( $field ); |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | |
@@ -153,10 +153,10 @@ discard block |
||
153 | 153 | $id = absint( $id ); |
154 | 154 | |
155 | 155 | if ( isset( $values['field_key'] ) ) { |
156 | - $values['field_key'] = FrmAppHelper::get_unique_key($values['field_key'], $wpdb->prefix .'frm_fields', 'field_key', $id); |
|
156 | + $values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id ); |
|
157 | 157 | } |
158 | 158 | |
159 | - if ( isset($values['required']) ) { |
|
159 | + if ( isset( $values['required'] ) ) { |
|
160 | 160 | $values['required'] = (int) $values['required']; |
161 | 161 | } |
162 | 162 | |
@@ -164,29 +164,29 @@ discard block |
||
164 | 164 | |
165 | 165 | // serialize array values |
166 | 166 | foreach ( array( 'default_value', 'field_options', 'options' ) as $opt ) { |
167 | - if ( isset( $values[ $opt ] ) && is_array( $values[ $opt ] ) ) { |
|
168 | - $values[ $opt ] = serialize( $values[ $opt ] ); |
|
167 | + if ( isset( $values[$opt] ) && is_array( $values[$opt] ) ) { |
|
168 | + $values[$opt] = serialize( $values[$opt] ); |
|
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | - $query_results = $wpdb->update( $wpdb->prefix .'frm_fields', $values, array( 'id' => $id ) ); |
|
172 | + $query_results = $wpdb->update( $wpdb->prefix . 'frm_fields', $values, array( 'id' => $id ) ); |
|
173 | 173 | |
174 | 174 | $form_id = 0; |
175 | 175 | if ( isset( $values['form_id'] ) ) { |
176 | 176 | $form_id = absint( $values['form_id'] ); |
177 | 177 | } else { |
178 | - $field = self::getOne($id); |
|
178 | + $field = self::getOne( $id ); |
|
179 | 179 | if ( $field ) { |
180 | 180 | $form_id = $field->form_id; |
181 | 181 | } |
182 | - unset($field); |
|
182 | + unset( $field ); |
|
183 | 183 | } |
184 | - unset($values); |
|
184 | + unset( $values ); |
|
185 | 185 | |
186 | 186 | if ( $query_results ) { |
187 | 187 | wp_cache_delete( $id, 'frm_field' ); |
188 | 188 | if ( $form_id ) { |
189 | - self::delete_form_transient($form_id); |
|
189 | + self::delete_form_transient( $form_id ); |
|
190 | 190 | } |
191 | 191 | } |
192 | 192 | |
@@ -224,21 +224,21 @@ discard block |
||
224 | 224 | |
225 | 225 | public static function delete_form_transient( $form_id ) { |
226 | 226 | $form_id = absint( $form_id ); |
227 | - delete_transient( 'frm_form_fields_'. $form_id .'excludeinclude' ); |
|
228 | - delete_transient( 'frm_form_fields_'. $form_id .'includeinclude' ); |
|
229 | - delete_transient( 'frm_form_fields_'. $form_id .'includeexclude' ); |
|
230 | - delete_transient( 'frm_form_fields_'. $form_id .'excludeexclude' ); |
|
227 | + delete_transient( 'frm_form_fields_' . $form_id . 'excludeinclude' ); |
|
228 | + delete_transient( 'frm_form_fields_' . $form_id . 'includeinclude' ); |
|
229 | + delete_transient( 'frm_form_fields_' . $form_id . 'includeexclude' ); |
|
230 | + delete_transient( 'frm_form_fields_' . $form_id . 'excludeexclude' ); |
|
231 | 231 | |
232 | 232 | global $wpdb; |
233 | - $wpdb->query( $wpdb->prepare( 'DELETE FROM '. $wpdb->options .' WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_' . $form_id .'ex%', '_transient_frm_form_fields_' . $form_id .'ex%', '_transient_timeout_frm_form_fields_' . $form_id .'in%', '_transient_frm_form_fields_' . $form_id .'in%' ) ); |
|
233 | + $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_' . $form_id . 'ex%', '_transient_frm_form_fields_' . $form_id . 'ex%', '_transient_timeout_frm_form_fields_' . $form_id . 'in%', '_transient_frm_form_fields_' . $form_id . 'in%' ) ); |
|
234 | 234 | |
235 | 235 | $cache_key = serialize( array( 'fi.form_id' => $form_id ) ) . 'field_orderlb'; |
236 | - wp_cache_delete($cache_key, 'frm_field'); |
|
236 | + wp_cache_delete( $cache_key, 'frm_field' ); |
|
237 | 237 | |
238 | 238 | // this cache key is autogenerated in FrmDb::get_var |
239 | 239 | wp_cache_delete( '(__fi.form_id=%d_OR_fr.parent_form_id=%d_)__' . $form_id . '_' . $form_id . '_ORDER_BY_field_orderfi.*__fr.name_as_form_name_results', 'frm_field' ); |
240 | 240 | |
241 | - $form = FrmForm::getOne($form_id); |
|
241 | + $form = FrmForm::getOne( $form_id ); |
|
242 | 242 | if ( $form && $form->parent_form_id ) { |
243 | 243 | self::delete_form_transient( $form->parent_form_id ); |
244 | 244 | } |
@@ -260,16 +260,16 @@ discard block |
||
260 | 260 | |
261 | 261 | global $wpdb; |
262 | 262 | |
263 | - $where = is_numeric($id) ? 'id=%d' : 'field_key=%s'; |
|
264 | - $query = $wpdb->prepare('SELECT * FROM '. $wpdb->prefix .'frm_fields WHERE '. $where, $id); |
|
263 | + $where = is_numeric( $id ) ? 'id=%d' : 'field_key=%s'; |
|
264 | + $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id ); |
|
265 | 265 | |
266 | 266 | $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 ); |
267 | 267 | |
268 | - if ( empty($results) ) { |
|
268 | + if ( empty( $results ) ) { |
|
269 | 269 | return $results; |
270 | 270 | } |
271 | 271 | |
272 | - if ( is_numeric($id) ) { |
|
272 | + if ( is_numeric( $id ) ) { |
|
273 | 273 | wp_cache_set( $results->field_key, $results, 'frm_field' ); |
274 | 274 | } else if ( $results ) { |
275 | 275 | wp_cache_set( $results->id, $results, 'frm_field' ); |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | |
278 | 278 | self::prepare_options( $results ); |
279 | 279 | |
280 | - return stripslashes_deep($results); |
|
280 | + return stripslashes_deep( $results ); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | /** |
@@ -310,20 +310,20 @@ discard block |
||
310 | 310 | continue; |
311 | 311 | } |
312 | 312 | |
313 | - $fields[ $result->id ] = $result; |
|
314 | - $count++; |
|
313 | + $fields[$result->id] = $result; |
|
314 | + $count ++; |
|
315 | 315 | if ( $limit == 1 ) { |
316 | 316 | $fields = $result; |
317 | 317 | break; |
318 | 318 | } |
319 | 319 | |
320 | - if ( ! empty($limit) && $count >= $limit ) { |
|
320 | + if ( ! empty( $limit ) && $count >= $limit ) { |
|
321 | 321 | break; |
322 | 322 | } |
323 | 323 | |
324 | - unset($result); |
|
324 | + unset( $result ); |
|
325 | 325 | } |
326 | - return stripslashes_deep($fields); |
|
326 | + return stripslashes_deep( $fields ); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | self::$use_cache = false; |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | self::maybe_include_repeating_fields( $inc_sub, $where ); |
333 | 333 | $results = self::getAll( $where, 'field_order', $limit ); |
334 | 334 | self::$use_cache = true; |
335 | - self::include_sub_fields($results, $inc_sub, $type); |
|
335 | + self::include_sub_fields( $results, $inc_sub, $type ); |
|
336 | 336 | |
337 | 337 | return $results; |
338 | 338 | } |
@@ -344,15 +344,15 @@ discard block |
||
344 | 344 | |
345 | 345 | $results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
346 | 346 | if ( ! empty( $results ) ) { |
347 | - if ( empty($limit) ) { |
|
347 | + if ( empty( $limit ) ) { |
|
348 | 348 | return $results; |
349 | 349 | } |
350 | 350 | |
351 | 351 | $fields = array(); |
352 | 352 | $count = 0; |
353 | 353 | foreach ( $results as $result ) { |
354 | - $fields[ $result->id ] = $result; |
|
355 | - if ( ! empty($limit) && $count >= $limit ) { |
|
354 | + $fields[$result->id] = $result; |
|
355 | + if ( ! empty( $limit ) && $count >= $limit ) { |
|
356 | 356 | break; |
357 | 357 | } |
358 | 358 | } |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | |
371 | 371 | self::include_sub_fields( $results, $inc_embed, 'all' ); |
372 | 372 | |
373 | - if ( empty($limit) ) { |
|
373 | + if ( empty( $limit ) ) { |
|
374 | 374 | self::set_field_transient( $results, $form_id, 0, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
375 | 375 | } |
376 | 376 | |
@@ -399,32 +399,32 @@ discard block |
||
399 | 399 | $form_fields = $results; |
400 | 400 | $index_offset = 1; |
401 | 401 | foreach ( $form_fields as $k => $field ) { |
402 | - if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) { |
|
402 | + if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) { |
|
403 | 403 | continue; |
404 | 404 | } |
405 | 405 | |
406 | 406 | if ( $type == 'all' ) { |
407 | 407 | $sub_fields = self::get_all_for_form( $field->field_options['form_select'] ); |
408 | 408 | } else { |
409 | - $sub_fields = self::get_all_types_in_form($field->form_id, $type); |
|
409 | + $sub_fields = self::get_all_types_in_form( $field->form_id, $type ); |
|
410 | 410 | } |
411 | 411 | |
412 | - if ( ! empty($sub_fields) ) { |
|
412 | + if ( ! empty( $sub_fields ) ) { |
|
413 | 413 | $index = $k + $index_offset; |
414 | 414 | $index_offset += count( $sub_fields ); |
415 | - array_splice($results, $index, 0, $sub_fields); |
|
415 | + array_splice( $results, $index, 0, $sub_fields ); |
|
416 | 416 | } |
417 | - unset($field, $sub_fields); |
|
417 | + unset( $field, $sub_fields ); |
|
418 | 418 | } |
419 | 419 | } |
420 | 420 | |
421 | 421 | public static function getAll( $where = array(), $order_by = '', $limit = '', $blog_id = false ) { |
422 | - $cache_key = maybe_serialize($where) . $order_by .'l'. $limit .'b'. $blog_id; |
|
422 | + $cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id; |
|
423 | 423 | if ( self::$use_cache ) { |
424 | 424 | // make sure old cache doesn't get saved as a transient |
425 | - $results = wp_cache_get($cache_key, 'frm_field'); |
|
425 | + $results = wp_cache_get( $cache_key, 'frm_field' ); |
|
426 | 426 | if ( false !== $results ) { |
427 | - return stripslashes_deep($results); |
|
427 | + return stripslashes_deep( $results ); |
|
428 | 428 | } |
429 | 429 | } |
430 | 430 | |
@@ -433,32 +433,32 @@ discard block |
||
433 | 433 | if ( $blog_id && is_multisite() ) { |
434 | 434 | global $wpmuBaseTablePrefix; |
435 | 435 | if ( $wpmuBaseTablePrefix ) { |
436 | - $prefix = $wpmuBaseTablePrefix . $blog_id .'_'; |
|
436 | + $prefix = $wpmuBaseTablePrefix . $blog_id . '_'; |
|
437 | 437 | } else { |
438 | 438 | $prefix = $wpdb->get_blog_prefix( $blog_id ); |
439 | 439 | } |
440 | 440 | |
441 | - $table_name = $prefix .'frm_fields'; |
|
442 | - $form_table_name = $prefix .'frm_forms'; |
|
441 | + $table_name = $prefix . 'frm_fields'; |
|
442 | + $form_table_name = $prefix . 'frm_forms'; |
|
443 | 443 | } else { |
444 | - $table_name = $wpdb->prefix .'frm_fields'; |
|
445 | - $form_table_name = $wpdb->prefix .'frm_forms'; |
|
444 | + $table_name = $wpdb->prefix . 'frm_fields'; |
|
445 | + $form_table_name = $wpdb->prefix . 'frm_forms'; |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) { |
449 | - $order_by = ' ORDER BY '. $order_by; |
|
449 | + $order_by = ' ORDER BY ' . $order_by; |
|
450 | 450 | } |
451 | 451 | |
452 | - $limit = FrmAppHelper::esc_limit($limit); |
|
452 | + $limit = FrmAppHelper::esc_limit( $limit ); |
|
453 | 453 | |
454 | 454 | $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"; |
455 | 455 | $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results'; |
456 | 456 | |
457 | - if ( is_array($where) ) { |
|
457 | + if ( is_array( $where ) ) { |
|
458 | 458 | $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 ); |
459 | 459 | } else { |
460 | 460 | // if the query is not an array, then it has already been prepared |
461 | - $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
461 | + $query .= FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
|
462 | 462 | |
463 | 463 | $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results'; |
464 | 464 | $results = $wpdb->$function_name( $query ); |
@@ -481,9 +481,9 @@ discard block |
||
481 | 481 | wp_cache_set( $result->id, $result, 'frm_field' ); |
482 | 482 | wp_cache_set( $result->field_key, $result, 'frm_field' ); |
483 | 483 | |
484 | - $results[ $r_key ]->field_options = maybe_unserialize( $result->field_options ); |
|
485 | - $results[ $r_key ]->options = maybe_unserialize( $result->options ); |
|
486 | - $results[ $r_key ]->default_value = maybe_unserialize( $result->default_value ); |
|
484 | + $results[$r_key]->field_options = maybe_unserialize( $result->field_options ); |
|
485 | + $results[$r_key]->options = maybe_unserialize( $result->options ); |
|
486 | + $results[$r_key]->default_value = maybe_unserialize( $result->default_value ); |
|
487 | 487 | |
488 | 488 | unset( $r_key, $result ); |
489 | 489 | } |
@@ -502,8 +502,8 @@ discard block |
||
502 | 502 | private static function prepare_options( &$results ) { |
503 | 503 | $results->field_options = maybe_unserialize( $results->field_options ); |
504 | 504 | |
505 | - $results->options = maybe_unserialize($results->options); |
|
506 | - $results->default_value = maybe_unserialize($results->default_value); |
|
505 | + $results->options = maybe_unserialize( $results->options ); |
|
506 | + $results->default_value = maybe_unserialize( $results->default_value ); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | /** |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | |
531 | 531 | if ( count( $next_fields ) >= self::$transient_size ) { |
532 | 532 | // if this transient is full, check for another |
533 | - $next++; |
|
533 | + $next ++; |
|
534 | 534 | self::get_next_transient( $fields, $base_name, $next ); |
535 | 535 | } |
536 | 536 | } |
@@ -556,24 +556,24 @@ discard block |
||
556 | 556 | return; |
557 | 557 | } |
558 | 558 | |
559 | - $next++; |
|
559 | + $next ++; |
|
560 | 560 | } |
561 | 561 | } |
562 | 562 | |
563 | 563 | public static function getIds( $where = '', $order_by = '', $limit = '' ) { |
564 | 564 | _deprecated_function( __FUNCTION__, '2.0' ); |
565 | 565 | global $wpdb; |
566 | - if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) { |
|
567 | - $order_by = ' ORDER BY '. $order_by; |
|
566 | + if ( ! empty( $order_by ) && ! strpos( $order_by, 'ORDER BY' ) !== false ) { |
|
567 | + $order_by = ' ORDER BY ' . $order_by; |
|
568 | 568 | } |
569 | 569 | |
570 | - $query = 'SELECT fi.id FROM '. $wpdb->prefix .'frm_fields fi ' . |
|
571 | - 'LEFT OUTER JOIN '. $wpdb->prefix .'frm_forms fr ON fi.form_id=fr.id' . |
|
572 | - FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
570 | + $query = 'SELECT fi.id FROM ' . $wpdb->prefix . 'frm_fields fi ' . |
|
571 | + 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON fi.form_id=fr.id' . |
|
572 | + FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
|
573 | 573 | |
574 | 574 | $method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col'; |
575 | - $cache_key = 'getIds_'. maybe_serialize($where) . $order_by . $limit; |
|
576 | - $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method); |
|
575 | + $cache_key = 'getIds_' . maybe_serialize( $where ) . $order_by . $limit; |
|
576 | + $results = FrmAppHelper::check_cache( $cache_key, 'frm_field', $query, $method ); |
|
577 | 577 | |
578 | 578 | return $results; |
579 | 579 | } |
@@ -600,9 +600,9 @@ discard block |
||
600 | 600 | } |
601 | 601 | |
602 | 602 | if ( is_array( $field ) ) { |
603 | - return $field['type'] == 'checkbox' || ( $field['type'] == 'data' && isset($field['data_type']) && $field['data_type'] == 'checkbox' ) || self::is_multiple_select( $field ); |
|
603 | + return $field['type'] == 'checkbox' || ( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'checkbox' ) || self::is_multiple_select( $field ); |
|
604 | 604 | } else { |
605 | - return $field->type == 'checkbox' || ( $field->type == 'data' && isset( $field->field_options['data_type'] ) && $field->field_options['data_type'] == 'checkbox' ) || self::is_multiple_select($field); |
|
605 | + return $field->type == 'checkbox' || ( $field->type == 'data' && isset( $field->field_options['data_type'] ) && $field->field_options['data_type'] == 'checkbox' ) || self::is_multiple_select( $field ); |
|
606 | 606 | } |
607 | 607 | } |
608 | 608 | |
@@ -614,9 +614,9 @@ discard block |
||
614 | 614 | */ |
615 | 615 | public static function is_multiple_select( $field ) { |
616 | 616 | if ( is_array( $field ) ) { |
617 | - return self::is_option_true( $field, 'multiple' ) && ( ( $field['type'] == 'select' || ( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'select') ) ); |
|
617 | + return self::is_option_true( $field, 'multiple' ) && ( ( $field['type'] == 'select' || ( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'select' ) ) ); |
|
618 | 618 | } else { |
619 | - 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') ) ); |
|
619 | + 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' ) ) ); |
|
620 | 620 | } |
621 | 621 | } |
622 | 622 | |
@@ -661,23 +661,23 @@ discard block |
||
661 | 661 | } |
662 | 662 | |
663 | 663 | public static function is_option_true_in_array( $field, $option ) { |
664 | - return isset( $field[ $option ] ) && $field[ $option ]; |
|
664 | + return isset( $field[$option] ) && $field[$option]; |
|
665 | 665 | } |
666 | 666 | |
667 | 667 | public static function is_option_true_in_object( $field, $option ) { |
668 | - return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ]; |
|
668 | + return isset( $field->field_options[$option] ) && $field->field_options[$option]; |
|
669 | 669 | } |
670 | 670 | |
671 | 671 | public static function is_option_empty_in_array( $field, $option ) { |
672 | - return ! isset( $field[ $option ] ) || empty( $field[ $option ] ); |
|
672 | + return ! isset( $field[$option] ) || empty( $field[$option] ); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | public static function is_option_empty_in_object( $field, $option ) { |
676 | - return ! isset( $field->field_options[ $option ] ) || empty( $field->field_options[ $option ] ); |
|
676 | + return ! isset( $field->field_options[$option] ) || empty( $field->field_options[$option] ); |
|
677 | 677 | } |
678 | 678 | |
679 | 679 | public static function is_option_value_in_object( $field, $option ) { |
680 | - return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != ''; |
|
680 | + return isset( $field->field_options[$option] ) && $field->field_options[$option] != ''; |
|
681 | 681 | } |
682 | 682 | |
683 | 683 | /** |
@@ -693,11 +693,11 @@ discard block |
||
693 | 693 | } |
694 | 694 | |
695 | 695 | public static function get_option_in_array( $field, $option ) { |
696 | - return $field[ $option ]; |
|
696 | + return $field[$option]; |
|
697 | 697 | } |
698 | 698 | |
699 | 699 | public static function get_option_in_object( $field, $option ) { |
700 | - return isset( $field->field_options[ $option ] ) ? $field->field_options[ $option ] : ''; |
|
700 | + return isset( $field->field_options[$option] ) ? $field->field_options[$option] : ''; |
|
701 | 701 | } |
702 | 702 | |
703 | 703 | /** |
@@ -1,376 +1,376 @@ discard block |
||
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; |
|
13 | - |
|
14 | - $new_values = array( |
|
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, |
|
8 | + /** |
|
9 | + * @return int|boolean id on success or false on failure |
|
10 | + */ |
|
11 | + public static function create( $values ) { |
|
12 | + global $wpdb; |
|
13 | + |
|
14 | + $new_values = array( |
|
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, |
|
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 | - $options = array(); |
|
27 | + $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 | - $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values ); |
|
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 | - } |
|
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; |
|
55 | - |
|
56 | - $values = self::getOne( $id, $blog_id ); |
|
57 | - if ( ! $values ) { |
|
58 | - return false; |
|
59 | - } |
|
60 | - |
|
61 | - $new_key = $copy_keys ? $values->form_key : ''; |
|
62 | - |
|
63 | - $new_values = array( |
|
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 | - } |
|
87 | - |
|
88 | - $query_results = $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values ); |
|
89 | - |
|
90 | - if ( $query_results ) { |
|
47 | + return $id; |
|
48 | + } |
|
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; |
|
55 | + |
|
56 | + $values = self::getOne( $id, $blog_id ); |
|
57 | + if ( ! $values ) { |
|
58 | + return false; |
|
59 | + } |
|
60 | + |
|
61 | + $new_key = $copy_keys ? $values->form_key : ''; |
|
62 | + |
|
63 | + $new_values = array( |
|
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 | + } |
|
87 | + |
|
88 | + $query_results = $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values ); |
|
89 | + |
|
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']) ) { |
|
131 | - $values['form_key'] = FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key', $id); |
|
132 | - } |
|
130 | + if ( isset($values['form_key']) ) { |
|
131 | + $values['form_key'] = FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key', $id); |
|
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 ) ) { |
|
149 | - $query_results = $wpdb->update( $wpdb->prefix .'frm_forms', $new_values, array( 'id' => $id ) ); |
|
150 | - if ( $query_results ) { |
|
148 | + if ( ! empty( $new_values ) ) { |
|
149 | + $query_results = $wpdb->update( $wpdb->prefix .'frm_forms', $new_values, array( 'id' => $id ) ); |
|
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 | - do_action('frm_update_form', $id, $values); |
|
161 | - do_action('frm_update_form_'. $id, $values); |
|
160 | + do_action('frm_update_form', $id, $values); |
|
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 | - $options = array(); |
|
174 | + $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 | if ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) { |
229 | - //updating the settings page |
|
229 | + //updating the settings page |
|
230 | 230 | if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) { |
231 | 231 | $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 ) ); |
232 | - $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
232 | + $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
233 | 233 | FrmField::update( $field_id, array( 'field_options' => $field->field_options ) ); |
234 | - } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) { |
|
235 | - $prev_opts = $field->field_options; |
|
236 | - $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
237 | - if ( $prev_opts != $field->field_options ) { |
|
234 | + } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) { |
|
235 | + $prev_opts = $field->field_options; |
|
236 | + $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
237 | + if ( $prev_opts != $field->field_options ) { |
|
238 | 238 | FrmField::update( $field_id, array( 'field_options' => $field->field_options ) ); |
239 | - } |
|
240 | - unset($prev_opts); |
|
241 | - } |
|
242 | - } |
|
239 | + } |
|
240 | + unset($prev_opts); |
|
241 | + } |
|
242 | + } |
|
243 | 243 | |
244 | 244 | if ( ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) && ! defined( 'WP_IMPORTING' ) ) { |
245 | - continue; |
|
246 | - } |
|
245 | + continue; |
|
246 | + } |
|
247 | 247 | |
248 | - //updating the form |
|
248 | + //updating the form |
|
249 | 249 | foreach ( array( 'size', 'max', 'label', 'invalid', 'blank', 'classes', 'captcha_size' ) as $opt ) { |
250 | 250 | $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( $values['field_options'][ $opt . '_' . $field_id ] ) : ''; |
251 | - } |
|
251 | + } |
|
252 | 252 | |
253 | 253 | $field->field_options['required_indicator'] = isset( $values['field_options'][ 'required_indicator_' . $field_id ] ) ? trim( $values['field_options'][ 'required_indicator_' . $field_id ] ) : '*'; |
254 | 254 | $field->field_options['separate_value'] = isset( $values['field_options'][ 'separate_value_' . $field_id ] ) ? trim( $values['field_options'][ 'separate_value_' . $field_id ] ) : 0; |
255 | 255 | |
256 | - $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values); |
|
256 | + $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values); |
|
257 | 257 | $default_value = maybe_serialize( $values['item_meta'][ $field_id ] ); |
258 | 258 | $field_key = isset( $values['field_options'][ 'field_key_' . $field_id ] ) ? $values['field_options'][ 'field_key_' . $field_id ] : $field->field_key; |
259 | 259 | $required = isset( $values['field_options'][ 'required_' . $field_id ] ) ? $values['field_options'][ 'required_' . $field_id ] : false; |
260 | 260 | $field_type = isset( $values['field_options'][ 'type_' . $field_id ] ) ? $values['field_options'][ 'type_' . $field_id ] : $field->type; |
261 | 261 | $field_description = isset( $values['field_options'][ 'description_' . $field_id ] ) ? $values['field_options'][ 'description_' . $field_id ] : $field->description; |
262 | 262 | |
263 | - FrmField::update($field_id, array( |
|
264 | - 'field_key' => $field_key, 'type' => $field_type, |
|
265 | - 'default_value' => $default_value, 'field_options' => $field->field_options, |
|
266 | - 'description' => $field_description, 'required' => $required, |
|
267 | - ) ); |
|
263 | + FrmField::update($field_id, array( |
|
264 | + 'field_key' => $field_key, 'type' => $field_type, |
|
265 | + 'default_value' => $default_value, 'field_options' => $field->field_options, |
|
266 | + 'description' => $field_description, 'required' => $required, |
|
267 | + ) ); |
|
268 | 268 | |
269 | - FrmField::delete_form_transient($field->form_id); |
|
270 | - } |
|
269 | + FrmField::delete_form_transient($field->form_id); |
|
270 | + } |
|
271 | 271 | |
272 | - return $values; |
|
273 | - } |
|
272 | + return $values; |
|
273 | + } |
|
274 | 274 | |
275 | - /** |
|
276 | - * @param string $status |
|
277 | - * @return int|boolean |
|
278 | - */ |
|
275 | + /** |
|
276 | + * @param string $status |
|
277 | + * @return int|boolean |
|
278 | + */ |
|
279 | 279 | public static function set_status( $id, $status ) { |
280 | - if ( 'trash' == $status ) { |
|
281 | - return self::trash($id); |
|
282 | - } |
|
280 | + if ( 'trash' == $status ) { |
|
281 | + return self::trash($id); |
|
282 | + } |
|
283 | 283 | |
284 | 284 | $statuses = array( 'published', 'draft', 'trash' ); |
285 | - if ( ! in_array( $status, $statuses ) ) { |
|
286 | - return false; |
|
287 | - } |
|
285 | + if ( ! in_array( $status, $statuses ) ) { |
|
286 | + return false; |
|
287 | + } |
|
288 | 288 | |
289 | - global $wpdb; |
|
289 | + global $wpdb; |
|
290 | 290 | |
291 | - if ( is_array($id) ) { |
|
291 | + if ( is_array($id) ) { |
|
292 | 292 | $where = array( 'id' => $id ); |
293 | 293 | FrmDb::get_where_clause_and_values( $where ); |
294 | 294 | array_unshift( $where['values'], $status ); |
295 | 295 | |
296 | 296 | $query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) ); |
297 | - } else { |
|
297 | + } else { |
|
298 | 298 | $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) ); |
299 | - } |
|
299 | + } |
|
300 | 300 | |
301 | - if ( $query_results ) { |
|
301 | + if ( $query_results ) { |
|
302 | 302 | self::clear_form_cache(); |
303 | - } |
|
303 | + } |
|
304 | 304 | |
305 | - return $query_results; |
|
306 | - } |
|
305 | + return $query_results; |
|
306 | + } |
|
307 | 307 | |
308 | - /** |
|
309 | - * @return int|boolean |
|
310 | - */ |
|
308 | + /** |
|
309 | + * @return int|boolean |
|
310 | + */ |
|
311 | 311 | public static function trash( $id ) { |
312 | - if ( ! EMPTY_TRASH_DAYS ) { |
|
313 | - return self::destroy( $id ); |
|
314 | - } |
|
312 | + if ( ! EMPTY_TRASH_DAYS ) { |
|
313 | + return self::destroy( $id ); |
|
314 | + } |
|
315 | 315 | |
316 | - $form = self::getOne($id); |
|
317 | - if ( ! $form ) { |
|
318 | - return false; |
|
319 | - } |
|
316 | + $form = self::getOne($id); |
|
317 | + if ( ! $form ) { |
|
318 | + return false; |
|
319 | + } |
|
320 | 320 | |
321 | - $options = $form->options; |
|
322 | - $options['trash_time'] = time(); |
|
321 | + $options = $form->options; |
|
322 | + $options['trash_time'] = time(); |
|
323 | 323 | |
324 | - global $wpdb; |
|
325 | - $query_results = $wpdb->update( |
|
326 | - $wpdb->prefix .'frm_forms', |
|
324 | + global $wpdb; |
|
325 | + $query_results = $wpdb->update( |
|
326 | + $wpdb->prefix .'frm_forms', |
|
327 | 327 | array( 'status' => 'trash', 'options' => serialize( $options ) ), |
328 | 328 | array( 'id' => $id ) |
329 | - ); |
|
329 | + ); |
|
330 | 330 | |
331 | - if ( $query_results ) { |
|
331 | + if ( $query_results ) { |
|
332 | 332 | self::clear_form_cache(); |
333 | - } |
|
333 | + } |
|
334 | 334 | |
335 | - return $query_results; |
|
336 | - } |
|
335 | + return $query_results; |
|
336 | + } |
|
337 | 337 | |
338 | - /** |
|
339 | - * @return int|boolean |
|
340 | - */ |
|
338 | + /** |
|
339 | + * @return int|boolean |
|
340 | + */ |
|
341 | 341 | public static function destroy( $id ) { |
342 | - global $wpdb; |
|
342 | + global $wpdb; |
|
343 | 343 | |
344 | - $form = self::getOne($id); |
|
345 | - if ( ! $form ) { |
|
346 | - return false; |
|
347 | - } |
|
344 | + $form = self::getOne($id); |
|
345 | + if ( ! $form ) { |
|
346 | + return false; |
|
347 | + } |
|
348 | 348 | |
349 | - // Disconnect the entries from this form |
|
349 | + // Disconnect the entries from this form |
|
350 | 350 | $entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) ); |
351 | - foreach ( $entries as $entry_id ) { |
|
352 | - FrmEntry::destroy($entry_id); |
|
353 | - unset($entry_id); |
|
354 | - } |
|
351 | + foreach ( $entries as $entry_id ) { |
|
352 | + FrmEntry::destroy($entry_id); |
|
353 | + unset($entry_id); |
|
354 | + } |
|
355 | 355 | |
356 | - // Disconnect the fields from this form |
|
357 | - $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)); |
|
356 | + // Disconnect the fields from this form |
|
357 | + $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)); |
|
358 | 358 | |
359 | - $query_results = $wpdb->query($wpdb->prepare('DELETE FROM '. $wpdb->prefix .'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id)); |
|
360 | - if ( $query_results ) { |
|
361 | - // Delete all form actions linked to this form |
|
362 | - $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
|
363 | - $action_control->destroy($id, 'all'); |
|
359 | + $query_results = $wpdb->query($wpdb->prepare('DELETE FROM '. $wpdb->prefix .'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id)); |
|
360 | + if ( $query_results ) { |
|
361 | + // Delete all form actions linked to this form |
|
362 | + $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
|
363 | + $action_control->destroy($id, 'all'); |
|
364 | 364 | |
365 | 365 | // Clear form caching |
366 | 366 | self::clear_form_cache(); |
367 | 367 | |
368 | - do_action('frm_destroy_form', $id); |
|
369 | - do_action('frm_destroy_form_'. $id); |
|
370 | - } |
|
368 | + do_action('frm_destroy_form', $id); |
|
369 | + do_action('frm_destroy_form_'. $id); |
|
370 | + } |
|
371 | 371 | |
372 | - return $query_results; |
|
373 | - } |
|
372 | + return $query_results; |
|
373 | + } |
|
374 | 374 | |
375 | 375 | /** |
376 | 376 | * Delete trashed forms based on how long they have been trashed |
@@ -402,49 +402,49 @@ discard block |
||
402 | 402 | return $count; |
403 | 403 | } |
404 | 404 | |
405 | - /** |
|
406 | - * @return string form name |
|
407 | - */ |
|
408 | - public static function &getName( $id ) { |
|
409 | - global $wpdb; |
|
410 | - |
|
411 | - $form = FrmAppHelper::check_cache($id, 'frm_form'); |
|
412 | - if ( $form ) { |
|
413 | - $r = stripslashes($form->name); |
|
414 | - return $r; |
|
415 | - } |
|
416 | - |
|
417 | - $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
|
418 | - $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
|
419 | - $r = stripslashes($r); |
|
420 | - |
|
421 | - return $r; |
|
422 | - } |
|
423 | - |
|
424 | - /** |
|
425 | - * @param string $key |
|
426 | - * @return int form id |
|
427 | - */ |
|
405 | + /** |
|
406 | + * @return string form name |
|
407 | + */ |
|
408 | + public static function &getName( $id ) { |
|
409 | + global $wpdb; |
|
410 | + |
|
411 | + $form = FrmAppHelper::check_cache($id, 'frm_form'); |
|
412 | + if ( $form ) { |
|
413 | + $r = stripslashes($form->name); |
|
414 | + return $r; |
|
415 | + } |
|
416 | + |
|
417 | + $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
|
418 | + $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
|
419 | + $r = stripslashes($r); |
|
420 | + |
|
421 | + return $r; |
|
422 | + } |
|
423 | + |
|
424 | + /** |
|
425 | + * @param string $key |
|
426 | + * @return int form id |
|
427 | + */ |
|
428 | 428 | public static function &getIdByKey( $key ) { |
429 | - $id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) ); |
|
430 | - return $id; |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * @param int $id |
|
435 | - * @return string form key |
|
436 | - */ |
|
429 | + $id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) ); |
|
430 | + return $id; |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * @param int $id |
|
435 | + * @return string form key |
|
436 | + */ |
|
437 | 437 | public static function &getKeyById( $id ) { |
438 | - $id = (int) $id; |
|
439 | - $cache = FrmAppHelper::check_cache($id, 'frm_form'); |
|
440 | - if ( $cache ) { |
|
441 | - return $cache->form_key; |
|
442 | - } |
|
438 | + $id = (int) $id; |
|
439 | + $cache = FrmAppHelper::check_cache($id, 'frm_form'); |
|
440 | + if ( $cache ) { |
|
441 | + return $cache->form_key; |
|
442 | + } |
|
443 | 443 | |
444 | - $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' ); |
|
444 | + $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' ); |
|
445 | 445 | |
446 | - return $key; |
|
447 | - } |
|
446 | + return $key; |
|
447 | + } |
|
448 | 448 | |
449 | 449 | /** |
450 | 450 | * If $form is numeric, get the form object |
@@ -457,47 +457,47 @@ discard block |
||
457 | 457 | } |
458 | 458 | } |
459 | 459 | |
460 | - /** |
|
461 | - * @return object form |
|
462 | - */ |
|
463 | - public static function getOne( $id, $blog_id = false ) { |
|
464 | - global $wpdb; |
|
465 | - |
|
466 | - if ( $blog_id && is_multisite() ) { |
|
467 | - global $wpmuBaseTablePrefix; |
|
468 | - $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id .'_' : $wpdb->get_blog_prefix( $blog_id ); |
|
469 | - |
|
470 | - $table_name = $prefix .'frm_forms'; |
|
471 | - } else { |
|
472 | - $table_name = $wpdb->prefix .'frm_forms'; |
|
473 | - $cache = wp_cache_get($id, 'frm_form'); |
|
474 | - if ( $cache ) { |
|
475 | - if ( isset($cache->options) ) { |
|
476 | - $cache->options = maybe_unserialize($cache->options); |
|
477 | - } |
|
478 | - |
|
479 | - return stripslashes_deep($cache); |
|
480 | - } |
|
481 | - } |
|
482 | - |
|
483 | - if ( is_numeric($id) ) { |
|
484 | - $where = array( 'id' => $id ); |
|
485 | - } else { |
|
486 | - $where = array( 'form_key' => $id ); |
|
487 | - } |
|
488 | - |
|
489 | - $results = FrmDb::get_row( $table_name, $where ); |
|
490 | - |
|
491 | - if ( isset($results->options) ) { |
|
492 | - wp_cache_set($results->id, $results, 'frm_form'); |
|
493 | - $results->options = maybe_unserialize($results->options); |
|
494 | - } |
|
495 | - return stripslashes_deep($results); |
|
496 | - } |
|
497 | - |
|
498 | - /** |
|
499 | - * @return object|array of objects |
|
500 | - */ |
|
460 | + /** |
|
461 | + * @return object form |
|
462 | + */ |
|
463 | + public static function getOne( $id, $blog_id = false ) { |
|
464 | + global $wpdb; |
|
465 | + |
|
466 | + if ( $blog_id && is_multisite() ) { |
|
467 | + global $wpmuBaseTablePrefix; |
|
468 | + $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id .'_' : $wpdb->get_blog_prefix( $blog_id ); |
|
469 | + |
|
470 | + $table_name = $prefix .'frm_forms'; |
|
471 | + } else { |
|
472 | + $table_name = $wpdb->prefix .'frm_forms'; |
|
473 | + $cache = wp_cache_get($id, 'frm_form'); |
|
474 | + if ( $cache ) { |
|
475 | + if ( isset($cache->options) ) { |
|
476 | + $cache->options = maybe_unserialize($cache->options); |
|
477 | + } |
|
478 | + |
|
479 | + return stripslashes_deep($cache); |
|
480 | + } |
|
481 | + } |
|
482 | + |
|
483 | + if ( is_numeric($id) ) { |
|
484 | + $where = array( 'id' => $id ); |
|
485 | + } else { |
|
486 | + $where = array( 'form_key' => $id ); |
|
487 | + } |
|
488 | + |
|
489 | + $results = FrmDb::get_row( $table_name, $where ); |
|
490 | + |
|
491 | + if ( isset($results->options) ) { |
|
492 | + wp_cache_set($results->id, $results, 'frm_form'); |
|
493 | + $results->options = maybe_unserialize($results->options); |
|
494 | + } |
|
495 | + return stripslashes_deep($results); |
|
496 | + } |
|
497 | + |
|
498 | + /** |
|
499 | + * @return object|array of objects |
|
500 | + */ |
|
501 | 501 | public static function getAll( $where = array(), $order_by = '', $limit = '' ) { |
502 | 502 | if ( is_array( $where ) && ! empty( $where ) ) { |
503 | 503 | $results = FrmDb::get_results( 'frm_forms', $where, '*', array( 'order_by' => $order_by, 'limit' => $limit ) ); |
@@ -521,8 +521,8 @@ discard block |
||
521 | 521 | $results = reset( $results ); |
522 | 522 | } |
523 | 523 | |
524 | - return stripslashes_deep($results); |
|
525 | - } |
|
524 | + return stripslashes_deep($results); |
|
525 | + } |
|
526 | 526 | |
527 | 527 | /** |
528 | 528 | * Get all published forms |
@@ -540,47 +540,47 @@ discard block |
||
540 | 540 | return $forms; |
541 | 541 | } |
542 | 542 | |
543 | - /** |
|
544 | - * @return int count of forms |
|
545 | - */ |
|
546 | - public static function &get_count() { |
|
547 | - global $wpdb; |
|
543 | + /** |
|
544 | + * @return int count of forms |
|
545 | + */ |
|
546 | + public static function &get_count() { |
|
547 | + global $wpdb; |
|
548 | 548 | |
549 | - $cache_key = 'frm_form_counts'; |
|
549 | + $cache_key = 'frm_form_counts'; |
|
550 | 550 | |
551 | - $counts = wp_cache_get( $cache_key, 'counts' ); |
|
552 | - if ( false !== $counts ) { |
|
553 | - return $counts; |
|
554 | - } |
|
551 | + $counts = wp_cache_get( $cache_key, 'counts' ); |
|
552 | + if ( false !== $counts ) { |
|
553 | + return $counts; |
|
554 | + } |
|
555 | 555 | |
556 | - $results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' ); |
|
556 | + $results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' ); |
|
557 | 557 | |
558 | 558 | $statuses = array( 'published', 'draft', 'template', 'trash' ); |
559 | - $counts = array_fill_keys( $statuses, 0 ); |
|
559 | + $counts = array_fill_keys( $statuses, 0 ); |
|
560 | 560 | |
561 | - foreach ( $results as $row ) { |
|
562 | - if ( 'trash' != $row->status ) { |
|
563 | - if ( $row->is_template ) { |
|
561 | + foreach ( $results as $row ) { |
|
562 | + if ( 'trash' != $row->status ) { |
|
563 | + if ( $row->is_template ) { |
|
564 | 564 | $counts['template']++; |
565 | - } else { |
|
565 | + } else { |
|
566 | 566 | $counts['published']++; |
567 | - } |
|
568 | - } else { |
|
567 | + } |
|
568 | + } else { |
|
569 | 569 | $counts['trash']++; |
570 | - } |
|
570 | + } |
|
571 | 571 | |
572 | - if ( 'draft' == $row->status ) { |
|
572 | + if ( 'draft' == $row->status ) { |
|
573 | 573 | $counts['draft']++; |
574 | - } |
|
574 | + } |
|
575 | 575 | |
576 | - unset($row); |
|
577 | - } |
|
576 | + unset($row); |
|
577 | + } |
|
578 | 578 | |
579 | - $counts = (object) $counts; |
|
580 | - wp_cache_set( $cache_key, $counts, 'counts' ); |
|
579 | + $counts = (object) $counts; |
|
580 | + wp_cache_set( $cache_key, $counts, 'counts' ); |
|
581 | 581 | |
582 | - return $counts; |
|
583 | - } |
|
582 | + return $counts; |
|
583 | + } |
|
584 | 584 | |
585 | 585 | /** |
586 | 586 | * Clear form caching |
@@ -593,14 +593,14 @@ discard block |
||
593 | 593 | FrmAppHelper::cache_delete_group( 'frm_form' ); |
594 | 594 | } |
595 | 595 | |
596 | - /** |
|
597 | - * @return array of errors |
|
598 | - */ |
|
596 | + /** |
|
597 | + * @return array of errors |
|
598 | + */ |
|
599 | 599 | public static function validate( $values ) { |
600 | - $errors = array(); |
|
600 | + $errors = array(); |
|
601 | 601 | |
602 | - return apply_filters('frm_validate_form', $errors, $values); |
|
603 | - } |
|
602 | + return apply_filters('frm_validate_form', $errors, $values); |
|
603 | + } |
|
604 | 604 | |
605 | 605 | public static function get_params( $form = null ) { |
606 | 606 | global $frm_vars; |
@@ -1,6 +1,6 @@ discard block |
||
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 { |
@@ -12,32 +12,32 @@ discard block |
||
12 | 12 | global $wpdb; |
13 | 13 | |
14 | 14 | $new_values = array( |
15 | - 'form_key' => FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key'), |
|
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 = 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']; |
39 | 39 | |
40 | - $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values ); |
|
40 | + $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values ); |
|
41 | 41 | |
42 | 42 | $id = $wpdb->insert_id; |
43 | 43 | |
@@ -61,38 +61,38 @@ discard block |
||
61 | 61 | $new_key = $copy_keys ? $values->form_key : ''; |
62 | 62 | |
63 | 63 | $new_values = array( |
64 | - 'form_key' => FrmAppHelper::get_unique_key($new_key, $wpdb->prefix .'frm_forms', 'form_key'), |
|
64 | + 'form_key' => FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_forms', 'form_key' ), |
|
65 | 65 | 'name' => $values->name, |
66 | 66 | 'description' => $values->description, |
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 | - $query_results = $wpdb->insert( $wpdb->prefix .'frm_forms', $new_values ); |
|
88 | + $query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values ); |
|
89 | 89 | |
90 | 90 | if ( $query_results ) { |
91 | 91 | // Clear form caching |
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 |
||
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 |
||
127 | 127 | $values['status'] = 'published'; |
128 | 128 | } |
129 | 129 | |
130 | - if ( isset($values['form_key']) ) { |
|
131 | - $values['form_key'] = FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix .'frm_forms', 'form_key', $id); |
|
130 | + if ( isset( $values['form_key'] ) ) { |
|
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 | |
@@ -146,19 +146,19 @@ discard block |
||
146 | 146 | } |
147 | 147 | |
148 | 148 | if ( ! empty( $new_values ) ) { |
149 | - $query_results = $wpdb->update( $wpdb->prefix .'frm_forms', $new_values, array( 'id' => $id ) ); |
|
149 | + $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $id ) ); |
|
150 | 150 | if ( $query_results ) { |
151 | 151 | self::clear_form_cache(); |
152 | 152 | } |
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 | - do_action('frm_update_form', $id, $values); |
|
161 | - do_action('frm_update_form_'. $id, $values); |
|
160 | + do_action( 'frm_update_form', $id, $values ); |
|
161 | + do_action( 'frm_update_form_' . $id, $values ); |
|
162 | 162 | |
163 | 163 | return $query_results; |
164 | 164 | } |
@@ -167,20 +167,20 @@ discard block |
||
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 = 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,82 +191,82 @@ discard block |
||
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 | - if ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) { |
|
228 | + if ( isset( $values['options'] ) || isset( $values['field_options']['custom_html_' . $field_id] ) ) { |
|
229 | 229 | //updating the settings page |
230 | - if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) { |
|
231 | - $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 ) ); |
|
232 | - $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
230 | + if ( isset( $values['field_options']['custom_html_' . $field_id] ) ) { |
|
231 | + $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 ) ); |
|
232 | + $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values ); |
|
233 | 233 | FrmField::update( $field_id, array( 'field_options' => $field->field_options ) ); |
234 | 234 | } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) { |
235 | 235 | $prev_opts = $field->field_options; |
236 | - $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
236 | + $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values ); |
|
237 | 237 | if ( $prev_opts != $field->field_options ) { |
238 | 238 | FrmField::update( $field_id, array( 'field_options' => $field->field_options ) ); |
239 | 239 | } |
240 | - unset($prev_opts); |
|
240 | + unset( $prev_opts ); |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 | |
244 | - if ( ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) && ! defined( 'WP_IMPORTING' ) ) { |
|
244 | + if ( ( isset( $values['options'] ) || isset( $values['field_options']['custom_html_' . $field_id] ) ) && ! defined( 'WP_IMPORTING' ) ) { |
|
245 | 245 | continue; |
246 | 246 | } |
247 | 247 | |
248 | 248 | //updating the form |
249 | 249 | foreach ( array( 'size', 'max', 'label', 'invalid', 'blank', 'classes', 'captcha_size' ) as $opt ) { |
250 | - $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( $values['field_options'][ $opt . '_' . $field_id ] ) : ''; |
|
250 | + $field->field_options[$opt] = isset( $values['field_options'][$opt . '_' . $field_id] ) ? trim( $values['field_options'][$opt . '_' . $field_id] ) : ''; |
|
251 | 251 | } |
252 | 252 | |
253 | - $field->field_options['required_indicator'] = isset( $values['field_options'][ 'required_indicator_' . $field_id ] ) ? trim( $values['field_options'][ 'required_indicator_' . $field_id ] ) : '*'; |
|
254 | - $field->field_options['separate_value'] = isset( $values['field_options'][ 'separate_value_' . $field_id ] ) ? trim( $values['field_options'][ 'separate_value_' . $field_id ] ) : 0; |
|
253 | + $field->field_options['required_indicator'] = isset( $values['field_options']['required_indicator_' . $field_id] ) ? trim( $values['field_options']['required_indicator_' . $field_id] ) : '*'; |
|
254 | + $field->field_options['separate_value'] = isset( $values['field_options']['separate_value_' . $field_id] ) ? trim( $values['field_options']['separate_value_' . $field_id] ) : 0; |
|
255 | 255 | |
256 | - $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values); |
|
257 | - $default_value = maybe_serialize( $values['item_meta'][ $field_id ] ); |
|
258 | - $field_key = isset( $values['field_options'][ 'field_key_' . $field_id ] ) ? $values['field_options'][ 'field_key_' . $field_id ] : $field->field_key; |
|
259 | - $required = isset( $values['field_options'][ 'required_' . $field_id ] ) ? $values['field_options'][ 'required_' . $field_id ] : false; |
|
260 | - $field_type = isset( $values['field_options'][ 'type_' . $field_id ] ) ? $values['field_options'][ 'type_' . $field_id ] : $field->type; |
|
261 | - $field_description = isset( $values['field_options'][ 'description_' . $field_id ] ) ? $values['field_options'][ 'description_' . $field_id ] : $field->description; |
|
256 | + $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values ); |
|
257 | + $default_value = maybe_serialize( $values['item_meta'][$field_id] ); |
|
258 | + $field_key = isset( $values['field_options']['field_key_' . $field_id] ) ? $values['field_options']['field_key_' . $field_id] : $field->field_key; |
|
259 | + $required = isset( $values['field_options']['required_' . $field_id] ) ? $values['field_options']['required_' . $field_id] : false; |
|
260 | + $field_type = isset( $values['field_options']['type_' . $field_id] ) ? $values['field_options']['type_' . $field_id] : $field->type; |
|
261 | + $field_description = isset( $values['field_options']['description_' . $field_id] ) ? $values['field_options']['description_' . $field_id] : $field->description; |
|
262 | 262 | |
263 | - FrmField::update($field_id, array( |
|
263 | + FrmField::update( $field_id, array( |
|
264 | 264 | 'field_key' => $field_key, 'type' => $field_type, |
265 | 265 | 'default_value' => $default_value, 'field_options' => $field->field_options, |
266 | 266 | 'description' => $field_description, 'required' => $required, |
267 | 267 | ) ); |
268 | 268 | |
269 | - FrmField::delete_form_transient($field->form_id); |
|
269 | + FrmField::delete_form_transient( $field->form_id ); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | return $values; |
@@ -278,17 +278,17 @@ discard block |
||
278 | 278 | */ |
279 | 279 | public static function set_status( $id, $status ) { |
280 | 280 | if ( 'trash' == $status ) { |
281 | - return self::trash($id); |
|
281 | + return self::trash( $id ); |
|
282 | 282 | } |
283 | 283 | |
284 | - $statuses = array( 'published', 'draft', 'trash' ); |
|
284 | + $statuses = array( 'published', 'draft', 'trash' ); |
|
285 | 285 | if ( ! in_array( $status, $statuses ) ) { |
286 | 286 | return false; |
287 | 287 | } |
288 | 288 | |
289 | 289 | global $wpdb; |
290 | 290 | |
291 | - if ( is_array($id) ) { |
|
291 | + if ( is_array( $id ) ) { |
|
292 | 292 | $where = array( 'id' => $id ); |
293 | 293 | FrmDb::get_where_clause_and_values( $where ); |
294 | 294 | array_unshift( $where['values'], $status ); |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | return self::destroy( $id ); |
314 | 314 | } |
315 | 315 | |
316 | - $form = self::getOne($id); |
|
316 | + $form = self::getOne( $id ); |
|
317 | 317 | if ( ! $form ) { |
318 | 318 | return false; |
319 | 319 | } |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | |
324 | 324 | global $wpdb; |
325 | 325 | $query_results = $wpdb->update( |
326 | - $wpdb->prefix .'frm_forms', |
|
326 | + $wpdb->prefix . 'frm_forms', |
|
327 | 327 | array( 'status' => 'trash', 'options' => serialize( $options ) ), |
328 | 328 | array( 'id' => $id ) |
329 | 329 | ); |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | public static function destroy( $id ) { |
342 | 342 | global $wpdb; |
343 | 343 | |
344 | - $form = self::getOne($id); |
|
344 | + $form = self::getOne( $id ); |
|
345 | 345 | if ( ! $form ) { |
346 | 346 | return false; |
347 | 347 | } |
@@ -349,24 +349,24 @@ discard block |
||
349 | 349 | // Disconnect the entries from this form |
350 | 350 | $entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) ); |
351 | 351 | foreach ( $entries as $entry_id ) { |
352 | - FrmEntry::destroy($entry_id); |
|
353 | - unset($entry_id); |
|
352 | + FrmEntry::destroy( $entry_id ); |
|
353 | + unset( $entry_id ); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | // Disconnect the fields from this form |
357 | - $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)); |
|
357 | + $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 ) ); |
|
358 | 358 | |
359 | - $query_results = $wpdb->query($wpdb->prepare('DELETE FROM '. $wpdb->prefix .'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id)); |
|
359 | + $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) ); |
|
360 | 360 | if ( $query_results ) { |
361 | 361 | // Delete all form actions linked to this form |
362 | 362 | $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
363 | - $action_control->destroy($id, 'all'); |
|
363 | + $action_control->destroy( $id, 'all' ); |
|
364 | 364 | |
365 | 365 | // Clear form caching |
366 | 366 | self::clear_form_cache(); |
367 | 367 | |
368 | - do_action('frm_destroy_form', $id); |
|
369 | - do_action('frm_destroy_form_'. $id); |
|
368 | + do_action( 'frm_destroy_form', $id ); |
|
369 | + do_action( 'frm_destroy_form_' . $id ); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | return $query_results; |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | $form->options = maybe_unserialize( $form->options ); |
395 | 395 | if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) { |
396 | 396 | self::destroy( $form->id ); |
397 | - $count++; |
|
397 | + $count ++; |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | unset( $form ); |
@@ -408,15 +408,15 @@ discard block |
||
408 | 408 | public static function &getName( $id ) { |
409 | 409 | global $wpdb; |
410 | 410 | |
411 | - $form = FrmAppHelper::check_cache($id, 'frm_form'); |
|
411 | + $form = FrmAppHelper::check_cache( $id, 'frm_form' ); |
|
412 | 412 | if ( $form ) { |
413 | - $r = stripslashes($form->name); |
|
413 | + $r = stripslashes( $form->name ); |
|
414 | 414 | return $r; |
415 | 415 | } |
416 | 416 | |
417 | 417 | $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
418 | 418 | $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
419 | - $r = stripslashes($r); |
|
419 | + $r = stripslashes( $r ); |
|
420 | 420 | |
421 | 421 | return $r; |
422 | 422 | } |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | */ |
437 | 437 | public static function &getKeyById( $id ) { |
438 | 438 | $id = (int) $id; |
439 | - $cache = FrmAppHelper::check_cache($id, 'frm_form'); |
|
439 | + $cache = FrmAppHelper::check_cache( $id, 'frm_form' ); |
|
440 | 440 | if ( $cache ) { |
441 | 441 | return $cache->form_key; |
442 | 442 | } |
@@ -465,22 +465,22 @@ discard block |
||
465 | 465 | |
466 | 466 | if ( $blog_id && is_multisite() ) { |
467 | 467 | global $wpmuBaseTablePrefix; |
468 | - $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id .'_' : $wpdb->get_blog_prefix( $blog_id ); |
|
468 | + $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix( $blog_id ); |
|
469 | 469 | |
470 | - $table_name = $prefix .'frm_forms'; |
|
470 | + $table_name = $prefix . 'frm_forms'; |
|
471 | 471 | } else { |
472 | - $table_name = $wpdb->prefix .'frm_forms'; |
|
473 | - $cache = wp_cache_get($id, 'frm_form'); |
|
472 | + $table_name = $wpdb->prefix . 'frm_forms'; |
|
473 | + $cache = wp_cache_get( $id, 'frm_form' ); |
|
474 | 474 | if ( $cache ) { |
475 | - if ( isset($cache->options) ) { |
|
476 | - $cache->options = maybe_unserialize($cache->options); |
|
475 | + if ( isset( $cache->options ) ) { |
|
476 | + $cache->options = maybe_unserialize( $cache->options ); |
|
477 | 477 | } |
478 | 478 | |
479 | - return stripslashes_deep($cache); |
|
479 | + return stripslashes_deep( $cache ); |
|
480 | 480 | } |
481 | 481 | } |
482 | 482 | |
483 | - if ( is_numeric($id) ) { |
|
483 | + if ( is_numeric( $id ) ) { |
|
484 | 484 | $where = array( 'id' => $id ); |
485 | 485 | } else { |
486 | 486 | $where = array( 'form_key' => $id ); |
@@ -488,11 +488,11 @@ discard block |
||
488 | 488 | |
489 | 489 | $results = FrmDb::get_row( $table_name, $where ); |
490 | 490 | |
491 | - if ( isset($results->options) ) { |
|
492 | - wp_cache_set($results->id, $results, 'frm_form'); |
|
493 | - $results->options = maybe_unserialize($results->options); |
|
491 | + if ( isset( $results->options ) ) { |
|
492 | + wp_cache_set( $results->id, $results, 'frm_form' ); |
|
493 | + $results->options = maybe_unserialize( $results->options ); |
|
494 | 494 | } |
495 | - return stripslashes_deep($results); |
|
495 | + return stripslashes_deep( $results ); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | /** |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | $results = reset( $results ); |
522 | 522 | } |
523 | 523 | |
524 | - return stripslashes_deep($results); |
|
524 | + return stripslashes_deep( $results ); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
@@ -561,19 +561,19 @@ discard block |
||
561 | 561 | foreach ( $results as $row ) { |
562 | 562 | if ( 'trash' != $row->status ) { |
563 | 563 | if ( $row->is_template ) { |
564 | - $counts['template']++; |
|
564 | + $counts['template'] ++; |
|
565 | 565 | } else { |
566 | - $counts['published']++; |
|
566 | + $counts['published'] ++; |
|
567 | 567 | } |
568 | 568 | } else { |
569 | - $counts['trash']++; |
|
569 | + $counts['trash'] ++; |
|
570 | 570 | } |
571 | 571 | |
572 | 572 | if ( 'draft' == $row->status ) { |
573 | - $counts['draft']++; |
|
573 | + $counts['draft'] ++; |
|
574 | 574 | } |
575 | 575 | |
576 | - unset($row); |
|
576 | + unset( $row ); |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | $counts = (object) $counts; |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | public static function validate( $values ) { |
600 | 600 | $errors = array(); |
601 | 601 | |
602 | - return apply_filters('frm_validate_form', $errors, $values); |
|
602 | + return apply_filters( 'frm_validate_form', $errors, $values ); |
|
603 | 603 | } |
604 | 604 | |
605 | 605 | public static function get_params( $form = null ) { |
@@ -611,11 +611,11 @@ discard block |
||
611 | 611 | self::maybe_get_form( $form ); |
612 | 612 | } |
613 | 613 | |
614 | - if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) { |
|
615 | - return $frm_vars['form_params'][ $form->id ]; |
|
614 | + if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][$form->id] ) ) { |
|
615 | + return $frm_vars['form_params'][$form->id]; |
|
616 | 616 | } |
617 | 617 | |
618 | - $action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action'; |
|
618 | + $action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
|
619 | 619 | $action = apply_filters( 'frm_show_new_entry_page', FrmAppHelper::get_param( $action_var, 'new', 'get', 'sanitize_title' ), $form ); |
620 | 620 | |
621 | 621 | $default_values = array( |
@@ -633,15 +633,15 @@ discard block |
||
633 | 633 | //if there are two forms on the same page, make sure not to submit both |
634 | 634 | foreach ( $default_values as $var => $default ) { |
635 | 635 | if ( $var == 'action' ) { |
636 | - $values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' ); |
|
636 | + $values[$var] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' ); |
|
637 | 637 | } else { |
638 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default ); |
|
638 | + $values[$var] = FrmAppHelper::get_param( $var, $default ); |
|
639 | 639 | } |
640 | 640 | unset( $var, $default ); |
641 | 641 | } |
642 | 642 | } else { |
643 | 643 | foreach ( $default_values as $var => $default ) { |
644 | - $values[ $var ] = $default; |
|
644 | + $values[$var] = $default; |
|
645 | 645 | unset( $var, $default ); |
646 | 646 | } |
647 | 647 | } |
@@ -656,7 +656,7 @@ discard block |
||
656 | 656 | public static function list_page_params() { |
657 | 657 | $values = array(); |
658 | 658 | foreach ( array( 'template' => 0, 'id' => '', 'paged' => 1, 'form' => '', 'search' => '', 'sort' => '', 'sdir' => '' ) as $var => $default ) { |
659 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default ); |
|
659 | + $values[$var] = FrmAppHelper::get_param( $var, $default ); |
|
660 | 660 | } |
661 | 661 | |
662 | 662 | return $values; |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | 'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'fid' => '', |
677 | 677 | 'keep_post' => '', |
678 | 678 | ) as $var => $default ) { |
679 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default ); |
|
679 | + $values[$var] = FrmAppHelper::get_param( $var, $default ); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | return $values; |
@@ -718,16 +718,16 @@ discard block |
||
718 | 718 | $small_form = new stdClass(); |
719 | 719 | foreach ( array( 'id', 'form_key', 'name' ) as $var ) { |
720 | 720 | $small_form->{$var} = $form->{$var}; |
721 | - unset($var); |
|
721 | + unset( $var ); |
|
722 | 722 | } |
723 | 723 | |
724 | 724 | $frm_vars['forms_loaded'][] = $small_form; |
725 | 725 | |
726 | - if ( $this_load && empty($global_load) ) { |
|
726 | + if ( $this_load && empty( $global_load ) ) { |
|
727 | 727 | $global_load = $frm_vars['load_css'] = true; |
728 | 728 | } |
729 | 729 | |
730 | - return ( ( ! isset($frm_vars['css_loaded']) || ! $frm_vars['css_loaded'] ) && $global_load ); |
|
730 | + return ( ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) && $global_load ); |
|
731 | 731 | } |
732 | 732 | |
733 | 733 | public static function show_submit( $form ) { |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | public $action_options; // Option array passed to wp_register_sidebar_widget() |
9 | 9 | public $control_options; // Option array passed to wp_register_widget_control() |
10 | 10 | |
11 | - public $form_id; // The ID of the form to evaluate |
|
11 | + public $form_id; // The ID of the form to evaluate |
|
12 | 12 | public $number = false; // Unique ID number of the current instance. |
13 | 13 | public $id = ''; // Unique ID string of the current instance (id_base-number) |
14 | 14 | public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice. |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | - * Echo the settings update form |
|
32 | + * Echo the settings update form |
|
33 | 33 | * |
34 | 34 | * @param array $instance Current settings |
35 | 35 | */ |
@@ -42,15 +42,15 @@ discard block |
||
42 | 42 | * @return array of the default options |
43 | 43 | */ |
44 | 44 | public function get_defaults() { |
45 | - return array(); |
|
45 | + return array(); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | public function get_switch_fields() { |
49 | - return array(); |
|
49 | + return array(); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | public function migrate_values( $action, $form ) { |
53 | - return $action; |
|
53 | + return $action; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | // Functions you'll need to call. |
@@ -69,24 +69,24 @@ discard block |
||
69 | 69 | * - height: currently not used but may be needed in the future |
70 | 70 | */ |
71 | 71 | public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) { |
72 | - if ( ! defined('ABSPATH') ) { |
|
73 | - die('You are not allowed to call this page directly.'); |
|
74 | - } |
|
72 | + if ( ! defined('ABSPATH') ) { |
|
73 | + die('You are not allowed to call this page directly.'); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | $this->id_base = strtolower($id_base); |
77 | 77 | $this->name = $name; |
78 | 78 | $this->option_name = 'frm_' . $this->id_base .'_action'; |
79 | 79 | |
80 | - $default_options = array( |
|
81 | - 'classes' => '', |
|
82 | - 'active' => true, |
|
80 | + $default_options = array( |
|
81 | + 'classes' => '', |
|
82 | + 'active' => true, |
|
83 | 83 | 'event' => array( 'create' ), |
84 | - 'limit' => 1, |
|
85 | - 'force_event' => false, |
|
86 | - 'priority' => 20, |
|
87 | - 'ajax_load' => true, |
|
88 | - 'tooltip' => $name, |
|
89 | - ); |
|
84 | + 'limit' => 1, |
|
85 | + 'force_event' => false, |
|
86 | + 'priority' => 20, |
|
87 | + 'ajax_load' => true, |
|
88 | + 'tooltip' => $name, |
|
89 | + ); |
|
90 | 90 | |
91 | 91 | $action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options ); |
92 | 92 | $this->action_options = wp_parse_args( $action_options, $default_options ); |
@@ -132,132 +132,132 @@ discard block |
||
132 | 132 | } |
133 | 133 | |
134 | 134 | public function prepare_new( $form_id = false ) { |
135 | - if ( $form_id ) { |
|
136 | - $this->form_id = $form_id; |
|
137 | - } |
|
138 | - |
|
139 | - $post_content = array(); |
|
140 | - $default_values = $this->get_global_defaults(); |
|
141 | - |
|
142 | - // fill default values |
|
143 | - $post_content = wp_parse_args( $post_content, $default_values); |
|
144 | - |
|
145 | - if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) { |
|
146 | - $post_content['event'] = array( reset($this->action_options['event']) ); |
|
147 | - } |
|
148 | - |
|
149 | - $form_action = array( |
|
150 | - 'post_title' => $this->name, |
|
151 | - 'post_content' => $post_content, |
|
152 | - 'post_excerpt' => $this->id_base, |
|
153 | - 'ID' => '', |
|
154 | - 'post_status' => 'publish', |
|
155 | - 'post_type' => FrmFormActionsController::$action_post_type, |
|
156 | - 'post_name' => $this->form_id .'_'. $this->id_base .'_'. $this->number, |
|
157 | - 'menu_order' => $this->form_id, |
|
158 | - ); |
|
159 | - unset($post_content); |
|
160 | - |
|
161 | - return (object) $form_action; |
|
162 | - } |
|
135 | + if ( $form_id ) { |
|
136 | + $this->form_id = $form_id; |
|
137 | + } |
|
138 | + |
|
139 | + $post_content = array(); |
|
140 | + $default_values = $this->get_global_defaults(); |
|
141 | + |
|
142 | + // fill default values |
|
143 | + $post_content = wp_parse_args( $post_content, $default_values); |
|
144 | + |
|
145 | + if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) { |
|
146 | + $post_content['event'] = array( reset($this->action_options['event']) ); |
|
147 | + } |
|
148 | + |
|
149 | + $form_action = array( |
|
150 | + 'post_title' => $this->name, |
|
151 | + 'post_content' => $post_content, |
|
152 | + 'post_excerpt' => $this->id_base, |
|
153 | + 'ID' => '', |
|
154 | + 'post_status' => 'publish', |
|
155 | + 'post_type' => FrmFormActionsController::$action_post_type, |
|
156 | + 'post_name' => $this->form_id .'_'. $this->id_base .'_'. $this->number, |
|
157 | + 'menu_order' => $this->form_id, |
|
158 | + ); |
|
159 | + unset($post_content); |
|
160 | + |
|
161 | + return (object) $form_action; |
|
162 | + } |
|
163 | 163 | |
164 | 164 | public function create( $form_id ) { |
165 | - $this->form_id = $form_id; |
|
165 | + $this->form_id = $form_id; |
|
166 | 166 | |
167 | - $action = $this->prepare_new(); |
|
167 | + $action = $this->prepare_new(); |
|
168 | 168 | |
169 | - return $this->save_settings($action); |
|
170 | - } |
|
169 | + return $this->save_settings($action); |
|
170 | + } |
|
171 | 171 | |
172 | 172 | public function duplicate_form_actions( $form_id, $old_id ) { |
173 | - if ( $form_id == $old_id ) { |
|
174 | - // don't duplicate the actions if this is a template getting updated |
|
175 | - return; |
|
176 | - } |
|
177 | - |
|
178 | - $this->form_id = $old_id; |
|
179 | - $actions = $this->get_all( $old_id ); |
|
180 | - |
|
181 | - $this->form_id = $form_id; |
|
182 | - foreach ( $actions as $action ) { |
|
183 | - $this->duplicate_one($action, $form_id); |
|
184 | - unset($action); |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - /* Check if imported action should be created or updated |
|
173 | + if ( $form_id == $old_id ) { |
|
174 | + // don't duplicate the actions if this is a template getting updated |
|
175 | + return; |
|
176 | + } |
|
177 | + |
|
178 | + $this->form_id = $old_id; |
|
179 | + $actions = $this->get_all( $old_id ); |
|
180 | + |
|
181 | + $this->form_id = $form_id; |
|
182 | + foreach ( $actions as $action ) { |
|
183 | + $this->duplicate_one($action, $form_id); |
|
184 | + unset($action); |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + /* Check if imported action should be created or updated |
|
189 | 189 | * |
190 | 190 | * Since 2.0 |
191 | 191 | * |
192 | 192 | * @param array $action |
193 | 193 | * @return integer $post_id |
194 | 194 | */ |
195 | - public function maybe_create_action( $action, $forms ) { |
|
195 | + public function maybe_create_action( $action, $forms ) { |
|
196 | 196 | if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[ $action['menu_order'] ] == 'updated' ) { |
197 | - // Update action only |
|
198 | - $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
|
199 | - $post_id = $this->save_settings( $action ); |
|
200 | - } else { |
|
201 | - // Create action |
|
202 | - $action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']); |
|
203 | - $post_id = $this->duplicate_one( (object) $action, $action['menu_order']); |
|
204 | - } |
|
205 | - return $post_id; |
|
206 | - } |
|
197 | + // Update action only |
|
198 | + $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
|
199 | + $post_id = $this->save_settings( $action ); |
|
200 | + } else { |
|
201 | + // Create action |
|
202 | + $action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']); |
|
203 | + $post_id = $this->duplicate_one( (object) $action, $action['menu_order']); |
|
204 | + } |
|
205 | + return $post_id; |
|
206 | + } |
|
207 | 207 | |
208 | 208 | public function duplicate_one( $action, $form_id ) { |
209 | - global $frm_duplicate_ids; |
|
209 | + global $frm_duplicate_ids; |
|
210 | 210 | |
211 | - $action->menu_order = $form_id; |
|
212 | - $switch = $this->get_global_switch_fields(); |
|
213 | - foreach ( (array) $action->post_content as $key => $val ) { |
|
211 | + $action->menu_order = $form_id; |
|
212 | + $switch = $this->get_global_switch_fields(); |
|
213 | + foreach ( (array) $action->post_content as $key => $val ) { |
|
214 | 214 | if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) { |
215 | 215 | $action->post_content[ $key ] = $frm_duplicate_ids[ $val ]; |
216 | - } else if ( ! is_array( $val ) ) { |
|
216 | + } else if ( ! is_array( $val ) ) { |
|
217 | 217 | $action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val ); |
218 | 218 | } else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) { |
219 | - // loop through each value if empty |
|
219 | + // loop through each value if empty |
|
220 | 220 | if ( empty( $switch[ $key ] ) ) { |
221 | 221 | $switch[ $key ] = array_keys( $val ); |
222 | 222 | } |
223 | 223 | |
224 | 224 | foreach ( $switch[ $key ] as $subkey ) { |
225 | 225 | $action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val ); |
226 | - } |
|
227 | - } |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - unset($key, $val); |
|
230 | - } |
|
231 | - unset($action->ID); |
|
229 | + unset($key, $val); |
|
230 | + } |
|
231 | + unset($action->ID); |
|
232 | 232 | |
233 | - return $this->save_settings($action); |
|
234 | - } |
|
233 | + return $this->save_settings($action); |
|
234 | + } |
|
235 | 235 | |
236 | 236 | private function duplicate_array_walk( $action, $subkey, $val ) { |
237 | - global $frm_duplicate_ids; |
|
237 | + global $frm_duplicate_ids; |
|
238 | 238 | |
239 | - if ( is_array($subkey) ) { |
|
240 | - foreach ( $subkey as $subkey2 ) { |
|
241 | - foreach ( (array) $val as $ck => $cv ) { |
|
242 | - if ( is_array($cv) ) { |
|
239 | + if ( is_array($subkey) ) { |
|
240 | + foreach ( $subkey as $subkey2 ) { |
|
241 | + foreach ( (array) $val as $ck => $cv ) { |
|
242 | + if ( is_array($cv) ) { |
|
243 | 243 | $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv ); |
244 | 244 | } else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) { |
245 | 245 | $action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ]; |
246 | - } |
|
247 | - } |
|
248 | - } |
|
249 | - } else { |
|
250 | - foreach ( (array) $val as $ck => $cv ) { |
|
251 | - if ( is_array($cv) ) { |
|
246 | + } |
|
247 | + } |
|
248 | + } |
|
249 | + } else { |
|
250 | + foreach ( (array) $val as $ck => $cv ) { |
|
251 | + if ( is_array($cv) ) { |
|
252 | 252 | $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv ); |
253 | 253 | } else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) { |
254 | 254 | $action[ $ck ] = $frm_duplicate_ids[ $cv ]; |
255 | - } |
|
256 | - } |
|
257 | - } |
|
255 | + } |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - return $action; |
|
260 | - } |
|
259 | + return $action; |
|
260 | + } |
|
261 | 261 | |
262 | 262 | /** |
263 | 263 | * Deal with changed settings. |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | * |
267 | 267 | */ |
268 | 268 | public function update_callback( $form_id ) { |
269 | - $this->form_id = $form_id; |
|
269 | + $this->form_id = $form_id; |
|
270 | 270 | |
271 | 271 | $all_instances = $this->get_settings(); |
272 | 272 | |
@@ -281,25 +281,25 @@ discard block |
||
281 | 281 | return; |
282 | 282 | } |
283 | 283 | |
284 | - $action_ids = array(); |
|
284 | + $action_ids = array(); |
|
285 | 285 | |
286 | 286 | foreach ( $settings as $number => $new_instance ) { |
287 | 287 | $this->_set($number); |
288 | 288 | |
289 | 289 | if ( ! isset($new_instance['post_title']) ) { |
290 | - // settings were never opened, so don't update |
|
291 | - $action_ids[] = $new_instance['ID']; |
|
292 | - $this->updated = true; |
|
293 | - continue; |
|
290 | + // settings were never opened, so don't update |
|
291 | + $action_ids[] = $new_instance['ID']; |
|
292 | + $this->updated = true; |
|
293 | + continue; |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array(); |
297 | 297 | |
298 | 298 | $new_instance['post_type'] = FrmFormActionsController::$action_post_type; |
299 | - $new_instance['post_name'] = $this->form_id .'_'. $this->id_base .'_'. $this->number; |
|
300 | - $new_instance['menu_order'] = $this->form_id; |
|
301 | - $new_instance['post_status'] = 'publish'; |
|
302 | - $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : ''; |
|
299 | + $new_instance['post_name'] = $this->form_id .'_'. $this->id_base .'_'. $this->number; |
|
300 | + $new_instance['menu_order'] = $this->form_id; |
|
301 | + $new_instance['post_status'] = 'publish'; |
|
302 | + $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : ''; |
|
303 | 303 | |
304 | 304 | $instance = $this->update( $new_instance, $old_instance ); |
305 | 305 | |
@@ -319,15 +319,15 @@ discard block |
||
319 | 319 | $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this ); |
320 | 320 | |
321 | 321 | $instance['post_content'] = apply_filters('frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this); |
322 | - $instance['post_content'] = apply_filters('frm_before_save_'. $this->id_base .'_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this); |
|
322 | + $instance['post_content'] = apply_filters('frm_before_save_'. $this->id_base .'_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this); |
|
323 | 323 | |
324 | 324 | if ( false !== $instance ) { |
325 | 325 | $all_instances[ $number ] = $instance; |
326 | 326 | } |
327 | 327 | |
328 | - $action_ids[] = $this->save_settings($instance); |
|
328 | + $action_ids[] = $this->save_settings($instance); |
|
329 | 329 | |
330 | - $this->updated = true; |
|
330 | + $this->updated = true; |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | return $action_ids; |
@@ -338,100 +338,100 @@ discard block |
||
338 | 338 | } |
339 | 339 | |
340 | 340 | public function get_single_action( $id ) { |
341 | - $action = get_post($id); |
|
341 | + $action = get_post($id); |
|
342 | 342 | if ( $action ) { |
343 | 343 | $action = $this->prepare_action( $action ); |
344 | 344 | $this->_set( $id ); |
345 | 345 | } |
346 | - return $action; |
|
346 | + return $action; |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | public function get_one( $form_id ) { |
350 | - return $this->get_all($form_id, 1); |
|
350 | + return $this->get_all($form_id, 1); |
|
351 | 351 | } |
352 | 352 | |
353 | - public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) { |
|
354 | - $action_controls = FrmFormActionsController::get_form_actions( $type ); |
|
355 | - if ( empty($action_controls) ) { |
|
356 | - // don't continue if there are no available actions |
|
357 | - return array(); |
|
358 | - } |
|
353 | + public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) { |
|
354 | + $action_controls = FrmFormActionsController::get_form_actions( $type ); |
|
355 | + if ( empty($action_controls) ) { |
|
356 | + // don't continue if there are no available actions |
|
357 | + return array(); |
|
358 | + } |
|
359 | 359 | |
360 | - if ( 'all' != $type ) { |
|
361 | - return $action_controls->get_all( $form_id, $limit ); |
|
362 | - } |
|
360 | + if ( 'all' != $type ) { |
|
361 | + return $action_controls->get_all( $form_id, $limit ); |
|
362 | + } |
|
363 | 363 | |
364 | 364 | $args = self::action_args( $form_id, $limit ); |
365 | 365 | $actions = FrmAppHelper::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' ); |
366 | 366 | |
367 | - if ( ! $actions ) { |
|
368 | - return array(); |
|
369 | - } |
|
367 | + if ( ! $actions ) { |
|
368 | + return array(); |
|
369 | + } |
|
370 | 370 | |
371 | - $settings = array(); |
|
372 | - foreach ( $actions as $action ) { |
|
371 | + $settings = array(); |
|
372 | + foreach ( $actions as $action ) { |
|
373 | 373 | // some plugins/themes are formatting the post_excerpt |
374 | 374 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
375 | 375 | |
376 | 376 | if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) { |
377 | - continue; |
|
378 | - } |
|
377 | + continue; |
|
378 | + } |
|
379 | 379 | |
380 | - $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action ); |
|
380 | + $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action ); |
|
381 | 381 | $settings[ $action->ID ] = $action; |
382 | 382 | |
383 | 383 | if ( count( $settings ) >= $limit ) { |
384 | 384 | break; |
385 | 385 | } |
386 | - } |
|
386 | + } |
|
387 | 387 | |
388 | - if ( 1 === $limit ) { |
|
389 | - $settings = reset($settings); |
|
390 | - } |
|
388 | + if ( 1 === $limit ) { |
|
389 | + $settings = reset($settings); |
|
390 | + } |
|
391 | 391 | |
392 | - return $settings; |
|
393 | - } |
|
392 | + return $settings; |
|
393 | + } |
|
394 | 394 | |
395 | 395 | public function get_all( $form_id = false, $limit = 99 ) { |
396 | - if ( $form_id ) { |
|
397 | - $this->form_id = $form_id; |
|
398 | - } |
|
396 | + if ( $form_id ) { |
|
397 | + $this->form_id = $form_id; |
|
398 | + } |
|
399 | 399 | |
400 | - $type = $this->id_base; |
|
400 | + $type = $this->id_base; |
|
401 | 401 | |
402 | - global $frm_vars; |
|
403 | - $frm_vars['action_type'] = $type; |
|
402 | + global $frm_vars; |
|
403 | + $frm_vars['action_type'] = $type; |
|
404 | 404 | |
405 | - add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
405 | + add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
406 | 406 | $query = self::action_args( $form_id, $limit ); |
407 | - $query['post_status'] = 'any'; |
|
408 | - $query['suppress_filters'] = false; |
|
407 | + $query['post_status'] = 'any'; |
|
408 | + $query['suppress_filters'] = false; |
|
409 | 409 | |
410 | 410 | $actions = FrmAppHelper::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' ); |
411 | - unset($query); |
|
411 | + unset($query); |
|
412 | 412 | |
413 | - remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
413 | + remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
414 | 414 | |
415 | - if ( empty($actions) ) { |
|
416 | - return array(); |
|
417 | - } |
|
415 | + if ( empty($actions) ) { |
|
416 | + return array(); |
|
417 | + } |
|
418 | 418 | |
419 | - $settings = array(); |
|
420 | - foreach ( $actions as $action ) { |
|
421 | - if ( count($settings) >= $limit ) { |
|
422 | - continue; |
|
423 | - } |
|
419 | + $settings = array(); |
|
420 | + foreach ( $actions as $action ) { |
|
421 | + if ( count($settings) >= $limit ) { |
|
422 | + continue; |
|
423 | + } |
|
424 | 424 | |
425 | - $action = $this->prepare_action($action); |
|
425 | + $action = $this->prepare_action($action); |
|
426 | 426 | |
427 | 427 | $settings[ $action->ID ] = $action; |
428 | - } |
|
428 | + } |
|
429 | 429 | |
430 | - if ( 1 === $limit ) { |
|
431 | - $settings = reset($settings); |
|
432 | - } |
|
430 | + if ( 1 === $limit ) { |
|
431 | + $settings = reset($settings); |
|
432 | + } |
|
433 | 433 | |
434 | - return $settings; |
|
434 | + return $settings; |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | public static function action_args( $form_id = 0, $limit = 99 ) { |
@@ -454,45 +454,45 @@ discard block |
||
454 | 454 | $action->post_content = (array) FrmAppHelper::maybe_json_decode($action->post_content); |
455 | 455 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
456 | 456 | |
457 | - $default_values = $this->get_global_defaults(); |
|
457 | + $default_values = $this->get_global_defaults(); |
|
458 | 458 | |
459 | - // fill default values |
|
460 | - $action->post_content += $default_values; |
|
459 | + // fill default values |
|
460 | + $action->post_content += $default_values; |
|
461 | 461 | |
462 | - foreach ( $default_values as $k => $vals ) { |
|
463 | - if ( is_array($vals) && ! empty($vals) ) { |
|
462 | + foreach ( $default_values as $k => $vals ) { |
|
463 | + if ( is_array($vals) && ! empty($vals) ) { |
|
464 | 464 | if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) { |
465 | - continue; |
|
466 | - } |
|
465 | + continue; |
|
466 | + } |
|
467 | 467 | $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals ); |
468 | - } |
|
469 | - } |
|
468 | + } |
|
469 | + } |
|
470 | 470 | |
471 | - if ( ! is_array($action->post_content['event']) ) { |
|
472 | - $action->post_content['event'] = explode(',', $action->post_content['event']); |
|
473 | - } |
|
471 | + if ( ! is_array($action->post_content['event']) ) { |
|
472 | + $action->post_content['event'] = explode(',', $action->post_content['event']); |
|
473 | + } |
|
474 | 474 | |
475 | - return $action; |
|
475 | + return $action; |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | public function destroy( $form_id = false, $type = 'default' ) { |
479 | - global $wpdb; |
|
479 | + global $wpdb; |
|
480 | 480 | |
481 | - $this->form_id = $form_id; |
|
481 | + $this->form_id = $form_id; |
|
482 | 482 | |
483 | - $query = array( 'post_type' => FrmFormActionsController::$action_post_type ); |
|
484 | - if ( $form_id ) { |
|
485 | - $query['menu_order'] = $form_id; |
|
486 | - } |
|
487 | - if ( 'all' != $type ) { |
|
488 | - $query['post_excerpt'] = $this->id_base; |
|
489 | - } |
|
483 | + $query = array( 'post_type' => FrmFormActionsController::$action_post_type ); |
|
484 | + if ( $form_id ) { |
|
485 | + $query['menu_order'] = $form_id; |
|
486 | + } |
|
487 | + if ( 'all' != $type ) { |
|
488 | + $query['post_excerpt'] = $this->id_base; |
|
489 | + } |
|
490 | 490 | |
491 | - $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' ); |
|
491 | + $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' ); |
|
492 | 492 | |
493 | - foreach ( $post_ids as $id ) { |
|
494 | - wp_delete_post($id); |
|
495 | - } |
|
493 | + foreach ( $post_ids as $id ) { |
|
494 | + wp_delete_post($id); |
|
495 | + } |
|
496 | 496 | self::clear_cache(); |
497 | 497 | } |
498 | 498 | |
@@ -510,69 +510,69 @@ discard block |
||
510 | 510 | } |
511 | 511 | |
512 | 512 | public function get_global_defaults() { |
513 | - $defaults = $this->get_defaults(); |
|
513 | + $defaults = $this->get_defaults(); |
|
514 | 514 | |
515 | - if ( ! isset($defaults['event']) ) { |
|
515 | + if ( ! isset($defaults['event']) ) { |
|
516 | 516 | $defaults['event'] = array( 'create' ); |
517 | - } |
|
517 | + } |
|
518 | 518 | |
519 | - if ( ! isset($defaults['conditions']) ) { |
|
520 | - $defaults['conditions'] = array( |
|
521 | - 'send_stop' => '', |
|
522 | - 'any_all' => '', |
|
523 | - ); |
|
524 | - } |
|
519 | + if ( ! isset($defaults['conditions']) ) { |
|
520 | + $defaults['conditions'] = array( |
|
521 | + 'send_stop' => '', |
|
522 | + 'any_all' => '', |
|
523 | + ); |
|
524 | + } |
|
525 | 525 | |
526 | - return $defaults; |
|
526 | + return $defaults; |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | public function get_global_switch_fields() { |
530 | - $switch = $this->get_switch_fields(); |
|
530 | + $switch = $this->get_switch_fields(); |
|
531 | 531 | $switch['conditions'] = array( 'hide_field' ); |
532 | - return $switch; |
|
532 | + return $switch; |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | /** |
536 | 536 | * Migrate settings from form->options into new action. |
537 | 537 | */ |
538 | 538 | public function migrate_to_2( $form, $update = 'update' ) { |
539 | - $action = $this->prepare_new($form->id); |
|
540 | - $form->options = maybe_unserialize($form->options); |
|
539 | + $action = $this->prepare_new($form->id); |
|
540 | + $form->options = maybe_unserialize($form->options); |
|
541 | 541 | |
542 | - // fill with existing options |
|
543 | - foreach ( $action->post_content as $name => $val ) { |
|
542 | + // fill with existing options |
|
543 | + foreach ( $action->post_content as $name => $val ) { |
|
544 | 544 | if ( isset( $form->options[ $name ] ) ) { |
545 | 545 | $action->post_content[ $name ] = $form->options[ $name ]; |
546 | 546 | unset( $form->options[ $name ] ); |
547 | - } |
|
548 | - } |
|
547 | + } |
|
548 | + } |
|
549 | 549 | |
550 | - $action = $this->migrate_values($action, $form); |
|
550 | + $action = $this->migrate_values($action, $form); |
|
551 | 551 | |
552 | - // check if action already exists |
|
553 | - $post_id = get_posts( array( |
|
554 | - 'name' => $action->post_name, |
|
555 | - 'post_type' => FrmFormActionsController::$action_post_type, |
|
556 | - 'post_status' => $action->post_status, |
|
557 | - 'numberposts' => 1, |
|
558 | - ) ); |
|
552 | + // check if action already exists |
|
553 | + $post_id = get_posts( array( |
|
554 | + 'name' => $action->post_name, |
|
555 | + 'post_type' => FrmFormActionsController::$action_post_type, |
|
556 | + 'post_status' => $action->post_status, |
|
557 | + 'numberposts' => 1, |
|
558 | + ) ); |
|
559 | 559 | |
560 | - if ( empty($post_id) ) { |
|
561 | - // create action now |
|
562 | - $post_id = $this->save_settings($action); |
|
563 | - } |
|
560 | + if ( empty($post_id) ) { |
|
561 | + // create action now |
|
562 | + $post_id = $this->save_settings($action); |
|
563 | + } |
|
564 | 564 | |
565 | - if ( $post_id && 'update' == $update ) { |
|
566 | - global $wpdb; |
|
567 | - $form->options = maybe_serialize($form->options); |
|
565 | + if ( $post_id && 'update' == $update ) { |
|
566 | + global $wpdb; |
|
567 | + $form->options = maybe_serialize($form->options); |
|
568 | 568 | |
569 | - // update form options |
|
569 | + // update form options |
|
570 | 570 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) ); |
571 | - wp_cache_delete( $form->id, 'frm_form'); |
|
572 | - } |
|
571 | + wp_cache_delete( $form->id, 'frm_form'); |
|
572 | + } |
|
573 | 573 | |
574 | - return $post_id; |
|
575 | - } |
|
574 | + return $post_id; |
|
575 | + } |
|
576 | 576 | |
577 | 577 | public static function action_conditions_met( $action, $entry ) { |
578 | 578 | $notification = $action->post_content; |
@@ -2,16 +2,16 @@ discard block |
||
2 | 2 | |
3 | 3 | class FrmFormAction { |
4 | 4 | |
5 | - public $id_base; // Root id for all actions of this type. |
|
6 | - public $name; // Name for this action type. |
|
5 | + public $id_base; // Root id for all actions of this type. |
|
6 | + public $name; // Name for this action type. |
|
7 | 7 | public $option_name; |
8 | - public $action_options; // Option array passed to wp_register_sidebar_widget() |
|
9 | - public $control_options; // Option array passed to wp_register_widget_control() |
|
8 | + public $action_options; // Option array passed to wp_register_sidebar_widget() |
|
9 | + public $control_options; // Option array passed to wp_register_widget_control() |
|
10 | 10 | |
11 | - public $form_id; // The ID of the form to evaluate |
|
12 | - public $number = false; // Unique ID number of the current instance. |
|
13 | - public $id = ''; // Unique ID string of the current instance (id_base-number) |
|
14 | - public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice. |
|
11 | + public $form_id; // The ID of the form to evaluate |
|
12 | + public $number = false; // Unique ID number of the current instance. |
|
13 | + public $id = ''; // Unique ID string of the current instance (id_base-number) |
|
14 | + public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice. |
|
15 | 15 | |
16 | 16 | // Member functions that you must over-ride. |
17 | 17 | |
@@ -69,13 +69,13 @@ discard block |
||
69 | 69 | * - height: currently not used but may be needed in the future |
70 | 70 | */ |
71 | 71 | public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) { |
72 | - if ( ! defined('ABSPATH') ) { |
|
73 | - die('You are not allowed to call this page directly.'); |
|
72 | + if ( ! defined( 'ABSPATH' ) ) { |
|
73 | + die( 'You are not allowed to call this page directly.' ); |
|
74 | 74 | } |
75 | 75 | |
76 | - $this->id_base = strtolower($id_base); |
|
76 | + $this->id_base = strtolower( $id_base ); |
|
77 | 77 | $this->name = $name; |
78 | - $this->option_name = 'frm_' . $this->id_base .'_action'; |
|
78 | + $this->option_name = 'frm_' . $this->id_base . '_action'; |
|
79 | 79 | |
80 | 80 | $default_options = array( |
81 | 81 | 'classes' => '', |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @return string Name attribute for $field_name |
110 | 110 | */ |
111 | 111 | public function get_field_name( $field_name, $post_field = 'post_content' ) { |
112 | - return $this->option_name . '[' . $this->number . ']'. ( empty($post_field) ? '' : '['. $post_field .']' ) .'[' . $field_name . ']'; |
|
112 | + return $this->option_name . '[' . $this->number . ']' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']'; |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * @return string ID attribute for $field_name |
122 | 122 | */ |
123 | 123 | public function get_field_id( $field_name ) { |
124 | - return $field_name .'_'. $this->number; |
|
124 | + return $field_name . '_' . $this->number; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | // Private Function. Don't worry about this. |
@@ -140,10 +140,10 @@ discard block |
||
140 | 140 | $default_values = $this->get_global_defaults(); |
141 | 141 | |
142 | 142 | // fill default values |
143 | - $post_content = wp_parse_args( $post_content, $default_values); |
|
143 | + $post_content = wp_parse_args( $post_content, $default_values ); |
|
144 | 144 | |
145 | - if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) { |
|
146 | - $post_content['event'] = array( reset($this->action_options['event']) ); |
|
145 | + if ( ! isset( $post_content['event'] ) && ! $this->action_options['force_event'] ) { |
|
146 | + $post_content['event'] = array( reset( $this->action_options['event'] ) ); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | $form_action = array( |
@@ -153,10 +153,10 @@ discard block |
||
153 | 153 | 'ID' => '', |
154 | 154 | 'post_status' => 'publish', |
155 | 155 | 'post_type' => FrmFormActionsController::$action_post_type, |
156 | - 'post_name' => $this->form_id .'_'. $this->id_base .'_'. $this->number, |
|
156 | + 'post_name' => $this->form_id . '_' . $this->id_base . '_' . $this->number, |
|
157 | 157 | 'menu_order' => $this->form_id, |
158 | 158 | ); |
159 | - unset($post_content); |
|
159 | + unset( $post_content ); |
|
160 | 160 | |
161 | 161 | return (object) $form_action; |
162 | 162 | } |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | |
167 | 167 | $action = $this->prepare_new(); |
168 | 168 | |
169 | - return $this->save_settings($action); |
|
169 | + return $this->save_settings( $action ); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | public function duplicate_form_actions( $form_id, $old_id ) { |
@@ -180,8 +180,8 @@ discard block |
||
180 | 180 | |
181 | 181 | $this->form_id = $form_id; |
182 | 182 | foreach ( $actions as $action ) { |
183 | - $this->duplicate_one($action, $form_id); |
|
184 | - unset($action); |
|
183 | + $this->duplicate_one( $action, $form_id ); |
|
184 | + unset( $action ); |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
@@ -193,14 +193,14 @@ discard block |
||
193 | 193 | * @return integer $post_id |
194 | 194 | */ |
195 | 195 | public function maybe_create_action( $action, $forms ) { |
196 | - if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[ $action['menu_order'] ] == 'updated' ) { |
|
196 | + if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[$action['menu_order']] == 'updated' ) { |
|
197 | 197 | // Update action only |
198 | 198 | $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
199 | 199 | $post_id = $this->save_settings( $action ); |
200 | 200 | } else { |
201 | 201 | // Create action |
202 | - $action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']); |
|
203 | - $post_id = $this->duplicate_one( (object) $action, $action['menu_order']); |
|
202 | + $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
|
203 | + $post_id = $this->duplicate_one( (object) $action, $action['menu_order'] ); |
|
204 | 204 | } |
205 | 205 | return $post_id; |
206 | 206 | } |
@@ -211,47 +211,47 @@ discard block |
||
211 | 211 | $action->menu_order = $form_id; |
212 | 212 | $switch = $this->get_global_switch_fields(); |
213 | 213 | foreach ( (array) $action->post_content as $key => $val ) { |
214 | - if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) { |
|
215 | - $action->post_content[ $key ] = $frm_duplicate_ids[ $val ]; |
|
214 | + if ( is_numeric( $val ) && isset( $frm_duplicate_ids[$val] ) ) { |
|
215 | + $action->post_content[$key] = $frm_duplicate_ids[$val]; |
|
216 | 216 | } else if ( ! is_array( $val ) ) { |
217 | - $action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val ); |
|
218 | - } else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) { |
|
217 | + $action->post_content[$key] = FrmFieldsHelper::switch_field_ids( $val ); |
|
218 | + } else if ( isset( $switch[$key] ) && is_array( $switch[$key] ) ) { |
|
219 | 219 | // loop through each value if empty |
220 | - if ( empty( $switch[ $key ] ) ) { |
|
221 | - $switch[ $key ] = array_keys( $val ); |
|
220 | + if ( empty( $switch[$key] ) ) { |
|
221 | + $switch[$key] = array_keys( $val ); |
|
222 | 222 | } |
223 | 223 | |
224 | - foreach ( $switch[ $key ] as $subkey ) { |
|
225 | - $action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val ); |
|
224 | + foreach ( $switch[$key] as $subkey ) { |
|
225 | + $action->post_content[$key] = $this->duplicate_array_walk( $action->post_content[$key], $subkey, $val ); |
|
226 | 226 | } |
227 | 227 | } |
228 | 228 | |
229 | - unset($key, $val); |
|
229 | + unset( $key, $val ); |
|
230 | 230 | } |
231 | - unset($action->ID); |
|
231 | + unset( $action->ID ); |
|
232 | 232 | |
233 | - return $this->save_settings($action); |
|
233 | + return $this->save_settings( $action ); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | private function duplicate_array_walk( $action, $subkey, $val ) { |
237 | 237 | global $frm_duplicate_ids; |
238 | 238 | |
239 | - if ( is_array($subkey) ) { |
|
239 | + if ( is_array( $subkey ) ) { |
|
240 | 240 | foreach ( $subkey as $subkey2 ) { |
241 | 241 | foreach ( (array) $val as $ck => $cv ) { |
242 | - if ( is_array($cv) ) { |
|
243 | - $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv ); |
|
244 | - } else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) { |
|
245 | - $action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ]; |
|
242 | + if ( is_array( $cv ) ) { |
|
243 | + $action[$ck] = $this->duplicate_array_walk( $action[$ck], $subkey2, $cv ); |
|
244 | + } else if ( isset( $cv[$subkey] ) && is_numeric( $cv[$subkey] ) && isset( $frm_duplicate_ids[$cv[$subkey]] ) ) { |
|
245 | + $action[$ck][$subkey] = $frm_duplicate_ids[$cv[$subkey]]; |
|
246 | 246 | } |
247 | 247 | } |
248 | 248 | } |
249 | 249 | } else { |
250 | 250 | foreach ( (array) $val as $ck => $cv ) { |
251 | - if ( is_array($cv) ) { |
|
252 | - $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv ); |
|
253 | - } else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) { |
|
254 | - $action[ $ck ] = $frm_duplicate_ids[ $cv ]; |
|
251 | + if ( is_array( $cv ) ) { |
|
252 | + $action[$ck] = $this->duplicate_array_walk( $action[$ck], $subkey, $cv ); |
|
253 | + } else if ( $ck == $subkey && isset( $frm_duplicate_ids[$cv] ) ) { |
|
254 | + $action[$ck] = $frm_duplicate_ids[$cv]; |
|
255 | 255 | } |
256 | 256 | } |
257 | 257 | } |
@@ -275,8 +275,8 @@ discard block |
||
275 | 275 | return; |
276 | 276 | } |
277 | 277 | |
278 | - if ( isset( $_POST[ $this->option_name ] ) && is_array( $_POST[ $this->option_name ] ) ) { |
|
279 | - $settings = $_POST[ $this->option_name ]; |
|
278 | + if ( isset( $_POST[$this->option_name] ) && is_array( $_POST[$this->option_name] ) ) { |
|
279 | + $settings = $_POST[$this->option_name]; |
|
280 | 280 | } else { |
281 | 281 | return; |
282 | 282 | } |
@@ -284,19 +284,19 @@ discard block |
||
284 | 284 | $action_ids = array(); |
285 | 285 | |
286 | 286 | foreach ( $settings as $number => $new_instance ) { |
287 | - $this->_set($number); |
|
287 | + $this->_set( $number ); |
|
288 | 288 | |
289 | - if ( ! isset($new_instance['post_title']) ) { |
|
289 | + if ( ! isset( $new_instance['post_title'] ) ) { |
|
290 | 290 | // settings were never opened, so don't update |
291 | 291 | $action_ids[] = $new_instance['ID']; |
292 | 292 | $this->updated = true; |
293 | 293 | continue; |
294 | 294 | } |
295 | 295 | |
296 | - $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array(); |
|
296 | + $old_instance = isset( $all_instances[$number] ) ? $all_instances[$number] : array(); |
|
297 | 297 | |
298 | - $new_instance['post_type'] = FrmFormActionsController::$action_post_type; |
|
299 | - $new_instance['post_name'] = $this->form_id .'_'. $this->id_base .'_'. $this->number; |
|
298 | + $new_instance['post_type'] = FrmFormActionsController::$action_post_type; |
|
299 | + $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number; |
|
300 | 300 | $new_instance['menu_order'] = $this->form_id; |
301 | 301 | $new_instance['post_status'] = 'publish'; |
302 | 302 | $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : ''; |
@@ -318,14 +318,14 @@ discard block |
||
318 | 318 | */ |
319 | 319 | $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this ); |
320 | 320 | |
321 | - $instance['post_content'] = apply_filters('frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this); |
|
322 | - $instance['post_content'] = apply_filters('frm_before_save_'. $this->id_base .'_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this); |
|
321 | + $instance['post_content'] = apply_filters( 'frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this ); |
|
322 | + $instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this ); |
|
323 | 323 | |
324 | 324 | if ( false !== $instance ) { |
325 | - $all_instances[ $number ] = $instance; |
|
325 | + $all_instances[$number] = $instance; |
|
326 | 326 | } |
327 | 327 | |
328 | - $action_ids[] = $this->save_settings($instance); |
|
328 | + $action_ids[] = $this->save_settings( $instance ); |
|
329 | 329 | |
330 | 330 | $this->updated = true; |
331 | 331 | } |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | } |
339 | 339 | |
340 | 340 | public function get_single_action( $id ) { |
341 | - $action = get_post($id); |
|
341 | + $action = get_post( $id ); |
|
342 | 342 | if ( $action ) { |
343 | 343 | $action = $this->prepare_action( $action ); |
344 | 344 | $this->_set( $id ); |
@@ -347,12 +347,12 @@ discard block |
||
347 | 347 | } |
348 | 348 | |
349 | 349 | public function get_one( $form_id ) { |
350 | - return $this->get_all($form_id, 1); |
|
350 | + return $this->get_all( $form_id, 1 ); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) { |
354 | 354 | $action_controls = FrmFormActionsController::get_form_actions( $type ); |
355 | - if ( empty($action_controls) ) { |
|
355 | + if ( empty( $action_controls ) ) { |
|
356 | 356 | // don't continue if there are no available actions |
357 | 357 | return array(); |
358 | 358 | } |
@@ -373,12 +373,12 @@ discard block |
||
373 | 373 | // some plugins/themes are formatting the post_excerpt |
374 | 374 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
375 | 375 | |
376 | - if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) { |
|
376 | + if ( ! isset( $action_controls[$action->post_excerpt] ) ) { |
|
377 | 377 | continue; |
378 | 378 | } |
379 | 379 | |
380 | - $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action ); |
|
381 | - $settings[ $action->ID ] = $action; |
|
380 | + $action = $action_controls[$action->post_excerpt]->prepare_action( $action ); |
|
381 | + $settings[$action->ID] = $action; |
|
382 | 382 | |
383 | 383 | if ( count( $settings ) >= $limit ) { |
384 | 384 | break; |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | } |
387 | 387 | |
388 | 388 | if ( 1 === $limit ) { |
389 | - $settings = reset($settings); |
|
389 | + $settings = reset( $settings ); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | return $settings; |
@@ -402,33 +402,33 @@ discard block |
||
402 | 402 | global $frm_vars; |
403 | 403 | $frm_vars['action_type'] = $type; |
404 | 404 | |
405 | - add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
405 | + add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' ); |
|
406 | 406 | $query = self::action_args( $form_id, $limit ); |
407 | 407 | $query['post_status'] = 'any'; |
408 | 408 | $query['suppress_filters'] = false; |
409 | 409 | |
410 | 410 | $actions = FrmAppHelper::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' ); |
411 | - unset($query); |
|
411 | + unset( $query ); |
|
412 | 412 | |
413 | - remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
413 | + remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' ); |
|
414 | 414 | |
415 | - if ( empty($actions) ) { |
|
415 | + if ( empty( $actions ) ) { |
|
416 | 416 | return array(); |
417 | 417 | } |
418 | 418 | |
419 | 419 | $settings = array(); |
420 | 420 | foreach ( $actions as $action ) { |
421 | - if ( count($settings) >= $limit ) { |
|
421 | + if ( count( $settings ) >= $limit ) { |
|
422 | 422 | continue; |
423 | 423 | } |
424 | 424 | |
425 | - $action = $this->prepare_action($action); |
|
425 | + $action = $this->prepare_action( $action ); |
|
426 | 426 | |
427 | - $settings[ $action->ID ] = $action; |
|
427 | + $settings[$action->ID] = $action; |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | if ( 1 === $limit ) { |
431 | - $settings = reset($settings); |
|
431 | + $settings = reset( $settings ); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | return $settings; |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | } |
452 | 452 | |
453 | 453 | public function prepare_action( $action ) { |
454 | - $action->post_content = (array) FrmAppHelper::maybe_json_decode($action->post_content); |
|
454 | + $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content ); |
|
455 | 455 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
456 | 456 | |
457 | 457 | $default_values = $this->get_global_defaults(); |
@@ -460,16 +460,16 @@ discard block |
||
460 | 460 | $action->post_content += $default_values; |
461 | 461 | |
462 | 462 | foreach ( $default_values as $k => $vals ) { |
463 | - if ( is_array($vals) && ! empty($vals) ) { |
|
464 | - if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) { |
|
463 | + if ( is_array( $vals ) && ! empty( $vals ) ) { |
|
464 | + if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[$k] ) ) { |
|
465 | 465 | continue; |
466 | 466 | } |
467 | - $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals ); |
|
467 | + $action->post_content[$k] = wp_parse_args( $action->post_content[$k], $vals ); |
|
468 | 468 | } |
469 | 469 | } |
470 | 470 | |
471 | - if ( ! is_array($action->post_content['event']) ) { |
|
472 | - $action->post_content['event'] = explode(',', $action->post_content['event']); |
|
471 | + if ( ! is_array( $action->post_content['event'] ) ) { |
|
472 | + $action->post_content['event'] = explode( ',', $action->post_content['event'] ); |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | return $action; |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' ); |
492 | 492 | |
493 | 493 | foreach ( $post_ids as $id ) { |
494 | - wp_delete_post($id); |
|
494 | + wp_delete_post( $id ); |
|
495 | 495 | } |
496 | 496 | self::clear_cache(); |
497 | 497 | } |
@@ -512,11 +512,11 @@ discard block |
||
512 | 512 | public function get_global_defaults() { |
513 | 513 | $defaults = $this->get_defaults(); |
514 | 514 | |
515 | - if ( ! isset($defaults['event']) ) { |
|
515 | + if ( ! isset( $defaults['event'] ) ) { |
|
516 | 516 | $defaults['event'] = array( 'create' ); |
517 | 517 | } |
518 | 518 | |
519 | - if ( ! isset($defaults['conditions']) ) { |
|
519 | + if ( ! isset( $defaults['conditions'] ) ) { |
|
520 | 520 | $defaults['conditions'] = array( |
521 | 521 | 'send_stop' => '', |
522 | 522 | 'any_all' => '', |
@@ -536,18 +536,18 @@ discard block |
||
536 | 536 | * Migrate settings from form->options into new action. |
537 | 537 | */ |
538 | 538 | public function migrate_to_2( $form, $update = 'update' ) { |
539 | - $action = $this->prepare_new($form->id); |
|
540 | - $form->options = maybe_unserialize($form->options); |
|
539 | + $action = $this->prepare_new( $form->id ); |
|
540 | + $form->options = maybe_unserialize( $form->options ); |
|
541 | 541 | |
542 | 542 | // fill with existing options |
543 | 543 | foreach ( $action->post_content as $name => $val ) { |
544 | - if ( isset( $form->options[ $name ] ) ) { |
|
545 | - $action->post_content[ $name ] = $form->options[ $name ]; |
|
546 | - unset( $form->options[ $name ] ); |
|
544 | + if ( isset( $form->options[$name] ) ) { |
|
545 | + $action->post_content[$name] = $form->options[$name]; |
|
546 | + unset( $form->options[$name] ); |
|
547 | 547 | } |
548 | 548 | } |
549 | 549 | |
550 | - $action = $this->migrate_values($action, $form); |
|
550 | + $action = $this->migrate_values( $action, $form ); |
|
551 | 551 | |
552 | 552 | // check if action already exists |
553 | 553 | $post_id = get_posts( array( |
@@ -557,18 +557,18 @@ discard block |
||
557 | 557 | 'numberposts' => 1, |
558 | 558 | ) ); |
559 | 559 | |
560 | - if ( empty($post_id) ) { |
|
560 | + if ( empty( $post_id ) ) { |
|
561 | 561 | // create action now |
562 | - $post_id = $this->save_settings($action); |
|
562 | + $post_id = $this->save_settings( $action ); |
|
563 | 563 | } |
564 | 564 | |
565 | 565 | if ( $post_id && 'update' == $update ) { |
566 | 566 | global $wpdb; |
567 | - $form->options = maybe_serialize($form->options); |
|
567 | + $form->options = maybe_serialize( $form->options ); |
|
568 | 568 | |
569 | 569 | // update form options |
570 | 570 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) ); |
571 | - wp_cache_delete( $form->id, 'frm_form'); |
|
571 | + wp_cache_delete( $form->id, 'frm_form' ); |
|
572 | 572 | } |
573 | 573 | |
574 | 574 | return $post_id; |
@@ -592,27 +592,27 @@ discard block |
||
592 | 592 | continue; |
593 | 593 | } |
594 | 594 | |
595 | - if ( is_array($condition['hide_opt']) ) { |
|
596 | - $condition['hide_opt'] = reset($condition['hide_opt']); |
|
595 | + if ( is_array( $condition['hide_opt'] ) ) { |
|
596 | + $condition['hide_opt'] = reset( $condition['hide_opt'] ); |
|
597 | 597 | } |
598 | 598 | |
599 | - $observed_value = isset( $entry->metas[ $condition['hide_field'] ] ) ? $entry->metas[ $condition['hide_field'] ] : ''; |
|
599 | + $observed_value = isset( $entry->metas[$condition['hide_field']] ) ? $entry->metas[$condition['hide_field']] : ''; |
|
600 | 600 | if ( $condition['hide_opt'] == 'current_user' ) { |
601 | 601 | $condition['hide_opt'] = get_current_user_id(); |
602 | 602 | } |
603 | 603 | |
604 | - $stop = FrmFieldsHelper::value_meets_condition($observed_value, $condition['hide_field_cond'], $condition['hide_opt']); |
|
604 | + $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] ); |
|
605 | 605 | |
606 | 606 | if ( $notification['conditions']['send_stop'] == 'send' ) { |
607 | 607 | $stop = $stop ? false : true; |
608 | 608 | } |
609 | 609 | |
610 | - $met[ $stop ] = $stop; |
|
610 | + $met[$stop] = $stop; |
|
611 | 611 | } |
612 | 612 | |
613 | 613 | if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) { |
614 | - $stop = ($notification['conditions']['send_stop'] == 'send'); |
|
615 | - } else if ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset($met[0]) ) { |
|
614 | + $stop = ( $notification['conditions']['send_stop'] == 'send' ); |
|
615 | + } else if ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset( $met[0] ) ) { |
|
616 | 616 | $stop = false; |
617 | 617 | } |
618 | 618 |
@@ -2,165 +2,165 @@ discard block |
||
2 | 2 | |
3 | 3 | class FrmNotification { |
4 | 4 | public function __construct() { |
5 | - if ( ! defined('ABSPATH') ) { |
|
6 | - die('You are not allowed to call this page directly.'); |
|
7 | - } |
|
8 | - add_action('frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3); |
|
9 | - } |
|
5 | + if ( ! defined('ABSPATH') ) { |
|
6 | + die('You are not allowed to call this page directly.'); |
|
7 | + } |
|
8 | + add_action('frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3); |
|
9 | + } |
|
10 | 10 | |
11 | 11 | public static function trigger_email( $action, $entry, $form ) { |
12 | 12 | if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { |
13 | - return; |
|
14 | - } |
|
15 | - |
|
16 | - global $wpdb; |
|
17 | - |
|
18 | - $notification = $action->post_content; |
|
19 | - $email_key = $action->ID; |
|
20 | - |
|
21 | - // Set the subject |
|
22 | - if ( empty($notification['email_subject']) ) { |
|
23 | - $notification['email_subject'] = sprintf(__( '%1$s Form submitted on %2$s', 'formidable' ), $form->name, '[sitename]'); |
|
24 | - } |
|
25 | - |
|
26 | - $plain_text = $notification['plain_text'] ? true : false; |
|
27 | - |
|
28 | - //Filter these fields |
|
29 | - $filter_fields = array( |
|
30 | - 'email_to', 'cc', 'bcc', |
|
31 | - 'reply_to', 'from', |
|
32 | - 'email_subject', 'email_message', |
|
33 | - ); |
|
34 | - |
|
35 | - add_filter('frm_plain_text_email', ($plain_text ? '__return_true' : '__return_false')); |
|
36 | - |
|
37 | - //Get all values in entry in order to get User ID field ID |
|
38 | - $values = FrmEntryMeta::getAll( array( 'it.field_id !' => 0, 'it.item_id' => $entry->id ), ' ORDER BY fi.field_order' ); |
|
39 | - $user_id_field = $user_id_key = ''; |
|
40 | - foreach ( $values as $value ) { |
|
41 | - if ( $value->field_type == 'user_id' ) { |
|
42 | - $user_id_field = $value->field_id; |
|
43 | - $user_id_key = $value->field_key; |
|
44 | - break; |
|
45 | - } |
|
46 | - unset($value); |
|
47 | - } |
|
48 | - |
|
49 | - //Filter and prepare the email fields |
|
50 | - foreach ( $filter_fields as $f ) { |
|
51 | - //Don't allow empty From |
|
13 | + return; |
|
14 | + } |
|
15 | + |
|
16 | + global $wpdb; |
|
17 | + |
|
18 | + $notification = $action->post_content; |
|
19 | + $email_key = $action->ID; |
|
20 | + |
|
21 | + // Set the subject |
|
22 | + if ( empty($notification['email_subject']) ) { |
|
23 | + $notification['email_subject'] = sprintf(__( '%1$s Form submitted on %2$s', 'formidable' ), $form->name, '[sitename]'); |
|
24 | + } |
|
25 | + |
|
26 | + $plain_text = $notification['plain_text'] ? true : false; |
|
27 | + |
|
28 | + //Filter these fields |
|
29 | + $filter_fields = array( |
|
30 | + 'email_to', 'cc', 'bcc', |
|
31 | + 'reply_to', 'from', |
|
32 | + 'email_subject', 'email_message', |
|
33 | + ); |
|
34 | + |
|
35 | + add_filter('frm_plain_text_email', ($plain_text ? '__return_true' : '__return_false')); |
|
36 | + |
|
37 | + //Get all values in entry in order to get User ID field ID |
|
38 | + $values = FrmEntryMeta::getAll( array( 'it.field_id !' => 0, 'it.item_id' => $entry->id ), ' ORDER BY fi.field_order' ); |
|
39 | + $user_id_field = $user_id_key = ''; |
|
40 | + foreach ( $values as $value ) { |
|
41 | + if ( $value->field_type == 'user_id' ) { |
|
42 | + $user_id_field = $value->field_id; |
|
43 | + $user_id_key = $value->field_key; |
|
44 | + break; |
|
45 | + } |
|
46 | + unset($value); |
|
47 | + } |
|
48 | + |
|
49 | + //Filter and prepare the email fields |
|
50 | + foreach ( $filter_fields as $f ) { |
|
51 | + //Don't allow empty From |
|
52 | 52 | if ( $f == 'from' && empty( $notification[ $f ] ) ) { |
53 | 53 | $notification[ $f ] = '[admin_email]'; |
54 | 54 | } else if ( in_array( $f, array( 'email_to', 'cc', 'bcc', 'reply_to', 'from' ) ) ) { |
55 | 55 | //Remove brackets |
56 | - //Add a space in case there isn't one |
|
56 | + //Add a space in case there isn't one |
|
57 | 57 | $notification[ $f ] = str_replace( '<', ' ', $notification[ $f ] ); |
58 | 58 | $notification[ $f ] = str_replace( array( '"', '>' ), '', $notification[ $f ] ); |
59 | 59 | |
60 | - //Switch userID shortcode to email address |
|
60 | + //Switch userID shortcode to email address |
|
61 | 61 | if ( strpos( $notification[ $f ], '[' . $user_id_field . ']' ) !== false || strpos( $notification[ $f ], '[' . $user_id_key . ']' ) !== false ) { |
62 | 62 | $user_data = get_userdata( $entry->metas[ $user_id_field ] ); |
63 | - $user_email = $user_data->user_email; |
|
63 | + $user_email = $user_data->user_email; |
|
64 | 64 | $notification[ $f ] = str_replace( array( '[' . $user_id_field . ']', '[' . $user_id_key . ']' ), $user_email, $notification[ $f ] ); |
65 | - } |
|
66 | - } |
|
65 | + } |
|
66 | + } |
|
67 | 67 | |
68 | 68 | $notification[ $f ] = FrmFieldsHelper::basic_replace_shortcodes( $notification[ $f ], $form, $entry ); |
69 | - } |
|
69 | + } |
|
70 | 70 | |
71 | - //Put recipients, cc, and bcc into an array if they aren't empty |
|
71 | + //Put recipients, cc, and bcc into an array if they aren't empty |
|
72 | 72 | $to_emails = self::explode_emails( $notification['email_to'] ); |
73 | 73 | $cc = self::explode_emails( $notification['cc'] ); |
74 | 74 | $bcc = self::explode_emails( $notification['bcc'] ); |
75 | 75 | |
76 | - $to_emails = apply_filters('frm_to_email', $to_emails, $values, $form->id, compact('email_key', 'entry', 'form')); |
|
76 | + $to_emails = apply_filters('frm_to_email', $to_emails, $values, $form->id, compact('email_key', 'entry', 'form')); |
|
77 | 77 | |
78 | - // Stop now if there aren't any recipients |
|
79 | - if ( empty( $to_emails ) && empty( $cc ) && empty( $bcc ) ) { |
|
80 | - return; |
|
81 | - } |
|
78 | + // Stop now if there aren't any recipients |
|
79 | + if ( empty( $to_emails ) && empty( $cc ) && empty( $bcc ) ) { |
|
80 | + return; |
|
81 | + } |
|
82 | 82 | |
83 | - $to_emails = array_unique( (array) $to_emails ); |
|
83 | + $to_emails = array_unique( (array) $to_emails ); |
|
84 | 84 | |
85 | - $prev_mail_body = $mail_body = $notification['email_message']; |
|
86 | - $mail_body = FrmEntriesHelper::replace_default_message($mail_body, array( |
|
87 | - 'id' => $entry->id, 'entry' => $entry, 'plain_text' => $plain_text, |
|
88 | - 'user_info' => (isset($notification['inc_user_info']) ? $notification['inc_user_info'] : false), |
|
89 | - ) ); |
|
85 | + $prev_mail_body = $mail_body = $notification['email_message']; |
|
86 | + $mail_body = FrmEntriesHelper::replace_default_message($mail_body, array( |
|
87 | + 'id' => $entry->id, 'entry' => $entry, 'plain_text' => $plain_text, |
|
88 | + 'user_info' => (isset($notification['inc_user_info']) ? $notification['inc_user_info'] : false), |
|
89 | + ) ); |
|
90 | 90 | |
91 | - // Add the user info if it isn't already included |
|
92 | - if ( $notification['inc_user_info'] && $prev_mail_body == $mail_body ) { |
|
93 | - $data = maybe_unserialize($entry->description); |
|
94 | - $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) ."\r\n"; |
|
95 | - $mail_body .= __( 'IP Address', 'formidable' ) . ': '. $entry->ip ."\r\n"; |
|
91 | + // Add the user info if it isn't already included |
|
92 | + if ( $notification['inc_user_info'] && $prev_mail_body == $mail_body ) { |
|
93 | + $data = maybe_unserialize($entry->description); |
|
94 | + $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) ."\r\n"; |
|
95 | + $mail_body .= __( 'IP Address', 'formidable' ) . ': '. $entry->ip ."\r\n"; |
|
96 | 96 | $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntryFormat::get_browser( $data['browser'] ) . "\r\n"; |
97 | - $mail_body .= __( 'Referrer', 'formidable' ) . ': '. $data['referrer']."\r\n"; |
|
98 | - } |
|
99 | - unset($prev_mail_body); |
|
100 | - |
|
101 | - // Add attachments |
|
102 | - $attachments = apply_filters('frm_notification_attachment', array(), $form, compact('entry', 'email_key') ); |
|
103 | - |
|
104 | - if ( ! empty($notification['email_subject']) ) { |
|
105 | - $notification['email_subject'] = apply_filters('frm_email_subject', $notification['email_subject'], compact('form', 'entry', 'email_key')); |
|
106 | - } |
|
107 | - |
|
108 | - // check for a phone number |
|
109 | - foreach ( (array) $to_emails as $email_key => $e ) { |
|
110 | - if ( $e != '[admin_email]' && ! is_email($e) ) { |
|
111 | - $e = explode(' ', $e); |
|
112 | - |
|
113 | - //If to_email has name <[email protected]> format |
|
114 | - if ( is_email(end($e)) ) { |
|
115 | - continue; |
|
116 | - } |
|
117 | - |
|
118 | - do_action('frm_send_to_not_email', array( |
|
119 | - 'e' => $e, |
|
120 | - 'subject' => $notification['email_subject'], |
|
121 | - 'mail_body' => $mail_body, |
|
122 | - 'reply_to' => $notification['reply_to'], |
|
123 | - 'from' => $notification['from'], |
|
124 | - 'plain_text' => $plain_text, |
|
125 | - 'attachments' => $attachments, |
|
126 | - 'form' => $form, |
|
127 | - 'email_key' => $email_key, |
|
128 | - ) ); |
|
97 | + $mail_body .= __( 'Referrer', 'formidable' ) . ': '. $data['referrer']."\r\n"; |
|
98 | + } |
|
99 | + unset($prev_mail_body); |
|
100 | + |
|
101 | + // Add attachments |
|
102 | + $attachments = apply_filters('frm_notification_attachment', array(), $form, compact('entry', 'email_key') ); |
|
103 | + |
|
104 | + if ( ! empty($notification['email_subject']) ) { |
|
105 | + $notification['email_subject'] = apply_filters('frm_email_subject', $notification['email_subject'], compact('form', 'entry', 'email_key')); |
|
106 | + } |
|
107 | + |
|
108 | + // check for a phone number |
|
109 | + foreach ( (array) $to_emails as $email_key => $e ) { |
|
110 | + if ( $e != '[admin_email]' && ! is_email($e) ) { |
|
111 | + $e = explode(' ', $e); |
|
112 | + |
|
113 | + //If to_email has name <[email protected]> format |
|
114 | + if ( is_email(end($e)) ) { |
|
115 | + continue; |
|
116 | + } |
|
117 | + |
|
118 | + do_action('frm_send_to_not_email', array( |
|
119 | + 'e' => $e, |
|
120 | + 'subject' => $notification['email_subject'], |
|
121 | + 'mail_body' => $mail_body, |
|
122 | + 'reply_to' => $notification['reply_to'], |
|
123 | + 'from' => $notification['from'], |
|
124 | + 'plain_text' => $plain_text, |
|
125 | + 'attachments' => $attachments, |
|
126 | + 'form' => $form, |
|
127 | + 'email_key' => $email_key, |
|
128 | + ) ); |
|
129 | 129 | |
130 | 130 | unset( $to_emails[ $email_key ] ); |
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - // Send the email now |
|
135 | - $sent_to = self::send_email( array( |
|
136 | - 'to_email' => $to_emails, |
|
137 | - 'subject' => $notification['email_subject'], |
|
138 | - 'message' => $mail_body, |
|
139 | - 'from' => $notification['from'], |
|
140 | - 'plain_text' => $plain_text, |
|
141 | - 'reply_to' => $notification['reply_to'], |
|
142 | - 'attachments' => $attachments, |
|
143 | - 'cc' => $cc, |
|
144 | - 'bcc' => $bcc, |
|
145 | - ) ); |
|
146 | - |
|
147 | - return $sent_to; |
|
148 | - } |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + // Send the email now |
|
135 | + $sent_to = self::send_email( array( |
|
136 | + 'to_email' => $to_emails, |
|
137 | + 'subject' => $notification['email_subject'], |
|
138 | + 'message' => $mail_body, |
|
139 | + 'from' => $notification['from'], |
|
140 | + 'plain_text' => $plain_text, |
|
141 | + 'reply_to' => $notification['reply_to'], |
|
142 | + 'attachments' => $attachments, |
|
143 | + 'cc' => $cc, |
|
144 | + 'bcc' => $bcc, |
|
145 | + ) ); |
|
146 | + |
|
147 | + return $sent_to; |
|
148 | + } |
|
149 | 149 | |
150 | 150 | public function entry_created( $entry_id, $form_id ) { |
151 | - _deprecated_function( __FUNCTION__, '2.0', 'FrmFormActionsController::trigger_actions("create", '. $form_id .', '. $entry_id .', "email")'); |
|
152 | - FrmFormActionsController::trigger_actions('create', $form_id, $entry_id, 'email'); |
|
153 | - } |
|
151 | + _deprecated_function( __FUNCTION__, '2.0', 'FrmFormActionsController::trigger_actions("create", '. $form_id .', '. $entry_id .', "email")'); |
|
152 | + FrmFormActionsController::trigger_actions('create', $form_id, $entry_id, 'email'); |
|
153 | + } |
|
154 | 154 | |
155 | 155 | public function send_notification_email( $to_email, $subject, $message, $from = '', $from_name = '', $plain_text = true, $attachments = array(), $reply_to = '' ) { |
156 | - _deprecated_function( __FUNCTION__, '2.0', 'FrmNotification::send_email' ); |
|
156 | + _deprecated_function( __FUNCTION__, '2.0', 'FrmNotification::send_email' ); |
|
157 | 157 | |
158 | - return self::send_email(compact( |
|
159 | - 'to_email', 'subject', 'message', |
|
160 | - 'from', 'from_name', 'plain_text', |
|
161 | - 'attachments', 'reply_to' |
|
162 | - )); |
|
163 | - } |
|
158 | + return self::send_email(compact( |
|
159 | + 'to_email', 'subject', 'message', |
|
160 | + 'from', 'from_name', 'plain_text', |
|
161 | + 'attachments', 'reply_to' |
|
162 | + )); |
|
163 | + } |
|
164 | 164 | |
165 | 165 | /** |
166 | 166 | * Extract the emails from cc and bcc. Allow separation by , or ;. |
@@ -178,53 +178,53 @@ discard block |
||
178 | 178 | return $emails; |
179 | 179 | } |
180 | 180 | |
181 | - /** |
|
182 | - * Put To, BCC, CC, Reply To, and From fields in Name <[email protected]> format |
|
183 | - * Formats that should work: Name, "Name", [email protected], <[email protected]>, Name <[email protected]>, |
|
184 | - * "Name" <[email protected]>, Name [email protected], "Name" [email protected], Name<[email protected]>, "Name"<[email protected]> |
|
185 | - * "First Last" <[email protected]> |
|
186 | - * |
|
187 | - * Things that won't work: First Last (with no email entered) |
|
188 | - * @since 2.0 |
|
189 | - * @param array $atts array of email fields, pass by reference |
|
190 | - * @param $admin_email |
|
191 | - */ |
|
192 | - private static function format_email_fields( &$atts, $admin_email ) { |
|
193 | - |
|
194 | - // If from is empty or is set to admin_email, set it now |
|
195 | - $atts['from'] = ( empty($atts['from']) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from']; |
|
196 | - |
|
197 | - // Filter values in these fields |
|
181 | + /** |
|
182 | + * Put To, BCC, CC, Reply To, and From fields in Name <[email protected]> format |
|
183 | + * Formats that should work: Name, "Name", [email protected], <[email protected]>, Name <[email protected]>, |
|
184 | + * "Name" <[email protected]>, Name [email protected], "Name" [email protected], Name<[email protected]>, "Name"<[email protected]> |
|
185 | + * "First Last" <[email protected]> |
|
186 | + * |
|
187 | + * Things that won't work: First Last (with no email entered) |
|
188 | + * @since 2.0 |
|
189 | + * @param array $atts array of email fields, pass by reference |
|
190 | + * @param $admin_email |
|
191 | + */ |
|
192 | + private static function format_email_fields( &$atts, $admin_email ) { |
|
193 | + |
|
194 | + // If from is empty or is set to admin_email, set it now |
|
195 | + $atts['from'] = ( empty($atts['from']) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from']; |
|
196 | + |
|
197 | + // Filter values in these fields |
|
198 | 198 | $filter_fields = array( 'to_email', 'bcc', 'cc', 'from', 'reply_to' ); |
199 | 199 | |
200 | - foreach ( $filter_fields as $f ) { |
|
201 | - // If empty, just skip it |
|
200 | + foreach ( $filter_fields as $f ) { |
|
201 | + // If empty, just skip it |
|
202 | 202 | if ( empty( $atts[ $f ] ) ) { |
203 | - continue; |
|
204 | - } |
|
203 | + continue; |
|
204 | + } |
|
205 | 205 | |
206 | - // to_email, cc, and bcc can be an array |
|
206 | + // to_email, cc, and bcc can be an array |
|
207 | 207 | if ( is_array( $atts[ $f ] ) ) { |
208 | 208 | foreach ( $atts[ $f ] as $key => $val ) { |
209 | - self::format_single_field( $atts, $f, $val, $key ); |
|
210 | - unset( $key, $val ); |
|
211 | - } |
|
212 | - unset($f); |
|
213 | - continue; |
|
214 | - } |
|
209 | + self::format_single_field( $atts, $f, $val, $key ); |
|
210 | + unset( $key, $val ); |
|
211 | + } |
|
212 | + unset($f); |
|
213 | + continue; |
|
214 | + } |
|
215 | 215 | |
216 | 216 | self::format_single_field( $atts, $f, $atts[ $f ] ); |
217 | - } |
|
217 | + } |
|
218 | 218 | |
219 | - // If reply-to isn't set, make it match the from settings |
|
220 | - if ( empty( $atts['reply_to'] ) ) { |
|
221 | - $atts['reply_to'] = self::get_email_from_formatted_string( $atts['from'] ); |
|
222 | - } |
|
219 | + // If reply-to isn't set, make it match the from settings |
|
220 | + if ( empty( $atts['reply_to'] ) ) { |
|
221 | + $atts['reply_to'] = self::get_email_from_formatted_string( $atts['from'] ); |
|
222 | + } |
|
223 | 223 | |
224 | - if ( ! is_array($atts['to_email']) && '[admin_email]' == $atts['to_email'] ) { |
|
225 | - $atts['to_email'] = $admin_email; |
|
226 | - } |
|
227 | - } |
|
224 | + if ( ! is_array($atts['to_email']) && '[admin_email]' == $atts['to_email'] ) { |
|
225 | + $atts['to_email'] = $admin_email; |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | 229 | private static function get_email_from_formatted_string( $value ) { |
230 | 230 | if ( strpos( $value, '<' ) !== false ) { |
@@ -234,48 +234,48 @@ discard block |
||
234 | 234 | return $value; |
235 | 235 | } |
236 | 236 | |
237 | - /** |
|
238 | - * Format individual email fields |
|
239 | - * |
|
240 | - * @since 2.0 |
|
241 | - * @param array $atts pass by reference |
|
242 | - * @param string $f (to, from, reply_to, etc) |
|
243 | - * @param string $val value saved in field |
|
244 | - * @param int $key if in array, this will be set |
|
245 | - */ |
|
246 | - private static function format_single_field( &$atts, $f, $val, $key = false ) { |
|
247 | - $val = trim($val); |
|
248 | - |
|
249 | - // If just a plain email is used |
|
250 | - if ( is_email($val) ) { |
|
251 | - // add sender's name if not included in $from |
|
252 | - if ( $f == 'from' ) { |
|
237 | + /** |
|
238 | + * Format individual email fields |
|
239 | + * |
|
240 | + * @since 2.0 |
|
241 | + * @param array $atts pass by reference |
|
242 | + * @param string $f (to, from, reply_to, etc) |
|
243 | + * @param string $val value saved in field |
|
244 | + * @param int $key if in array, this will be set |
|
245 | + */ |
|
246 | + private static function format_single_field( &$atts, $f, $val, $key = false ) { |
|
247 | + $val = trim($val); |
|
248 | + |
|
249 | + // If just a plain email is used |
|
250 | + if ( is_email($val) ) { |
|
251 | + // add sender's name if not included in $from |
|
252 | + if ( $f == 'from' ) { |
|
253 | 253 | $part_2 = $atts[ $f ]; |
254 | - $part_1 = $atts['from_name'] ? $atts['from_name'] : wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ); |
|
255 | - } else { |
|
256 | - return; |
|
257 | - } |
|
258 | - } else { |
|
259 | - $parts = explode(' ', $val); |
|
260 | - $part_2 = end($parts); |
|
261 | - |
|
262 | - // If inputted correcly, $part_2 should be an email |
|
263 | - if ( is_email( $part_2 ) ) { |
|
264 | - $part_1 = trim( str_replace( $part_2, '', $val ) ); |
|
265 | - } else if ( in_array( $f, array( 'from', 'reply_to' ) ) ) { |
|
254 | + $part_1 = $atts['from_name'] ? $atts['from_name'] : wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ); |
|
255 | + } else { |
|
256 | + return; |
|
257 | + } |
|
258 | + } else { |
|
259 | + $parts = explode(' ', $val); |
|
260 | + $part_2 = end($parts); |
|
261 | + |
|
262 | + // If inputted correcly, $part_2 should be an email |
|
263 | + if ( is_email( $part_2 ) ) { |
|
264 | + $part_1 = trim( str_replace( $part_2, '', $val ) ); |
|
265 | + } else if ( in_array( $f, array( 'from', 'reply_to' ) ) ) { |
|
266 | 266 | // In case someone just puts a name in the From or Reply To field |
267 | 267 | $part_1 = $val; |
268 | - $part_2 = get_option('admin_email'); |
|
269 | - } else { |
|
268 | + $part_2 = get_option('admin_email'); |
|
269 | + } else { |
|
270 | 270 | // In case someone just puts a name in any other email field |
271 | - if ( false !== $key ) { |
|
271 | + if ( false !== $key ) { |
|
272 | 272 | unset( $atts[ $f ][ $key ] ); |
273 | - return; |
|
274 | - } |
|
273 | + return; |
|
274 | + } |
|
275 | 275 | $atts[ $f ] = ''; |
276 | - return; |
|
277 | - } |
|
278 | - } |
|
276 | + return; |
|
277 | + } |
|
278 | + } |
|
279 | 279 | |
280 | 280 | // if sending the email from a yahoo address, change it to the WordPress default |
281 | 281 | if ( $f == 'from' && strpos( $part_2, '@yahoo.com' ) ) { |
@@ -288,110 +288,110 @@ discard block |
||
288 | 288 | $part_2 = 'wordpress@' . $sitename; |
289 | 289 | } |
290 | 290 | |
291 | - // Set up formatted value |
|
291 | + // Set up formatted value |
|
292 | 292 | $final_val = str_replace( '"', '', $part_1 ) . ' <'. $part_2 .'>'; |
293 | 293 | |
294 | - // If value is an array |
|
295 | - if ( false !== $key ) { |
|
294 | + // If value is an array |
|
295 | + if ( false !== $key ) { |
|
296 | 296 | $atts[ $f ][ $key ] = $final_val; |
297 | - return; |
|
298 | - } |
|
297 | + return; |
|
298 | + } |
|
299 | 299 | $atts[ $f ] = $final_val; |
300 | - } |
|
300 | + } |
|
301 | 301 | |
302 | 302 | public static function send_email( $atts ) { |
303 | - $admin_email = get_option('admin_email'); |
|
304 | - $defaults = array( |
|
305 | - 'to_email' => $admin_email, |
|
306 | - 'subject' => '', |
|
307 | - 'message' => '', |
|
308 | - 'from' => $admin_email, |
|
309 | - 'from_name' => '', |
|
310 | - 'cc' => '', |
|
311 | - 'bcc' => '', |
|
312 | - 'plain_text' => true, |
|
313 | - 'reply_to' => $admin_email, |
|
314 | - 'attachments' => array(), |
|
315 | - ); |
|
316 | - $atts = wp_parse_args($atts, $defaults); |
|
317 | - |
|
318 | - // Put To, BCC, CC, Reply To, and From fields in the correct format |
|
319 | - self::format_email_fields( $atts, $admin_email ); |
|
320 | - |
|
321 | - $recipient = $atts['to_email']; //recipient |
|
322 | - $header = array(); |
|
323 | - $header[] = 'From: ' . $atts['from']; |
|
324 | - |
|
325 | - //Allow for cc and bcc arrays |
|
303 | + $admin_email = get_option('admin_email'); |
|
304 | + $defaults = array( |
|
305 | + 'to_email' => $admin_email, |
|
306 | + 'subject' => '', |
|
307 | + 'message' => '', |
|
308 | + 'from' => $admin_email, |
|
309 | + 'from_name' => '', |
|
310 | + 'cc' => '', |
|
311 | + 'bcc' => '', |
|
312 | + 'plain_text' => true, |
|
313 | + 'reply_to' => $admin_email, |
|
314 | + 'attachments' => array(), |
|
315 | + ); |
|
316 | + $atts = wp_parse_args($atts, $defaults); |
|
317 | + |
|
318 | + // Put To, BCC, CC, Reply To, and From fields in the correct format |
|
319 | + self::format_email_fields( $atts, $admin_email ); |
|
320 | + |
|
321 | + $recipient = $atts['to_email']; //recipient |
|
322 | + $header = array(); |
|
323 | + $header[] = 'From: ' . $atts['from']; |
|
324 | + |
|
325 | + //Allow for cc and bcc arrays |
|
326 | 326 | $array_fields = array( 'CC' => $atts['cc'], 'BCC' => $atts['bcc'] ); |
327 | 327 | $cc = array( 'CC' => array(), 'BCC' => array() ); |
328 | - foreach ( $array_fields as $key => $a_field ) { |
|
329 | - if ( empty($a_field) ) { |
|
330 | - continue; |
|
331 | - } |
|
328 | + foreach ( $array_fields as $key => $a_field ) { |
|
329 | + if ( empty($a_field) ) { |
|
330 | + continue; |
|
331 | + } |
|
332 | 332 | |
333 | 333 | foreach ( (array) $a_field as $email ) { |
334 | 334 | $cc[ $key ][] = $email; |
335 | - } |
|
336 | - unset($key, $a_field); |
|
337 | - } |
|
335 | + } |
|
336 | + unset($key, $a_field); |
|
337 | + } |
|
338 | 338 | $cc = array_filter( $cc ); // remove cc and bcc if they are empty |
339 | 339 | |
340 | 340 | foreach ( $cc as $k => $v ) { |
341 | 341 | $header[] = $k . ': '. implode( ',', $v ); |
342 | 342 | } |
343 | 343 | |
344 | - $content_type = $atts['plain_text'] ? 'text/plain' : 'text/html'; |
|
345 | - $charset = get_option('blog_charset'); |
|
344 | + $content_type = $atts['plain_text'] ? 'text/plain' : 'text/html'; |
|
345 | + $charset = get_option('blog_charset'); |
|
346 | 346 | |
347 | - $header[] = 'Reply-To: '. $atts['reply_to']; |
|
347 | + $header[] = 'Reply-To: '. $atts['reply_to']; |
|
348 | 348 | $header[] = 'Content-Type: ' . $content_type . '; charset="' . esc_attr( $charset ) . '"'; |
349 | - $atts['subject'] = wp_specialchars_decode(strip_tags(stripslashes($atts['subject'])), ENT_QUOTES ); |
|
349 | + $atts['subject'] = wp_specialchars_decode(strip_tags(stripslashes($atts['subject'])), ENT_QUOTES ); |
|
350 | 350 | |
351 | - $message = do_shortcode($atts['message']); |
|
351 | + $message = do_shortcode($atts['message']); |
|
352 | 352 | |
353 | - if ( $atts['plain_text'] ) { |
|
354 | - //$message = wordwrap($message, 70, "\r\n"); //in case any lines are longer than 70 chars |
|
355 | - $message = wp_specialchars_decode(strip_tags($message), ENT_QUOTES ); |
|
356 | - } else { |
|
353 | + if ( $atts['plain_text'] ) { |
|
354 | + //$message = wordwrap($message, 70, "\r\n"); //in case any lines are longer than 70 chars |
|
355 | + $message = wp_specialchars_decode(strip_tags($message), ENT_QUOTES ); |
|
356 | + } else { |
|
357 | 357 | // remove line breaks in HTML emails to prevent conflicts with Mandrill |
358 | - add_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' ); |
|
359 | - } |
|
358 | + add_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' ); |
|
359 | + } |
|
360 | 360 | $message = apply_filters( 'frm_email_message', $message, $atts ); |
361 | 361 | |
362 | - $header = apply_filters('frm_email_header', $header, array( |
|
362 | + $header = apply_filters('frm_email_header', $header, array( |
|
363 | 363 | 'to_email' => $atts['to_email'], 'subject' => $atts['subject'], |
364 | 364 | ) ); |
365 | 365 | |
366 | - if ( apply_filters('frm_encode_subject', 1, $atts['subject'] ) ) { |
|
367 | - $atts['subject'] = '=?'. $charset .'?B?'. base64_encode($atts['subject']) .'?='; |
|
368 | - } |
|
366 | + if ( apply_filters('frm_encode_subject', 1, $atts['subject'] ) ) { |
|
367 | + $atts['subject'] = '=?'. $charset .'?B?'. base64_encode($atts['subject']) .'?='; |
|
368 | + } |
|
369 | 369 | |
370 | - remove_filter('wp_mail_from', 'bp_core_email_from_address_filter' ); |
|
371 | - remove_filter('wp_mail_from_name', 'bp_core_email_from_name_filter'); |
|
370 | + remove_filter('wp_mail_from', 'bp_core_email_from_address_filter' ); |
|
371 | + remove_filter('wp_mail_from_name', 'bp_core_email_from_name_filter'); |
|
372 | 372 | |
373 | - $sent = wp_mail($recipient, $atts['subject'], $message, $header, $atts['attachments']); |
|
374 | - if ( ! $sent ) { |
|
375 | - $header = 'From: '. $atts['from'] ."\r\n"; |
|
376 | - $recipient = implode(',', (array) $recipient); |
|
377 | - $sent = mail($recipient, $atts['subject'], $message, $header); |
|
378 | - } |
|
373 | + $sent = wp_mail($recipient, $atts['subject'], $message, $header, $atts['attachments']); |
|
374 | + if ( ! $sent ) { |
|
375 | + $header = 'From: '. $atts['from'] ."\r\n"; |
|
376 | + $recipient = implode(',', (array) $recipient); |
|
377 | + $sent = mail($recipient, $atts['subject'], $message, $header); |
|
378 | + } |
|
379 | 379 | |
380 | 380 | // remove the filter now so other emails can still use it |
381 | 381 | remove_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' ); |
382 | 382 | |
383 | - do_action('frm_notification', $recipient, $atts['subject'], $message); |
|
383 | + do_action('frm_notification', $recipient, $atts['subject'], $message); |
|
384 | 384 | |
385 | - if ( $sent ) { |
|
385 | + if ( $sent ) { |
|
386 | 386 | $sent_to = array_merge( (array) $atts['to_email'], (array) $atts['cc'], (array) $atts['bcc'] ); |
387 | - $sent_to = array_filter( $sent_to ); |
|
388 | - if ( apply_filters('frm_echo_emails', false) ) { |
|
389 | - $temp = str_replace('<', '<', $sent_to); |
|
387 | + $sent_to = array_filter( $sent_to ); |
|
388 | + if ( apply_filters('frm_echo_emails', false) ) { |
|
389 | + $temp = str_replace('<', '<', $sent_to); |
|
390 | 390 | echo ' ' . FrmAppHelper::kses( implode(', ', (array) $temp ) ); |
391 | - } |
|
392 | - return $sent_to; |
|
393 | - } |
|
394 | - } |
|
391 | + } |
|
392 | + return $sent_to; |
|
393 | + } |
|
394 | + } |
|
395 | 395 | |
396 | 396 | /** |
397 | 397 | * This function should only be fired when Mandrill is sending an HTML email |
@@ -2,14 +2,14 @@ discard block |
||
2 | 2 | |
3 | 3 | class FrmNotification { |
4 | 4 | public function __construct() { |
5 | - if ( ! defined('ABSPATH') ) { |
|
6 | - die('You are not allowed to call this page directly.'); |
|
5 | + if ( ! defined( 'ABSPATH' ) ) { |
|
6 | + die( 'You are not allowed to call this page directly.' ); |
|
7 | 7 | } |
8 | - add_action('frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3); |
|
8 | + add_action( 'frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3 ); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | public static function trigger_email( $action, $entry, $form ) { |
12 | - if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { |
|
12 | + if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { |
|
13 | 13 | return; |
14 | 14 | } |
15 | 15 | |
@@ -19,8 +19,8 @@ discard block |
||
19 | 19 | $email_key = $action->ID; |
20 | 20 | |
21 | 21 | // Set the subject |
22 | - if ( empty($notification['email_subject']) ) { |
|
23 | - $notification['email_subject'] = sprintf(__( '%1$s Form submitted on %2$s', 'formidable' ), $form->name, '[sitename]'); |
|
22 | + if ( empty( $notification['email_subject'] ) ) { |
|
23 | + $notification['email_subject'] = sprintf( __( '%1$s Form submitted on %2$s', 'formidable' ), $form->name, '[sitename]' ); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | $plain_text = $notification['plain_text'] ? true : false; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | 'email_subject', 'email_message', |
33 | 33 | ); |
34 | 34 | |
35 | - add_filter('frm_plain_text_email', ($plain_text ? '__return_true' : '__return_false')); |
|
35 | + add_filter( 'frm_plain_text_email', ( $plain_text ? '__return_true' : '__return_false' ) ); |
|
36 | 36 | |
37 | 37 | //Get all values in entry in order to get User ID field ID |
38 | 38 | $values = FrmEntryMeta::getAll( array( 'it.field_id !' => 0, 'it.item_id' => $entry->id ), ' ORDER BY fi.field_order' ); |
@@ -43,29 +43,29 @@ discard block |
||
43 | 43 | $user_id_key = $value->field_key; |
44 | 44 | break; |
45 | 45 | } |
46 | - unset($value); |
|
46 | + unset( $value ); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | //Filter and prepare the email fields |
50 | 50 | foreach ( $filter_fields as $f ) { |
51 | 51 | //Don't allow empty From |
52 | - if ( $f == 'from' && empty( $notification[ $f ] ) ) { |
|
53 | - $notification[ $f ] = '[admin_email]'; |
|
52 | + if ( $f == 'from' && empty( $notification[$f] ) ) { |
|
53 | + $notification[$f] = '[admin_email]'; |
|
54 | 54 | } else if ( in_array( $f, array( 'email_to', 'cc', 'bcc', 'reply_to', 'from' ) ) ) { |
55 | 55 | //Remove brackets |
56 | 56 | //Add a space in case there isn't one |
57 | - $notification[ $f ] = str_replace( '<', ' ', $notification[ $f ] ); |
|
58 | - $notification[ $f ] = str_replace( array( '"', '>' ), '', $notification[ $f ] ); |
|
57 | + $notification[$f] = str_replace( '<', ' ', $notification[$f] ); |
|
58 | + $notification[$f] = str_replace( array( '"', '>' ), '', $notification[$f] ); |
|
59 | 59 | |
60 | 60 | //Switch userID shortcode to email address |
61 | - if ( strpos( $notification[ $f ], '[' . $user_id_field . ']' ) !== false || strpos( $notification[ $f ], '[' . $user_id_key . ']' ) !== false ) { |
|
62 | - $user_data = get_userdata( $entry->metas[ $user_id_field ] ); |
|
61 | + if ( strpos( $notification[$f], '[' . $user_id_field . ']' ) !== false || strpos( $notification[$f], '[' . $user_id_key . ']' ) !== false ) { |
|
62 | + $user_data = get_userdata( $entry->metas[$user_id_field] ); |
|
63 | 63 | $user_email = $user_data->user_email; |
64 | - $notification[ $f ] = str_replace( array( '[' . $user_id_field . ']', '[' . $user_id_key . ']' ), $user_email, $notification[ $f ] ); |
|
64 | + $notification[$f] = str_replace( array( '[' . $user_id_field . ']', '[' . $user_id_key . ']' ), $user_email, $notification[$f] ); |
|
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
68 | - $notification[ $f ] = FrmFieldsHelper::basic_replace_shortcodes( $notification[ $f ], $form, $entry ); |
|
68 | + $notification[$f] = FrmFieldsHelper::basic_replace_shortcodes( $notification[$f], $form, $entry ); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | //Put recipients, cc, and bcc into an array if they aren't empty |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | $cc = self::explode_emails( $notification['cc'] ); |
74 | 74 | $bcc = self::explode_emails( $notification['bcc'] ); |
75 | 75 | |
76 | - $to_emails = apply_filters('frm_to_email', $to_emails, $values, $form->id, compact('email_key', 'entry', 'form')); |
|
76 | + $to_emails = apply_filters( 'frm_to_email', $to_emails, $values, $form->id, compact( 'email_key', 'entry', 'form' ) ); |
|
77 | 77 | |
78 | 78 | // Stop now if there aren't any recipients |
79 | 79 | if ( empty( $to_emails ) && empty( $cc ) && empty( $bcc ) ) { |
@@ -83,39 +83,39 @@ discard block |
||
83 | 83 | $to_emails = array_unique( (array) $to_emails ); |
84 | 84 | |
85 | 85 | $prev_mail_body = $mail_body = $notification['email_message']; |
86 | - $mail_body = FrmEntriesHelper::replace_default_message($mail_body, array( |
|
86 | + $mail_body = FrmEntriesHelper::replace_default_message( $mail_body, array( |
|
87 | 87 | 'id' => $entry->id, 'entry' => $entry, 'plain_text' => $plain_text, |
88 | - 'user_info' => (isset($notification['inc_user_info']) ? $notification['inc_user_info'] : false), |
|
88 | + 'user_info' => ( isset( $notification['inc_user_info'] ) ? $notification['inc_user_info'] : false ), |
|
89 | 89 | ) ); |
90 | 90 | |
91 | 91 | // Add the user info if it isn't already included |
92 | 92 | if ( $notification['inc_user_info'] && $prev_mail_body == $mail_body ) { |
93 | - $data = maybe_unserialize($entry->description); |
|
94 | - $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) ."\r\n"; |
|
95 | - $mail_body .= __( 'IP Address', 'formidable' ) . ': '. $entry->ip ."\r\n"; |
|
93 | + $data = maybe_unserialize( $entry->description ); |
|
94 | + $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n"; |
|
95 | + $mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $entry->ip . "\r\n"; |
|
96 | 96 | $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntryFormat::get_browser( $data['browser'] ) . "\r\n"; |
97 | - $mail_body .= __( 'Referrer', 'formidable' ) . ': '. $data['referrer']."\r\n"; |
|
97 | + $mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n"; |
|
98 | 98 | } |
99 | - unset($prev_mail_body); |
|
99 | + unset( $prev_mail_body ); |
|
100 | 100 | |
101 | 101 | // Add attachments |
102 | - $attachments = apply_filters('frm_notification_attachment', array(), $form, compact('entry', 'email_key') ); |
|
102 | + $attachments = apply_filters( 'frm_notification_attachment', array(), $form, compact( 'entry', 'email_key' ) ); |
|
103 | 103 | |
104 | - if ( ! empty($notification['email_subject']) ) { |
|
105 | - $notification['email_subject'] = apply_filters('frm_email_subject', $notification['email_subject'], compact('form', 'entry', 'email_key')); |
|
104 | + if ( ! empty( $notification['email_subject'] ) ) { |
|
105 | + $notification['email_subject'] = apply_filters( 'frm_email_subject', $notification['email_subject'], compact( 'form', 'entry', 'email_key' ) ); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | // check for a phone number |
109 | 109 | foreach ( (array) $to_emails as $email_key => $e ) { |
110 | - if ( $e != '[admin_email]' && ! is_email($e) ) { |
|
111 | - $e = explode(' ', $e); |
|
110 | + if ( $e != '[admin_email]' && ! is_email( $e ) ) { |
|
111 | + $e = explode( ' ', $e ); |
|
112 | 112 | |
113 | 113 | //If to_email has name <[email protected]> format |
114 | - if ( is_email(end($e)) ) { |
|
114 | + if ( is_email( end( $e ) ) ) { |
|
115 | 115 | continue; |
116 | 116 | } |
117 | 117 | |
118 | - do_action('frm_send_to_not_email', array( |
|
118 | + do_action( 'frm_send_to_not_email', array( |
|
119 | 119 | 'e' => $e, |
120 | 120 | 'subject' => $notification['email_subject'], |
121 | 121 | 'mail_body' => $mail_body, |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | 'email_key' => $email_key, |
128 | 128 | ) ); |
129 | 129 | |
130 | - unset( $to_emails[ $email_key ] ); |
|
130 | + unset( $to_emails[$email_key] ); |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | |
@@ -148,18 +148,18 @@ discard block |
||
148 | 148 | } |
149 | 149 | |
150 | 150 | public function entry_created( $entry_id, $form_id ) { |
151 | - _deprecated_function( __FUNCTION__, '2.0', 'FrmFormActionsController::trigger_actions("create", '. $form_id .', '. $entry_id .', "email")'); |
|
152 | - FrmFormActionsController::trigger_actions('create', $form_id, $entry_id, 'email'); |
|
151 | + _deprecated_function( __FUNCTION__, '2.0', 'FrmFormActionsController::trigger_actions("create", ' . $form_id . ', ' . $entry_id . ', "email")' ); |
|
152 | + FrmFormActionsController::trigger_actions( 'create', $form_id, $entry_id, 'email' ); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | public function send_notification_email( $to_email, $subject, $message, $from = '', $from_name = '', $plain_text = true, $attachments = array(), $reply_to = '' ) { |
156 | 156 | _deprecated_function( __FUNCTION__, '2.0', 'FrmNotification::send_email' ); |
157 | 157 | |
158 | - return self::send_email(compact( |
|
158 | + return self::send_email( compact( |
|
159 | 159 | 'to_email', 'subject', 'message', |
160 | 160 | 'from', 'from_name', 'plain_text', |
161 | 161 | 'attachments', 'reply_to' |
162 | - )); |
|
162 | + ) ); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -192,28 +192,28 @@ discard block |
||
192 | 192 | private static function format_email_fields( &$atts, $admin_email ) { |
193 | 193 | |
194 | 194 | // If from is empty or is set to admin_email, set it now |
195 | - $atts['from'] = ( empty($atts['from']) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from']; |
|
195 | + $atts['from'] = ( empty( $atts['from'] ) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from']; |
|
196 | 196 | |
197 | 197 | // Filter values in these fields |
198 | 198 | $filter_fields = array( 'to_email', 'bcc', 'cc', 'from', 'reply_to' ); |
199 | 199 | |
200 | 200 | foreach ( $filter_fields as $f ) { |
201 | 201 | // If empty, just skip it |
202 | - if ( empty( $atts[ $f ] ) ) { |
|
202 | + if ( empty( $atts[$f] ) ) { |
|
203 | 203 | continue; |
204 | 204 | } |
205 | 205 | |
206 | 206 | // to_email, cc, and bcc can be an array |
207 | - if ( is_array( $atts[ $f ] ) ) { |
|
208 | - foreach ( $atts[ $f ] as $key => $val ) { |
|
207 | + if ( is_array( $atts[$f] ) ) { |
|
208 | + foreach ( $atts[$f] as $key => $val ) { |
|
209 | 209 | self::format_single_field( $atts, $f, $val, $key ); |
210 | 210 | unset( $key, $val ); |
211 | 211 | } |
212 | - unset($f); |
|
212 | + unset( $f ); |
|
213 | 213 | continue; |
214 | 214 | } |
215 | 215 | |
216 | - self::format_single_field( $atts, $f, $atts[ $f ] ); |
|
216 | + self::format_single_field( $atts, $f, $atts[$f] ); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | // If reply-to isn't set, make it match the from settings |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | $atts['reply_to'] = self::get_email_from_formatted_string( $atts['from'] ); |
222 | 222 | } |
223 | 223 | |
224 | - if ( ! is_array($atts['to_email']) && '[admin_email]' == $atts['to_email'] ) { |
|
224 | + if ( ! is_array( $atts['to_email'] ) && '[admin_email]' == $atts['to_email'] ) { |
|
225 | 225 | $atts['to_email'] = $admin_email; |
226 | 226 | } |
227 | 227 | } |
@@ -244,20 +244,20 @@ discard block |
||
244 | 244 | * @param int $key if in array, this will be set |
245 | 245 | */ |
246 | 246 | private static function format_single_field( &$atts, $f, $val, $key = false ) { |
247 | - $val = trim($val); |
|
247 | + $val = trim( $val ); |
|
248 | 248 | |
249 | 249 | // If just a plain email is used |
250 | - if ( is_email($val) ) { |
|
250 | + if ( is_email( $val ) ) { |
|
251 | 251 | // add sender's name if not included in $from |
252 | 252 | if ( $f == 'from' ) { |
253 | - $part_2 = $atts[ $f ]; |
|
254 | - $part_1 = $atts['from_name'] ? $atts['from_name'] : wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ); |
|
253 | + $part_2 = $atts[$f]; |
|
254 | + $part_1 = $atts['from_name'] ? $atts['from_name'] : wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ); |
|
255 | 255 | } else { |
256 | 256 | return; |
257 | 257 | } |
258 | 258 | } else { |
259 | - $parts = explode(' ', $val); |
|
260 | - $part_2 = end($parts); |
|
259 | + $parts = explode( ' ', $val ); |
|
260 | + $part_2 = end( $parts ); |
|
261 | 261 | |
262 | 262 | // If inputted correcly, $part_2 should be an email |
263 | 263 | if ( is_email( $part_2 ) ) { |
@@ -265,14 +265,14 @@ discard block |
||
265 | 265 | } else if ( in_array( $f, array( 'from', 'reply_to' ) ) ) { |
266 | 266 | // In case someone just puts a name in the From or Reply To field |
267 | 267 | $part_1 = $val; |
268 | - $part_2 = get_option('admin_email'); |
|
268 | + $part_2 = get_option( 'admin_email' ); |
|
269 | 269 | } else { |
270 | 270 | // In case someone just puts a name in any other email field |
271 | 271 | if ( false !== $key ) { |
272 | - unset( $atts[ $f ][ $key ] ); |
|
272 | + unset( $atts[$f][$key] ); |
|
273 | 273 | return; |
274 | 274 | } |
275 | - $atts[ $f ] = ''; |
|
275 | + $atts[$f] = ''; |
|
276 | 276 | return; |
277 | 277 | } |
278 | 278 | } |
@@ -289,18 +289,18 @@ discard block |
||
289 | 289 | } |
290 | 290 | |
291 | 291 | // Set up formatted value |
292 | - $final_val = str_replace( '"', '', $part_1 ) . ' <'. $part_2 .'>'; |
|
292 | + $final_val = str_replace( '"', '', $part_1 ) . ' <' . $part_2 . '>'; |
|
293 | 293 | |
294 | 294 | // If value is an array |
295 | 295 | if ( false !== $key ) { |
296 | - $atts[ $f ][ $key ] = $final_val; |
|
296 | + $atts[$f][$key] = $final_val; |
|
297 | 297 | return; |
298 | 298 | } |
299 | - $atts[ $f ] = $final_val; |
|
299 | + $atts[$f] = $final_val; |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | public static function send_email( $atts ) { |
303 | - $admin_email = get_option('admin_email'); |
|
303 | + $admin_email = get_option( 'admin_email' ); |
|
304 | 304 | $defaults = array( |
305 | 305 | 'to_email' => $admin_email, |
306 | 306 | 'subject' => '', |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | 'reply_to' => $admin_email, |
314 | 314 | 'attachments' => array(), |
315 | 315 | ); |
316 | - $atts = wp_parse_args($atts, $defaults); |
|
316 | + $atts = wp_parse_args( $atts, $defaults ); |
|
317 | 317 | |
318 | 318 | // Put To, BCC, CC, Reply To, and From fields in the correct format |
319 | 319 | self::format_email_fields( $atts, $admin_email ); |
@@ -326,68 +326,68 @@ discard block |
||
326 | 326 | $array_fields = array( 'CC' => $atts['cc'], 'BCC' => $atts['bcc'] ); |
327 | 327 | $cc = array( 'CC' => array(), 'BCC' => array() ); |
328 | 328 | foreach ( $array_fields as $key => $a_field ) { |
329 | - if ( empty($a_field) ) { |
|
329 | + if ( empty( $a_field ) ) { |
|
330 | 330 | continue; |
331 | 331 | } |
332 | 332 | |
333 | 333 | foreach ( (array) $a_field as $email ) { |
334 | - $cc[ $key ][] = $email; |
|
334 | + $cc[$key][] = $email; |
|
335 | 335 | } |
336 | - unset($key, $a_field); |
|
336 | + unset( $key, $a_field ); |
|
337 | 337 | } |
338 | 338 | $cc = array_filter( $cc ); // remove cc and bcc if they are empty |
339 | 339 | |
340 | 340 | foreach ( $cc as $k => $v ) { |
341 | - $header[] = $k . ': '. implode( ',', $v ); |
|
341 | + $header[] = $k . ': ' . implode( ',', $v ); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | $content_type = $atts['plain_text'] ? 'text/plain' : 'text/html'; |
345 | - $charset = get_option('blog_charset'); |
|
345 | + $charset = get_option( 'blog_charset' ); |
|
346 | 346 | |
347 | - $header[] = 'Reply-To: '. $atts['reply_to']; |
|
348 | - $header[] = 'Content-Type: ' . $content_type . '; charset="' . esc_attr( $charset ) . '"'; |
|
349 | - $atts['subject'] = wp_specialchars_decode(strip_tags(stripslashes($atts['subject'])), ENT_QUOTES ); |
|
347 | + $header[] = 'Reply-To: ' . $atts['reply_to']; |
|
348 | + $header[] = 'Content-Type: ' . $content_type . '; charset="' . esc_attr( $charset ) . '"'; |
|
349 | + $atts['subject'] = wp_specialchars_decode( strip_tags( stripslashes( $atts['subject'] ) ), ENT_QUOTES ); |
|
350 | 350 | |
351 | - $message = do_shortcode($atts['message']); |
|
351 | + $message = do_shortcode( $atts['message'] ); |
|
352 | 352 | |
353 | 353 | if ( $atts['plain_text'] ) { |
354 | 354 | //$message = wordwrap($message, 70, "\r\n"); //in case any lines are longer than 70 chars |
355 | - $message = wp_specialchars_decode(strip_tags($message), ENT_QUOTES ); |
|
355 | + $message = wp_specialchars_decode( strip_tags( $message ), ENT_QUOTES ); |
|
356 | 356 | } else { |
357 | 357 | // remove line breaks in HTML emails to prevent conflicts with Mandrill |
358 | 358 | add_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' ); |
359 | 359 | } |
360 | 360 | $message = apply_filters( 'frm_email_message', $message, $atts ); |
361 | 361 | |
362 | - $header = apply_filters('frm_email_header', $header, array( |
|
362 | + $header = apply_filters( 'frm_email_header', $header, array( |
|
363 | 363 | 'to_email' => $atts['to_email'], 'subject' => $atts['subject'], |
364 | 364 | ) ); |
365 | 365 | |
366 | - if ( apply_filters('frm_encode_subject', 1, $atts['subject'] ) ) { |
|
367 | - $atts['subject'] = '=?'. $charset .'?B?'. base64_encode($atts['subject']) .'?='; |
|
366 | + if ( apply_filters( 'frm_encode_subject', 1, $atts['subject'] ) ) { |
|
367 | + $atts['subject'] = '=?' . $charset . '?B?' . base64_encode( $atts['subject'] ) . '?='; |
|
368 | 368 | } |
369 | 369 | |
370 | - remove_filter('wp_mail_from', 'bp_core_email_from_address_filter' ); |
|
371 | - remove_filter('wp_mail_from_name', 'bp_core_email_from_name_filter'); |
|
370 | + remove_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' ); |
|
371 | + remove_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' ); |
|
372 | 372 | |
373 | - $sent = wp_mail($recipient, $atts['subject'], $message, $header, $atts['attachments']); |
|
373 | + $sent = wp_mail( $recipient, $atts['subject'], $message, $header, $atts['attachments'] ); |
|
374 | 374 | if ( ! $sent ) { |
375 | - $header = 'From: '. $atts['from'] ."\r\n"; |
|
376 | - $recipient = implode(',', (array) $recipient); |
|
377 | - $sent = mail($recipient, $atts['subject'], $message, $header); |
|
375 | + $header = 'From: ' . $atts['from'] . "\r\n"; |
|
376 | + $recipient = implode( ',', (array) $recipient ); |
|
377 | + $sent = mail( $recipient, $atts['subject'], $message, $header ); |
|
378 | 378 | } |
379 | 379 | |
380 | 380 | // remove the filter now so other emails can still use it |
381 | 381 | remove_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' ); |
382 | 382 | |
383 | - do_action('frm_notification', $recipient, $atts['subject'], $message); |
|
383 | + do_action( 'frm_notification', $recipient, $atts['subject'], $message ); |
|
384 | 384 | |
385 | 385 | if ( $sent ) { |
386 | 386 | $sent_to = array_merge( (array) $atts['to_email'], (array) $atts['cc'], (array) $atts['bcc'] ); |
387 | 387 | $sent_to = array_filter( $sent_to ); |
388 | - if ( apply_filters('frm_echo_emails', false) ) { |
|
389 | - $temp = str_replace('<', '<', $sent_to); |
|
390 | - echo ' ' . FrmAppHelper::kses( implode(', ', (array) $temp ) ); |
|
388 | + if ( apply_filters( 'frm_echo_emails', false ) ) { |
|
389 | + $temp = str_replace( '<', '<', $sent_to ); |
|
390 | + echo ' ' . FrmAppHelper::kses( implode( ', ', (array) $temp ) ); |
|
391 | 391 | } |
392 | 392 | return $sent_to; |
393 | 393 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class FrmSettings{ |
|
3 | +class FrmSettings { |
|
4 | 4 | public $option_name = 'frm_options'; |
5 | 5 | public $menu; |
6 | 6 | public $mu_menu; |
@@ -28,19 +28,19 @@ discard block |
||
28 | 28 | public $re_msg; |
29 | 29 | |
30 | 30 | public function __construct() { |
31 | - if ( ! defined('ABSPATH') ) { |
|
32 | - die('You are not allowed to call this page directly.'); |
|
31 | + if ( ! defined( 'ABSPATH' ) ) { |
|
32 | + die( 'You are not allowed to call this page directly.' ); |
|
33 | 33 | } |
34 | 34 | |
35 | - $settings = get_transient($this->option_name); |
|
35 | + $settings = get_transient( $this->option_name ); |
|
36 | 36 | |
37 | - if ( ! is_object($settings) ) { |
|
38 | - $settings = $this->translate_settings($settings); |
|
37 | + if ( ! is_object( $settings ) ) { |
|
38 | + $settings = $this->translate_settings( $settings ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | foreach ( $settings as $setting_name => $setting ) { |
42 | 42 | $this->{$setting_name} = $setting; |
43 | - unset($setting_name, $setting); |
|
43 | + unset( $setting_name, $setting ); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | $this->set_default_options(); |
@@ -48,24 +48,24 @@ discard block |
||
48 | 48 | |
49 | 49 | private function translate_settings( $settings ) { |
50 | 50 | if ( $settings ) { //workaround for W3 total cache conflict |
51 | - return unserialize(serialize($settings)); |
|
51 | + return unserialize( serialize( $settings ) ); |
|
52 | 52 | } |
53 | 53 | |
54 | - $settings = get_option($this->option_name); |
|
55 | - if ( is_object($settings) ) { |
|
56 | - set_transient($this->option_name, $settings); |
|
54 | + $settings = get_option( $this->option_name ); |
|
55 | + if ( is_object( $settings ) ) { |
|
56 | + set_transient( $this->option_name, $settings ); |
|
57 | 57 | return $settings; |
58 | 58 | } |
59 | 59 | |
60 | 60 | // If unserializing didn't work |
61 | 61 | if ( $settings ) { //workaround for W3 total cache conflict |
62 | - $settings = unserialize(serialize($settings)); |
|
62 | + $settings = unserialize( serialize( $settings ) ); |
|
63 | 63 | } else { |
64 | 64 | $settings = $this; |
65 | 65 | } |
66 | 66 | |
67 | - update_option($this->option_name, $settings); |
|
68 | - set_transient($this->option_name, $settings); |
|
67 | + update_option( $this->option_name, $settings ); |
|
68 | + set_transient( $this->option_name, $settings ); |
|
69 | 69 | |
70 | 70 | return $settings; |
71 | 71 | } |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | private function set_default_options() { |
99 | 99 | $this->fill_recaptcha_settings(); |
100 | 100 | |
101 | - if ( ! isset($this->load_style) ) { |
|
102 | - if ( ! isset($this->custom_style) ) { |
|
101 | + if ( ! isset( $this->load_style ) ) { |
|
102 | + if ( ! isset( $this->custom_style ) ) { |
|
103 | 103 | $this->custom_style = true; |
104 | 104 | } |
105 | 105 | |
@@ -109,16 +109,16 @@ discard block |
||
109 | 109 | $this->fill_with_defaults(); |
110 | 110 | |
111 | 111 | if ( is_multisite() && is_admin() ) { |
112 | - $mu_menu = get_site_option('frm_admin_menu_name'); |
|
113 | - if ( $mu_menu && ! empty($mu_menu) ) { |
|
112 | + $mu_menu = get_site_option( 'frm_admin_menu_name' ); |
|
113 | + if ( $mu_menu && ! empty( $mu_menu ) ) { |
|
114 | 114 | $this->menu = $mu_menu; |
115 | 115 | $this->mu_menu = 1; |
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
119 | - $frm_roles = FrmAppHelper::frm_capabilities('pro'); |
|
119 | + $frm_roles = FrmAppHelper::frm_capabilities( 'pro' ); |
|
120 | 120 | foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
121 | - if ( ! isset($this->$frm_role) ) { |
|
121 | + if ( ! isset( $this->$frm_role ) ) { |
|
122 | 122 | $this->$frm_role = 'administrator'; |
123 | 123 | } |
124 | 124 | } |
@@ -128,12 +128,12 @@ discard block |
||
128 | 128 | $settings = $this->default_options(); |
129 | 129 | |
130 | 130 | foreach ( $settings as $setting => $default ) { |
131 | - if ( isset( $params[ 'frm_' . $setting ] ) ) { |
|
132 | - $this->{$setting} = $params[ 'frm_' . $setting ]; |
|
133 | - } else if ( ! isset($this->{$setting}) ) { |
|
131 | + if ( isset( $params['frm_' . $setting] ) ) { |
|
132 | + $this->{$setting} = $params['frm_' . $setting]; |
|
133 | + } else if ( ! isset( $this->{$setting}) ) { |
|
134 | 134 | $this->{$setting} = $default; |
135 | 135 | } |
136 | - unset($setting, $default); |
|
136 | + unset( $setting, $default ); |
|
137 | 137 | } |
138 | 138 | } |
139 | 139 | |
@@ -141,23 +141,23 @@ discard block |
||
141 | 141 | $privkey = ''; |
142 | 142 | $re_lang = 'en'; |
143 | 143 | |
144 | - if ( ! isset($this->pubkey) ) { |
|
144 | + if ( ! isset( $this->pubkey ) ) { |
|
145 | 145 | // get the options from the database |
146 | - $recaptcha_opt = is_multisite() ? get_site_option('recaptcha') : get_option('recaptcha'); |
|
147 | - $this->pubkey = isset($recaptcha_opt['pubkey']) ? $recaptcha_opt['pubkey'] : ''; |
|
148 | - $privkey = isset($recaptcha_opt['privkey']) ? $recaptcha_opt['privkey'] : $privkey; |
|
149 | - $re_lang = isset($recaptcha_opt['re_lang']) ? $recaptcha_opt['re_lang'] : $re_lang; |
|
146 | + $recaptcha_opt = is_multisite() ? get_site_option( 'recaptcha' ) : get_option( 'recaptcha' ); |
|
147 | + $this->pubkey = isset( $recaptcha_opt['pubkey'] ) ? $recaptcha_opt['pubkey'] : ''; |
|
148 | + $privkey = isset( $recaptcha_opt['privkey'] ) ? $recaptcha_opt['privkey'] : $privkey; |
|
149 | + $re_lang = isset( $recaptcha_opt['re_lang'] ) ? $recaptcha_opt['re_lang'] : $re_lang; |
|
150 | 150 | } |
151 | 151 | |
152 | - if ( ! isset($this->re_msg) || empty($this->re_msg) ) { |
|
152 | + if ( ! isset( $this->re_msg ) || empty( $this->re_msg ) ) { |
|
153 | 153 | $this->re_msg = __( 'The reCAPTCHA was not entered correctly', 'formidable' ); |
154 | 154 | } |
155 | 155 | |
156 | - if ( ! isset($this->privkey) ) { |
|
156 | + if ( ! isset( $this->privkey ) ) { |
|
157 | 157 | $this->privkey = $privkey; |
158 | 158 | } |
159 | 159 | |
160 | - if ( ! isset($this->re_lang) ) { |
|
160 | + if ( ! isset( $this->re_lang ) ) { |
|
161 | 161 | $this->re_lang = $re_lang; |
162 | 162 | } |
163 | 163 | } |
@@ -168,31 +168,31 @@ discard block |
||
168 | 168 | } |
169 | 169 | |
170 | 170 | public function update( $params ) { |
171 | - $this->fill_with_defaults($params); |
|
172 | - $this->update_settings($params); |
|
171 | + $this->fill_with_defaults( $params ); |
|
172 | + $this->update_settings( $params ); |
|
173 | 173 | |
174 | 174 | if ( $this->mu_menu ) { |
175 | - update_site_option('frm_admin_menu_name', $this->menu); |
|
176 | - } else if ( current_user_can('administrator') ) { |
|
177 | - update_site_option('frm_admin_menu_name', false); |
|
175 | + update_site_option( 'frm_admin_menu_name', $this->menu ); |
|
176 | + } else if ( current_user_can( 'administrator' ) ) { |
|
177 | + update_site_option( 'frm_admin_menu_name', false ); |
|
178 | 178 | } |
179 | 179 | |
180 | - $this->update_roles($params); |
|
180 | + $this->update_roles( $params ); |
|
181 | 181 | |
182 | 182 | do_action( 'frm_update_settings', $params ); |
183 | 183 | } |
184 | 184 | |
185 | 185 | private function update_settings( $params ) { |
186 | - $this->mu_menu = isset($params['frm_mu_menu']) ? $params['frm_mu_menu'] : 0; |
|
186 | + $this->mu_menu = isset( $params['frm_mu_menu'] ) ? $params['frm_mu_menu'] : 0; |
|
187 | 187 | |
188 | - $this->pubkey = trim($params['frm_pubkey']); |
|
188 | + $this->pubkey = trim( $params['frm_pubkey'] ); |
|
189 | 189 | $this->privkey = $params['frm_privkey']; |
190 | 190 | $this->re_lang = $params['frm_re_lang']; |
191 | 191 | |
192 | 192 | $this->load_style = $params['frm_load_style']; |
193 | 193 | $this->preview_page_id = (int) $params['frm-preview-page-id']; |
194 | 194 | |
195 | - $this->use_html = isset($params['frm_use_html']) ? $params['frm_use_html'] : 0; |
|
195 | + $this->use_html = isset( $params['frm_use_html'] ) ? $params['frm_use_html'] : 0; |
|
196 | 196 | //$this->custom_style = isset($params['frm_custom_style']) ? $params['frm_custom_style'] : 0; |
197 | 197 | $this->jquery_css = isset( $params['frm_jquery_css'] ) ? absint( $params['frm_jquery_css'] ) : 0; |
198 | 198 | $this->accordion_js = isset( $params['frm_accordion_js'] ) ? absint( $params['frm_accordion_js'] ) : 0; |
@@ -205,30 +205,30 @@ discard block |
||
205 | 205 | $frm_roles = FrmAppHelper::frm_capabilities(); |
206 | 206 | $roles = get_editable_roles(); |
207 | 207 | foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
208 | - $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' ); |
|
208 | + $this->$frm_role = (array) ( isset( $params[$frm_role] ) ? $params[$frm_role] : 'administrator' ); |
|
209 | 209 | |
210 | - if ( count($this->$frm_role) === 1 ) { |
|
211 | - $set_role = reset($this->$frm_role); |
|
210 | + if ( count( $this->$frm_role ) === 1 ) { |
|
211 | + $set_role = reset( $this->$frm_role ); |
|
212 | 212 | switch ( $set_role ) { |
213 | 213 | case 'subscriber': |
214 | - array_push($this->$frm_role, 'contributor'); |
|
214 | + array_push( $this->$frm_role, 'contributor' ); |
|
215 | 215 | case 'contributor': |
216 | - array_push($this->$frm_role, 'author'); |
|
216 | + array_push( $this->$frm_role, 'author' ); |
|
217 | 217 | case 'author': |
218 | - array_push($this->$frm_role, 'editor'); |
|
218 | + array_push( $this->$frm_role, 'editor' ); |
|
219 | 219 | case 'editor': |
220 | - array_push($this->$frm_role, 'administrator'); |
|
220 | + array_push( $this->$frm_role, 'administrator' ); |
|
221 | 221 | } |
222 | - unset($set_role); |
|
222 | + unset( $set_role ); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | foreach ( $roles as $role => $details ) { |
226 | - if ( in_array($role, $this->$frm_role) ) { |
|
226 | + if ( in_array( $role, $this->$frm_role ) ) { |
|
227 | 227 | $wp_roles->add_cap( $role, $frm_role ); |
228 | 228 | } else { |
229 | 229 | $wp_roles->remove_cap( $role, $frm_role ); |
230 | 230 | } |
231 | - unset($role, $details); |
|
231 | + unset( $role, $details ); |
|
232 | 232 | } |
233 | 233 | } |
234 | 234 | } |
@@ -236,10 +236,10 @@ discard block |
||
236 | 236 | public function store() { |
237 | 237 | // Save the posted value in the database |
238 | 238 | |
239 | - update_option('frm_options', $this); |
|
239 | + update_option( 'frm_options', $this ); |
|
240 | 240 | |
241 | - delete_transient('frm_options'); |
|
242 | - set_transient('frm_options', $this); |
|
241 | + delete_transient( 'frm_options' ); |
|
242 | + set_transient( 'frm_options', $this ); |
|
243 | 243 | |
244 | 244 | do_action( 'frm_store_settings' ); |
245 | 245 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class FrmSettings{ |
|
3 | +class FrmSettings { |
|
4 | 4 | public $option_name = 'frm_options'; |
5 | 5 | public $menu; |
6 | 6 | public $mu_menu; |
@@ -47,7 +47,8 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | private function translate_settings( $settings ) { |
50 | - if ( $settings ) { //workaround for W3 total cache conflict |
|
50 | + if ( $settings ) { |
|
51 | +//workaround for W3 total cache conflict |
|
51 | 52 | return unserialize(serialize($settings)); |
52 | 53 | } |
53 | 54 | |
@@ -58,7 +59,8 @@ discard block |
||
58 | 59 | } |
59 | 60 | |
60 | 61 | // If unserializing didn't work |
61 | - if ( $settings ) { //workaround for W3 total cache conflict |
|
62 | + if ( $settings ) { |
|
63 | +//workaround for W3 total cache conflict |
|
62 | 64 | $settings = unserialize(serialize($settings)); |
63 | 65 | } else { |
64 | 66 | $settings = $this; |
@@ -1,251 +1,251 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | class FrmSettings{ |
4 | - public $option_name = 'frm_options'; |
|
5 | - public $menu; |
|
6 | - public $mu_menu; |
|
7 | - public $preview_page_id; |
|
8 | - public $use_html; |
|
9 | - public $jquery_css; |
|
10 | - public $accordion_js; |
|
11 | - |
|
12 | - public $success_msg; |
|
13 | - public $blank_msg; |
|
14 | - public $unique_msg; |
|
15 | - public $invalid_msg; |
|
16 | - public $failed_msg; |
|
17 | - public $submit_value; |
|
18 | - public $login_msg; |
|
19 | - public $admin_permission; |
|
20 | - |
|
21 | - public $email_to; |
|
22 | - public $load_style; |
|
23 | - public $custom_style; |
|
24 | - |
|
25 | - public $pubkey; |
|
26 | - public $privkey; |
|
27 | - public $re_lang; |
|
28 | - public $re_msg; |
|
29 | - |
|
30 | - public function __construct() { |
|
31 | - if ( ! defined('ABSPATH') ) { |
|
32 | - die('You are not allowed to call this page directly.'); |
|
33 | - } |
|
34 | - |
|
35 | - $settings = get_transient($this->option_name); |
|
36 | - |
|
37 | - if ( ! is_object($settings) ) { |
|
38 | - $settings = $this->translate_settings($settings); |
|
39 | - } |
|
40 | - |
|
41 | - foreach ( $settings as $setting_name => $setting ) { |
|
42 | - $this->{$setting_name} = $setting; |
|
43 | - unset($setting_name, $setting); |
|
44 | - } |
|
45 | - |
|
46 | - $this->set_default_options(); |
|
47 | - } |
|
4 | + public $option_name = 'frm_options'; |
|
5 | + public $menu; |
|
6 | + public $mu_menu; |
|
7 | + public $preview_page_id; |
|
8 | + public $use_html; |
|
9 | + public $jquery_css; |
|
10 | + public $accordion_js; |
|
11 | + |
|
12 | + public $success_msg; |
|
13 | + public $blank_msg; |
|
14 | + public $unique_msg; |
|
15 | + public $invalid_msg; |
|
16 | + public $failed_msg; |
|
17 | + public $submit_value; |
|
18 | + public $login_msg; |
|
19 | + public $admin_permission; |
|
20 | + |
|
21 | + public $email_to; |
|
22 | + public $load_style; |
|
23 | + public $custom_style; |
|
24 | + |
|
25 | + public $pubkey; |
|
26 | + public $privkey; |
|
27 | + public $re_lang; |
|
28 | + public $re_msg; |
|
29 | + |
|
30 | + public function __construct() { |
|
31 | + if ( ! defined('ABSPATH') ) { |
|
32 | + die('You are not allowed to call this page directly.'); |
|
33 | + } |
|
34 | + |
|
35 | + $settings = get_transient($this->option_name); |
|
36 | + |
|
37 | + if ( ! is_object($settings) ) { |
|
38 | + $settings = $this->translate_settings($settings); |
|
39 | + } |
|
40 | + |
|
41 | + foreach ( $settings as $setting_name => $setting ) { |
|
42 | + $this->{$setting_name} = $setting; |
|
43 | + unset($setting_name, $setting); |
|
44 | + } |
|
45 | + |
|
46 | + $this->set_default_options(); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | private function translate_settings( $settings ) { |
50 | - if ( $settings ) { //workaround for W3 total cache conflict |
|
51 | - return unserialize(serialize($settings)); |
|
52 | - } |
|
53 | - |
|
54 | - $settings = get_option($this->option_name); |
|
55 | - if ( is_object($settings) ) { |
|
56 | - set_transient($this->option_name, $settings); |
|
57 | - return $settings; |
|
58 | - } |
|
59 | - |
|
60 | - // If unserializing didn't work |
|
61 | - if ( $settings ) { //workaround for W3 total cache conflict |
|
62 | - $settings = unserialize(serialize($settings)); |
|
63 | - } else { |
|
64 | - $settings = $this; |
|
65 | - } |
|
66 | - |
|
67 | - update_option($this->option_name, $settings); |
|
68 | - set_transient($this->option_name, $settings); |
|
69 | - |
|
70 | - return $settings; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @return array |
|
75 | - */ |
|
50 | + if ( $settings ) { //workaround for W3 total cache conflict |
|
51 | + return unserialize(serialize($settings)); |
|
52 | + } |
|
53 | + |
|
54 | + $settings = get_option($this->option_name); |
|
55 | + if ( is_object($settings) ) { |
|
56 | + set_transient($this->option_name, $settings); |
|
57 | + return $settings; |
|
58 | + } |
|
59 | + |
|
60 | + // If unserializing didn't work |
|
61 | + if ( $settings ) { //workaround for W3 total cache conflict |
|
62 | + $settings = unserialize(serialize($settings)); |
|
63 | + } else { |
|
64 | + $settings = $this; |
|
65 | + } |
|
66 | + |
|
67 | + update_option($this->option_name, $settings); |
|
68 | + set_transient($this->option_name, $settings); |
|
69 | + |
|
70 | + return $settings; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @return array |
|
75 | + */ |
|
76 | 76 | public function default_options() { |
77 | - return array( |
|
78 | - 'menu' => apply_filters( 'frm_default_menu', __( 'Forms', 'formidable' ) ), |
|
79 | - 'mu_menu' => 0, |
|
80 | - 'preview_page_id' => 0, |
|
81 | - 'use_html' => true, |
|
82 | - 'jquery_css' => false, |
|
83 | - 'accordion_js' => false, |
|
84 | - |
|
85 | - 'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ), |
|
86 | - 'blank_msg' => __( 'This field cannot be blank.', 'formidable' ), |
|
87 | - 'unique_msg' => __( 'This value must be unique.', 'formidable' ), |
|
88 | - 'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ), |
|
89 | - 'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ), |
|
90 | - 'submit_value' => __( 'Submit', 'formidable' ), |
|
91 | - 'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ), |
|
92 | - 'admin_permission' => __( 'You do not have permission to do that', 'formidable' ), |
|
93 | - |
|
94 | - 'email_to' => '[admin_email]', |
|
95 | - ); |
|
96 | - } |
|
77 | + return array( |
|
78 | + 'menu' => apply_filters( 'frm_default_menu', __( 'Forms', 'formidable' ) ), |
|
79 | + 'mu_menu' => 0, |
|
80 | + 'preview_page_id' => 0, |
|
81 | + 'use_html' => true, |
|
82 | + 'jquery_css' => false, |
|
83 | + 'accordion_js' => false, |
|
84 | + |
|
85 | + 'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ), |
|
86 | + 'blank_msg' => __( 'This field cannot be blank.', 'formidable' ), |
|
87 | + 'unique_msg' => __( 'This value must be unique.', 'formidable' ), |
|
88 | + 'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ), |
|
89 | + 'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ), |
|
90 | + 'submit_value' => __( 'Submit', 'formidable' ), |
|
91 | + 'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ), |
|
92 | + 'admin_permission' => __( 'You do not have permission to do that', 'formidable' ), |
|
93 | + |
|
94 | + 'email_to' => '[admin_email]', |
|
95 | + ); |
|
96 | + } |
|
97 | 97 | |
98 | 98 | private function set_default_options() { |
99 | - $this->fill_recaptcha_settings(); |
|
100 | - |
|
101 | - if ( ! isset($this->load_style) ) { |
|
102 | - if ( ! isset($this->custom_style) ) { |
|
103 | - $this->custom_style = true; |
|
104 | - } |
|
105 | - |
|
106 | - $this->load_style = 'all'; |
|
107 | - } |
|
108 | - |
|
109 | - $this->fill_with_defaults(); |
|
110 | - |
|
111 | - if ( is_multisite() && is_admin() ) { |
|
112 | - $mu_menu = get_site_option('frm_admin_menu_name'); |
|
113 | - if ( $mu_menu && ! empty($mu_menu) ) { |
|
114 | - $this->menu = $mu_menu; |
|
115 | - $this->mu_menu = 1; |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - $frm_roles = FrmAppHelper::frm_capabilities('pro'); |
|
120 | - foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
121 | - if ( ! isset($this->$frm_role) ) { |
|
122 | - $this->$frm_role = 'administrator'; |
|
123 | - } |
|
124 | - } |
|
125 | - } |
|
99 | + $this->fill_recaptcha_settings(); |
|
100 | + |
|
101 | + if ( ! isset($this->load_style) ) { |
|
102 | + if ( ! isset($this->custom_style) ) { |
|
103 | + $this->custom_style = true; |
|
104 | + } |
|
105 | + |
|
106 | + $this->load_style = 'all'; |
|
107 | + } |
|
108 | + |
|
109 | + $this->fill_with_defaults(); |
|
110 | + |
|
111 | + if ( is_multisite() && is_admin() ) { |
|
112 | + $mu_menu = get_site_option('frm_admin_menu_name'); |
|
113 | + if ( $mu_menu && ! empty($mu_menu) ) { |
|
114 | + $this->menu = $mu_menu; |
|
115 | + $this->mu_menu = 1; |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + $frm_roles = FrmAppHelper::frm_capabilities('pro'); |
|
120 | + foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
121 | + if ( ! isset($this->$frm_role) ) { |
|
122 | + $this->$frm_role = 'administrator'; |
|
123 | + } |
|
124 | + } |
|
125 | + } |
|
126 | 126 | |
127 | 127 | public function fill_with_defaults( $params = array() ) { |
128 | - $settings = $this->default_options(); |
|
128 | + $settings = $this->default_options(); |
|
129 | 129 | |
130 | - foreach ( $settings as $setting => $default ) { |
|
130 | + foreach ( $settings as $setting => $default ) { |
|
131 | 131 | if ( isset( $params[ 'frm_' . $setting ] ) ) { |
132 | 132 | $this->{$setting} = $params[ 'frm_' . $setting ]; |
133 | - } else if ( ! isset($this->{$setting}) ) { |
|
134 | - $this->{$setting} = $default; |
|
135 | - } |
|
133 | + } else if ( ! isset($this->{$setting}) ) { |
|
134 | + $this->{$setting} = $default; |
|
135 | + } |
|
136 | 136 | |
137 | 137 | if ( $setting == 'menu' && empty( $this->{$setting} ) ) { |
138 | 138 | $this->{$setting} = $default; |
139 | 139 | } |
140 | 140 | |
141 | - unset($setting, $default); |
|
142 | - } |
|
143 | - } |
|
144 | - |
|
145 | - private function fill_recaptcha_settings() { |
|
146 | - $privkey = ''; |
|
147 | - $re_lang = 'en'; |
|
148 | - |
|
149 | - if ( ! isset($this->pubkey) ) { |
|
150 | - // get the options from the database |
|
151 | - $recaptcha_opt = is_multisite() ? get_site_option('recaptcha') : get_option('recaptcha'); |
|
152 | - $this->pubkey = isset($recaptcha_opt['pubkey']) ? $recaptcha_opt['pubkey'] : ''; |
|
153 | - $privkey = isset($recaptcha_opt['privkey']) ? $recaptcha_opt['privkey'] : $privkey; |
|
154 | - $re_lang = isset($recaptcha_opt['re_lang']) ? $recaptcha_opt['re_lang'] : $re_lang; |
|
155 | - } |
|
141 | + unset($setting, $default); |
|
142 | + } |
|
143 | + } |
|
144 | + |
|
145 | + private function fill_recaptcha_settings() { |
|
146 | + $privkey = ''; |
|
147 | + $re_lang = 'en'; |
|
148 | + |
|
149 | + if ( ! isset($this->pubkey) ) { |
|
150 | + // get the options from the database |
|
151 | + $recaptcha_opt = is_multisite() ? get_site_option('recaptcha') : get_option('recaptcha'); |
|
152 | + $this->pubkey = isset($recaptcha_opt['pubkey']) ? $recaptcha_opt['pubkey'] : ''; |
|
153 | + $privkey = isset($recaptcha_opt['privkey']) ? $recaptcha_opt['privkey'] : $privkey; |
|
154 | + $re_lang = isset($recaptcha_opt['re_lang']) ? $recaptcha_opt['re_lang'] : $re_lang; |
|
155 | + } |
|
156 | 156 | |
157 | - if ( ! isset($this->re_msg) || empty($this->re_msg) ) { |
|
158 | - $this->re_msg = __( 'The reCAPTCHA was not entered correctly', 'formidable' ); |
|
159 | - } |
|
157 | + if ( ! isset($this->re_msg) || empty($this->re_msg) ) { |
|
158 | + $this->re_msg = __( 'The reCAPTCHA was not entered correctly', 'formidable' ); |
|
159 | + } |
|
160 | 160 | |
161 | - if ( ! isset($this->privkey) ) { |
|
162 | - $this->privkey = $privkey; |
|
163 | - } |
|
161 | + if ( ! isset($this->privkey) ) { |
|
162 | + $this->privkey = $privkey; |
|
163 | + } |
|
164 | 164 | |
165 | - if ( ! isset($this->re_lang) ) { |
|
166 | - $this->re_lang = $re_lang; |
|
167 | - } |
|
168 | - } |
|
165 | + if ( ! isset($this->re_lang) ) { |
|
166 | + $this->re_lang = $re_lang; |
|
167 | + } |
|
168 | + } |
|
169 | 169 | |
170 | - public function validate( $params, $errors ) { |
|
171 | - $errors = apply_filters( 'frm_validate_settings', $errors, $params ); |
|
172 | - return $errors; |
|
173 | - } |
|
170 | + public function validate( $params, $errors ) { |
|
171 | + $errors = apply_filters( 'frm_validate_settings', $errors, $params ); |
|
172 | + return $errors; |
|
173 | + } |
|
174 | 174 | |
175 | 175 | public function update( $params ) { |
176 | - $this->fill_with_defaults($params); |
|
177 | - $this->update_settings($params); |
|
176 | + $this->fill_with_defaults($params); |
|
177 | + $this->update_settings($params); |
|
178 | 178 | |
179 | - if ( $this->mu_menu ) { |
|
180 | - update_site_option('frm_admin_menu_name', $this->menu); |
|
181 | - } else if ( current_user_can('administrator') ) { |
|
182 | - update_site_option('frm_admin_menu_name', false); |
|
183 | - } |
|
179 | + if ( $this->mu_menu ) { |
|
180 | + update_site_option('frm_admin_menu_name', $this->menu); |
|
181 | + } else if ( current_user_can('administrator') ) { |
|
182 | + update_site_option('frm_admin_menu_name', false); |
|
183 | + } |
|
184 | 184 | |
185 | - $this->update_roles($params); |
|
185 | + $this->update_roles($params); |
|
186 | 186 | |
187 | - do_action( 'frm_update_settings', $params ); |
|
188 | - } |
|
187 | + do_action( 'frm_update_settings', $params ); |
|
188 | + } |
|
189 | 189 | |
190 | 190 | private function update_settings( $params ) { |
191 | - $this->mu_menu = isset($params['frm_mu_menu']) ? $params['frm_mu_menu'] : 0; |
|
191 | + $this->mu_menu = isset($params['frm_mu_menu']) ? $params['frm_mu_menu'] : 0; |
|
192 | 192 | |
193 | - $this->pubkey = trim($params['frm_pubkey']); |
|
194 | - $this->privkey = $params['frm_privkey']; |
|
195 | - $this->re_lang = $params['frm_re_lang']; |
|
193 | + $this->pubkey = trim($params['frm_pubkey']); |
|
194 | + $this->privkey = $params['frm_privkey']; |
|
195 | + $this->re_lang = $params['frm_re_lang']; |
|
196 | 196 | |
197 | - $this->load_style = $params['frm_load_style']; |
|
198 | - $this->preview_page_id = (int) $params['frm-preview-page-id']; |
|
197 | + $this->load_style = $params['frm_load_style']; |
|
198 | + $this->preview_page_id = (int) $params['frm-preview-page-id']; |
|
199 | 199 | |
200 | - $this->use_html = isset($params['frm_use_html']) ? $params['frm_use_html'] : 0; |
|
201 | - //$this->custom_style = isset($params['frm_custom_style']) ? $params['frm_custom_style'] : 0; |
|
200 | + $this->use_html = isset($params['frm_use_html']) ? $params['frm_use_html'] : 0; |
|
201 | + //$this->custom_style = isset($params['frm_custom_style']) ? $params['frm_custom_style'] : 0; |
|
202 | 202 | $this->jquery_css = isset( $params['frm_jquery_css'] ) ? absint( $params['frm_jquery_css'] ) : 0; |
203 | 203 | $this->accordion_js = isset( $params['frm_accordion_js'] ) ? absint( $params['frm_accordion_js'] ) : 0; |
204 | - } |
|
204 | + } |
|
205 | 205 | |
206 | 206 | private function update_roles( $params ) { |
207 | - //update roles |
|
208 | - global $wp_roles; |
|
209 | - |
|
210 | - $frm_roles = FrmAppHelper::frm_capabilities(); |
|
211 | - $roles = get_editable_roles(); |
|
212 | - foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
213 | - $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' ); |
|
214 | - |
|
215 | - if ( count($this->$frm_role) === 1 ) { |
|
216 | - $set_role = reset($this->$frm_role); |
|
217 | - switch ( $set_role ) { |
|
218 | - case 'subscriber': |
|
219 | - array_push($this->$frm_role, 'contributor'); |
|
220 | - case 'contributor': |
|
221 | - array_push($this->$frm_role, 'author'); |
|
222 | - case 'author': |
|
223 | - array_push($this->$frm_role, 'editor'); |
|
224 | - case 'editor': |
|
225 | - array_push($this->$frm_role, 'administrator'); |
|
226 | - } |
|
227 | - unset($set_role); |
|
228 | - } |
|
229 | - |
|
230 | - foreach ( $roles as $role => $details ) { |
|
231 | - if ( in_array($role, $this->$frm_role) ) { |
|
232 | - $wp_roles->add_cap( $role, $frm_role ); |
|
233 | - } else { |
|
234 | - $wp_roles->remove_cap( $role, $frm_role ); |
|
235 | - } |
|
236 | - unset($role, $details); |
|
237 | - } |
|
238 | - } |
|
239 | - } |
|
207 | + //update roles |
|
208 | + global $wp_roles; |
|
209 | + |
|
210 | + $frm_roles = FrmAppHelper::frm_capabilities(); |
|
211 | + $roles = get_editable_roles(); |
|
212 | + foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
213 | + $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' ); |
|
214 | + |
|
215 | + if ( count($this->$frm_role) === 1 ) { |
|
216 | + $set_role = reset($this->$frm_role); |
|
217 | + switch ( $set_role ) { |
|
218 | + case 'subscriber': |
|
219 | + array_push($this->$frm_role, 'contributor'); |
|
220 | + case 'contributor': |
|
221 | + array_push($this->$frm_role, 'author'); |
|
222 | + case 'author': |
|
223 | + array_push($this->$frm_role, 'editor'); |
|
224 | + case 'editor': |
|
225 | + array_push($this->$frm_role, 'administrator'); |
|
226 | + } |
|
227 | + unset($set_role); |
|
228 | + } |
|
229 | + |
|
230 | + foreach ( $roles as $role => $details ) { |
|
231 | + if ( in_array($role, $this->$frm_role) ) { |
|
232 | + $wp_roles->add_cap( $role, $frm_role ); |
|
233 | + } else { |
|
234 | + $wp_roles->remove_cap( $role, $frm_role ); |
|
235 | + } |
|
236 | + unset($role, $details); |
|
237 | + } |
|
238 | + } |
|
239 | + } |
|
240 | 240 | |
241 | 241 | public function store() { |
242 | - // Save the posted value in the database |
|
242 | + // Save the posted value in the database |
|
243 | 243 | |
244 | - update_option('frm_options', $this); |
|
244 | + update_option('frm_options', $this); |
|
245 | 245 | |
246 | - delete_transient('frm_options'); |
|
247 | - set_transient('frm_options', $this); |
|
246 | + delete_transient('frm_options'); |
|
247 | + set_transient('frm_options', $this); |
|
248 | 248 | |
249 | - do_action( 'frm_store_settings' ); |
|
250 | - } |
|
249 | + do_action( 'frm_store_settings' ); |
|
250 | + } |
|
251 | 251 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | <?php |
5 | 5 | |
6 | 6 | foreach ( $plugins as $slug => $plugin ) { |
7 | - $license = get_option( 'edd_'. $slug .'_license_key' ); |
|
8 | - $status = get_option( 'edd_'. $slug .'_license_active' ); |
|
7 | + $license = get_option( 'edd_' . $slug . '_license_key' ); |
|
8 | + $status = get_option( 'edd_' . $slug . '_license_active' ); |
|
9 | 9 | $activate = ( false !== $license && $status == 'valid' ) ? 'deactivate' : 'activate'; |
10 | 10 | $icon_class = ( empty( $license ) ) ? 'frm_hidden' : ''; |
11 | 11 | ?> |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <?php |
2 | 2 | if ( ! isset( $entry) ) { |
3 | - $entry = $record; |
|
3 | + $entry = $record; |
|
4 | 4 | } ?> |
5 | 5 | |
6 | 6 | <div class="misc-pub-section curtime misc-pub-curtime"> |
7 | 7 | <span id="timestamp"> |
8 | 8 | <?php |
9 | - $date_format = __( 'M j, Y @ G:i' ); |
|
9 | + $date_format = __( 'M j, Y @ G:i' ); |
|
10 | 10 | printf( __( 'Published on: <b>%1$s</b>' ), FrmAppHelper::get_localized_date( $date_format, $entry->created_at ) ); ?> |
11 | 11 | </span> |
12 | 12 | </div> |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! isset( $entry) ) { |
|
2 | +if ( ! isset( $entry ) ) { |
|
3 | 3 | $entry = $record; |
4 | 4 | } ?> |
5 | 5 | |
@@ -18,4 +18,4 @@ discard block |
||
18 | 18 | </div> |
19 | 19 | <?php } ?> |
20 | 20 | |
21 | -<?php do_action('frm_entry_shared_sidebar', $entry); ?> |
|
21 | +<?php do_action( 'frm_entry_shared_sidebar', $entry ); ?> |
@@ -4,30 +4,30 @@ |
||
4 | 4 | <?php |
5 | 5 | } |
6 | 6 | if ( isset( $message ) && $message != '' ) { |
7 | - if ( FrmAppHelper::is_admin() ) { |
|
7 | + if ( FrmAppHelper::is_admin() ) { |
|
8 | 8 | ?><div id="message" class="frm_message updated frm_msg_padding"><?php echo wp_kses_post( $message ) ?></div><?php |
9 | 9 | } else { |
10 | - FrmFormsHelper::get_scroll_js($form->id); |
|
10 | + FrmFormsHelper::get_scroll_js($form->id); |
|
11 | 11 | |
12 | 12 | // we need to allow scripts here for javascript in the success message |
13 | 13 | echo $message; |
14 | - } |
|
14 | + } |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | if ( isset($errors) && is_array( $errors ) && ! empty( $errors ) ) { |
18 | 18 | |
19 | 19 | if ( isset( $form ) && is_object( $form ) ) { |
20 | - FrmFormsHelper::get_scroll_js( $form->id ); |
|
20 | + FrmFormsHelper::get_scroll_js( $form->id ); |
|
21 | 21 | } ?> |
22 | 22 | <div class="frm_error_style"> |
23 | 23 | <?php |
24 | 24 | $img = ''; |
25 | 25 | if ( ! FrmAppHelper::is_admin() ) { |
26 | - $img = apply_filters('frm_error_icon', $img); |
|
27 | - if ( $img && ! empty($img) ) { |
|
28 | - ?><img src="<?php echo esc_attr( $img ) ?>" alt="" /> |
|
26 | + $img = apply_filters('frm_error_icon', $img); |
|
27 | + if ( $img && ! empty($img) ) { |
|
28 | + ?><img src="<?php echo esc_attr( $img ) ?>" alt="" /> |
|
29 | 29 | <?php |
30 | - } |
|
30 | + } |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | FrmFormsHelper::show_errors( compact( 'img', 'errors' ) ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( isset($include_extra_container) ) { ?> |
|
2 | +if ( isset( $include_extra_container ) ) { ?> |
|
3 | 3 | <div class="<?php echo esc_attr( $include_extra_container ) ?>" id="frm_form_<?php echo esc_attr( $form->id ) ?>_container"> |
4 | 4 | <?php |
5 | 5 | } |
@@ -7,14 +7,14 @@ discard block |
||
7 | 7 | if ( FrmAppHelper::is_admin() ) { |
8 | 8 | ?><div id="message" class="frm_message updated frm_msg_padding"><?php echo wp_kses_post( $message ) ?></div><?php |
9 | 9 | } else { |
10 | - FrmFormsHelper::get_scroll_js($form->id); |
|
10 | + FrmFormsHelper::get_scroll_js( $form->id ); |
|
11 | 11 | |
12 | 12 | // we need to allow scripts here for javascript in the success message |
13 | 13 | echo $message; |
14 | 14 | } |
15 | 15 | } |
16 | 16 | |
17 | -if ( isset($errors) && is_array( $errors ) && ! empty( $errors ) ) { |
|
17 | +if ( isset( $errors ) && is_array( $errors ) && ! empty( $errors ) ) { |
|
18 | 18 | |
19 | 19 | if ( isset( $form ) && is_object( $form ) ) { |
20 | 20 | FrmFormsHelper::get_scroll_js( $form->id ); |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | <?php |
24 | 24 | $img = ''; |
25 | 25 | if ( ! FrmAppHelper::is_admin() ) { |
26 | - $img = apply_filters('frm_error_icon', $img); |
|
27 | - if ( $img && ! empty($img) ) { |
|
26 | + $img = apply_filters( 'frm_error_icon', $img ); |
|
27 | + if ( $img && ! empty( $img ) ) { |
|
28 | 28 | ?><img src="<?php echo esc_attr( $img ) ?>" alt="" /> |
29 | 29 | <?php |
30 | 30 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | <?php |
38 | 38 | } |
39 | 39 | |
40 | -if ( isset($include_extra_container) ) { ?> |
|
40 | +if ( isset( $include_extra_container ) ) { ?> |
|
41 | 41 | </div> |
42 | 42 | <?php |
43 | 43 | } |