PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.2.1
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.2.1
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / weforms.php

weforms.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.2.1, at weforms.php

439 lines 12.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: weForms
4 * Description: The best contact form plugin for WordPress
5 * Plugin URI: https://wedevs.com/weforms/
6 * Author: weDevs
7 * Author URI: https://wedevs.com/
8 * Version: 1.2.1
9 * License: GPL2 or later
10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
11 * Text Domain: weforms
12 * Domain Path: /languages
13 */
14
15 /**
16 * Copyright (c) 2017 weDevs LLC (email: info@wedevs.com). All rights reserved.
17 *
18 * Released under the GPL license
19 * http://www.opensource.org/licenses/gpl-license.php
20 *
21 * This is an add-on for WordPress
22 * http://wordpress.org/
23 *
24 * **********************************************************************
25 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation; either version 2 of the License, or
28 * (at your option) any later version.
29 *
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
34 *
35 * You should have received a copy of the GNU General Public License
36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
38 * **********************************************************************
39 */
40
41 // don't call the file directly
42 if ( !defined( 'ABSPATH' ) ) exit;
43
44 /**
45 * WeForms class
46 *
47 * @class WeForms The class that holds the entire WeForms plugin
48 */
49 final class WeForms {
50
51 /**
52 * Plugin version
53 *
54 * @var string
55 */
56 public $version = '1.2.1';
57
58 /**
59 * Form field value seperator
60 *
61 * @var string
62 */
63 static $field_separator = '| ';
64
65 /**
66 * Holds various class instances
67 *
68 * @var array
69 */
70 private $container = array();
71
72
73 /**
74 * Minimum PHP version required
75 *
76 * @var string
77 */
78 private $min_php = '5.4.0';
79
80
81 /**
82 * Constructor for the WeForms class
83 *
84 * Sets up all the appropriate hooks and actions
85 * within our plugin.
86 */
87 public function __construct() {
88
89 $this->define_constants();
90
91 if ( ! $this->is_supported_php() ) {
92 register_activation_hook( __FILE__, array( $this, 'auto_deactivate' ) );
93 add_action( 'admin_notices', array( $this, 'php_version_notice' ) );
94 return;
95 }
96
97 register_activation_hook( __FILE__, array( $this, 'activate' ) );
98 register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
99
100 add_action( 'plugins_loaded', array( $this, 'plugin_upgrades') );
101 add_action( 'plugins_loaded', array( $this, 'init_plugin' ) );
102 }
103
104 /**
105 * Magic getter to bypass referencing plugin.
106 *
107 * @param $prop
108 *
109 * @return mixed
110 */
111 public function __get( $prop ) {
112 if ( array_key_exists( $prop, $this->container ) ) {
113 return $this->container[ $prop ];
114 }
115
116 return $this->{$prop};
117 }
118
119 /**
120 * Magic isset to bypass referencing plugin.
121 *
122 * @param $prop
123 *
124 * @return mixed
125 */
126 public function __isset( $prop ) {
127 return isset( $this->{$prop} ) || isset( $this->container[ $prop ] );
128 }
129
130 /**
131 * Initializes the WeForms() class
132 *
133 * Checks for an existing WeForms() instance
134 * and if it doesn't find one, creates it.
135 */
136 public static function init() {
137 static $instance = false;
138
139 if ( ! $instance ) {
140 $instance = new WeForms();
141 }
142
143 return $instance;
144 }
145
146 /**
147 * Define the constants
148 *
149 * @return void
150 */
151 private function define_constants() {
152 define( 'WEFORMS_VERSION', $this->version );
153 define( 'WEFORMS_FILE', __FILE__ );
154 define( 'WEFORMS_ROOT', dirname( __FILE__ ) );
155 define( 'WEFORMS_INCLUDES', WEFORMS_ROOT . '/includes' );
156 define( 'WEFORMS_ROOT_URI', plugins_url( '', __FILE__ ) );
157 define( 'WEFORMS_ASSET_URI', WEFORMS_ROOT_URI . '/assets' );
158 }
159
160 /**
161 * Load the plugin after WP User Frontend is loaded
162 *
163 * @return void
164 */
165 public function init_plugin() {
166
167 $this->includes();
168 $this->init_hooks();
169
170 do_action( 'weforms_loaded' );
171 }
172
173 /**
174 * Placeholder for activation function
175 */
176 public function activate() {
177
178 // prepare the environment
179 require_once WEFORMS_INCLUDES . '/functions.php';
180 require_once WEFORMS_INCLUDES . '/class-installer.php';
181 require_once WEFORMS_INCLUDES . '/class-field-manager.php';
182 require_once WEFORMS_INCLUDES . '/class-form-manager.php';
183 require_once WEFORMS_INCLUDES . '/class-template-manager.php';
184
185 if ( ! array_key_exists( 'fields', $this->container ) ) {
186 $this->container['fields'] = new WeForms_Field_Manager();
187 }
188
189 if ( ! array_key_exists( 'form', $this->container ) ) {
190 $this->container['form'] = new WeForms_Form_Manager();
191 }
192
193 if ( ! array_key_exists( 'templates', $this->container ) ) {
194 $this->container['templates'] = new WeForms_Template_Manager();
195 }
196
197 $installer = new WeForms_Installer();
198 $installer->install();
199 }
200
201 /**
202 * Placeholder for deactivation function
203 *
204 * Nothing being called here yet.
205 */
206 public function deactivate() {
207
208 }
209
210 /**
211 * Include the required classes
212 *
213 * @return void
214 */
215 public function includes() {
216
217 require_once WEFORMS_INCLUDES . '/compat/class-abstract-wpuf-integration.php';
218
219 if ( is_admin() ) {
220 // compatibility
221 require_once WEFORMS_INCLUDES . '/class-template-manager.php';
222
223 require_once WEFORMS_INCLUDES . '/admin/class-admin.php';
224 require_once WEFORMS_INCLUDES . '/admin/class-admin-welcome.php';
225 require_once WEFORMS_INCLUDES . '/class-importer-manager.php';
226
227 require_once WEFORMS_INCLUDES . '/admin/class-pro-upgrades.php';
228
229 } else {
230
231 require_once WEFORMS_INCLUDES . '/class-frontend-form.php';
232
233 // add reCaptcha library if not found
234 if ( ! function_exists( 'recaptcha_get_html' ) ) {
235 require_once WEFORMS_INCLUDES . '/library/reCaptcha/recaptchalib.php';
236 require_once WEFORMS_INCLUDES . '/library/reCaptcha/recaptchalib_noCaptcha.php';
237 }
238 }
239
240 require_once WEFORMS_INCLUDES . '/class-scripts-styles.php';
241 require_once WEFORMS_INCLUDES . '/class-emailer.php';
242 require_once WEFORMS_INCLUDES . '/class-field-manager.php';
243 require_once WEFORMS_INCLUDES . '/class-form-manager.php';
244 require_once WEFORMS_INCLUDES . '/class-form-entry-manager.php';
245 require_once WEFORMS_INCLUDES . '/class-form-entry.php';
246 require_once WEFORMS_INCLUDES . '/class-form.php';
247
248 require_once WEFORMS_INCLUDES . '/integrations/class-abstract-integration.php';
249 require_once WEFORMS_INCLUDES . '/class-integration-manager.php';
250
251 require_once WEFORMS_INCLUDES . '/class-ajax.php';
252 require_once WEFORMS_INCLUDES . '/class-ajax-upload.php';
253 require_once WEFORMS_INCLUDES . '/class-notification.php';
254 require_once WEFORMS_INCLUDES . '/class-form-preview.php';
255 require_once WEFORMS_INCLUDES . '/functions.php';
256 }
257
258 /**
259 * Do plugin upgrades
260 *
261 * @since 1.1.2
262 *
263 * @return void
264 */
265 function plugin_upgrades() {
266
267 if ( ! is_admin() && ! current_user_can( 'manage_options' ) ) {
268 return;
269 }
270
271 require_once WEFORMS_INCLUDES . '/class-upgrades.php';
272
273 $upgrader = new WeForms_Upgrades();
274
275 if ( $upgrader->needs_update() ) {
276 $upgrader->perform_updates();
277 }
278 }
279
280 /**
281 * Initialize the hooks
282 *
283 * @return void
284 */
285 public function init_hooks() {
286
287 // Localize our plugin
288 add_action( 'init', array( $this, 'localization_setup' ) );
289
290 // initialize the classes
291 add_action( 'init', array( $this, 'init_classes' ) );
292 add_action( 'init', array( $this, 'wpdb_table_shortcuts' ), 0 );
293
294 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
295 }
296
297 /**
298 * Set WPDB table shortcut names
299 *
300 * @return void
301 */
302 public function wpdb_table_shortcuts() {
303 global $wpdb;
304
305 $wpdb->weforms_entries = $wpdb->prefix . 'weforms_entries';
306 $wpdb->weforms_entrymeta = $wpdb->prefix . 'weforms_entrymeta';
307 }
308
309 /**
310 * Initialize plugin for localization
311 *
312 * @uses load_plugin_textdomain()
313 */
314 public function localization_setup() {
315 load_plugin_textdomain( 'weforms', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
316 }
317
318 /**
319 * Instantiate the required classes
320 *
321 * @return void
322 */
323 public function init_classes() {
324
325 if ( is_admin() ) {
326 $this->container['admin'] = new WeForms_Admin();
327 // $this->container['welcome'] = new WeForms_Admin_Welcome();
328 $this->container['templates'] = new WeForms_Template_Manager();
329 $this->container['pro_upgrades'] = new WeForms_Pro_Upgrades();
330 $this->container['importer'] = new WeForms_Importer_Manager();
331 } else {
332 $this->container['frontend'] = new WeForms_Frontend_Form();
333 }
334
335 $this->container['emailer'] = new WeForms_Emailer();
336 $this->container['form'] = new WeForms_Form_Manager();
337 $this->container['fields'] = new WeForms_Field_Manager();
338 $this->container['integrations'] = new WeForms_Integration_Manager();
339 $this->container['preview'] = new WeForms_Form_Preview();
340 $this->container['scripts'] = new WeForms_Scripts_Styles();
341
342 // instantiate the integrations
343 $this->integrations->get_integrations();
344
345 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
346 $this->container['ajax'] = new WeForms_Ajax();
347 $this->container['ajax_upload'] = new WeForms_Ajax_Upload();
348 }
349 }
350
351 /**
352 * Plugin action links
353 *
354 * @param array $links
355 *
356 * @return array
357 */
358 function plugin_action_links( $links ) {
359
360 $links[] = '<a href="https://wedevs.com/docs/weforms/?utm_source=weforms-action-link&utm_medium=textlink&utm_campaign=plugin-docs-link" target="_blank">' . __( 'Docs', 'weforms' ) . '</a>';
361 $links[] = '<a href="' . admin_url( 'admin.php?page=weforms' ) . '">' . __( 'Settings', 'weforms' ) . '</a>';
362
363 return $links;
364 }
365
366 /**
367 * Check if the PHP version is supported
368 *
369 * @return bool
370 */
371 public function is_supported_php( $min_php = null ) {
372
373 $min_php = $min_php ? $min_php : $this->min_php;
374
375 if ( version_compare( PHP_VERSION, $min_php , '<=' ) ) {
376 return false;
377 }
378
379 return true;
380 }
381
382 /**
383 * Show notice about PHP version
384 *
385 * @return void
386 */
387 function php_version_notice() {
388
389 if ( $this->is_supported_php() || !current_user_can( 'manage_options' ) ) {
390 return;
391 }
392
393 $error = __( 'Your installed PHP Version is: ', 'erp' ) . PHP_VERSION . '. ';
394 $error .= __( 'The <strong>weForms</strong> plugin requires PHP version <strong>', 'weforms' ) . $this->min_php . __( '</strong> or greater.', 'weforms' );
395 ?>
396 <div class="error">
397 <p><?php printf( $error ); ?></p>
398 </div>
399 <?php
400 }
401
402
403
404 /**
405 * Bail out if the php version is lower than
406 *
407 * @return void
408 */
409 function auto_deactivate() {
410 if ( $this->is_supported_php() ) {
411 return;
412 }
413
414 deactivate_plugins( plugin_basename( __FILE__ ) );
415
416 $error = __( '<h1>An Error Occured</h1>', 'weforms' );
417 $error .= __( '<h2>Your installed PHP Version is: ', 'weforms' ) . PHP_VERSION . '</h2>';
418 $error .= __( '<p>The <strong>weforms</strong> plugin requires PHP version <strong>', 'weforms' ) . $this->min_php . __( '</strong> or greater', 'weforms' );
419 $error .= __( '<p>The version of your PHP is ', 'weforms' ) . '<a href="http://php.net/supported-versions.php" target="_blank"><strong>' . __( 'unsupported and old', 'weforms' ) . '</strong></a>.';
420 $error .= __( 'You should update your PHP software or contact your host regarding this matter.</p>', 'weforms' );
421
422 wp_die( $error, __( 'Plugin Activation Error', 'weforms' ), array( 'back_link' => true ) );
423 }
424
425
426 } // WeForms
427
428 /**
429 * Initialize the plugin
430 *
431 * @return \WeForms
432 */
433 function weforms() {
434 return WeForms::init();
435 }
436
437 // kick-off
438 weforms();
439