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
← All changes | weforms.php +295 -264 1.6.51.0.4 View file →
@@ -1,12 +1,12 @@
1 1 <?php
2 2 /**
3 3 * Plugin Name: weForms
4 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.5
5 + * Plugin URI: https://wedevs.com/weforms/
6 + * Author: weDevs
7 + * Author URI: https://wedevs.com/
8 + * Version: 1.0.4
9 9 * License: GPL2 or later
10 10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
11 11 * Text Domain: weforms
12 12 * Domain Path: /languages
@@ -12,9 +12,9 @@
12 12 * Domain Path: /languages
13 13 */
14 14
15 15 /**
16 - * Copyright (c) 2020 weForms LLC (email: support@weformspro.com). All rights reserved.
16 + * Copyright (c) 2017 weDevs LLC (email: info@wedevs.com). All rights reserved.
17 17 *
18 18 * Released under the GPL license
19 19 * http://www.opensource.org/licenses/gpl-license.php
20 20 *
@@ -38,11 +38,9 @@
38 38 * **********************************************************************
39 39 */
40 40
41 41 // don't call the file directly
42 -if ( !defined( 'ABSPATH' ) ) {
43 - exit;
44 -}
42 +if ( !defined( 'ABSPATH' ) ) exit;
45 43
46 44 /**
47 45 * WeForms class
48 46 *
@@ -54,80 +52,62 @@
54 52 * Plugin version
55 53 *
56 54 * @var string
57 55 */
58 - public $version = '1.6.5';
56 + public $version = '1.0.4';
59 57
60 58 /**
61 - * Form field value seperator
59 + * Emailer instance
62 60 *
63 - * @var string
61 + * @var WeForms_Emailer
64 62 */
65 - public static $field_separator = '| ';
63 + public $emailer = null;
66 64
67 65 /**
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 66 * Constructor for the WeForms class
83 67 *
84 68 * Sets up all the appropriate hooks and actions
85 69 * within our plugin.
70 + *
71 + * @uses register_activation_hook()
72 + * @uses register_deactivation_hook()
73 + * @uses is_admin()
74 + * @uses add_action()
86 75 */
87 76 public function __construct() {
88 77 $this->define_constants();
89 78
90 - if ( !$this->is_supported_php() ) {
91 - register_activation_hook( __FILE__, [ $this, 'auto_deactivate' ] );
92 - add_action( 'admin_notices', [ $this, 'php_version_notice' ] );
79 + register_activation_hook( __FILE__, array( $this, 'activate' ) );
80 + register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
93 81
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 - $this->init_appsero();
82 + add_action( 'init', array( $this, 'maybe_requires_core' ) );
83 + add_action( 'wpuf_loaded', array( $this, 'init_plugin' ) );
104 84 }
105 85
106 86 /**
107 - * Magic getter to bypass referencing plugin.
87 + * Define the constants
108 88 *
109 - * @param $prop
110 - *
111 - * @return mixed
89 + * @return void
112 90 */
113 - public function __get( $prop ) {
114 - if ( array_key_exists( $prop, $this->container ) ) {
115 - return $this->container[ $prop ];
116 - }
117 -
118 - return $this->{$prop};
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' );
119 98 }
120 99
121 100 /**
122 - * Magic isset to bypass referencing plugin.
101 + * Load the plugin after WP User Frontend is loaded
123 102 *
124 - * @param $prop
125 - *
126 - * @return mixed
103 + * @return void
127 104 */
128 - public function __isset( $prop ) {
129 - return isset( $this->{$prop} ) || isset( $this->container[ $prop ] );
105 + public function init_plugin() {
106 + $this->includes();
107 + $this->init_hooks();
108 +
109 + do_action( 'weforms_loaded' );
130 110 }
131 111
132 112 /**
133 113 * Initializes the WeForms() class
@@ -137,10 +117,9 @@
137 117 */
138 118 public static function init() {
139 119 static $instance = false;
140 120
141 - if ( !$instance ) {
142 - self::log();
121 + if ( ! $instance ) {
143 122 $instance = new WeForms();
144 123 }
145 124
146 125 return $instance;
@@ -146,59 +125,62 @@
146 125 return $instance;
147 126 }
148 127
149 128 /**
150 - * Define the constants
129 + * Placeholder for activation function
151 130 *
152 - * @return void
131 + * Nothing being called here yet.
153 132 */
154 - private function define_constants() {
155 - define( 'WEFORMS_VERSION', $this->version );
156 - define( 'WEFORMS_FILE', __FILE__ );
157 - define( 'WEFORMS_ROOT', __DIR__ );
158 - define( 'WEFORMS_INCLUDES', WEFORMS_ROOT . '/includes' );
159 - define( 'WEFORMS_ROOT_URI', plugins_url( '', __FILE__ ) );
160 - define( 'WEFORMS_ASSET_URI', WEFORMS_ROOT_URI . '/assets' );
161 - }
133 + public function activate() {
134 + global $wpdb;
162 135
163 - /**
164 - * Load the plugin after WP User Frontend is loaded
165 - *
166 - * @return void
167 - */
168 - public function init_plugin() {
169 - $this->includes();
170 - $this->init_hooks();
136 + $collate = '';
171 137
172 - do_action( 'weforms_loaded' );
173 - }
138 + if ( $wpdb->has_cap( 'collation' ) ) {
139 + if ( ! empty($wpdb->charset ) ) {
140 + $collate .= "DEFAULT CHARACTER SET $wpdb->charset";
141 + }
174 142
175 - /**
176 - * Placeholder for activation function
177 - */
178 - public function activate() {
143 + if ( ! empty($wpdb->collate ) ) {
144 + $collate .= " COLLATE $wpdb->collate";
145 + }
146 + }
179 147
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';
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;",
186 161
187 - if ( !array_key_exists( 'fields', $this->container ) ) {
188 - $this->container['fields'] = new WeForms_Field_Manager();
189 - }
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 + );
190 172
191 - if ( !array_key_exists( 'form', $this->container ) ) {
192 - $this->container['form'] = new WeForms_Form_Manager();
173 + require_once ABSPATH . 'wp-admin/includes/upgrade.php';
174 + foreach ( $table_schema as $table ) {
175 + dbDelta( $table );
193 176 }
194 177
195 - if ( !array_key_exists( 'templates', $this->container ) ) {
196 - $this->container['templates'] = new WeForms_Template_Manager();
197 - }
178 + $this->maybe_set_default_settings();
179 + $this->create_default_form();
198 180
199 - $installer = new WeForms_Installer();
200 - $installer->install();
181 + update_option( 'weforms_installed', time() );
182 + update_option( 'weforms_version', WEFORMS_VERSION );
201 183 }
202 184
203 185 /**
204 186 * Placeholder for deactivation function
@@ -205,8 +187,9 @@
205 187 *
206 188 * Nothing being called here yet.
207 189 */
208 190 public function deactivate() {
191 +
209 192 }
210 193
211 194 /**
212 195 * Include the required classes
@@ -213,105 +196,150 @@
213 196 *
214 197 * @return void
215 198 */
216 199 public function includes() {
217 - require_once WEFORMS_INCLUDES . '/compat/class-abstract-wpuf-integration.php';
218 200
219 - if ( $this->is_request( 'admin' ) ) {
220 - // compatibility
221 - require_once WEFORMS_INCLUDES . '/class-template-manager.php';
201 + if ( is_admin() ) {
202 + require_once WEFORMS_INCLUDES . '/admin/class-admin.php';
222 203
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';
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';
226 210
227 - require_once WEFORMS_INCLUDES . '/admin/class-pro-upgrades.php';
228 - require_once WEFORMS_INCLUDES . '/admin/class-promotion.php';
229 - require_once WEFORMS_INCLUDES . '/admin/class-shortcode-button.php';
230 - require_once WEFORMS_INCLUDES . '/admin/class-privacy.php';
211 + require_once WEFORMS_INCLUDES . '/admin/class-form-template.php';
212 + require_once WEFORMS_INCLUDES . '/admin/class-pro-integrations.php';
231 213 } 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 - }
214 + require_once WPUF_ROOT . '/class/render-form.php';
215 + require_once WEFORMS_INCLUDES . '/class-frontend-form.php';
238 216 }
239 217
240 - if ( $this->is_request( 'frontend' ) || $this->is_request( 'ajax' ) ) {
241 - require_once WEFORMS_INCLUDES . '/class-frontend-form.php';
242 - }
243 - require_once WEFORMS_INCLUDES . '/api/class-weforms-api-rest-controller.php';
244 - require_once WEFORMS_INCLUDES . '/class-weforms-api.php';
245 - require_once WEFORMS_INCLUDES . '/class-scripts-styles.php';
246 - require_once WEFORMS_INCLUDES . '/admin/class-gutenblock.php';
247 218 require_once WEFORMS_INCLUDES . '/class-emailer.php';
248 - require_once WEFORMS_INCLUDES . '/class-field-manager.php';
249 - require_once WEFORMS_INCLUDES . '/class-form-manager.php';
250 - require_once WEFORMS_INCLUDES . '/class-form-entry-manager.php';
251 - require_once WEFORMS_INCLUDES . '/class-form-entry.php';
252 - require_once WEFORMS_INCLUDES . '/class-form.php';
253 - require_once WEFORMS_INCLUDES . '/class-form-widget.php';
254 -
255 - require_once WEFORMS_INCLUDES . '/integrations/class-abstract-integration.php';
256 - require_once WEFORMS_INCLUDES . '/class-integration-manager.php';
257 -
258 219 require_once WEFORMS_INCLUDES . '/class-ajax.php';
259 - require_once WEFORMS_INCLUDES . '/class-ajax-upload.php';
260 220 require_once WEFORMS_INCLUDES . '/class-notification.php';
261 221 require_once WEFORMS_INCLUDES . '/class-form-preview.php';
262 - require_once WEFORMS_INCLUDES . '/class-dokan-integration.php';
263 222 require_once WEFORMS_INCLUDES . '/functions.php';
223 + require_once WEFORMS_INCLUDES . '/functions-template-contact-form.php';
264 224 }
265 225
266 226 /**
267 - * Do plugin upgrades
227 + * Initialize the hooks
268 228 *
269 - * @since 1.1.2
270 - *
271 229 * @return void
272 230 */
273 - public function plugin_upgrades() {
274 - if ( !current_user_can( 'manage_options' ) ) {
275 - return;
276 - }
231 + public function init_hooks() {
277 232
278 - require_once WEFORMS_INCLUDES . '/class-upgrades.php';
233 + // Localize our plugin
234 + add_action( 'init', array( $this, 'localization_setup' ) );
279 235
280 - $upgrader = new WeForms_Upgrades();
236 + // initialize the classes
237 + add_action( 'init', array( $this, 'init_classes' ) );
238 + add_action( 'init', array( $this, 'wpdb_table_shortcuts' ), 0 );
281 239
282 - if ( $upgrader->needs_update() ) {
283 - $upgrader->perform_updates();
284 - }
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' ) );
285 243 }
286 244
287 245 /**
288 - * Initialize the hooks
246 + * Set WPDB table shortcut names
289 247 *
290 248 * @return void
291 249 */
292 - public function init_hooks() {
250 + public function wpdb_table_shortcuts() {
251 + global $wpdb;
293 252
294 - // Localize our plugin
295 - add_action( 'init', [ $this, 'localization_setup' ] );
253 + $wpdb->weforms_entries = $wpdb->prefix . 'weforms_entries';
254 + $wpdb->weforms_entrymeta = $wpdb->prefix . 'weforms_entrymeta';
255 + }
296 256
297 - // initialize the classes
298 - add_action( 'init', [ $this, 'init_classes' ] );
299 - add_action( 'init', [ $this, 'wpdb_table_shortcuts' ], 0 );
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 + }
300 265
301 - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), [ $this, 'plugin_action_links' ] );
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' ) );
302 281 }
303 282
304 283 /**
305 - * Set WPDB table shortcut names
284 + * The prompt to install the core plugin
306 285 *
307 286 * @return void
308 287 */
309 - public function wpdb_table_shortcuts() {
310 - global $wpdb;
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>
311 292
312 - $wpdb->weforms_entries = $wpdb->prefix . 'weforms_entries';
313 - $wpdb->weforms_entrymeta = $wpdb->prefix . 'weforms_entrymeta';
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
314 342 }
315 343
316 344 /**
317 345 * Initialize plugin for localization
@@ -327,71 +355,77 @@
327 355 *
328 356 * @return void
329 357 */
330 358 public function init_classes() {
331 - if ( $this->is_request( 'admin' ) ) {
332 - $this->container['admin'] = new WeForms_Admin();
333 - // $this->container['welcome'] = new WeForms_Admin_Welcome();
334 - $this->container['templates'] = new WeForms_Template_Manager();
335 - $this->container['pro_upgrades'] = new WeForms_Pro_Upgrades();
336 - $this->container['importer'] = new WeForms_Importer_Manager();
337 - $this->container['promo_offer'] = new WeForms_Admin_Promotion();
338 - $this->container['privacy'] = new WeForms_Privacy();
339 - }
340 359
341 - if ( $this->is_request( 'frontend' ) || $this->is_request( 'ajax' ) ) {
342 - $this->container['frontend'] = new WeForms_Frontend_Form();
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();
343 372 }
344 373
345 - $this->container['emailer'] = new WeForms_Emailer();
346 - $this->container['form'] = new WeForms_Form_Manager();
347 - $this->container['fields'] = new WeForms_Field_Manager();
348 - $this->container['integrations'] = new WeForms_Integration_Manager();
349 - $this->container['preview'] = new WeForms_Form_Preview();
350 - $this->container['scripts'] = new WeForms_Scripts_Styles();
351 - $this->container['block'] = new weForms_FormBlock();
352 - $this->container['dokan_integration'] = new weForms_Dokan_Integration();
353 - // instantiate the integrations
354 - $this->integrations->get_integrations();
374 + $this->emailer = new WeForms_Emailer();
375 + new WeForms_Form_Preview();
355 376
356 - if ( $this->is_request( 'ajax' ) ) {
357 - $this->container['ajax'] = new WeForms_Ajax();
358 - $this->container['ajax_upload'] = new WeForms_Ajax_Upload();
377 + if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
378 + new WeForms_Ajax();
359 379 }
360 - $this->container['weforms_api'] = new WeForms_Api();
361 380 }
362 381
363 382 /**
364 - * The main logging function
383 + * Install the WP User Frontend plugin via ajax
365 384 *
366 - * @uses error_log
367 - *
368 - * @param string $type type of the error. e.g: debug, error, info
369 - * @param string $msg
385 + * @return void
370 386 */
371 - public static function log( $type = '', $msg = '' ) {
387 + public function install_wp_user_frontend() {
372 388
373 - if(file_exists(WP_CONTENT_DIR . '/weforms.log')){
374 - unlink(WP_CONTENT_DIR . '/weforms.log');
389 + if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'wpuf-installer-nonce' ) ) {
390 + wp_send_json_error( __( 'Error: Nonce verification failed', 'weforms' ) );
375 391 }
376 - return;
377 - // default we are turning the debug mood on, but can be turned off
378 - if ( defined( 'WEFORMS_DEBUG_LOG' ) && false === WEFORMS_DEBUG_LOG ) {
379 - return;
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 );
380 404 }
381 - $msg = sprintf( "[%s][%s] %s\n", date( 'd.m.Y h:i:s' ), $type, $msg );
382 - @error_log( $msg, 3, weforms_log_file_path() );
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();
383 417 }
384 418
385 419 /**
386 420 * Plugin action links
387 421 *
388 - * @param array $links
422 + * @param array $links
389 423 *
390 424 * @return array
391 425 */
392 - public function plugin_action_links( $links ) {
393 - $links[] = '<a href="https://weformspro.com/?utm_source=weforms-action-link&utm_medium=textlink&utm_campaign=plugin-docs-link" target="_blank">' . __( 'Docs', 'weforms' ) . '</a>';
426 + function plugin_action_links( $links ) {
427 +
394 428 $links[] = '<a href="' . admin_url( 'admin.php?page=weforms' ) . '">' . __( 'Settings', 'weforms' ) . '</a>';
395 429
396 430 return $links;
397 431 }
@@ -396,102 +430,99 @@
396 430 return $links;
397 431 }
398 432
399 433 /**
400 - * Check if the PHP version is supported
434 + * Register default integrations
401 435 *
402 - * @return bool
436 + * @param array $integrations
437 + *
438 + * @return array
403 439 */
404 - public function is_supported_php( $min_php = null ) {
405 - $min_php = $min_php ? $min_php : $this->min_php;
440 + public function register_default_integrations( $integrations ) {
441 + require_once WEFORMS_INCLUDES . '/integrations/slack/class-integration-slack.php';
406 442
407 - if ( version_compare( PHP_VERSION, $min_php, '<=' ) ) {
408 - return false;
409 - }
443 + $integrations = array_merge( $integrations, array( 'WeForms_Integration_Slack' ) );
410 444
411 - return true;
445 + return $integrations;
412 446 }
413 447
414 448 /**
415 - * Show notice about PHP version
449 + * Set the required default settings key if not present
416 450 *
451 + * This is required for setting up the component settings data
452 + *
417 453 * @return void
418 454 */
419 - public function php_version_notice() {
420 - if ( $this->is_supported_php() || !current_user_can( 'manage_options' ) ) {
421 - return;
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 + }
422 470 }
423 471
424 - $error = __( 'Your installed PHP Version is: ', 'weforms' ) . PHP_VERSION . '. ';
425 - $error .= __( 'The <strong>weForms</strong> plugin requires PHP version <strong>', 'weforms' ) . $this->min_php . __( '</strong> or greater.', 'weforms' ); ?>
426 - <div class="error">
427 - <p><?php printf( wp_kses_post ( $error ) ); ?></p>
428 - </div>
429 - <?php
472 + if ( $requires_update ) {
473 + update_option( 'weforms_settings', $settings );
474 + }
430 475 }
431 476
432 477 /**
433 - * Bail out if the php version is lower than
478 + * Create a default form
434 479 *
435 480 * @return void
436 481 */
437 - public function auto_deactivate() {
438 - if ( $this->is_supported_php() ) {
482 + public function create_default_form() {
483 + $version = get_option( 'weforms_version' );
484 +
485 + // seems like it's already installed
486 + if ( $version ) {
439 487 return;
440 488 }
441 489
442 - deactivate_plugins( plugin_basename( __FILE__ ) );
490 + if ( ! function_exists( 'weforms_get_contactform_template_fields' ) ) {
491 + require_once dirname( __FILE__ ) . '/includes/functions-template-contact-form.php';
492 + }
443 493
444 - $error = __( '<h1>An Error Occured</h1>', 'weforms' );
445 - $error .= __( '<h2>Your installed PHP Version is: ', 'weforms' ) . PHP_VERSION . '</h2>';
446 - $error .= __( '<p>The <strong>weforms</strong> plugin requires PHP version <strong>', 'weforms' ) . $this->min_php . __( '</strong> or greater', 'weforms' );
447 - $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>.';
448 - $error .= __( 'You should update your PHP software or contact your host regarding this matter.</p>', 'weforms' );
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 + );
449 500
450 - wp_die( wp_kses_post( $error ), esc_html_e( 'Plugin Activation Error', 'weforms' ), [ 'back_link' => true ] );
451 - }
501 + $form_id = wp_insert_post( $form_post_data );
452 502
453 - /**
454 - * What type of request is this?
455 - *
456 - * @since 1.2.3
457 - *
458 - * @param string $type admin, ajax, cron, api or frontend
459 - *
460 - * @return bool
461 - */
462 - private function is_request( $type ) {
463 - switch ( $type ) {
464 - case 'admin':
465 - return is_admin();
503 + if ( is_wp_error( $form_id ) ) {
504 + return;
505 + }
466 506
467 - case 'ajax':
468 - return defined( 'DOING_AJAX' );
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() );
469 509
470 - case 'cron':
471 - return defined( 'DOING_CRON' );
510 + $form_fields = weforms_get_contactform_template_fields();
472 511
473 - case 'api':
474 - return defined( 'REST_REQUEST' );
475 -
476 - case 'frontend':
477 - return ( !is_admin() || defined( 'DOING_AJAX' ) ) && !defined( 'DOING_CRON' );
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 + }
478 522 }
479 523 }
480 524
481 - /**
482 - * Init appsero tracker
483 - */
484 - private function init_appsero() {
485 - if ( ! class_exists( 'Appsero\Client' ) ) {
486 - require_once WEFORMS_INCLUDES . '/library/appsero/Client.php';
487 - }
488 -
489 - $client = new Appsero\Client( '213fd70e-0bf3-4710-a35e-934b5a376e13', 'weForms', __FILE__ );
490 -
491 - // Active insights
492 - $client->insights()->init();
493 - }
494 525 } // WeForms
495 526
496 527 /**
497 528 * Initialize the plugin