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
|
<?php
add_action( 'init', 'wpcf7_control_init', 11 );
function wpcf7_control_init() { if ( ! isset( $_SERVER['REQUEST_METHOD'] ) ) { return; }
if ( 'GET' == $_SERVER['REQUEST_METHOD'] ) { if ( isset( $_GET['_wpcf7_is_ajax_call'] ) ) { wpcf7_ajax_onload(); } }
if ( 'POST' == $_SERVER['REQUEST_METHOD'] ) { if ( isset( $_POST['_wpcf7_is_ajax_call'] ) ) { wpcf7_ajax_json_echo(); }
wpcf7_submit_nonajax(); } }
function wpcf7_ajax_onload() { $echo = ''; $items = array();
if ( isset( $_GET['_wpcf7'] ) && $contact_form = wpcf7_contact_form( (int) $_GET['_wpcf7'] ) ) { $items = apply_filters( 'wpcf7_ajax_onload', $items ); }
$echo = json_encode( $items );
if ( wpcf7_is_xhr() ) { @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) ); echo $echo; }
exit(); }
function wpcf7_ajax_json_echo() { $echo = '';
if ( isset( $_POST['_wpcf7'] ) ) { $id = (int) $_POST['_wpcf7']; $unit_tag = wpcf7_sanitize_unit_tag( $_POST['_wpcf7_unit_tag'] );
if ( $contact_form = wpcf7_contact_form( $id ) ) { $items = array( 'mailSent' => false, 'into' => '#' . $unit_tag, 'captcha' => null );
$result = $contact_form->submit( true );
if ( ! empty( $result['message'] ) ) { $items['message'] = $result['message']; }
if ( 'mail_sent' == $result['status'] ) { $items['mailSent'] = true; }
if ( 'validation_failed' == $result['status'] ) { $invalids = array();
foreach ( $result['invalid_fields'] as $name => $field ) { $invalids[] = array( 'into' => 'span.wpcf7-form-control-wrap.' . sanitize_html_class( $name ), 'message' => $field['reason'], 'idref' => $field['idref'] ); }
$items['invalids'] = $invalids; }
if ( 'spam' == $result['status'] ) { $items['spam'] = true; }
if ( ! empty( $result['scripts_on_sent_ok'] ) ) { $items['onSentOk'] = $result['scripts_on_sent_ok']; }
if ( ! empty( $result['scripts_on_submit'] ) ) { $items['onSubmit'] = $result['scripts_on_submit']; }
$items = apply_filters( 'wpcf7_ajax_json_echo', $items, $result ); } }
$echo = json_encode( $items );
if ( wpcf7_is_xhr() ) { @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) ); echo $echo; } else { @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); echo '<textarea>' . $echo . '</textarea>'; }
exit(); }
function wpcf7_is_xhr() { if ( ! isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) ) return false;
return $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'; }
function wpcf7_submit_nonajax() { if ( ! isset( $_POST['_wpcf7'] ) ) return;
if ( $contact_form = wpcf7_contact_form( (int) $_POST['_wpcf7'] ) ) { $contact_form->submit(); } }
add_filter( 'widget_text', 'wpcf7_widget_text_filter', 9 );
function wpcf7_widget_text_filter( $content ) { if ( ! preg_match( '/\[[\r\n\t ]*contact-form(-7)?[\r\n\t ].*?\]/', $content ) ) return $content;
$content = do_shortcode( $content );
return $content; }
/* Shortcodes */
add_action( 'plugins_loaded', 'wpcf7_add_shortcodes' );
function wpcf7_add_shortcodes() { add_shortcode( 'contact-form-7', 'wpcf7_contact_form_tag_func' ); add_shortcode( 'contact-form', 'wpcf7_contact_form_tag_func' ); }
function wpcf7_contact_form_tag_func( $atts, $content = null, $code = '' ) { if ( is_feed() ) return '[contact-form-7]';
if ( 'contact-form-7' == $code ) { $atts = shortcode_atts( array( 'id' => 0, 'title' => '', 'html_id' => '', 'html_name' => '', 'html_class' => '', 'output' => 'form' ), $atts );
$id = (int) $atts['id']; $title = trim( $atts['title'] );
if ( ! $contact_form = wpcf7_contact_form( $id ) ) $contact_form = wpcf7_get_contact_form_by_title( $title );
} else { if ( is_string( $atts ) ) $atts = explode( ' ', $atts, 2 );
$id = (int) array_shift( $atts ); $contact_form = wpcf7_get_contact_form_by_old_id( $id ); }
if ( ! $contact_form ) return '[contact-form-7 404 "Not Found"]';
return $contact_form->form_html( $atts ); }
add_action( 'wp_enqueue_scripts', 'wpcf7_do_enqueue_scripts' );
function wpcf7_do_enqueue_scripts() { if ( wpcf7_load_js() ) { wpcf7_enqueue_scripts(); }
if ( wpcf7_load_css() ) { wpcf7_enqueue_styles(); } }
function wpcf7_enqueue_scripts() { // jquery.form.js originally bundled with WordPress is out of date and deprecated // so we need to deregister it and re-register the latest one wp_deregister_script( 'jquery-form' ); wp_register_script( 'jquery-form', wpcf7_plugin_url( 'includes/js/jquery.form.min.js' ), array( 'jquery' ), '3.51.0-2014.06.20', true );
$in_footer = true;
if ( 'header' === wpcf7_load_js() ) { $in_footer = false; }
wp_enqueue_script( 'contact-form-7', wpcf7_plugin_url( 'includes/js/scripts.js' ), array( 'jquery', 'jquery-form' ), WPCF7_VERSION, $in_footer );
$_wpcf7 = array( 'loaderUrl' => wpcf7_ajax_loader(), 'sending' => __( 'Sending ...', 'contact-form-7' ) );
if ( defined( 'WP_CACHE' ) && WP_CACHE ) $_wpcf7['cached'] = 1;
if ( wpcf7_support_html5_fallback() ) $_wpcf7['jqueryUi'] = 1;
wp_localize_script( 'contact-form-7', '_wpcf7', $_wpcf7 );
do_action( 'wpcf7_enqueue_scripts' ); }
function wpcf7_script_is() { return wp_script_is( 'contact-form-7' ); }
function wpcf7_enqueue_styles() { wp_enqueue_style( 'contact-form-7', wpcf7_plugin_url( 'includes/css/styles.css' ), array(), WPCF7_VERSION, 'all' );
if ( wpcf7_is_rtl() ) { wp_enqueue_style( 'contact-form-7-rtl', wpcf7_plugin_url( 'includes/css/styles-rtl.css' ), array(), WPCF7_VERSION, 'all' ); }
do_action( 'wpcf7_enqueue_styles' ); }
function wpcf7_style_is() { return wp_style_is( 'contact-form-7' ); }
/* HTML5 Fallback */
add_action( 'wp_enqueue_scripts', 'wpcf7_html5_fallback', 20 );
function wpcf7_html5_fallback() { if ( ! wpcf7_support_html5_fallback() ) { return; }
if ( wpcf7_script_is() ) { wp_enqueue_script( 'jquery-ui-datepicker' ); wp_enqueue_script( 'jquery-ui-spinner' ); }
if ( wpcf7_style_is() ) { wp_enqueue_style( 'jquery-ui-smoothness', wpcf7_plugin_url( 'includes/js/jquery-ui/themes/smoothness/jquery-ui.min.css' ), array(), '1.10.3', 'screen' ); } }
?>
|