PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 3.6.2
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v3.6.2
6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 3.6.66 All 195 releases
fluentform / app / Modules / Activator.php

Activator.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 3.6.2, at app/Modules/Activator.php

154 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace FluentForm\App\Modules;
3
4 use FluentForm\App\Databases\Migrations\FormLogs;
5 use FluentForm\App\Databases\Migrations\FormSubmissionDetails;
6 use FluentForm\App\Modules\Acl\Acl;
7 use FluentForm\App\Databases\DatabaseMigrator;
8
9 class Activator
10 {
11 /**
12 * This method will be called on plugin activation
13 * @return void
14 */
15 public function handleActivation($network_wide)
16 {
17 global $wpdb;
18 if ($network_wide) {
19 // Retrieve all site IDs from this network (WordPress >= 4.6 provides easy to use functions for that).
20 if (function_exists('get_sites') && function_exists('get_current_network_id')) {
21 $site_ids = get_sites(array('fields' => 'ids', 'network_id' => get_current_network_id()));
22 } else {
23 $site_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE site_id = $wpdb->siteid;");
24 }
25 // Install the plugin for all these sites.
26 foreach ($site_ids as $site_id) {
27 switch_to_blog($site_id);
28 $this->migrate();
29 restore_current_blog();
30 }
31 } else {
32 $this->migrate();
33 }
34
35 self::setCronSchedule();
36 }
37
38 public function migrate()
39 {
40 // We are going to migrate all the database tables here.
41 DatabaseMigrator::run();
42 // Assign fluentform permission set.
43 Acl::setPermissions();
44 $this->setDefaultGlobalSettings();
45 $this->setCurrentVersion();
46 $this->maybeMigrateDB();
47 }
48
49 public function maybeMigrateDB()
50 {
51 // First we have to check if global modules is set or not
52 $this->migrateGlobalAddOns();
53
54 if(!get_option('fluentform_entry_details_migrated')) {
55 FormSubmissionDetails::migrate();
56 }
57
58 if(!get_option('fluentform_db_fluentform_logs_added')) {
59 FormLogs::migrate();
60 }
61 }
62
63 public function migrateGlobalAddOns()
64 {
65 $globalModules = get_option('fluentform_global_modules_status');
66 // Modules already set
67 if(is_array($globalModules)) {
68 return;
69 }
70
71 $possibleGloablModules = [
72 'mailchimp' => '_fluentform_mailchimp_details',
73 'activecampaign' => '_fluentform_activecampaign_settings',
74 'campaign_monitor' => '_fluentform_campaignmonitor_settings',
75 'constatantcontact' => '_fluentform_constantcontact_settings',
76 'getresponse' => '_fluentform_getresponse_settings',
77 'icontact' => '_fluentform_icontact_settings'
78 ];
79
80 $possibleMetaModules = [
81 'webhook' => 'fluentform_webhook_feed',
82 'zapier' => 'fluentform_zapier_feed',
83 'slack' => 'slack'
84 ];
85
86 $moduleStatuses = [];
87 foreach ($possibleGloablModules as $moduleName => $settingsKey)
88 {
89 if(get_option($settingsKey)) {
90 $moduleStatuses[$moduleName] = 'yes';
91 } else {
92 $moduleStatuses[$moduleName] = 'no';
93 }
94 }
95
96 global $wpdb;
97
98 foreach ($possibleMetaModules as $moduleName => $metaName) {
99 $row = $wpdb->get_row("SELECT * FROM `{$wpdb->prefix}fluentform_form_meta` WHERE `meta_key` = '{$metaName}' LIMIT 1");
100
101 if ($row) {
102 $moduleStatuses[$moduleName] = 'yes';
103 } else {
104 $moduleStatuses[$moduleName] = 'no';
105 }
106 }
107
108 update_option('fluentform_global_modules_status', $moduleStatuses, 'no');
109 }
110
111 private function setDefaultGlobalSettings()
112 {
113 if (!get_option('_fluentform_global_form_settings')) {
114 update_option('__fluentform_global_form_settings', array(
115 'layout' => array(
116 'labelPlacement' => 'top',
117 'asteriskPlacement' => 'asterisk-right',
118 'helpMessagePlacement' => 'with_label',
119 'errorMessagePlacement' => 'inline',
120 'cssClassName' => ''
121 )
122 ), 'no');
123 }
124 }
125
126 private function setCurrentVersion()
127 {
128 update_option('_fluentform_installed_version', FLUENTFORM_VERSION, 'no');
129 }
130
131 public static function setCronSchedule()
132 {
133
134 add_filter('cron_schedules', function ($schedules) {
135 $schedules['ff_every_five_minutes'] = array(
136 'interval' => 300,
137 'display' => esc_html__('Every 5 Minutes (FluentForm)', 'fluentform'),
138 );
139 return $schedules;
140 }, 10, 1);
141
142 $hookName = 'fluentform_do_scheduled_tasks';
143 if (!wp_next_scheduled($hookName)) {
144 wp_schedule_event(time(), 'ff_every_five_minutes', $hookName);
145 }
146
147 $emailReportHookName = 'fluentform_do_email_report_scheduled_tasks';
148 if (!wp_next_scheduled($emailReportHookName)) {
149 wp_schedule_event(time(), 'daily', $emailReportHookName);
150 }
151
152 }
153 }
154