PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.2.4
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.2.4
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.4, at weforms.php

492 lines 14.3 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.4
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' ) ) {
43 exit;
44 }
45
46 /**
47 * WeForms class
48 *
49 * @class WeForms The class that holds the entire WeForms plugin
50 */
51 final class WeForms {
52
53 /**
54 * Plugin version
55 *
56 * @var string
57 */
58 public $version = '1.2.4';
59
60 /**
61 * Form field value seperator
62 *
63 * @var string
64 */
65 static $field_separator = '| ';
66
67 /**
68 * Holds various class instances
69 *
70 * @var array
71 */
72 private $container = array();
73
74
75 /**
76 * Minimum PHP version required
77 *
78 * @var string
79 */
80 private $min_php = '5.4.0';
81
82
83 /**
84 * Constructor for the WeForms class
85 *
86 * Sets up all the appropriate hooks and actions
87 * within our plugin.
88 */
89 public function __construct() {
90
91 $this->define_constants();
92
93 if ( ! $this->is_supported_php() ) {
94 register_activation_hook( __FILE__, array( $this, 'auto_deactivate' ) );
95 add_action( 'admin_notices', array( $this, 'php_version_notice' ) );
96 return;
97 }
98
99 register_activation_hook( __FILE__, array( $this, 'activate' ) );
100 register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
101
102 add_action( 'admin_init', array( $this, 'plugin_upgrades' ) );
103 add_action( 'plugins_loaded', array( $this, 'init_plugin' ) );
104 }
105
106 /**
107 * Magic getter to bypass referencing plugin.
108 *
109 * @param $prop
110 *
111 * @return mixed
112 */
113 public function __get( $prop ) {
114 if ( array_key_exists( $prop, $this->container ) ) {
115 return $this->container[ $prop ];
116 }
117
118 return $this->{$prop};
119 }
120
121 /**
122 * Magic isset to bypass referencing plugin.
123 *
124 * @param $prop
125 *
126 * @return mixed
127 */
128 public function __isset( $prop ) {
129 return isset( $this->{$prop} ) || isset( $this->container[ $prop ] );
130 }
131
132 /**
133 * Initializes the WeForms() class
134 *
135 * Checks for an existing WeForms() instance
136 * and if it doesn't find one, creates it.
137 */
138 public static function init() {
139 static $instance = false;
140
141 if ( ! $instance ) {
142 $instance = new WeForms();
143 }
144
145 return $instance;
146 }
147
148 /**
149 * Define the constants
150 *
151 * @return void
152 */
153 private function define_constants() {
154 define( 'WEFORMS_VERSION', $this->version );
155 define( 'WEFORMS_FILE', __FILE__ );
156 define( 'WEFORMS_ROOT', dirname( __FILE__ ) );
157 define( 'WEFORMS_INCLUDES', WEFORMS_ROOT . '/includes' );
158 define( 'WEFORMS_ROOT_URI', plugins_url( '', __FILE__ ) );
159 define( 'WEFORMS_ASSET_URI', WEFORMS_ROOT_URI . '/assets' );
160 }
161
162 /**
163 * Load the plugin after WP User Frontend is loaded
164 *
165 * @return void
166 */
167 public function init_plugin() {
168
169 $this->includes();
170 $this->init_hooks();
171
172 do_action( 'weforms_loaded' );
173 }
174
175 /**
176 * Placeholder for activation function
177 */
178 public function activate() {
179
180 // prepare the environment
181 require_once WEFORMS_INCLUDES . '/functions.php';
182 require_once WEFORMS_INCLUDES . '/class-installer.php';
183 require_once WEFORMS_INCLUDES . '/class-field-manager.php';
184 require_once WEFORMS_INCLUDES . '/class-form-manager.php';
185 require_once WEFORMS_INCLUDES . '/class-template-manager.php';
186
187 if ( ! array_key_exists( 'fields', $this->container ) ) {
188 $this->container['fields'] = new WeForms_Field_Manager();
189 }
190
191 if ( ! array_key_exists( 'form', $this->container ) ) {
192 $this->container['form'] = new WeForms_Form_Manager();
193 }
194
195 if ( ! array_key_exists( 'templates', $this->container ) ) {
196 $this->container['templates'] = new WeForms_Template_Manager();
197 }
198
199 $installer = new WeForms_Installer();
200 $installer->install();
201 }
202
203 /**
204 * Placeholder for deactivation function
205 *
206 * Nothing being called here yet.
207 */
208 public function deactivate() {
209
210 }
211
212 /**
213 * Include the required classes
214 *
215 * @return void
216 */
217 public function includes() {
218
219 require_once WEFORMS_INCLUDES . '/compat/class-abstract-wpuf-integration.php';
220
221 if ( $this->is_request( 'admin' ) ) {
222 // compatibility
223 require_once WEFORMS_INCLUDES . '/class-template-manager.php';
224
225 require_once WEFORMS_INCLUDES . '/admin/class-admin.php';
226 require_once WEFORMS_INCLUDES . '/admin/class-admin-welcome.php';
227 require_once WEFORMS_INCLUDES . '/class-importer-manager.php';
228
229 require_once WEFORMS_INCLUDES . '/admin/class-pro-upgrades.php';
230
231 } else {
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 if ( $this->is_request( 'frontend' ) || $this->is_request( 'ajax' ) ) {
241 require_once WEFORMS_INCLUDES . '/class-frontend-form.php';
242 }
243
244 require_once WEFORMS_INCLUDES . '/admin/class-wedevs-insights.php';
245 require_once WEFORMS_INCLUDES . '/class-scripts-styles.php';
246 require_once WEFORMS_INCLUDES . '/class-emailer.php';
247 require_once WEFORMS_INCLUDES . '/class-field-manager.php';
248 require_once WEFORMS_INCLUDES . '/class-form-manager.php';
249 require_once WEFORMS_INCLUDES . '/class-form-entry-manager.php';
250 require_once WEFORMS_INCLUDES . '/class-form-entry.php';
251 require_once WEFORMS_INCLUDES . '/class-form.php';
252
253 require_once WEFORMS_INCLUDES . '/integrations/class-abstract-integration.php';
254 require_once WEFORMS_INCLUDES . '/class-integration-manager.php';
255
256 require_once WEFORMS_INCLUDES . '/class-ajax.php';
257 require_once WEFORMS_INCLUDES . '/class-ajax-upload.php';
258 require_once WEFORMS_INCLUDES . '/class-notification.php';
259 require_once WEFORMS_INCLUDES . '/class-form-preview.php';
260 require_once WEFORMS_INCLUDES . '/functions.php';
261 }
262
263 /**
264 * Do plugin upgrades
265 *
266 * @since 1.1.2
267 *
268 * @return void
269 */
270 function plugin_upgrades() {
271
272 if ( ! current_user_can( 'manage_options' ) ) {
273 return;
274 }
275
276 require_once WEFORMS_INCLUDES . '/class-upgrades.php';
277
278 $upgrader = new WeForms_Upgrades();
279
280 if ( $upgrader->needs_update() ) {
281 $upgrader->perform_updates();
282 }
283 }
284
285 /**
286 * Initialize the hooks
287 *
288 * @return void
289 */
290 public function init_hooks() {
291
292 // Localize our plugin
293 add_action( 'init', array( $this, 'localization_setup' ) );
294
295 // initialize the classes
296 add_action( 'init', array( $this, 'init_classes' ) );
297 add_action( 'init', array( $this, 'wpdb_table_shortcuts' ), 0 );
298
299 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
300 }
301
302 /**
303 * Set WPDB table shortcut names
304 *
305 * @return void
306 */
307 public function wpdb_table_shortcuts() {
308 global $wpdb;
309
310 $wpdb->weforms_entries = $wpdb->prefix . 'weforms_entries';
311 $wpdb->weforms_entrymeta = $wpdb->prefix . 'weforms_entrymeta';
312 }
313
314 /**
315 * Initialize plugin for localization
316 *
317 * @uses load_plugin_textdomain()
318 */
319 public function localization_setup() {
320 load_plugin_textdomain( 'weforms', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
321 }
322
323 /**
324 * Instantiate the required classes
325 *
326 * @return void
327 */
328 public function init_classes() {
329
330 if ( $this->is_request( 'admin' ) ) {
331 $this->container['admin'] = new WeForms_Admin();
332 // $this->container['welcome'] = new WeForms_Admin_Welcome();
333 $this->container['templates'] = new WeForms_Template_Manager();
334 $this->container['pro_upgrades'] = new WeForms_Pro_Upgrades();
335 $this->container['importer'] = new WeForms_Importer_Manager();
336 }
337
338 if ( $this->is_request( 'frontend' ) || $this->is_request( 'ajax' ) ) {
339 $this->container['frontend'] = new WeForms_Frontend_Form();
340 }
341
342 $this->container['insights'] = new WeDevs_Insights( 'weforms', 'weForms', __FILE__ );
343 $this->container['emailer'] = new WeForms_Emailer();
344 $this->container['form'] = new WeForms_Form_Manager();
345 $this->container['fields'] = new WeForms_Field_Manager();
346 $this->container['integrations'] = new WeForms_Integration_Manager();
347 $this->container['preview'] = new WeForms_Form_Preview();
348 $this->container['scripts'] = new WeForms_Scripts_Styles();
349
350 // instantiate the integrations
351 $this->integrations->get_integrations();
352
353 if ( $this->is_request( 'ajax' ) ) {
354 $this->container['ajax'] = new WeForms_Ajax();
355 $this->container['ajax_upload'] = new WeForms_Ajax_Upload();
356 }
357 }
358
359 /**
360 * The main logging function
361 *
362 * @uses error_log
363 * @param string $type type of the error. e.g: debug, error, info
364 * @param string $msg
365 */
366 public static function log( $type = '', $msg = '' ) {
367
368 // default we are turning the debug mood on, but can be turned off
369 if ( defined( 'WEFORMS_DEBUG_LOG' ) && false === WEFORMS_DEBUG_LOG ) {
370 return;
371 }
372
373 $msg = sprintf( "[%s][%s] %s\n", date( 'd.m.Y h:i:s' ), $type, $msg );
374 @error_log( $msg, 3, weforms_log_file_path() );
375 }
376
377 /**
378 * Plugin action links
379 *
380 * @param array $links
381 *
382 * @return array
383 */
384 function plugin_action_links( $links ) {
385
386 $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>';
387 $links[] = '<a href="' . admin_url( 'admin.php?page=weforms' ) . '">' . __( 'Settings', 'weforms' ) . '</a>';
388
389 return $links;
390 }
391
392 /**
393 * Check if the PHP version is supported
394 *
395 * @return bool
396 */
397 public function is_supported_php( $min_php = null ) {
398
399 $min_php = $min_php ? $min_php : $this->min_php;
400
401 if ( version_compare( PHP_VERSION, $min_php , '<=' ) ) {
402 return false;
403 }
404
405 return true;
406 }
407
408 /**
409 * Show notice about PHP version
410 *
411 * @return void
412 */
413 function php_version_notice() {
414
415 if ( $this->is_supported_php() || ! current_user_can( 'manage_options' ) ) {
416 return;
417 }
418
419 $error = __( 'Your installed PHP Version is: ', 'weforms' ) . PHP_VERSION . '. ';
420 $error .= __( 'The <strong>weForms</strong> plugin requires PHP version <strong>', 'weforms' ) . $this->min_php . __( '</strong> or greater.', 'weforms' );
421 ?>
422 <div class="error">
423 <p><?php printf( $error ); ?></p>
424 </div>
425 <?php
426 }
427
428 /**
429 * Bail out if the php version is lower than
430 *
431 * @return void
432 */
433 function auto_deactivate() {
434 if ( $this->is_supported_php() ) {
435 return;
436 }
437
438 deactivate_plugins( plugin_basename( __FILE__ ) );
439
440 $error = __( '<h1>An Error Occured</h1>', 'weforms' );
441 $error .= __( '<h2>Your installed PHP Version is: ', 'weforms' ) . PHP_VERSION . '</h2>';
442 $error .= __( '<p>The <strong>weforms</strong> plugin requires PHP version <strong>', 'weforms' ) . $this->min_php . __( '</strong> or greater', 'weforms' );
443 $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>.';
444 $error .= __( 'You should update your PHP software or contact your host regarding this matter.</p>', 'weforms' );
445
446 wp_die( $error, __( 'Plugin Activation Error', 'weforms' ), array( 'back_link' => true ) );
447 }
448
449 /**
450 * What type of request is this?
451 *
452 * @since 1.2.3
453 *
454 * @param string $type admin, ajax, cron, api or frontend.
455 *
456 * @return bool
457 */
458 private function is_request( $type ) {
459
460 switch ( $type ) {
461 case 'admin' :
462 return is_admin();
463
464 case 'ajax' :
465 return defined( 'DOING_AJAX' );
466
467 case 'cron' :
468 return defined( 'DOING_CRON' );
469
470 case 'api':
471 return defined( 'REST_REQUEST' );
472
473 case 'frontend' :
474 return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' );
475 }
476 }
477
478
479 } // WeForms
480
481 /**
482 * Initialize the plugin
483 *
484 * @return \WeForms
485 */
486 function weforms() {
487 return WeForms::init();
488 }
489
490 // kick-off
491 weforms();
492