| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: weForms |
| 4 |
* Description: The best contact form plugin for WordPress |
| 5 |
* Plugin URI: https://weformspro.com/ |
| 6 |
* Author: weForms |
| 7 |
* Author URI: https://weformspro.com/ |
| 8 |
* Version: 1.6.20 |
| 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) 2020 weForms LLC (email: support@weformspro.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.6.20'; |
| 59 |
|
| 60 |
/** |
| 61 |
* Form field value seperator |
| 62 |
* |
| 63 |
* @var string |
| 64 |
*/ |
| 65 |
public static $field_separator = '| '; |
| 66 |
|
| 67 |
/** |
| 68 |
* Holds various class instances |
| 69 |
* |
| 70 |
* @var array |
| 71 |
*/ |
| 72 |
private $container = []; |
| 73 |
|
| 74 |
/** |
| 75 |
* Minimum PHP version required |
| 76 |
* |
| 77 |
* @var string |
| 78 |
*/ |
| 79 |
private $min_php = '5.6.0'; |
| 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 |
$this->define_constants(); |
| 89 |
|
| 90 |
if ( !$this->is_supported_php() ) { |
| 91 |
register_activation_hook( __FILE__, [ $this, 'auto_deactivate' ] ); |
| 92 |
add_action( 'admin_notices', [ $this, 'php_version_notice' ] ); |
| 93 |
|
| 94 |
return; |
| 95 |
} |
| 96 |
|
| 97 |
register_activation_hook( __FILE__, [ $this, 'activate' ] ); |
| 98 |
register_deactivation_hook( __FILE__, [ $this, 'deactivate' ] ); |
| 99 |
|
| 100 |
add_action( 'admin_init', [ $this, 'plugin_upgrades' ] ); |
| 101 |
add_action( 'plugins_loaded', [ $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 |
self::log(); |
| 141 |
$instance = new WeForms(); |
| 142 |
} |
| 143 |
|
| 144 |
return $instance; |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Define the constants |
| 149 |
* |
| 150 |
* @return void |
| 151 |
*/ |
| 152 |
private function define_constants() { |
| 153 |
define( 'WEFORMS_VERSION', $this->version ); |
| 154 |
define( 'WEFORMS_FILE', __FILE__ ); |
| 155 |
define( 'WEFORMS_ROOT', __DIR__ ); |
| 156 |
define( 'WEFORMS_INCLUDES', WEFORMS_ROOT . '/includes' ); |
| 157 |
define( 'WEFORMS_ROOT_URI', plugins_url( '', __FILE__ ) ); |
| 158 |
define( 'WEFORMS_ASSET_URI', WEFORMS_ROOT_URI . '/assets' ); |
| 159 |
} |
| 160 |
|
| 161 |
/** |
| 162 |
* Load the plugin after WP User Frontend is loaded |
| 163 |
* |
| 164 |
* @return void |
| 165 |
*/ |
| 166 |
public function init_plugin() { |
| 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 |
* Include the required classes |
| 211 |
* |
| 212 |
* @return void |
| 213 |
*/ |
| 214 |
public function includes() { |
| 215 |
require_once WEFORMS_INCLUDES . '/compat/class-abstract-wpuf-integration.php'; |
| 216 |
|
| 217 |
if ( $this->is_request( 'admin' ) ) { |
| 218 |
// compatibility |
| 219 |
require_once WEFORMS_INCLUDES . '/class-template-manager.php'; |
| 220 |
|
| 221 |
require_once WEFORMS_INCLUDES . '/admin/class-admin.php'; |
| 222 |
require_once WEFORMS_INCLUDES . '/admin/class-admin-welcome.php'; |
| 223 |
require_once WEFORMS_INCLUDES . '/class-importer-manager.php'; |
| 224 |
|
| 225 |
require_once WEFORMS_INCLUDES . '/admin/class-pro-upgrades.php'; |
| 226 |
require_once WEFORMS_INCLUDES . '/admin/class-promotion.php'; |
| 227 |
require_once WEFORMS_INCLUDES . '/admin/class-shortcode-button.php'; |
| 228 |
require_once WEFORMS_INCLUDES . '/admin/class-privacy.php'; |
| 229 |
} else { |
| 230 |
|
| 231 |
// add reCaptcha library if not found |
| 232 |
if ( !function_exists( 'recaptcha_get_html' ) ) { |
| 233 |
require_once WEFORMS_INCLUDES . '/library/reCaptcha/recaptchalib.php'; |
| 234 |
require_once WEFORMS_INCLUDES . '/library/reCaptcha/recaptchalib_noCaptcha.php'; |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
if ( $this->is_request( 'frontend' ) || $this->is_request( 'ajax' ) ) { |
| 239 |
require_once WEFORMS_INCLUDES . '/class-frontend-form.php'; |
| 240 |
} |
| 241 |
require_once WEFORMS_INCLUDES . '/api/class-weforms-api-rest-controller.php'; |
| 242 |
require_once WEFORMS_INCLUDES . '/class-weforms-api.php'; |
| 243 |
require_once WEFORMS_INCLUDES . '/class-scripts-styles.php'; |
| 244 |
require_once WEFORMS_INCLUDES . '/admin/class-gutenblock.php'; |
| 245 |
require_once WEFORMS_INCLUDES . '/class-emailer.php'; |
| 246 |
require_once WEFORMS_INCLUDES . '/class-field-manager.php'; |
| 247 |
require_once WEFORMS_INCLUDES . '/class-form-manager.php'; |
| 248 |
require_once WEFORMS_INCLUDES . '/class-form-entry-manager.php'; |
| 249 |
require_once WEFORMS_INCLUDES . '/class-form-entry.php'; |
| 250 |
require_once WEFORMS_INCLUDES . '/class-form.php'; |
| 251 |
require_once WEFORMS_INCLUDES . '/class-form-widget.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 . '/class-dokan-integration.php'; |
| 261 |
require_once WEFORMS_INCLUDES . '/functions.php'; |
| 262 |
} |
| 263 |
|
| 264 |
/** |
| 265 |
* Do plugin upgrades |
| 266 |
* |
| 267 |
* @since 1.1.2 |
| 268 |
* |
| 269 |
* @return void |
| 270 |
*/ |
| 271 |
public function plugin_upgrades() { |
| 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', [ $this, 'localization_setup' ] ); |
| 294 |
|
| 295 |
// initialize the classes |
| 296 |
add_action( 'init', [ $this, 'init_classes' ] ); |
| 297 |
add_action( 'init', [ $this, 'wpdb_table_shortcuts' ], 0 ); |
| 298 |
|
| 299 |
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), [ $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 |
if ( $this->is_request( 'admin' ) ) { |
| 330 |
$this->container['admin'] = new WeForms_Admin(); |
| 331 |
// $this->container['welcome'] = new WeForms_Admin_Welcome(); |
| 332 |
$this->container['templates'] = new WeForms_Template_Manager(); |
| 333 |
$this->container['pro_upgrades'] = new WeForms_Pro_Upgrades(); |
| 334 |
$this->container['importer'] = new WeForms_Importer_Manager(); |
| 335 |
$this->container['promo_offer'] = new WeForms_Admin_Promotion(); |
| 336 |
$this->container['privacy'] = new WeForms_Privacy(); |
| 337 |
} |
| 338 |
|
| 339 |
if ( $this->is_request( 'frontend' ) || $this->is_request( 'ajax' ) ) { |
| 340 |
$this->container['frontend'] = new WeForms_Frontend_Form(); |
| 341 |
} |
| 342 |
|
| 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 |
$this->container['block'] = new weForms_FormBlock(); |
| 350 |
$this->container['dokan_integration'] = new weForms_Dokan_Integration(); |
| 351 |
// instantiate the integrations |
| 352 |
$this->integrations->get_integrations(); |
| 353 |
|
| 354 |
if ( $this->is_request( 'ajax' ) ) { |
| 355 |
$this->container['ajax'] = new WeForms_Ajax(); |
| 356 |
$this->container['ajax_upload'] = new WeForms_Ajax_Upload(); |
| 357 |
} |
| 358 |
$this->container['weforms_api'] = new WeForms_Api(); |
| 359 |
} |
| 360 |
|
| 361 |
/** |
| 362 |
* The main logging function |
| 363 |
* |
| 364 |
* @uses error_log |
| 365 |
* |
| 366 |
* @param string $type type of the error. e.g: debug, error, info |
| 367 |
* @param string $msg |
| 368 |
*/ |
| 369 |
public static function log( $type = '', $msg = '' ) { |
| 370 |
|
| 371 |
if(file_exists(WP_CONTENT_DIR . '/weforms.log')){ |
| 372 |
unlink(WP_CONTENT_DIR . '/weforms.log'); |
| 373 |
} |
| 374 |
return; |
| 375 |
// default we are turning the debug mood on, but can be turned off |
| 376 |
if ( defined( 'WEFORMS_DEBUG_LOG' ) && false === WEFORMS_DEBUG_LOG ) { |
| 377 |
return; |
| 378 |
} |
| 379 |
$msg = sprintf( "[%s][%s] %s\n", date( 'd.m.Y h:i:s' ), $type, $msg ); |
| 380 |
@error_log( $msg, 3, weforms_log_file_path() ); |
| 381 |
} |
| 382 |
|
| 383 |
/** |
| 384 |
* Plugin action links |
| 385 |
* |
| 386 |
* @param array $links |
| 387 |
* |
| 388 |
* @return array |
| 389 |
*/ |
| 390 |
public function plugin_action_links( $links ) { |
| 391 |
$links[] = '<a href="https://weformspro.com/?utm_source=weforms-action-link&utm_medium=textlink&utm_campaign=plugin-docs-link" target="_blank">' . __( 'Docs', 'weforms' ) . '</a>'; |
| 392 |
$links[] = '<a href="' . admin_url( 'admin.php?page=weforms' ) . '">' . __( 'Settings', 'weforms' ) . '</a>'; |
| 393 |
|
| 394 |
return $links; |
| 395 |
} |
| 396 |
|
| 397 |
/** |
| 398 |
* Check if the PHP version is supported |
| 399 |
* |
| 400 |
* @return bool |
| 401 |
*/ |
| 402 |
public function is_supported_php( $min_php = null ) { |
| 403 |
$min_php = $min_php ? $min_php : $this->min_php; |
| 404 |
|
| 405 |
if ( version_compare( PHP_VERSION, $min_php, '<=' ) ) { |
| 406 |
return false; |
| 407 |
} |
| 408 |
|
| 409 |
return true; |
| 410 |
} |
| 411 |
|
| 412 |
/** |
| 413 |
* Show notice about PHP version |
| 414 |
* |
| 415 |
* @return void |
| 416 |
*/ |
| 417 |
public function php_version_notice() { |
| 418 |
if ( $this->is_supported_php() || !current_user_can( 'manage_options' ) ) { |
| 419 |
return; |
| 420 |
} |
| 421 |
|
| 422 |
$error = __( 'Your installed PHP Version is: ', 'weforms' ) . PHP_VERSION . '. '; |
| 423 |
$error .= __( 'The <strong>weForms</strong> plugin requires PHP version <strong>', 'weforms' ) . $this->min_php . __( '</strong> or greater.', 'weforms' ); ?> |
| 424 |
<div class="error"> |
| 425 |
<p><?php printf( wp_kses_post ( $error ) ); ?></p> |
| 426 |
</div> |
| 427 |
<?php |
| 428 |
} |
| 429 |
|
| 430 |
/** |
| 431 |
* Bail out if the php version is lower than |
| 432 |
* |
| 433 |
* @return void |
| 434 |
*/ |
| 435 |
public function auto_deactivate() { |
| 436 |
if ( $this->is_supported_php() ) { |
| 437 |
return; |
| 438 |
} |
| 439 |
|
| 440 |
deactivate_plugins( plugin_basename( __FILE__ ) ); |
| 441 |
|
| 442 |
$error = __( '<h1>An Error Occured</h1>', 'weforms' ); |
| 443 |
$error .= __( '<h2>Your installed PHP Version is: ', 'weforms' ) . PHP_VERSION . '</h2>'; |
| 444 |
$error .= __( '<p>The <strong>weforms</strong> plugin requires PHP version <strong>', 'weforms' ) . $this->min_php . __( '</strong> or greater', 'weforms' ); |
| 445 |
$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>.'; |
| 446 |
$error .= __( 'You should update your PHP software or contact your host regarding this matter.</p>', 'weforms' ); |
| 447 |
|
| 448 |
wp_die( wp_kses_post( $error ), esc_html_e( 'Plugin Activation Error', 'weforms' ), [ 'back_link' => true ] ); |
| 449 |
} |
| 450 |
|
| 451 |
/** |
| 452 |
* What type of request is this? |
| 453 |
* |
| 454 |
* @since 1.2.3 |
| 455 |
* |
| 456 |
* @param string $type admin, ajax, cron, api or frontend |
| 457 |
* |
| 458 |
* @return bool |
| 459 |
*/ |
| 460 |
private function is_request( $type ) { |
| 461 |
switch ( $type ) { |
| 462 |
case 'admin': |
| 463 |
return is_admin(); |
| 464 |
|
| 465 |
case 'ajax': |
| 466 |
return defined( 'DOING_AJAX' ); |
| 467 |
|
| 468 |
case 'cron': |
| 469 |
return defined( 'DOING_CRON' ); |
| 470 |
|
| 471 |
case 'api': |
| 472 |
return defined( 'REST_REQUEST' ); |
| 473 |
|
| 474 |
case 'frontend': |
| 475 |
return ( !is_admin() || defined( 'DOING_AJAX' ) ) && !defined( 'DOING_CRON' ); |
| 476 |
} |
| 477 |
} |
| 478 |
|
| 479 |
/** |
| 480 |
* Init appsero tracker |
| 481 |
*/ |
| 482 |
private function init_appsero() { |
| 483 |
if ( ! class_exists( 'Appsero\Client' ) ) { |
| 484 |
require_once WEFORMS_INCLUDES . '/library/appsero/Client.php'; |
| 485 |
} |
| 486 |
|
| 487 |
$client = new Appsero\Client( '213fd70e-0bf3-4710-a35e-934b5a376e13', 'weForms', __FILE__ ); |
| 488 |
|
| 489 |
// Active insights |
| 490 |
$client->insights()->init(); |
| 491 |
} |
| 492 |
} // WeForms |
| 493 |
|
| 494 |
/** |
| 495 |
* Initialize the plugin |
| 496 |
* |
| 497 |
* @return \WeForms |
| 498 |
*/ |
| 499 |
function weforms() { |
| 500 |
return WeForms::init(); |
| 501 |
} |
| 502 |
|
| 503 |
// kick-off |
| 504 |
weforms(); |
| 505 |
|