PluginProbe ʕ •ᴥ•ʔ
WPForms – Easy Form Builder for WordPress – Contact Forms, Payment Forms, Surveys, & More / 1.10.0.3
WPForms – Easy Form Builder for WordPress – Contact Forms, Payment Forms, Surveys, & More v1.10.0.3
1.10.1.1 1.10.1 1.10.0.5 trunk 1.1.4 1.1.4.2 1.1.5 1.1.5.1 1.1.6 1.1.6.1 1.1.7 1.1.7.1 1.1.7.2 1.1.8 1.1.8.1 1.1.8.2 1.1.8.3 1.1.8.4 1.10.0.1 1.10.0.2 1.10.0.3 1.10.0.4 1.2.0 1.2.0.1 1.2.1 1.2.2 1.2.2.1 1.2.2.2 1.2.3 1.2.3.1 1.2.3.2 1.2.4 1.2.4.1 1.2.5 1.2.5.1 1.2.6 1.2.7 1.2.8 1.2.8.1 1.2.9 1.3.0 1.3.1 1.3.1.1 1.3.1.2 1.3.2 1.3.3 1.3.5 1.3.6 1.3.6.1 1.3.6.2 1.3.7.2 1.3.7.3 1.3.7.4 1.3.8 1.3.9.1 1.4.0.1 1.4.1.1 1.4.2 1.4.2.1 1.4.2.2 1.4.3 1.4.4 1.4.4.1 1.4.5 1.4.5.1 1.4.5.2 1.4.5.3 1.4.6 1.4.7.1 1.4.7.2 1.4.8.1 1.4.9 1.5.0.1 1.5.0.3 1.5.0.4 1.5.1 1.5.1.1 1.5.1.3 1.5.2.1 1.5.2.2 1.5.2.3 1.5.3 1.5.3.1 1.5.4.1 1.5.4.2 1.5.5 1.5.5.1 1.5.6 1.5.6.2 1.5.7 1.5.8.2 1.5.9.1 1.5.9.4 1.5.9.5 1.6.0.1 1.6.0.2 1.6.1 1.6.2.2 1.6.2.3 1.6.3.1 1.6.4 1.6.4.1 1.6.5 1.6.6 1.6.7 1.6.7.1 1.6.7.2 1.6.7.3 1.6.8 1.6.8.1 1.6.9 1.7.0 1.7.1.1 1.7.1.2 1.7.2 1.7.2.1 1.7.3 1.7.4 1.7.4.1 1.7.4.2 1.7.5.1 1.7.5.2 1.7.5.3 1.7.5.5 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.7.9.1 1.8.0.1 1.8.0.2 1.8.1.1 1.8.1.2 1.8.1.3 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.3.1 1.8.4 1.8.4.1 1.8.5.2 1.8.5.3 1.8.5.4 1.8.6.2 1.8.6.3 1.8.6.4 1.8.7.2 1.8.8.2 1.8.8.3 1.8.9.1 1.8.9.2 1.8.9.4 1.8.9.5 1.8.9.6 1.9.0.1 1.9.0.2 1.9.0.3 1.9.0.4 1.9.1.1 1.9.1.2 1.9.1.3 1.9.1.4 1.9.1.5 1.9.1.6 1.9.2.1 1.9.2.2 1.9.2.3 1.9.3.1 1.9.3.2 1.9.4.1 1.9.4.2 1.9.5 1.9.5.1 1.9.5.2 1.9.6 1.9.6.1 1.9.6.2 1.9.7.1 1.9.7.2 1.9.7.3 1.9.8.1 1.9.8.2 1.9.8.4 1.9.8.7 1.9.9.2 1.9.9.3 1.9.9.4
wpforms-lite / includes / class-install.php
wpforms-lite / includes Last commit date
admin 2 months ago emails 4 months ago fields 2 months ago functions 2 months ago providers 10 months ago templates 4 months ago class-db.php 1 year ago class-fields.php 1 year ago class-form.php 4 months ago class-install.php 1 year ago class-process.php 4 months ago class-providers.php 1 year ago class-templates.php 2 years ago class-widget.php 1 year ago deprecated.php 8 months ago functions-list.php 3 years ago functions.php 11 months ago integrations.php 4 months ago
class-install.php
230 lines
1 <?php
2
3 // phpcs:disable Generic.Commenting.DocComment.MissingShort
4 /** @noinspection PhpIllegalPsrClassPathInspection */
5 /** @noinspection AutoloadingIssuesInspection */
6 // phpcs:enable Generic.Commenting.DocComment.MissingShort
7
8 use WPForms\Helpers\DB;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 /**
15 * Handle plugin installation upon activation.
16 *
17 * @since 1.0.0
18 */
19 class WPForms_Install {
20
21 /**
22 * Primary class constructor.
23 *
24 * @since 1.0.0
25 */
26 public function __construct() {
27
28 // When activated, trigger install method.
29 register_activation_hook( WPFORMS_PLUGIN_FILE, [ $this, 'install' ] );
30 register_deactivation_hook( WPFORMS_PLUGIN_FILE, [ $this, 'deactivate' ] );
31
32 $this->hooks();
33 }
34
35 /**
36 * Hooks.
37 *
38 * @since 1.9.0
39 *
40 * @return void
41 */
42 private function hooks() {
43
44 // Watch for new multisite blogs.
45 add_action( 'wp_initialize_site', [ $this, 'new_multisite_blog' ], 10, 2 );
46
47 // Watch for delayed admin install.
48 add_action( 'admin_init', [ $this, 'admin' ] );
49 }
50
51 /**
52 * Perform certain actions on plugin activation.
53 *
54 * @since 1.0.0
55 *
56 * @param bool $network_wide Whether to enable the plugin for all sites in the network
57 * or just the current site. Multisite only. Default is false.
58 *
59 * @noinspection DisconnectedForeachInstructionInspection
60 */
61 public function install( $network_wide = false ) {
62
63 // Check if we are on multisite and network activating.
64 if ( $network_wide && is_multisite() ) {
65
66 // Multisite - go through each subsite and run the installer.
67 $sites = get_sites(
68 [
69 'fields' => 'ids',
70 'number' => 0,
71 ]
72 );
73
74 foreach ( $sites as $blog_id ) {
75 switch_to_blog( $blog_id );
76 $this->run();
77 restore_current_blog();
78 }
79 } else {
80
81 // Normal single site.
82 $this->run();
83 }
84
85 set_transient( 'wpforms_just_activated', wpforms()->is_pro() ? 'pro' : 'lite', 60 );
86
87 // Abort, so we only set the transient for single site installs.
88 if ( isset( $_GET['activate-multi'] ) || is_network_admin() ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
89 return;
90 }
91
92 // Add transient to trigger redirect to the Welcome screen.
93 set_transient( 'wpforms_activation_redirect', true, 30 );
94 }
95
96 /**
97 * Run manual installation.
98 *
99 * @since 1.5.4.2
100 *
101 * @param bool $silent Silent install, disables welcome page.
102 */
103 public function manual( $silent = false ) {
104
105 $this->install( is_plugin_active_for_network( plugin_basename( WPFORMS_PLUGIN_FILE ) ) );
106
107 if ( $silent ) {
108 delete_transient( 'wpforms_activation_redirect' );
109 }
110 }
111
112 /**
113 * Perform certain actions on plugin deactivation.
114 *
115 * @since 1.5.9
116 */
117 public function deactivate() {
118
119 // Unschedule all ActionScheduler actions by group.
120 wpforms()->obj( 'tasks' )->cancel_all();
121
122 // Remove plugin cron jobs.
123 wp_clear_scheduled_hook( 'wpforms_email_summaries_cron' );
124
125 // Check if the event is scheduled before attempting to clear it.
126 // This event is only registered for the Lite edition of the plugin.
127 // It's advisable to verify if the CRON event is scheduled using `wp_next_scheduled`.
128 // This precaution ensures that you are not attempting to clear a scheduled
129 // hook that may not exist, which could result in unexpected behavior.
130 if ( wp_next_scheduled( 'wpforms_weekly_entries_count_cron' ) ) {
131 wp_clear_scheduled_hook( 'wpforms_weekly_entries_count_cron' );
132 }
133 }
134
135 /**
136 * Watch for delayed install procedure from WPForms admin.
137 *
138 * @since 1.5.4.2
139 */
140 public function admin() {
141
142 if ( ! is_admin() ) {
143 return;
144 }
145
146 $install = get_option( 'wpforms_install', false );
147
148 if ( empty( $install ) ) {
149 return;
150 }
151
152 $this->manual( true );
153
154 delete_option( 'wpforms_install' );
155 }
156
157 /**
158 * Run the actual installer.
159 *
160 * @since 1.5.4.2
161 */
162 protected function run() {
163
164 // Create custom database tables.
165 $this->maybe_create_tables();
166
167 // Hook for Pro users.
168 /**
169 * Fires before WPForms plugin installation is performed.
170 *
171 * @since 1.3.0
172 */
173 do_action( 'wpforms_install' );
174
175 /*
176 * Set the current version to be referenced in future updates.
177 */
178 // Used by Pro migrations.
179 update_option( 'wpforms_version', WPFORMS_VERSION );
180 // Used by Lite migrations.
181 update_option( 'wpforms_version_lite', WPFORMS_VERSION );
182
183 // Store the date when the initial activation was performed.
184 $type = class_exists( 'WPForms_Lite', false ) ? 'lite' : 'pro';
185 $activated = (array) get_option( 'wpforms_activated', [] );
186
187 if ( empty( $activated[ $type ] ) ) {
188 $activated[ $type ] = time();
189
190 update_option( 'wpforms_activated', $activated );
191 }
192 }
193
194 /**
195 * When a new site is created in multisite, see if we are network activated,
196 * and if so run the installer.
197 *
198 * @since 1.3.0
199 * @since 1.8.4 Added $new_site and $args parameters and removed $blog_id, $user_id, $domain, $path, $site_id,
200 * and $meta parameters.
201 *
202 * @param WP_Site $new_site New site object.
203 * @param array $args Arguments for the initialization.
204 *
205 * @noinspection PhpUnusedParameterInspection
206 * @noinspection PhpMissingParamTypeInspection
207 */
208 public function new_multisite_blog( $new_site, $args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
209
210 if ( is_plugin_active_for_network( plugin_basename( WPFORMS_PLUGIN_FILE ) ) ) {
211 switch_to_blog( $new_site->blog_id );
212 $this->run();
213 restore_current_blog();
214 }
215 }
216
217 /**
218 * Create database tables if they do not exist.
219 * It covers new installations.
220 *
221 * @since 1.8.2
222 */
223 private function maybe_create_tables() {
224
225 DB::create_custom_tables( true );
226 }
227 }
228
229 new WPForms_Install();
230