-
Notifications
You must be signed in to change notification settings - Fork 6
/
wpforms.php
412 lines (352 loc) · 10.3 KB
/
wpforms.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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
<?php
/**
* Plugin Name: WPForms Lite
* Plugin URI: https://wpforms.com
* Description: Beginner friendly WordPress contact form plugin. Use our Drag & Drop form builder to create your WordPress forms.
* Author: WPForms
* Author URI: https://wpforms.com
* Version: 1.4.7.2
* Text Domain: wpforms
* Domain Path: languages
*
* WPForms is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* any later version.
*
* WPForms is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WPForms. If not, see <http://www.gnu.org/licenses/>.
*
* @package WPForms
* @author WPForms
* @since 1.0.0
* @license GPL-2.0+
* @copyright Copyright (c) 2016, WPForms LLC
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Don't allow multiple versions to be active.
if ( class_exists( 'WPForms' ) ) {
/**
* Deactivate if WPForms already activated.
*
* @since 1.0.0
*/
function wpforms_deactivate() {
deactivate_plugins( plugin_basename( __FILE__ ) );
}
add_action( 'admin_init', 'wpforms_deactivate' );
/**
* Display notice after deactivation.
*
* @since 1.0.0
*/
function wpforms_lite_notice() {
echo '<div class="notice notice-warning"><p>' . esc_html__( 'Please deactivate WPForms Lite before activating WPForms.', 'wpforms' ) . '</p></div>';
if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}
}
add_action( 'admin_notices', 'wpforms_lite_notice' );
} else {
/**
* Main WPForms class.
*
* @since 1.0.0
*
* @package WPForms
*/
final class WPForms {
/**
* One is the loneliest number that you'll ever do.
*
* @since 1.0.0
*
* @var WPForms
*/
private static $instance;
/**
* Plugin version for enqueueing, etc.
*
* @since 1.0.0
*
* @var string
*/
public $version = '1.4.7.2';
/**
* The form data handler instance.
*
* @since 1.0.0
*
* @var WPForms_Form_Handler
*/
public $form;
/**
* The entry data handler instance (Pro).
*
* @since 1.0.0
*
* @var WPForms_Entry_Handler
*/
public $entry;
/**
* The entry fields data handler instance (Pro).
*
* @since 1.4.3
*
* @var WPForms_Entry_Fields_Handler
*/
public $entry_fields;
/**
* The entry meta data handler instance (Pro).
*
* @since 1.1.6
*
* @var WPForms_Entry_Meta_Handler
*/
public $entry_meta;
/**
* The front-end instance.
*
* @since 1.0.0
*
* @var WPForms_Frontend
*/
public $frontend;
/**
* The process instance.
*
* @since 1.0.0
*
* @var WPForms_Process
*/
public $process;
/**
* The smart tags instance.
*
* @since 1.0.0
*
* @var WPForms_Smart_Tags
*/
public $smart_tags;
/**
* The Logging instance.
*
* @since 1.0.0
*
* @var WPForms_Logging
*/
public $logs;
/**
* The Preview instance.
*
* @since 1.1.9
*
* @var WPForms_Preview
*/
public $preview;
/**
* The License class instance (Pro).
*
* @since 1.0.0
*
* @var WPForms_License
*/
public $license;
/**
* Paid returns true, free (Lite) returns false.
*
* @since 1.3.9
*
* @var boolean
*/
public $pro = false;
/**
* Main WPForms Instance.
*
* Insures that only one instance of WPForms exists in memory at any one
* time. Also prevents needing to define globals all over the place.
*
* @since 1.0.0
*
* @return WPForms
*/
public static function instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WPForms ) ) {
self::$instance = new WPForms();
self::$instance->constants();
self::$instance->conditional_logic_addon_check();
self::$instance->includes();
// Load Pro or Lite specific files.
if ( self::$instance->pro ) {
require_once WPFORMS_PLUGIN_DIR . 'pro/wpforms-pro.php';
} else {
require_once WPFORMS_PLUGIN_DIR . 'lite/wpforms-lite.php';
}
add_action( 'plugins_loaded', array( self::$instance, 'load_textdomain' ), 10 );
add_action( 'plugins_loaded', array( self::$instance, 'objects' ), 10 );
}
return self::$instance;
}
/**
* Setup plugin constants.
*
* @since 1.0.0
*/
private function constants() {
// Plugin version.
if ( ! defined( 'WPFORMS_VERSION' ) ) {
define( 'WPFORMS_VERSION', $this->version );
}
// Plugin Folder Path.
if ( ! defined( 'WPFORMS_PLUGIN_DIR' ) ) {
define( 'WPFORMS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
// Plugin Folder URL.
if ( ! defined( 'WPFORMS_PLUGIN_URL' ) ) {
define( 'WPFORMS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
// Plugin Root File.
if ( ! defined( 'WPFORMS_PLUGIN_FILE' ) ) {
define( 'WPFORMS_PLUGIN_FILE', __FILE__ );
}
// Plugin Slug - Determine plugin type and set slug accordingly.
if ( file_exists( WPFORMS_PLUGIN_DIR . 'pro/wpforms-pro.php' ) ) {
$this->pro = true;
define( 'WPFORMS_PLUGIN_SLUG', 'wpforms' );
} else {
define( 'WPFORMS_PLUGIN_SLUG', 'wpforms-lite' );
}
}
/**
* Loads the plugin language files.
*
* @since 1.0.0
*/
public function load_textdomain() {
load_plugin_textdomain( 'wpforms', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Check to see if the conditional logic addon is running, if so then
* deactivate the plugin to prevent conflicts.
*
* @since 1.3.8
*/
private function conditional_logic_addon_check() {
if ( function_exists( 'wpforms_conditional_logic' ) ) {
// Load core files needed to activate deactivate_plugins().
require_once ABSPATH . 'wp-admin/includes/plugin.php';
require_once ABSPATH . 'wp-includes/pluggable.php';
// Deactivate Conditional Logic addon.
deactivate_plugins( 'wpforms-conditional-logic/wpforms-conditional-logic.php' );
// To avoid namespace collisions, reload current page.
$url = esc_url_raw( remove_query_arg( 'wpforms-test' ) );
wp_redirect( $url );
exit;
}
}
/**
* Include files.
*
* @since 1.0.0
*/
private function includes() {
$this->includes_magic();
// Global includes.
require_once WPFORMS_PLUGIN_DIR . 'includes/functions.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/class-install.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/class-form.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/class-fields.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/class-frontend.php';
// TODO: class-templates.php should be loaded in admin area only.
require_once WPFORMS_PLUGIN_DIR . 'includes/class-templates.php';
// TODO: class-providers.php should be loaded in admin area only.
require_once WPFORMS_PLUGIN_DIR . 'includes/class-providers.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/class-process.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/class-smart-tags.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/class-logging.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/class-widget.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/class-preview.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/class-conditional-logic-core.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/emails/class-emails.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/integrations.php';
// Admin/Dashboard only includes, also in ajax.
if ( is_admin() ) {
require_once WPFORMS_PLUGIN_DIR . 'includes/admin/admin.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-notices.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-menu.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/admin/overview/class-overview.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/admin/builder/class-builder.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/admin/builder/functions.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-settings.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-welcome.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-tools.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-editor.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-review.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-importers.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/admin/ajax-actions.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-am-notification.php';
require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-am-deactivation-survey.php';
}
}
/**
* Including the new files with PHP 5.3 style.
*
* @since 1.4.7
*/
private function includes_magic() {
// We require PHP 5.3 for that to work.
if ( version_compare( phpversion(), '5.3', '<' ) ) {
return;
}
// Autoloader is put into its own file to save space here.
require_once WPFORMS_PLUGIN_DIR . 'autoloader.php';
/*
* Properly init the providers loader, that will handle all the related logic and further loading.
*/
add_action( 'wpforms_loaded', array( '\WPForms\Providers\Loader', 'get_instance' ) );
}
/**
* Setup objects.
*
* @since 1.0.0
*/
public function objects() {
// Global objects.
$this->form = new WPForms_Form_Handler();
$this->frontend = new WPForms_Frontend();
$this->process = new WPForms_Process();
$this->smart_tags = new WPForms_Smart_Tags();
$this->logs = new WPForms_Logging();
$this->preview = new WPForms_Preview();
if ( is_admin() ) {
if ( ! wpforms_setting( 'hide-announcements', false ) ) {
new AM_Notification( WPFORMS_PLUGIN_SLUG, $this->version );
}
if ( $this->pro || ( ! $this->pro && ! file_exists( WP_PLUGIN_DIR . '/wpforms/wpforms.php' ) ) ) {
new AM_Deactivation_Survey( 'WPForms', basename( dirname( __FILE__ ) ) );
}
}
// Hook now that all of the WPForms stuff is loaded.
do_action( 'wpforms_loaded' );
}
}
/**
* The function which returns the one WPForms instance.
*
* @since 1.0.0
*
* @return WPForms
*/
function wpforms() {
return WPForms::instance();
}
wpforms();
}