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

538 lines 17.0 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.0.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' ) ) 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.0.4';
57
58 /**
59 * Emailer instance
60 *
61 * @var WeForms_Emailer
62 */
63 public $emailer = null;
64
65 /**
66 * Constructor for the WeForms class
67 *
68 * Sets up all the appropriate hooks and actions
69 * within our plugin.
70 *
71 * @uses register_activation_hook()
72 * @uses register_deactivation_hook()
73 * @uses is_admin()
74 * @uses add_action()
75 */
76 public function __construct() {
77 $this->define_constants();
78
79 register_activation_hook( __FILE__, array( $this, 'activate' ) );
80 register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
81
82 add_action( 'init', array( $this, 'maybe_requires_core' ) );
83 add_action( 'wpuf_loaded', array( $this, 'init_plugin' ) );
84 }
85
86 /**
87 * Define the constants
88 *
89 * @return void
90 */
91 private function define_constants() {
92 define( 'WEFORMS_VERSION', '1.0' );
93 define( 'WEFORMS_FILE', __FILE__ );
94 define( 'WEFORMS_ROOT', dirname( __FILE__ ) );
95 define( 'WEFORMS_INCLUDES', WEFORMS_ROOT . '/includes' );
96 define( 'WEFORMS_ROOT_URI', plugins_url( '', __FILE__ ) );
97 define( 'WEFORMS_ASSET_URI', WEFORMS_ROOT_URI . '/assets' );
98 }
99
100 /**
101 * Load the plugin after WP User Frontend is loaded
102 *
103 * @return void
104 */
105 public function init_plugin() {
106 $this->includes();
107 $this->init_hooks();
108
109 do_action( 'weforms_loaded' );
110 }
111
112 /**
113 * Initializes the WeForms() class
114 *
115 * Checks for an existing WeForms() instance
116 * and if it doesn't find one, creates it.
117 */
118 public static function init() {
119 static $instance = false;
120
121 if ( ! $instance ) {
122 $instance = new WeForms();
123 }
124
125 return $instance;
126 }
127
128 /**
129 * Placeholder for activation function
130 *
131 * Nothing being called here yet.
132 */
133 public function activate() {
134 global $wpdb;
135
136 $collate = '';
137
138 if ( $wpdb->has_cap( 'collation' ) ) {
139 if ( ! empty($wpdb->charset ) ) {
140 $collate .= "DEFAULT CHARACTER SET $wpdb->charset";
141 }
142
143 if ( ! empty($wpdb->collate ) ) {
144 $collate .= " COLLATE $wpdb->collate";
145 }
146 }
147
148 $table_schema = array(
149 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}weforms_entries` (
150 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
151 `form_id` bigint(20) unsigned DEFAULT NULL,
152 `user_id` bigint(20) unsigned DEFAULT NULL,
153 `user_ip` int(11) unsigned DEFAULT NULL,
154 `user_device` varchar(50) DEFAULT NULL,
155 `referer` varchar(255) DEFAULT NULL,
156 `status` varchar(10) DEFAULT 'publish',
157 `created_at` datetime DEFAULT NULL,
158 PRIMARY KEY (`id`),
159 KEY `form_id` (`form_id`)
160 ) $collate;",
161
162 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}weforms_entrymeta` (
163 `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
164 `weforms_entry_id` bigint(20) unsigned DEFAULT NULL,
165 `meta_key` varchar(255) DEFAULT NULL,
166 `meta_value` longtext,
167 PRIMARY KEY (`meta_id`),
168 KEY `meta_key` (`meta_key`),
169 KEY `entry_id` (`weforms_entry_id`)
170 ) $collate;",
171 );
172
173 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
174 foreach ( $table_schema as $table ) {
175 dbDelta( $table );
176 }
177
178 $this->maybe_set_default_settings();
179 $this->create_default_form();
180
181 update_option( 'weforms_installed', time() );
182 update_option( 'weforms_version', WEFORMS_VERSION );
183 }
184
185 /**
186 * Placeholder for deactivation function
187 *
188 * Nothing being called here yet.
189 */
190 public function deactivate() {
191
192 }
193
194 /**
195 * Include the required classes
196 *
197 * @return void
198 */
199 public function includes() {
200
201 if ( is_admin() ) {
202 require_once WEFORMS_INCLUDES . '/admin/class-admin.php';
203
204 require_once WEFORMS_INCLUDES . '/importer/class-importer-abstract.php';
205 require_once WEFORMS_INCLUDES . '/importer/class-importer-cf7.php';
206 require_once WEFORMS_INCLUDES . '/importer/class-importer-gf.php';
207 require_once WEFORMS_INCLUDES . '/importer/class-importer-wpforms.php';
208 require_once WEFORMS_INCLUDES . '/importer/class-importer-ninja-forms.php';
209 require_once WEFORMS_INCLUDES . '/importer/class-importer-caldera-forms.php';
210
211 require_once WEFORMS_INCLUDES . '/admin/class-form-template.php';
212 require_once WEFORMS_INCLUDES . '/admin/class-pro-integrations.php';
213 } else {
214 require_once WPUF_ROOT . '/class/render-form.php';
215 require_once WEFORMS_INCLUDES . '/class-frontend-form.php';
216 }
217
218 require_once WEFORMS_INCLUDES . '/class-emailer.php';
219 require_once WEFORMS_INCLUDES . '/class-ajax.php';
220 require_once WEFORMS_INCLUDES . '/class-notification.php';
221 require_once WEFORMS_INCLUDES . '/class-form-preview.php';
222 require_once WEFORMS_INCLUDES . '/functions.php';
223 require_once WEFORMS_INCLUDES . '/functions-template-contact-form.php';
224 }
225
226 /**
227 * Initialize the hooks
228 *
229 * @return void
230 */
231 public function init_hooks() {
232
233 // Localize our plugin
234 add_action( 'init', array( $this, 'localization_setup' ) );
235
236 // initialize the classes
237 add_action( 'init', array( $this, 'init_classes' ) );
238 add_action( 'init', array( $this, 'wpdb_table_shortcuts' ), 0 );
239
240 add_filter( 'wpuf_integrations', array( $this, 'register_default_integrations' ) );
241
242 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
243 }
244
245 /**
246 * Set WPDB table shortcut names
247 *
248 * @return void
249 */
250 public function wpdb_table_shortcuts() {
251 global $wpdb;
252
253 $wpdb->weforms_entries = $wpdb->prefix . 'weforms_entries';
254 $wpdb->weforms_entrymeta = $wpdb->prefix . 'weforms_entrymeta';
255 }
256
257 /**
258 * Check if the core WP User Frontend is installed
259 *
260 * @return boolean
261 */
262 public function is_core_installed() {
263 return class_exists( 'WP_User_Frontend' );
264 }
265
266 /**
267 * If the core isn't installed
268 *
269 * @return void
270 */
271 public function maybe_requires_core() {
272 if ( $this->is_core_installed() ) {
273 return;
274 }
275
276 // show the notice
277 add_action( 'admin_notices', array( $this, 'core_activation_notice' ) );
278
279 // install the core
280 add_action( 'wp_ajax_wpuf_cf_install_wpuf', array( $this, 'install_wp_user_frontend' ) );
281 }
282
283 /**
284 * The prompt to install the core plugin
285 *
286 * @return void
287 */
288 public function core_activation_notice() {
289 ?>
290 <div class="updated" id="wpuf-contact-form-installer-notice" style="padding: 1em; position: relative;">
291 <h2><?php _e( 'weForms is almost ready!', 'weforms' ); ?></h2>
292
293 <?php
294 $plugin_file = basename( dirname( __FILE__ ) ) . '/weforms.php';
295 $core_plugin_file = 'wp-user-frontend/wpuf.php';
296 ?>
297 <a href="<?php echo wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=all&amp;paged=1&amp;s=', 'deactivate-plugin_' . $plugin_file ); ?>" class="notice-dismiss" style="text-decoration: none;" title="<?php _e( 'Dismiss this notice', 'weforms' ); ?>"></a>
298
299 <?php if ( file_exists( WP_PLUGIN_DIR . '/' . $core_plugin_file ) && is_plugin_inactive( 'wpuf-user-frontend' ) ): ?>
300 <p><?php _e( 'You just need to activate the Core Plugin to make it functional.', 'weforms' ); ?></p>
301 <p>
302 <a class="button button-primary" href="<?php echo wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . $core_plugin_file . '&amp;plugin_status=all&amp;paged=1&amp;s=', 'activate-plugin_' . $core_plugin_file ); ?>" title="<?php _e( 'Activate this plugin', 'weforms' ); ?>"><?php _e( 'Activate', 'weforms' ); ?></a>
303 </p>
304 <?php else: ?>
305 <p><?php echo sprintf( __( "You just need to install the %sCore Plugin%s to make it functional.", "wpuf-contact-form" ), '<a target="_blank" href="https://wordpress.org/plugins/wp-user-frontend/">', '</a>' ); ?></p>
306
307 <p>
308 <button id="wpuf-contact-form-installer" class="button"><?php _e( 'Install Now', 'weforms' ); ?></button>
309 </p>
310 <?php endif; ?>
311 </div>
312
313 <script type="text/javascript">
314 (function ($) {
315 var wrapper = $('#wpuf-contact-form-installer-notice');
316
317 wrapper.on('click', '#wpuf-contact-form-installer', function (e) {
318 var self = $(this);
319
320 e.preventDefault();
321 self.addClass('install-now updating-message');
322 self.text('<?php echo esc_js( 'Installing...', 'weforms' ); ?>');
323
324 var data = {
325 action: 'wpuf_cf_install_wpuf',
326 _wpnonce: '<?php echo wp_create_nonce('wpuf-installer-nonce'); ?>'
327 };
328
329 $.post(ajaxurl, data, function (response) {
330 if (response.success) {
331 self.attr('disabled', 'disabled');
332 self.removeClass('install-now updating-message');
333 self.text('<?php echo esc_js( 'Installed', 'weforms' ); ?>');
334
335 window.location.href = '<?php echo admin_url( 'admin.php?page=weforms' ); ?>';
336 }
337 });
338 });
339 })(jQuery);
340 </script>
341 <?php
342 }
343
344 /**
345 * Initialize plugin for localization
346 *
347 * @uses load_plugin_textdomain()
348 */
349 public function localization_setup() {
350 load_plugin_textdomain( 'weforms', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
351 }
352
353 /**
354 * Instantiate the required classes
355 *
356 * @return void
357 */
358 public function init_classes() {
359
360 if ( is_admin() ) {
361 new WeForms_Admin();
362 new WeForms_Form_Template();
363 new WeForms_Pro_Integrations();
364 new WeForms_Importer_CF7();
365 new WeForms_Importer_GF();
366 // new WeForms_Importer_WPForms();
367 new WeForms_Importer_WPForms();
368 new WeForms_Importer_Ninja_Forms();
369 new WeForms_Importer_Caldera_Forms();
370 } else {
371 new WeForms_Frontend();
372 }
373
374 $this->emailer = new WeForms_Emailer();
375 new WeForms_Form_Preview();
376
377 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
378 new WeForms_Ajax();
379 }
380 }
381
382 /**
383 * Install the WP User Frontend plugin via ajax
384 *
385 * @return void
386 */
387 public function install_wp_user_frontend() {
388
389 if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'wpuf-installer-nonce' ) ) {
390 wp_send_json_error( __( 'Error: Nonce verification failed', 'weforms' ) );
391 }
392
393 include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
394 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
395
396 $plugin = 'wp-user-frontend';
397 $api = plugins_api( 'plugin_information', array( 'slug' => $plugin, 'fields' => array( 'sections' => false ) ) );
398
399 $upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() );
400 $result = $upgrader->install( $api->download_link );
401
402 if ( is_wp_error( $result ) ) {
403 wp_send_json_error( $result );
404 }
405
406 $result = activate_plugin( 'wp-user-frontend/wpuf.php' );
407
408 if ( is_wp_error( $result ) ) {
409 wp_send_json_error( $result );
410 }
411
412 // hide wpuf page creation notice and tracking
413 update_option( '_wpuf_page_created', '1' );
414 update_option( 'wp-user-frontend_tracking_notice', 'hide' );
415
416 wp_send_json_success();
417 }
418
419 /**
420 * Plugin action links
421 *
422 * @param array $links
423 *
424 * @return array
425 */
426 function plugin_action_links( $links ) {
427
428 $links[] = '<a href="' . admin_url( 'admin.php?page=weforms' ) . '">' . __( 'Settings', 'weforms' ) . '</a>';
429
430 return $links;
431 }
432
433 /**
434 * Register default integrations
435 *
436 * @param array $integrations
437 *
438 * @return array
439 */
440 public function register_default_integrations( $integrations ) {
441 require_once WEFORMS_INCLUDES . '/integrations/slack/class-integration-slack.php';
442
443 $integrations = array_merge( $integrations, array( 'WeForms_Integration_Slack' ) );
444
445 return $integrations;
446 }
447
448 /**
449 * Set the required default settings key if not present
450 *
451 * This is required for setting up the component settings data
452 *
453 * @return void
454 */
455 public function maybe_set_default_settings() {
456 $requires_update = false;
457 $settings = get_option( 'weforms_settings', array() );
458 $additional_keys = array(
459 'email_gateway' => 'wordpress',
460 'credit' => false,
461 'recaptcha' => array( 'key' => '', 'secret' => '' )
462 );
463
464 foreach ($additional_keys as $key => $value) {
465 if ( ! isset( $settings[ $key ] ) ) {
466 $settings[ $key ] = $value;
467
468 $requires_update = true;
469 }
470 }
471
472 if ( $requires_update ) {
473 update_option( 'weforms_settings', $settings );
474 }
475 }
476
477 /**
478 * Create a default form
479 *
480 * @return void
481 */
482 public function create_default_form() {
483 $version = get_option( 'weforms_version' );
484
485 // seems like it's already installed
486 if ( $version ) {
487 return;
488 }
489
490 if ( ! function_exists( 'weforms_get_contactform_template_fields' ) ) {
491 require_once dirname( __FILE__ ) . '/includes/functions-template-contact-form.php';
492 }
493
494 $form_post_data = array(
495 'post_title' => __( 'Contact Form', 'weforms' ),
496 'post_type' => 'wpuf_contact_form',
497 'post_status' => 'publish',
498 'post_author' => get_current_user_id()
499 );
500
501 $form_id = wp_insert_post( $form_post_data );
502
503 if ( is_wp_error( $form_id ) ) {
504 return;
505 }
506
507 update_post_meta( $form_id, 'wpuf_form_settings', weforms_get_contactform_template_settings() );
508 update_post_meta( $form_id, 'notifications', weforms_get_contactform_template_notification() );
509
510 $form_fields = weforms_get_contactform_template_fields();
511
512 if ( $form_fields ) {
513 foreach ($form_fields as $menu_order => $field) {
514 wp_insert_post( array(
515 'post_type' => 'wpuf_input',
516 'post_status' => 'publish',
517 'post_content' => maybe_serialize( $field ),
518 'post_parent' => $form_id,
519 'menu_order' => $menu_order
520 ) );
521 }
522 }
523 }
524
525 } // WeForms
526
527 /**
528 * Initialize the plugin
529 *
530 * @return \WeForms
531 */
532 function weforms() {
533 return WeForms::init();
534 }
535
536 // kick-off
537 weforms();
538