forked from felixarntz/bootstrap-for-contact-form-7
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modifications.php
executable file
·362 lines (300 loc) · 8.56 KB
/
modifications.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<?php
/**
* Utility functions
*
* @package CF7BS
* @author Felix Arntz <[email protected]>
* @since 1.0.0
*/
function cf7bs_selected( $selected, $current = true, $echo = true ) {
$result = '';
if ( $selected == $current ) {
$result = ' selected';
if ( ! wpcf7_support_html5() ) {
$result .= '="selected"';
}
}
if ( $echo ) {
echo $result;
}
return $result;
}
function cf7bs_multiple_selected( $selected, $current = true, $echo = true ) {
$result = '';
if ( is_array( $selected ) ) {
if ( in_array( $current, $selected ) ) {
$result = ' selected';
if ( ! wpcf7_support_html5() ) {
$result .= '="selected"';
}
}
}
if ( $echo ) {
echo $result;
}
return $result;
}
function cf7bs_checked( $checked, $current = true, $echo = true ) {
$result = '';
if ( $checked == $current ) {
$result = ' checked';
if ( ! wpcf7_support_html5() ) {
$result .= '="checked"';
}
}
if ( $echo ) {
echo $result;
}
return $result;
}
function cf7bs_multiple_checked( $checked, $current = true, $echo = true ) {
$result = '';
if ( is_array( $checked ) ) {
if ( in_array( $current, $checked ) ) {
$result = ' checked';
if ( ! wpcf7_support_html5() ) {
$result .= '="checked"';
}
}
}
if ( $echo ) {
echo $result;
}
return $result;
}
function cf7bs_enqueue_scripts() {
$in_footer = true;
if ( 'header' === WPCF7_LOAD_JS ) {
$in_footer = false;
}
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_script( 'contact-form-7-bootstrap', CF7BS_URL . '/assets/dist/js/scripts' . $min . '.js', array( 'jquery', 'jquery-form', 'contact-form-7' ), CF7BS_VERSION, $in_footer );
}
add_action( 'wpcf7_enqueue_scripts', 'cf7bs_enqueue_scripts' );
function cf7bs_enqueue_styles() {
wp_dequeue_style( 'contact-form-7' );
if ( version_compare( CF7BS_VERSION, '1.4.8', '>=' ) ) {
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_style( 'contact-form-7-bootstrap-style', CF7BS_URL . '/assets/dist/css/style' . $min . '.css' );
}
}
add_action( 'wpcf7_enqueue_styles', 'cf7bs_enqueue_styles' );
function cf7bs_inline_styles() {
$url = function_exists( 'wpcf7_plugin_url' ) ? wpcf7_plugin_url() : WPCF7_PLUGIN_URL;
$url = untrailingslashit( $url );
if ( version_compare( CF7BS_VERSION, '1.4.8', '>=' ) ) {
?>
<style type="text/css">
.wpcf7 .ajax-loader {
background-image: url('<?php echo $url . '/assets/ajax-loader.gif'; ?>');
}
</style>
<?php
return;
}
?>
<style type="text/css">
.wpcf7 .screen-reader-response {
position: absolute;
overflow: hidden;
clip: rect(1px, 1px, 1px, 1px);
height: 1px;
width: 1px;
margin: 0;
padding: 0;
border: 0;
}
form.init .wpcf7-response-output,
form.resetting .wpcf7-response-output,
form.submitting .wpcf7-response-output {
display: none;
}
.wpcf7 .form-inline img.ajax-loader {
display: inline;
}
.wpcf7 .ajax-loader {
visibility: hidden;
display: inline-block;
background-image: url('<?php echo $url . '/assets/ajax-loader.gif'; ?>');
width: 16px;
height: 16px;
border: none;
padding: 0;
margin: 0 0 0 4px;
vertical-align: middle;
}
.wpcf7 form.submitting .ajax-loader {
visibility: visible;
}
.wpcf7 div.ajax-error {
display: none;
}
.wpcf7 .wpcf7-display-none {
display: none;
}
.wpcf7 .placeheld {
color: #888;
}
.wpcf7 .wpcf7-recaptcha iframe {
margin-bottom: 0;
}
.wpcf7 input[type="file"] {
cursor: pointer;
}
.wpcf7 input[type="file"]:disabled {
cursor: default;
}
.wpcf7 .form-inline .form-group {
max-width: 250px;
}
.wpcf7 .input-group-addon img {
height: 100%;
width: auto;
max-width: none !important;
border-radius: 5px;
}
.wpcf7 .input-group-addon.input-group-has-image {
padding: 0;
}
</style>
<?php
}
add_action( 'wp_head', 'cf7bs_inline_styles' );
function cf7bs_form_class_attr( $class = '' ) {
$layout = cf7bs_get_form_property( 'layout' );
if ( in_array( $layout, array( 'horizontal', 'inline' ) ) ) {
if ( ! empty( $class ) ) {
$class .= ' ';
}
$class .= 'form-' . $layout;
}
return $class;
}
add_filter( 'wpcf7_form_class_attr', 'cf7bs_form_class_attr' );
function cf7bs_form_novalidate( $novalidate ) {
if ( wpcf7_support_html5() ) {
return ' novalidate';
}
return '';
}
add_filter( 'wpcf7_form_novalidate', 'cf7bs_form_novalidate' );
function cf7bs_form_response_output( $output, $class, $content, $form_obj ) {
$type = 'warning';
if ( false !== strpos( $class, 'wpcf7-display-none' ) ) {
$type = '';
} else {
if ( false !== strpos( $class, 'wpcf7-mail-sent-ng' ) ) {
$type = 'danger';
} elseif ( false !== strpos( $class, 'wpcf7-mail-sent-ok' ) ) {
$type = 'success';
} else {
$type = 'warning';
}
}
$alert = new CF7BS_Alert( array(
'type' => $type,
'class' => $class,
'dismissible' => defined( 'CF7BS_ALERT_DISMISSIBLE' ) && CF7BS_ALERT_DISMISSIBLE,
) );
return $alert->open( false ) . esc_html( $content ) . $alert->close( false );
}
add_filter( 'wpcf7_form_response_output', 'cf7bs_form_response_output', 10, 4 );
function cf7bs_validation_error( $output, $name, $form_obj ) {
$alert = new CF7BS_Alert( array(
'type' => 'warning',
'class' => 'wpcf7-not-valid-tip',
'dismissible' => defined( 'CF7BS_ALERT_DISMISSIBLE' ) && CF7BS_ALERT_DISMISSIBLE,
) );
$output = str_replace( '<span role="alert" class="wpcf7-not-valid-tip">', $alert->open( false ), $output );
$output = str_replace( '</span>', $alert->close( false ), $output );
return $output;
}
add_filter( 'wpcf7_validation_error', 'cf7bs_validation_error', 10, 3 );
function cf7bs_ajax_json_echo( $items, $result ) {
if ( isset( $items['invalid_fields'] ) ) {
foreach ( $items['invalid_fields'] as &$invalid ) {
$invalid['into'] = str_replace( 'span.wpcf7-form-control-wrap', 'div.form-group', $invalid['into'] );
}
}
return $items;
}
add_filter( 'wpcf7_feedback_response', 'cf7bs_ajax_json_echo', 10, 2 );
function cf7bs_default_template( $template, $prop = 'form' ) {
if ( 'form' == $prop ) {
$template = cf7bs_default_form_template();
}
return $template;
}
add_filter( 'wpcf7_default_template', 'cf7bs_default_template', 10, 2 );
function cf7bs_default_form_template() {
$template = '[text* your-name]' . __( 'Your Name', 'bootstrap-for-contact-form-7' ) . '[/text*]' . "\n"
. '[email* your-email]' . __( 'Your Email', 'bootstrap-for-contact-form-7' ) . '[/email*]' . "\n"
. '[text your-subject]' . __( 'Subject', 'bootstrap-for-contact-form-7' ) . '[/text]' . "\n"
. '[textarea your-message]' . __( 'Your Message', 'bootstrap-for-contact-form-7' ) . '[/textarea]' . "\n"
. '[submit "' . __( 'Send', 'bootstrap-for-contact-form-7' ) . '"]';
return $template;
}
function cf7bs_parameter_encode( $item ) {
$encoded = '';
if ( is_object( $item ) ) {
return '';
} elseif ( is_array( $item ) ) {
$encoded = cf7bs_array_encode( $item );
} else {
$encoded = $item;
}
return rawurlencode( $encoded );
}
function cf7bs_array_encode( $values ) {
if ( ! is_array( $values ) ) {
return '';
}
$encoded = '';
foreach ( $values as $value ) {
if ( ! empty( $encoded ) ) {
$encoded .= '---';
}
$encoded .= $value;
}
return $encoded;
}
function cf7bs_array_decode( $values ) {
if ( ! is_string( $values ) ) {
return array();
}
$decoded = explode( '---', $values );
return $decoded;
}
function cf7bs_editor_panel_additional_settings( $post ) {
if ( ! function_exists( 'wpcf7_editor_panel_additional_settings' ) ) {
return;
}
ob_start();
wpcf7_editor_panel_additional_settings( $post );
$output = ob_get_clean();
$output = str_replace( 'http://contactform7.com/additional-settings/', __( 'https://wordpress.org/plugins/bootstrap-for-contact-form-7/other_notes/', 'bootstrap-for-contact-form-7' ), $output );
echo $output;
}
function cf7bs_editor_panels( $panels ) {
if ( ! isset( $panels['additional-settings-panel'] ) ) {
return $panels;
}
$panels['additional-settings-panel']['callback'] = 'cf7bs_editor_panel_additional_settings';
return $panels;
}
add_filter( 'wpcf7_editor_panels', 'cf7bs_editor_panels' );
function cf7bs_adjust_rest_feedback_response( $response, $result ) {
if ( 'validation_failed' == $result['status'] ) {
$invalid_fields = array();
foreach ( (array) $result['invalid_fields'] as $name => $field ) {
$invalid_fields[] = array(
'into' => '.form-group.' . sanitize_html_class( $name ),
'message' => $field['reason'],
'idref' => $field['idref'],
);
}
$response['invalidFields'] = $invalid_fields;
}
return $response;
}
add_filter( 'wpcf7_feedback_response', 'cf7bs_adjust_rest_feedback_response', 10, 2 );