PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.5.5
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.5.5
3.4.2 3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 All 195 releases
← All changes | includes/class-convertkit-setup.php +27 -248 3.3.22.5.5 View file →
@@ -22,32 +22,16 @@
22 22 */
23 23 public function activate() {
24 24
25 25 // Call any functions to e.g. schedule WordPress Cron events now.
26 - $this->schedule_cron_events();
26 + $posts = new ConvertKit_Resource_Posts( 'cron' );
27 + $posts->schedule_cron_event();
27 28
28 - // Install entries database table.
29 - $entries = new ConvertKit_Form_Entries();
30 - $entries->create_database_table();
31 -
32 29 }
33 30
34 31 /**
35 - * Runs routines on every Plugin request e.g.
36 - * ensuring WordPress Cron events are scheduled.
32 + * Runs routines when the Plugin version has been updated.
37 33 *
38 - * @since 2.6.6
39 - */
40 - public function initialize() {
41 -
42 - // Call any functions to e.g. schedule WordPress Cron events now.
43 - $this->schedule_cron_events();
44 -
45 - }
46 -
47 - /**
48 - * Runs routines if the Plugin version has been updated.
49 - *
50 34 * @since 1.9.7.4
51 35 */
52 36 public function update() {
53 37
@@ -60,35 +44,8 @@
60 44 return;
61 45 }
62 46
63 47 /**
64 - * 3.0.4: Add form_id to entries database table.
65 - */
66 - if ( version_compare( $current_version, '3.0.4', '<' ) ) {
67 - $this->add_form_id_column_and_key_to_form_entries_database_table();
68 - }
69 -
70 - /**
71 - * 3.0.0: Migrate reCAPTCHA settings from Restrict Content to General settings.
72 - * Install entries database table.
73 - */
74 - if ( version_compare( $current_version, '3.0.0', '<' ) ) {
75 - $this->migrate_recaptcha_settings();
76 -
77 - // Install entries database table.
78 - $entries = new ConvertKit_Form_Entries();
79 - $entries->create_database_table();
80 - }
81 -
82 - /**
83 - * 2.6.6: Migrate 'Default' Form value in _wp_convertkit_term_meta[form] from 0 to -1,
84 - * to match Posts.
85 - */
86 - if ( version_compare( $current_version, '2.6.6', '<' ) ) {
87 - $this->migrate_term_default_form_settings();
88 - }
89 -
90 - /**
91 48 * 2.5.4: Migrate WishList Member to ConvertKit Form Mappings
92 49 */
93 50 if ( ! $current_version || version_compare( $current_version, '2.5.4', '<' ) ) {
94 51 $this->migrate_wlm_none_setting();
@@ -133,11 +90,19 @@
133 90 $this->migrate_term_form_settings();
134 91 }
135 92
136 93 /**
94 + * 1.6.1+: Refresh Forms, Landing Pages and Tags data stored in settings,
95 + * to get new Forms Builder Settings.
96 + */
97 + if ( version_compare( $current_version, '1.6.1', '<' ) ) {
98 + $this->refresh_resources();
99 + }
100 +
101 + /**
137 102 * 1.9.6+: Migrate _wp_convertkit_settings[default_form] to _wp_convertkit_settings[page_form] and
138 103 * _wp_convertkit_settings[post_form], now that each Post Type has its own Default Form setting
139 - * in Settings > Kit > General.
104 + * in Settings > ConvertKit > General.
140 105 */
141 106 if ( version_compare( $current_version, '1.9.6', '<' ) ) {
142 107 $this->migrate_default_form_settings();
143 108 }
@@ -150,13 +115,8 @@
150 115 $posts = new ConvertKit_Resource_Posts( 'cron' );
151 116 $posts->schedule_cron_event();
152 117 }
153 118
154 - // Actions that should run regardless of the version number
155 - // whenever the Plugin is updated.
156 - $this->remove_v3_api_secret_from_settings();
157 - $this->maybe_delete_old_cached_resource_structure();
158 -
159 119 // Update the installed version number in the options table.
160 120 update_option( 'convertkit_version', CONVERTKIT_PLUGIN_VERSION );
161 121
162 122 }
@@ -161,181 +121,8 @@
161 121
162 122 }
163 123
164 124 /**
165 - * Remove v3 API Secret from settings.
166 - *
167 - * @since 3.2.4
168 - */
169 - private function remove_v3_api_secret_from_settings() {
170 -
171 - $settings = new ConvertKit_Settings();
172 - $settings->save(
173 - array(
174 - 'api_secret' => '',
175 - )
176 - );
177 -
178 - }
179 -
180 - /**
181 - * Deletes any cached resources stored in the options table if they are a flat array
182 - * that originates from between 1.6.0 and 1.9.5.2 of the Plugin.
183 - * i.e. [id => name], rather than the expected [id => [id => '...', name => '...', ...]].
184 - *
185 - * This will permit the Resources classes to fetch and cache the Form resources correctly
186 - * from the API, and prevent fatal errors when a user activates the latest version of the Plugin
187 - * on a site that previously had a very old Plugin version installed.
188 - *
189 - * @since 3.2.5
190 - */
191 - private function maybe_delete_old_cached_resource_structure() {
192 -
193 - // Define the resource options to check.
194 - $resource_options = array(
195 - 'convertkit_forms',
196 - 'convertkit_landing_pages',
197 - 'convertkit_tags',
198 - );
199 -
200 - foreach ( $resource_options as $resource_option ) {
201 - // Get the resource option.
202 - $resource = get_option( $resource_option, false );
203 -
204 - // If the resource option does not exist, there's nothing to delete.
205 - if ( false === $resource ) {
206 - return;
207 - }
208 -
209 - // If the resource structure is correct e.g. [id => [name => '...']], there's nothing to delete.
210 - if ( is_array( reset( $resource ) ) ) {
211 - return;
212 - }
213 -
214 - // Delete the cached resource.
215 - delete_option( $resource_option );
216 - }
217 -
218 - }
219 -
220 - /**
221 - * Adds form_id column and key to form entries database table.
222 - *
223 - * @since 3.0.4
224 - */
225 - private function add_form_id_column_and_key_to_form_entries_database_table() {
226 -
227 - global $wpdb;
228 -
229 - // Check if the column exists.
230 - $exists = $wpdb->get_var(
231 - $wpdb->prepare(
232 - 'SELECT COLUMN_NAME
233 - FROM INFORMATION_SCHEMA.COLUMNS
234 - WHERE table_name = %s
235 - AND table_schema = %s
236 - AND column_name = %s',
237 - $wpdb->prefix . 'kit_form_entries',
238 - $wpdb->dbname,
239 - 'form_id'
240 - )
241 - );
242 -
243 - // If the column exists, don't add it again.
244 - if ( $exists === 'form_id' ) {
245 - return;
246 - }
247 -
248 - // Add the form_id column and key.
249 - $wpdb->query(
250 - $wpdb->prepare( 'ALTER TABLE %i ADD COLUMN `form_id` int(11) NOT NULL AFTER `custom_fields`', $wpdb->prefix . 'kit_form_entries' )
251 - );
252 - $wpdb->query(
253 - $wpdb->prepare( 'ALTER TABLE %i ADD KEY `form_id` (`form_id`)', $wpdb->prefix . 'kit_form_entries' )
254 - );
255 -
256 - }
257 -
258 - /**
259 - * 3.0.0: Migrate reCAPTCHA settings from Restrict Content settings to General settings.
260 - *
261 - * @since 3.0.0
262 - */
263 - private function migrate_recaptcha_settings() {
264 -
265 - // Read Restrict Content settings directly from options table,
266 - // as Convertkit_Settings_Restrict_Content won't have helper
267 - // methods to return the specific settings.
268 - $settings = get_option( '_wp_convertkit_settings_restrict_content' );
269 -
270 - // If no reCAPTCHA settings exist, bail.
271 - if ( ! isset( $settings['recaptcha_site_key'] ) || ! isset( $settings['recaptcha_secret_key'] ) || ! isset( $settings['recaptcha_minimum_score'] ) ) {
272 - return;
273 - }
274 -
275 - // Load settings class, saving the reCAPTCHA settings to the General settings.
276 - $convertkit_settings = new ConvertKit_Settings();
277 - $convertkit_settings->save(
278 - array(
279 - 'recaptcha_site_key' => $settings['recaptcha_site_key'],
280 - 'recaptcha_secret_key' => $settings['recaptcha_secret_key'],
281 - 'recaptcha_minimum_score' => $settings['recaptcha_minimum_score'],
282 - )
283 - );
284 -
285 - // Remove reCAPTCHA settings from Restrict Content settings.
286 - unset( $settings['recaptcha_site_key'] );
287 - unset( $settings['recaptcha_secret_key'] );
288 - unset( $settings['recaptcha_minimum_score'] );
289 - update_option( '_wp_convertkit_settings_restrict_content', $settings );
290 -
291 - }
292 -
293 - /**
294 - * Change the Default value of 0 to -1 in wp_convertkit_term_meta[form], to
295 - * match how the Default value is stored in Posts.
296 - *
297 - * @since 2.6.6
298 - */
299 - private function migrate_term_default_form_settings() {
300 -
301 - // Get all Terms that have ConvertKit settings defined.
302 - $query = new WP_Term_Query(
303 - array(
304 - 'taxonomy' => 'category',
305 - 'hide_empty' => false,
306 - 'fields' => 'ids',
307 - 'meta_query' => array(
308 - array(
309 - 'key' => '_wp_convertkit_term_meta',
310 - 'comparison' => 'EXISTS',
311 - ),
312 - ),
313 - )
314 - );
315 -
316 - // Bail if no Terms exist.
317 - if ( ! $query->terms ) {
318 - return;
319 - }
320 -
321 - // Iterate through Terms, mapping settings.
322 - foreach ( $query->terms as $term_id ) {
323 - $term_settings = new ConvertKit_Term( $term_id );
324 -
325 - // If the Form setting is Default i.e. it does not have a formchange it from 0 to -1.
326 - if ( ! $term_settings->has_form() ) {
327 - $term_settings->save(
328 - array(
329 - 'form' => -1,
330 - )
331 - );
332 - }
333 - }
334 -
335 - }
336 -
337 - /**
338 125 * 2.5.4: Migrate WLM settings:
339 126 * - Prefix any WishList Member to ConvertKit Form ID mappings with `form:`,
340 127 * - Prefix any WishList Member to ConvertKit Tag ID mappings with `tag:`,
341 128 * - Standardise the settings keys to the format {wlm_level_id}_subscribe
@@ -616,10 +403,9 @@
616 403 // Get Access Token by API Key and Secret.
617 404 $api = new ConvertKit_API_V4( CONVERTKIT_OAUTH_CLIENT_ID, CONVERTKIT_OAUTH_CLIENT_REDIRECT_URI );
618 405 $result = $api->get_access_token_by_api_key_and_secret(
619 406 $convertkit_settings->get_api_key(),
620 - $convertkit_settings->get_api_secret(),
621 - get_site_url()
407 + $convertkit_settings->get_api_secret()
622 408 );
623 409
624 410 // Bail if an error occured.
625 411 if ( is_wp_error( $result ) ) {
@@ -685,9 +471,9 @@
685 471
686 472 /**
687 473 * 1.9.6+: Migrate _wp_convertkit_settings[default_form] to _wp_convertkit_settings[page_form] and
688 474 * _wp_convertkit_settings[post_form], now that each Post Type has its own Default Form setting
689 - * in Settings > Kit > General.
475 + * in Settings > ConvertKit > General.
690 476 */
691 477 private function migrate_default_form_settings() {
692 478
693 479 $convertkit_settings = new ConvertKit_Settings();
@@ -713,38 +499,31 @@
713 499
714 500 }
715 501
716 502 /**
717 - * Runs routines when the Plugin is deactivated.
718 - *
719 - * @since 1.9.7.4
503 + * 1.6.1: Refresh Forms, Landing Pages and Tags data stored in settings,
504 + * to get new Forms Builder Settings.
720 505 */
721 - public function deactivate() {
506 + private function refresh_resources() {
722 507
723 - // Call any functions to e.g. unschedule WordPress Cron events now.
724 - $this->unschedule_cron_events();
508 + $forms = new ConvertKit_Resource_Forms( 'setup' );
509 + $landing_pages = new ConvertKit_Resource_Landing_Pages( 'setup' );
510 + $tags = new ConvertKit_Resource_Tags( 'setup' );
725 511
726 - }
512 + $forms->refresh();
513 + $landing_pages->refresh();
514 + $tags->refresh();
727 515
728 - /**
729 - * Schedules any Plugin specific CRON events, if they do not already exist.
730 - *
731 - * @since 2.6.6
732 - */
733 - private function schedule_cron_events() {
734 -
735 - $posts = new ConvertKit_Resource_Posts( 'cron' );
736 - $posts->schedule_cron_event();
737 -
738 516 }
739 517
740 518 /**
741 - * Unschedules any Plugin specific CRON events, if they exist.
519 + * Runs routines when the Plugin is deactivated.
742 520 *
743 - * @since 2.6.6
521 + * @since 1.9.7.4
744 522 */
745 - private function unschedule_cron_events() {
523 + public function deactivate() {
746 524
525 + // Call any functions to e.g. unschedule WordPress Cron events now.
747 526 $posts = new ConvertKit_Resource_Posts( 'cron' );
748 527 $posts->unschedule_cron_event();
749 528
750 529 }