├── css
└── form_settings.css
├── entryexpiration.php
├── readme.txt
└── class-gf-entryexpiration.php
/css/form_settings.css:
--------------------------------------------------------------------------------
1 | .gaddon-setting.small {
2 | width: 10%;
3 | }
4 |
--------------------------------------------------------------------------------
/entryexpiration.php:
--------------------------------------------------------------------------------
1 | #### [Entry Automation for Gravity Forms](https://cosmicgiant.com/plugins/entry-automation/?utm_source=wordpress&utm_medium=readme&utm_campaign=readme) makes entry deletion more powerful and allows you to export your entries too!
14 | >
15 | > Entry Expiration started out as a simple tool to automatically remove your old form entries. But what if you need more control over when entries are deleted? Want to apply conditional logic to target specific entries? Or maybe delete specific field values rather than the whole entry? Need to generate an export file before getting rid of those entries?
16 | >
17 | > [Check out Entry Automation](https://cosmicgiant.com/plugins/entry-automation/?utm_source=wordpress&utm_medium=readme&utm_campaign=readme) today!
18 |
19 |
20 | When integrating Gravity Forms with a third-party service, it's often not necessary to keep entries around after a short period of time as you already have the data imported elsewhere.
21 |
22 | Entry Expiration for Gravity Forms allows you to automatically delete Gravity Forms entries older than a defined timeframe. After activating the plugin, set the oldest age for an entry on the Entry Expiration Settings page. At midnight, the plugin will delete all entries on enabled forms that are older than the time you set.
23 |
24 | == Installation ==
25 | = Requirements =
26 | * WordPress version 5.3.0 and later (tested at 5.8.0)
27 | * Gravity Forms 1.8.17 and later
28 |
29 | = Installation =
30 | 1. Unpack the download package.
31 | 1. Upload all files to the `/wp-content/plugins/` directory, with folder
32 | 1. Activate the plugin through the 'Plugins' menu in WordPress
33 | 1. Navigate to the Form Settings page for each form you want to have entries automatically expire and click the 'Entry Expiration' tab.
34 | 1. Define how often you want entries to be deleted and the minimum age required for entries to be deleted.
35 |
36 | == Changelog ==
37 | = Version 2.2.1 (2023-08-01) =
38 | - Updated references to ForGravity.
39 | - Updated WordPress tested up to version.
40 | = Version 2.2 (2021-09-02) =
41 | * Fixed entries not deleting on schedule when server and WordPress timezones do not match.
42 | = Version 2.1 (2020-08-07) =
43 | * Added capabilities.
44 | * Added support for Gravity Forms 2.5.
45 | * Updated installation instructions.
46 | * Fixed fatal error during 2.0 upgrade process.
47 | * Fixed PHP notices.
48 | * Fixed search criteria not correctly preparing in certain scenarios.
49 | * Fixed search criteria not correctly preparing the search end date.
50 | = Version 2.0 =
51 | * Added additional logging
52 | * Added expiration time and recurrence at the form level.
53 | * Added filter for setting entry expiration time for each form
54 | * Adjusted entry older than date to not be relative to midnight
55 | * Changed plugin loading method.
56 | * Rewrote expiration procedure to be more efficient.
57 | = Version 1.2 =
58 | * Fixed update routine to not automatically enable forms for processing if running a fresh install
59 | * Changed expiration time setting to allow choosing between hours, days, weeks and months
60 | = Version 1.1 =
61 | * Switched forms from being able to be excluded to having to include them for processing
62 | * Deletion cron now runs hourly instead of daily
63 | * Cron now only deletes 1000 entries at a time to prevent long execution times
64 | * Added filters for: payment status, number of entries to be processed at a time
65 | = Version 1.0 =
66 | * Initial release
67 |
--------------------------------------------------------------------------------
/class-gf-entryexpiration.php:
--------------------------------------------------------------------------------
1 | $this->_slug . '_form_settings',
192 | 'src' => $this->get_base_url() . '/css/form_settings.css',
193 | 'version' => $this->_version,
194 | 'enqueue' => array( array( 'admin_page' => array( 'form_settings' ) ) ),
195 | ),
196 | );
197 |
198 | return array_merge( parent::styles(), $styles );
199 |
200 | }
201 |
202 |
203 |
204 |
205 |
206 | // # SETUP ---------------------------------------------------------------------------------------------------------
207 |
208 | /**
209 | * Add quarter-hourly cron schedule.
210 | *
211 | * @since 2.0
212 | * @access public
213 | *
214 | * @param array $schedules An array of non-default cron schedules.
215 | *
216 | * @return array
217 | */
218 | public function add_cron_schedule( $schedules = array() ) {
219 |
220 | // Add fifteen minutes.
221 | if ( ! isset( $schedules['fifteen_minutes'] ) ) {
222 | $schedules['fifteen_minutes'] = array(
223 | 'interval' => 15 * MINUTE_IN_SECONDS,
224 | 'display' => esc_html__( 'Every Fifteen Minutes', 'gravity-forms-entry-expiration' ),
225 | );
226 | }
227 |
228 | return $schedules;
229 |
230 | }
231 |
232 | /**
233 | * Display upgrade message.
234 | *
235 | * @since 2.1
236 | */
237 | public function maybe_display_upgrade_message() {
238 |
239 | // If message has already been displayed, exit.
240 | if ( get_option( 'gf_entryexpiration_message_displayed', false ) ) {
241 | return;
242 | }
243 |
244 | // Get lifetime processed entries.
245 | $lifetime_processed = get_option( 'gf_entryexpiration_lifetime_processed', 0 );
246 |
247 | // If we have not yet processed 100 entries, exit.
248 | if ( $lifetime_processed < 100 ) {
249 | return;
250 | }
251 |
252 | // Round processed entries.
253 | $lifetime_processed = ceil( $lifetime_processed / 100 ) * 100;
254 |
255 | // Prepare message.
256 | $message = sprintf(
257 | 'Entry Expiration has removed over %d entries!
Upgrade to Entry Automation to delete entries based off conditional logic, delete only specific fields from an entry and automatically export entries!',
258 | $lifetime_processed,
259 | 'https://cosmicgiant.com/plugins/entry-automation/?utm_source=wordpress&utm_medium=alert&utm_campaign=entry_expiration'
260 | );
261 |
262 | // Display message.
263 | GFCommon::add_dismissible_message( $message, 'gf_entryexpiration_upgrade_message', 'success', 'update_options', true );
264 |
265 | // Set flag that message was displayed.
266 | update_option( 'gf_entryexpiration_message_displayed', true );
267 |
268 | }
269 |
270 |
271 |
272 |
273 | // # UNINSTALL -----------------------------------------------------------------------------------------------------
274 |
275 | /**
276 | * Remove cron event.
277 | *
278 | * @since 2.0
279 | * @access public
280 | *
281 | * @param array $schedules An array of non-default cron schedules.
282 | *
283 | * @return array
284 | */
285 | public function uninstall( $schedules = array() ) {
286 |
287 | wp_clear_scheduled_hook( 'gf_entryexpiration_maybe_expire' );
288 |
289 | }
290 |
291 |
292 |
293 |
294 |
295 | // # FORM SETTINGS -------------------------------------------------------------------------------------------------
296 |
297 | /**
298 | * Setup fields for form settings.
299 | *
300 | * @since 2.0
301 | * @access public
302 | *
303 | * @param array $form The current form object.
304 | *
305 | * @return array
306 | */
307 | public function form_settings_fields( $form ) {
308 |
309 | return array(
310 | array(
311 | 'fields' => array(
312 | array(
313 | 'name' => 'deletionEnable',
314 | 'label' => esc_html__( 'Enable Expiration', 'gravity-forms-entry-expiration' ),
315 | 'type' => 'checkbox',
316 | 'onclick' => "jQuery( this ).parents( 'form' ).submit()",
317 | 'choices' => array(
318 | array(
319 | 'name' => 'deletionEnable',
320 | 'label' => esc_html__( 'Automatically delete form entries on a defined schedule', 'gravity-forms-entry-expiration' ),
321 | ),
322 | ),
323 | ),
324 | array(
325 | 'name' => 'deletionDate',
326 | 'label' => esc_html__( 'Delete entries older than', 'gravity-forms-entry-expiration' ),
327 | 'type' => 'text_select',
328 | 'required' => true,
329 | 'dependency' => array( 'field' => 'deletionEnable', 'values' => array( '1' ) ),
330 | 'text' => array(
331 | 'name' => 'deletionDate[number]',
332 | 'class' => 'small',
333 | 'input_type' => 'number',
334 | 'after_input' => ' ',
335 | ),
336 | 'select' => array(
337 | 'name' => 'deletionDate[unit]',
338 | 'choices' => array(
339 | array( 'label' => 'minutes', 'value' => esc_html__( 'minutes', 'gravity-forms-entry-expiration' ) ),
340 | array( 'label' => 'hours', 'value' => esc_html__( 'hours', 'gravity-forms-entry-expiration' ) ),
341 | array( 'label' => 'days', 'value' => esc_html__( 'days', 'gravity-forms-entry-expiration' ) ),
342 | array( 'label' => 'weeks', 'value' => esc_html__( 'weeks', 'gravity-forms-entry-expiration' ) ),
343 | array( 'label' => 'months', 'value' => esc_html__( 'months', 'gravity-forms-entry-expiration' ) ),
344 | array( 'label' => 'years', 'value' => esc_html__( 'years', 'gravity-forms-entry-expiration' ) ),
345 | ),
346 | ),
347 | ),
348 | array(
349 | 'name' => 'deletionRunTime',
350 | 'label' => esc_html__( 'Run deletion every', 'gravity-forms-entry-expiration' ),
351 | 'type' => 'text_select',
352 | 'required' => true,
353 | 'dependency' => array( 'field' => 'deletionEnable', 'values' => array( '1' ) ),
354 | 'text' => array(
355 | 'name' => 'deletionRunTime[number]',
356 | 'class' => 'small',
357 | 'input_type' => 'number',
358 | 'after_input' => ' ',
359 | ),
360 | 'select' => array(
361 | 'name' => 'deletionRunTime[unit]',
362 | 'choices' => array(
363 | array( 'label' => 'hours', 'value' => esc_html__( 'hours', 'gravity-forms-entry-expiration' ) ),
364 | array( 'label' => 'days', 'value' => esc_html__( 'days', 'gravity-forms-entry-expiration' ) ),
365 | ),
366 | ),
367 | ),
368 | ),
369 | ),
370 | array(
371 | 'fields' => array(
372 | array(
373 | 'type' => 'save',
374 | 'messages' => array(
375 | 'error' => esc_html__( 'There was an error while saving the Entry Expiration settings. Please review the errors below and try again.', 'gravity-forms-entry-expiration' ),
376 | 'success' => esc_html__( 'Entry Expiration settings updated.', 'gravity-forms-entry-expiration' ),
377 | ),
378 | ),
379 | ),
380 | ),
381 | );
382 |
383 | }
384 |
385 | /**
386 | * Render a select settings field.
387 | *
388 | * @since 2.0
389 | * @access public
390 | *
391 | * @param array $field Field settings.
392 | * @param bool $echo Display field. Defaults to true.
393 | *
394 | * @uses GFAddOn::field_failed_validation()
395 | * @uses GFAddOn::get_error_icon()
396 | * @uses GFAddOn::get_field_attributes()
397 | * @uses GFAddOn::get_select_options()
398 | * @uses GFAddOn::get_setting()
399 | *
400 | * @return string
401 | */
402 | public function settings_select( $field, $echo = true ) {
403 |
404 | // Get after select value.
405 | $after_select = rgar( $field, 'after_select' );
406 |
407 | // Remove after select property.
408 | unset( $field['after_select'] );
409 |
410 | // Get select field markup.
411 | $html = parent::settings_select( $field, false );
412 |
413 | // Add after select.
414 | if ( ! rgblank( $after_select ) ) {
415 | $html .= ' ' . $after_select;
416 | }
417 |
418 | if ( $echo ) {
419 | echo $html;
420 | }
421 |
422 | return $html;
423 |
424 | }
425 |
426 | /**
427 | * Render a text and select settings field.
428 | *
429 | * @since 2.0
430 | * @access public
431 | *
432 | * @param array $field Field settings.
433 | * @param bool $echo Display field. Defaults to true.
434 | *
435 | * @return string
436 | */
437 | public function settings_text_select( $field, $echo = true ) {
438 |
439 | // Initialize return HTML.
440 | $html = '';
441 |
442 | // Prepare text field.
443 | $text_field = $field['text'];
444 | $text_field['type'] = 'text';
445 |
446 | // Prepare select field.
447 | $select_field = $field['select'];
448 | $select_field['type'] = 'select';
449 |
450 | $html .= $this->settings_text( $text_field, false );
451 | $html .= $this->settings_select( $select_field, false );
452 |
453 | if ( $this->field_failed_validation( $field ) ) {
454 | $html .= $this->get_error_icon( $field );
455 | }
456 |
457 | if ( $echo ) {
458 | echo $html;
459 | }
460 |
461 | return $html;
462 |
463 | }
464 |
465 | /**
466 | * Validates a text and select settings field.
467 | *
468 | * @since 2.0
469 | * @access public
470 | *
471 | * @param array $field Field settings.
472 | * @param array $settings Submitted settings values.
473 | */
474 | public function validate_text_select_settings( $field, $settings ) {
475 |
476 | // Convert text field name.
477 | $text_field_name = str_replace( array( '[', ']' ), array( '/', '' ), $field['text']['name'] );
478 |
479 | // Get text field value.
480 | $text_field_value = rgars( $settings, $text_field_name );
481 |
482 | // If text field is empty and field is required, set error.
483 | if ( rgblank( $text_field_value ) && rgar( $field, 'required' ) ) {
484 | $this->set_field_error( $field, esc_html__( 'This field is required.', 'gravity-forms-entry-expiration' ) );
485 | return;
486 | }
487 |
488 | // If text field is not numeric, set error.
489 | if ( ! rgblank( $text_field_value ) && ! ctype_digit( $text_field_value ) ) {
490 | $this->set_field_error( $field, esc_html__( 'You must use a whole number.', 'gravity-forms-entry-expiration' ) );
491 | return;
492 | }
493 |
494 | }
495 |
496 | /**
497 | * Define the title for the form settings page.
498 | *
499 | * @since 2.0
500 | * @access public
501 | *
502 | * @return string
503 | */
504 | public function form_settings_page_title() {
505 |
506 | return esc_html__( 'Entry Expiration Settings', 'gravity-forms-entry-expiration' );
507 |
508 | }
509 |
510 |
511 |
512 |
513 |
514 | // # ENTRY EXPIRATION ----------------------------------------------------------------------------------------------
515 |
516 | /**
517 | * Run Entry Expiration on forms that pass expiration conditions.
518 | *
519 | * @since 2.0
520 | * @access public
521 | *
522 | * @uses GFAPI::get_forms()
523 | * @uses GF_Entry_Expiration::maybe_run_deletion()
524 | */
525 | public function maybe_run_expiration() {
526 |
527 | // Get forms.
528 | $forms = GFAPI::get_forms();
529 |
530 | // Loop through forms.
531 | foreach ( $forms as $form ) {
532 |
533 | // Get Entry Expiration settings.
534 | $settings = rgar( $form, $this->_slug );
535 |
536 | // If deletion is enabled, run deletion.
537 | if ( rgar( $settings, 'deletionEnable' ) ) {
538 | $this->maybe_run_deletion( $form, $settings );
539 | }
540 |
541 | }
542 |
543 | }
544 |
545 | /**
546 | * Delete entries if form pass conditions.
547 | *
548 | * @since 1.0
549 | * @access public
550 | *
551 | * @param array $form The form object.
552 | * @param array $settings Entry Expiration settings.
553 | *
554 | * @uses GFAPI::count_entries()
555 | * @uses GF_Entry_Expiration::delete_form_entries()
556 | * @uses GF_Entry_Expiration::get_search_criteria()
557 | */
558 | public function maybe_run_deletion( $form, $settings ) {
559 |
560 | // Get Entry Expiration transient for deletion.
561 | $transient_exists = get_transient( $this->_slug . '_' . $form['id'] );
562 |
563 | // If transient exists, skip form.
564 | if ( '1' === $transient_exists ) {
565 | $this->log_debug( __METHOD__ . '(): Skipping deletion for form #' . $form['id'] . ' because it is not due to be run yet.' );
566 | return;
567 | }
568 |
569 | // Define next run time.
570 | $next_run_time = $this->prepare_next_run_time( $settings );
571 |
572 | // Get search criteria for form.
573 | $search_criteria = $this->get_search_criteria( $settings, $form );
574 |
575 | // Log the search criteria.
576 | $this->log_debug( __METHOD__ . '(): Search criteria for form #' . $form['id'] . ': ' . print_r( $search_criteria, true ) );
577 |
578 | // Get entries found for search criteria.
579 | $found_entries = GFAPI::count_entries( $form['id'], $search_criteria );
580 |
581 | // If no entries were found, exit.
582 | if ( ! $found_entries ) {
583 |
584 | // Log that no entries were found.
585 | $this->log_debug( __METHOD__ . '(): Not deleting entries for form #' . $form['id'] . ' because no entries were found matching the search criteria.' );
586 |
587 | // Set transient.
588 | set_transient( $this->_slug . '_' . $form['id'], '1', $next_run_time );
589 |
590 | return;
591 |
592 | }
593 |
594 | // Delete form entries.
595 | $this->delete_form_entries( $form, $settings );
596 |
597 | // Set transient.
598 | set_transient( $this->_slug . '_' . $form['id'], '1', $next_run_time );
599 |
600 | }
601 |
602 | /**
603 | * Delete form entries.
604 | *
605 | * @since 2.0
606 | * @access public
607 | *
608 | * @param array $form The form object.
609 | * @param array $settings Entry Expiration settings.
610 | *
611 | * @uses GFAPI::get_entries()
612 | * @uses GFAPI::delete_entry()
613 | * @uses GF_Entry_Expiration::get_search_criteria()
614 | */
615 | public function delete_form_entries( $form, $settings ) {
616 |
617 | // Prepare search critera.
618 | $search_criteria = $this->get_search_criteria( $settings, $form );
619 |
620 | // Prepare paging criteria.
621 | $paging = array(
622 | 'offset' => 0,
623 | 'page_size' => 50,
624 | );
625 |
626 | // Get total entry count.
627 | $found_entries = GFAPI::count_entries( $form['id'], $search_criteria );
628 |
629 | // Set entries processed count.
630 | $entries_processed = 0;
631 |
632 | // Loop until all entries have been processed.
633 | while ( $entries_processed < $found_entries ) {
634 |
635 | // Log the page number.
636 | $this->log_debug( __METHOD__ . '(): Starting deletion of page ' . ( round( $entries_processed / $paging['page_size'] ) + 1 ) . ' of ' . ( round( $found_entries / $paging['page_size'] ) ) );
637 |
638 | // Get entries.
639 | $entries = GFAPI::get_entries( $form['id'], $search_criteria, null, $paging );
640 |
641 | // If no more entries were found, break.
642 | if ( empty( $entries ) ) {
643 | $this->log_debug( __METHOD__ . '(): No entries were found for this page.' );
644 | break;
645 | }
646 |
647 | // Loop through entries.
648 | foreach ( $entries as $entry ) {
649 |
650 | // Delete entry.
651 | GFAPI::delete_entry( $entry['id'] );
652 |
653 | // Increase entries processed count.
654 | $entries_processed++;
655 |
656 | }
657 |
658 | // Increase offset.
659 | $paging['offset'] += $paging['page_size'];
660 |
661 | }
662 |
663 | // Add to total processed.
664 | $lifetime_processed = get_option( 'gf_entryexpiration_lifetime_processed', 0 );
665 | $lifetime_processed += $entries_processed;
666 | update_option( 'gf_entryexpiration_lifetime_processed', $lifetime_processed );
667 |
668 | // Log that deletion has been completed.
669 | $this->log_debug( __METHOD__ . '(): Deletion completed.' );
670 |
671 | }
672 |
673 | /**
674 | * Get Entry Expiration search criteria for form.
675 | *
676 | * @since 2.0
677 | * @access public
678 | *
679 | * @param array $form The form object.
680 | * @param array $settings Entry Expiration settings.
681 | *
682 | * @return array
683 | */
684 | public function get_search_criteria( $settings, $form ) {
685 |
686 | // Initialize search criteria.
687 | $search_criteria = array(
688 | 'start_date' => wp_date( 'Y-m-d H:i:s', 0 ),
689 | 'end_date' => wp_date( 'Y-m-d H:i:s', strtotime( '-' . $settings['deletionDate']['number'] . ' ' . $settings['deletionDate']['unit'] ) ),
690 | 'payment_status' => null,
691 | );
692 |
693 | /**
694 | * Filter the entry expiration time.
695 | *
696 | * @since 1.2.3
697 | *
698 | * @param string $older_than Current entry expiration time.
699 | * @param array $form Form object.
700 | */
701 | $search_criteria['end_date'] = gf_apply_filters( array( 'gf_entryexpiration_older_than', $form['id'] ), $search_criteria['end_date'], $form );
702 |
703 | /**
704 | * Set the payment status when searching for expired entries.
705 | *
706 | * @since 1.1
707 | *
708 | * @param string null Payment status.
709 | * @param array $form Form object.
710 | */
711 | $search_criteria['payment_status'] = gf_apply_filters( array( 'gf_entryexpiration_payment', $form['id'] ), $search_criteria['payment_status'], $form );
712 |
713 | return $search_criteria;
714 |
715 | }
716 |
717 | /**
718 | * Prepare the next time Entry Expiration should run.
719 | *
720 | * @since 2.0.3
721 | * @access public
722 | *
723 | * @param array $settings Entry Expiration settings.
724 | *
725 | * @return int
726 | */
727 | public function prepare_next_run_time( $settings ) {
728 |
729 | // Get run time number.
730 | $number = $settings['deletionRunTime']['number'];
731 |
732 | // Prepare run time based on unit.
733 | switch ( $settings['deletionRunTime']['unit'] ) {
734 |
735 | case 'days':
736 | $next_run_time = $number * DAY_IN_SECONDS;
737 | break;
738 |
739 | case 'hours':
740 | $next_run_time = $number * HOUR_IN_SECONDS;
741 | break;
742 |
743 | case 'months':
744 | $next_run_time = $number * MONTH_IN_SECONDS;
745 | break;
746 |
747 | case 'weeks':
748 | $next_run_time = $number * WEEK_IN_SECONDS;
749 | break;
750 |
751 | }
752 |
753 | // Adjust run time by five seconds.
754 | $next_run_time -= 5;
755 |
756 | return $next_run_time;
757 |
758 | }
759 |
760 |
761 |
762 |
763 |
764 | // # UPGRADE -------------------------------------------------------------------------------------------------------
765 |
766 | /**
767 | * Migrate needed settings.
768 | *
769 | * @since 1.1.0
770 | * @access public
771 | *
772 | * @param string $previous_version Version number the plugin is upgrading from.
773 | *
774 | * @uses GFAddOn::get_plugin_settings()
775 | * @uses GFAddOn::save_form_settings()
776 | * @uses GFAddOn::update_plugin_settings()
777 | * @uses GFAPI::get_forms()
778 | * @uses GFAPI::update_form()
779 | */
780 | public function upgrade( $previous_version ) {
781 |
782 | // Get plugin settings.
783 | $settings = $this->get_plugin_settings();
784 |
785 | // If existing scheduled event exists and is daily, remove and switch to hourly.
786 | if ( 'daily' === wp_get_schedule( 'gf_entryexpiration_delete_old_entries' ) ) {
787 | wp_clear_scheduled_hook( 'gf_entryexpiration_delete_old_entries' );
788 | wp_schedule_event( strtotime( 'midnight' ), 'hourly', 'gf_entryexpiration_delete_old_entries' );
789 | }
790 |
791 | // Upgrade: 1.1.0.
792 | if ( ! empty( $previous_version ) && version_compare( $previous_version, '1.1.0', '<' ) ) {
793 |
794 | // Get the forms.
795 | $forms = GFAPI::get_forms();
796 |
797 | // Loop through each form and switch to include setting where needed.
798 | foreach ( $forms as &$form ) {
799 |
800 | // If exclude is set, remove. Otherwise, set to include.
801 | if ( rgar( $form, 'gf_entryexpiration_exclude' ) ) {
802 | unset( $form['gf_entryexpiration_exclude'] );
803 | } else {
804 | $form['gf_entryexpiration_include'] = '1';
805 | }
806 |
807 | // Save form.
808 | GFAPI::update_form( $form );
809 |
810 | }
811 |
812 | }
813 |
814 | // Upgrade: 1.2.0
815 | if ( ! empty( $previous_version ) && version_compare( $previous_version, '1.2.0', '<' ) ) {
816 |
817 | // Change settings from "days" to allow hours, days, weeks and months.
818 | $settings['gf_entryexpiration_expire_time'] = array(
819 | 'amount' => $settings['gf_entryexpiration_days_old'],
820 | 'type' => 'days'
821 | );
822 |
823 | // Remove days old setting.
824 | unset( $settings['gf_entryexpiration_days_old'] );
825 |
826 | // Save settings.
827 | $this->update_plugin_settings( $settings );
828 |
829 | }
830 |
831 | // Upgrade: 2.0
832 | if ( ! empty( $previous_version ) && version_compare( $previous_version, '2.0', '<' ) ) {
833 |
834 | // Remove old cron hook.
835 | wp_clear_scheduled_hook( 'gf_entryexpiration_delete_old_entries' );
836 |
837 | // Get plugin settings.
838 | $plugin_settings = $this->get_plugin_settings();
839 |
840 | // Get forms.
841 | $forms = GFAPI::get_forms();
842 |
843 | // Loop through forms.
844 | foreach ( $forms as $form ) {
845 |
846 | // If form is not included in Entry Expiration, skip it.
847 | if ( ! rgar( $form, 'gf_entryexpiration_include' ) ) {
848 | continue;
849 | }
850 |
851 | // Prepare form settings.
852 | $form_settings = array(
853 | 'deletionEnable' => '1',
854 | 'deletionDate' => array(
855 | 'number' => rgars( $plugin_settings, 'gf_entryexpiration_expire_time/amount' ),
856 | 'unit' => rgars( $plugin_settings, 'gf_entryexpiration_expire_time/type' ),
857 | ),
858 | 'deletionRunTime' => array(
859 | 'number' => 1,
860 | 'unit' => 'hours',
861 | ),
862 | );
863 |
864 | // Save form settings.
865 | $this->save_form_settings( $form, $form_settings );
866 |
867 | // Remove old setting.
868 | unset( $form['gf_entryexpiration_include'] );
869 |
870 | // Save form.
871 | GFAPI::update_form( $form );
872 |
873 | }
874 |
875 | // Clear plugin settings.
876 | $this->update_plugin_settings( array() );
877 |
878 | }
879 |
880 | }
881 |
882 | }
883 |
--------------------------------------------------------------------------------