Skip to content

Commit 2032349

Browse files
committed
Add upgrade message
1 parent 850cb4a commit 2032349

File tree

1 file changed

+50
-7
lines changed

1 file changed

+50
-7
lines changed

class-gf-entryexpiration.php

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ public function pre_init() {
172172

173173
add_action( 'gf_entryexpiration_maybe_expire', array( $this, 'maybe_run_expiration' ) );
174174

175+
add_action( 'admin_init', array( $this, 'maybe_display_upgrade_message' ) );
176+
175177
}
176178

177179
/**
@@ -227,6 +229,43 @@ public function add_cron_schedule( $schedules = array() ) {
227229

228230
}
229231

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 <strong>removed over %d entries!</strong><br /><a href="%s">Upgrade to Entry Automation</a> to delete entries based off conditional logic, delete only specific fields from an entry and automatically export entries!',
258+
$lifetime_processed,
259+
'https://forgravity.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+
}
230269

231270

232271

@@ -400,14 +439,13 @@ public function settings_text_select( $field, $echo = true ) {
400439
// Initialize return HTML.
401440
$html = '';
402441

403-
// Duplicate fields.
404-
$select_field = $text_field = $field;
442+
// Prepare text field.
443+
$text_field = $field['text'];
444+
$text_field['type'] = 'text';
405445

406-
// Merge properties.
407-
$text_field = array_merge( $text_field, $text_field['text'] );
408-
$select_field = array_merge( $select_field, $select_field['select'] );
409-
410-
unset( $text_field['text'], $select_field['text'], $text_field['select'], $select_field['select'] );
446+
// Prepare select field.
447+
$select_field = $field['select'];
448+
$select_field['type'] = 'select';
411449

412450
$html .= $this->settings_text( $text_field, false );
413451
$html .= $this->settings_select( $select_field, false );
@@ -622,6 +660,11 @@ public function delete_form_entries( $form, $settings ) {
622660

623661
}
624662

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+
625668
// Log that deletion has been completed.
626669
$this->log_debug( __METHOD__ . '(): Deletion completed.' );
627670

0 commit comments

Comments
 (0)