| 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.1.0 |
| 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.1.0'; |
| 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 |
* Constructor for the WeForms class |
| 74 |
* |
| 75 |
* Sets up all the appropriate hooks and actions |
| 76 |
* within our plugin. |
| 77 |
*/ |
| 78 |
public function __construct() { |
| 79 |
$this->define_constants(); |
| 80 |
|
| 81 |
register_activation_hook( __FILE__, array( $this, 'activate' ) ); |
| 82 |
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) ); |
| 83 |
|
| 84 |
add_action( 'plugins_loaded', array( $this, 'init_plugin' ) ); |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Magic getter to bypass referencing plugin. |
| 89 |
* |
| 90 |
* @param $prop |
| 91 |
* |
| 92 |
* @return mixed |
| 93 |
*/ |
| 94 |
public function __get( $prop ) { |
| 95 |
if ( array_key_exists( $prop, $this->container ) ) { |
| 96 |
return $this->container[ $prop ]; |
| 97 |
} |
| 98 |
|
| 99 |
return $this->{$prop}; |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Magic isset to bypass referencing plugin. |
| 104 |
* |
| 105 |
* @param $prop |
| 106 |
* |
| 107 |
* @return mixed |
| 108 |
*/ |
| 109 |
public function __isset( $prop ) { |
| 110 |
return isset( $this->{$prop} ) || isset( $this->container[ $prop ] ); |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Initializes the WeForms() class |
| 115 |
* |
| 116 |
* Checks for an existing WeForms() instance |
| 117 |
* and if it doesn't find one, creates it. |
| 118 |
*/ |
| 119 |
public static function init() { |
| 120 |
static $instance = false; |
| 121 |
|
| 122 |
if ( ! $instance ) { |
| 123 |
$instance = new WeForms(); |
| 124 |
} |
| 125 |
|
| 126 |
return $instance; |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* Define the constants |
| 131 |
* |
| 132 |
* @return void |
| 133 |
*/ |
| 134 |
private function define_constants() { |
| 135 |
define( 'WEFORMS_VERSION', '1.1.0' ); |
| 136 |
define( 'WEFORMS_FILE', __FILE__ ); |
| 137 |
define( 'WEFORMS_ROOT', dirname( __FILE__ ) ); |
| 138 |
define( 'WEFORMS_INCLUDES', WEFORMS_ROOT . '/includes' ); |
| 139 |
define( 'WEFORMS_ROOT_URI', plugins_url( '', __FILE__ ) ); |
| 140 |
define( 'WEFORMS_ASSET_URI', WEFORMS_ROOT_URI . '/assets' ); |
| 141 |
} |
| 142 |
|
| 143 |
/** |
| 144 |
* Load the plugin after WP User Frontend is loaded |
| 145 |
* |
| 146 |
* @return void |
| 147 |
*/ |
| 148 |
public function init_plugin() { |
| 149 |
$this->includes(); |
| 150 |
$this->init_hooks(); |
| 151 |
|
| 152 |
do_action( 'weforms_loaded' ); |
| 153 |
} |
| 154 |
|
| 155 |
/** |
| 156 |
* Placeholder for activation function |
| 157 |
* |
| 158 |
* Nothing being called here yet. |
| 159 |
*/ |
| 160 |
public function activate() { |
| 161 |
require_once WEFORMS_INCLUDES . '/class-installer.php'; |
| 162 |
|
| 163 |
$installer = new WeForms_Installer(); |
| 164 |
$installer->install(); |
| 165 |
} |
| 166 |
|
| 167 |
/** |
| 168 |
* Placeholder for deactivation function |
| 169 |
* |
| 170 |
* Nothing being called here yet. |
| 171 |
*/ |
| 172 |
public function deactivate() { |
| 173 |
|
| 174 |
} |
| 175 |
|
| 176 |
/** |
| 177 |
* Include the required classes |
| 178 |
* |
| 179 |
* @return void |
| 180 |
*/ |
| 181 |
public function includes() { |
| 182 |
|
| 183 |
require_once WEFORMS_INCLUDES . '/compat/class-abstract-wpuf-integration.php'; |
| 184 |
|
| 185 |
if ( is_admin() ) { |
| 186 |
// compatibility |
| 187 |
require_once WEFORMS_INCLUDES . '/class-template-manager.php'; |
| 188 |
|
| 189 |
require_once WEFORMS_INCLUDES . '/admin/class-admin.php'; |
| 190 |
require_once WEFORMS_INCLUDES . '/admin/class-admin-welcome.php'; |
| 191 |
require_once WEFORMS_INCLUDES . '/class-importer-manager.php'; |
| 192 |
|
| 193 |
require_once WEFORMS_INCLUDES . '/admin/class-pro-upgrades.php'; |
| 194 |
|
| 195 |
} else { |
| 196 |
|
| 197 |
require_once WEFORMS_INCLUDES . '/class-frontend-form.php'; |
| 198 |
|
| 199 |
// add reCaptcha library if not found |
| 200 |
if ( ! function_exists( 'recaptcha_get_html' ) ) { |
| 201 |
require_once WEFORMS_INCLUDES . '/library/reCaptcha/recaptchalib.php'; |
| 202 |
require_once WEFORMS_INCLUDES . '/library/reCaptcha/recaptchalib_noCaptcha.php'; |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
require_once WEFORMS_INCLUDES . '/class-scripts-styles.php'; |
| 207 |
require_once WEFORMS_INCLUDES . '/class-emailer.php'; |
| 208 |
require_once WEFORMS_INCLUDES . '/class-field-manager.php'; |
| 209 |
require_once WEFORMS_INCLUDES . '/class-form-manager.php'; |
| 210 |
require_once WEFORMS_INCLUDES . '/class-form-entry-manager.php'; |
| 211 |
require_once WEFORMS_INCLUDES . '/class-form-entry.php'; |
| 212 |
require_once WEFORMS_INCLUDES . '/class-form.php'; |
| 213 |
|
| 214 |
require_once WEFORMS_INCLUDES . '/integrations/class-abstract-integration.php'; |
| 215 |
require_once WEFORMS_INCLUDES . '/class-integration-manager.php'; |
| 216 |
|
| 217 |
require_once WEFORMS_INCLUDES . '/class-ajax.php'; |
| 218 |
require_once WEFORMS_INCLUDES . '/class-ajax-upload.php'; |
| 219 |
require_once WEFORMS_INCLUDES . '/class-notification.php'; |
| 220 |
require_once WEFORMS_INCLUDES . '/class-form-preview.php'; |
| 221 |
require_once WEFORMS_INCLUDES . '/functions.php'; |
| 222 |
} |
| 223 |
|
| 224 |
/** |
| 225 |
* Initialize the hooks |
| 226 |
* |
| 227 |
* @return void |
| 228 |
*/ |
| 229 |
public function init_hooks() { |
| 230 |
|
| 231 |
// Localize our plugin |
| 232 |
add_action( 'init', array( $this, 'localization_setup' ) ); |
| 233 |
|
| 234 |
// initialize the classes |
| 235 |
add_action( 'init', array( $this, 'init_classes' ) ); |
| 236 |
add_action( 'init', array( $this, 'wpdb_table_shortcuts' ), 0 ); |
| 237 |
|
| 238 |
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
| 239 |
} |
| 240 |
|
| 241 |
/** |
| 242 |
* Set WPDB table shortcut names |
| 243 |
* |
| 244 |
* @return void |
| 245 |
*/ |
| 246 |
public function wpdb_table_shortcuts() { |
| 247 |
global $wpdb; |
| 248 |
|
| 249 |
$wpdb->weforms_entries = $wpdb->prefix . 'weforms_entries'; |
| 250 |
$wpdb->weforms_entrymeta = $wpdb->prefix . 'weforms_entrymeta'; |
| 251 |
} |
| 252 |
|
| 253 |
/** |
| 254 |
* Initialize plugin for localization |
| 255 |
* |
| 256 |
* @uses load_plugin_textdomain() |
| 257 |
*/ |
| 258 |
public function localization_setup() { |
| 259 |
load_plugin_textdomain( 'weforms', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
| 260 |
} |
| 261 |
|
| 262 |
/** |
| 263 |
* Instantiate the required classes |
| 264 |
* |
| 265 |
* @return void |
| 266 |
*/ |
| 267 |
public function init_classes() { |
| 268 |
|
| 269 |
if ( is_admin() ) { |
| 270 |
$this->container['admin'] = new WeForms_Admin(); |
| 271 |
// $this->container['welcome'] = new WeForms_Admin_Welcome(); |
| 272 |
$this->container['templates'] = new WeForms_Template_Manager(); |
| 273 |
$this->container['pro_upgrades'] = new WeForms_Pro_Upgrades(); |
| 274 |
$this->container['importer'] = new WeForms_Importer_Manager(); |
| 275 |
} else { |
| 276 |
$this->container['frontend'] = new WeForms_Frontend_Form(); |
| 277 |
} |
| 278 |
|
| 279 |
$this->container['emailer'] = new WeForms_Emailer(); |
| 280 |
$this->container['form'] = new WeForms_Form_Manager(); |
| 281 |
$this->container['fields'] = new WeForms_Field_Manager(); |
| 282 |
$this->container['integrations'] = new WeForms_Integration_Manager(); |
| 283 |
$this->container['preview'] = new WeForms_Form_Preview(); |
| 284 |
$this->container['scripts'] = new WeForms_Scripts_Styles(); |
| 285 |
|
| 286 |
// instantiate the integrations |
| 287 |
$this->integrations->get_integrations(); |
| 288 |
|
| 289 |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
| 290 |
$this->container['ajax'] = new WeForms_Ajax(); |
| 291 |
$this->container['ajax_upload'] = new WeForms_Ajax_Upload(); |
| 292 |
} |
| 293 |
} |
| 294 |
|
| 295 |
/** |
| 296 |
* Plugin action links |
| 297 |
* |
| 298 |
* @param array $links |
| 299 |
* |
| 300 |
* @return array |
| 301 |
*/ |
| 302 |
function plugin_action_links( $links ) { |
| 303 |
|
| 304 |
$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>'; |
| 305 |
$links[] = '<a href="' . admin_url( 'admin.php?page=weforms' ) . '">' . __( 'Settings', 'weforms' ) . '</a>'; |
| 306 |
|
| 307 |
return $links; |
| 308 |
} |
| 309 |
|
| 310 |
} // WeForms |
| 311 |
|
| 312 |
/** |
| 313 |
* Initialize the plugin |
| 314 |
* |
| 315 |
* @return \WeForms |
| 316 |
*/ |
| 317 |
function weforms() { |
| 318 |
return WeForms::init(); |
| 319 |
} |
| 320 |
|
| 321 |
// kick-off |
| 322 |
weforms(); |
| 323 |
|