-
Notifications
You must be signed in to change notification settings - Fork 145
/
controller.php
180 lines (145 loc) · 3.03 KB
/
controller.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
<?php
/**
* Controller for front-end requests, scripts, and styles
*/
add_action(
'parse_request',
'wpcf7_control_init',
20, 0
);
/**
* Handles a submission in non-Ajax mode.
*/
function wpcf7_control_init() {
if ( WPCF7_Submission::is_restful() ) {
return;
}
if ( isset( $_POST['_wpcf7'] ) ) {
$contact_form = wpcf7_contact_form( (int) $_POST['_wpcf7'] );
if ( $contact_form ) {
$contact_form->submit();
}
}
}
/**
* Registers main scripts and styles.
*/
add_action(
'wp_enqueue_scripts',
static function () {
$assets = array();
$asset_file = wpcf7_plugin_path( 'includes/js/index.asset.php' );
if ( file_exists( $asset_file ) ) {
$assets = include( $asset_file );
}
$assets = wp_parse_args( $assets, array(
'dependencies' => array(),
'version' => WPCF7_VERSION,
) );
wp_register_script(
'contact-form-7',
wpcf7_plugin_url( 'includes/js/index.js' ),
array_merge(
$assets['dependencies'],
array( 'swv' )
),
$assets['version'],
true
);
wp_register_script(
'contact-form-7-html5-fallback',
wpcf7_plugin_url( 'includes/js/html5-fallback.js' ),
array( 'jquery-ui-datepicker' ),
WPCF7_VERSION,
true
);
if ( wpcf7_load_js() ) {
wpcf7_enqueue_scripts();
}
wp_register_style(
'contact-form-7',
wpcf7_plugin_url( 'includes/css/styles.css' ),
array(),
WPCF7_VERSION,
'all'
);
wp_register_style(
'contact-form-7-rtl',
wpcf7_plugin_url( 'includes/css/styles-rtl.css' ),
array( 'contact-form-7' ),
WPCF7_VERSION,
'all'
);
wp_register_style(
'jquery-ui-smoothness',
wpcf7_plugin_url(
'includes/js/jquery-ui/themes/smoothness/jquery-ui.min.css'
),
array(),
'1.12.1',
'screen'
);
if ( wpcf7_load_css() ) {
wpcf7_enqueue_styles();
}
},
10, 0
);
/**
* Enqueues scripts.
*/
function wpcf7_enqueue_scripts() {
wp_enqueue_script( 'contact-form-7' );
$wpcf7 = array(
'api' => array(
'root' => sanitize_url( get_rest_url() ),
'namespace' => 'contact-form-7/v1',
),
);
if ( defined( 'WP_CACHE' ) and WP_CACHE ) {
$wpcf7['cached'] = 1;
}
wp_localize_script( 'contact-form-7', 'wpcf7', $wpcf7 );
do_action( 'wpcf7_enqueue_scripts' );
}
/**
* Returns true if the main script is enqueued.
*/
function wpcf7_script_is() {
return wp_script_is( 'contact-form-7' );
}
/**
* Enqueues styles.
*/
function wpcf7_enqueue_styles() {
wp_enqueue_style( 'contact-form-7' );
if ( wpcf7_is_rtl() ) {
wp_enqueue_style( 'contact-form-7-rtl' );
}
do_action( 'wpcf7_enqueue_styles' );
}
/**
* Returns true if the main stylesheet is enqueued.
*/
function wpcf7_style_is() {
return wp_style_is( 'contact-form-7' );
}
add_action(
'wp_enqueue_scripts',
'wpcf7_html5_fallback',
20, 0
);
/**
* Enqueues scripts and styles for the HTML5 fallback.
*/
function wpcf7_html5_fallback() {
if ( ! wpcf7_support_html5_fallback() ) {
return;
}
if ( wpcf7_script_is() ) {
wp_enqueue_script( 'contact-form-7-html5-fallback' );
}
if ( wpcf7_style_is() ) {
wp_enqueue_style( 'jquery-ui-smoothness' );
}
}