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