Skip to content

Commit

Permalink
Merge pull request #165 from soup-bowl/soup-bowl/log-expiry
Browse files Browse the repository at this point in the history
Change log expiry via hook & expiry visibility
  • Loading branch information
soup-bowl authored Jul 21, 2024
2 parents dfbf1ca + c854309 commit b6a6573
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
56 changes: 55 additions & 1 deletion src/settings/class-singular.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,22 @@ private function render_settings() {
$page = intval( wp_unslash( $_REQUEST['wpss_page'] ) );
}

echo wp_kses( '<h2 id="log">' . __( 'Email Log', 'simple-smtp' ) . '</h2>', [ 'h2' => [ 'id' => [] ] ] );
$log_limit = apply_filters( 'simple_smtp_log_expiry', 2629800 );
$log_disabled = apply_filters( 'simple_smtp_disable_log_prune', false );
$expiry_string = sprintf(
/* translators: %s: time amount or never. */
__( 'Log entries are deleted after: %s', 'simple-smtp' ),
( ( ! $log_disabled ) ? $this->seconds_to_duration( $log_limit ) : __( 'never', 'simple-smtp' ) )
);

echo wp_kses(
'<h2 id="log">' . __( 'Email Log', 'simple-smtp' ) . '</h2>
<p>' . $expiry_string . '</p>',
[
'h2' => [ 'id' => [] ],
'p' => [],
]
);
$this->log_table->display( $page );
}
}
Expand All @@ -305,4 +320,43 @@ private function render_settings() {
</div>
<?php
}

/**
* Generates a human-readable time string from an input in second format.
*
* @param integer $seconds Seconds.
* @return string Human-readable representation of seconds.
*/
private function seconds_to_duration( $seconds ) {
$minute = 60;
$hour = 60 * $minute;
$day = 24 * $hour;
$month = 30 * $day;
$year = 12 * $month;

if ( $seconds < $minute ) {
/* translators: %s: time to deletion in seconds. */
return sprintf( _n( '%s second', '%s seconds', $seconds, 'simple-smtp' ), $seconds );
} elseif ( $seconds < $hour ) {
$minutes = round( $seconds / $minute );
/* translators: %s: time to deletion in minutes. */
return sprintf( _n( '%s minute', '%s minutes', $minutes, 'simple-smtp' ), $minutes );
} elseif ( $seconds < $day ) {
$hours = round( $seconds / $hour );
/* translators: %s: time to deletion in hours. */
return sprintf( _n( '%s hour', '%s hours', $hours, 'simple-smtp' ), $hours );
} elseif ( $seconds < $month ) {
$days = round( $seconds / $day );
/* translators: %s: time to deletion in days. */
return sprintf( _n( '%s day', '%s days', $days, 'simple-smtp' ), $days );
} elseif ( $seconds < $year ) {
$months = round( $seconds / $month );
/* translators: %s: time to deletion in months. */
return sprintf( _n( '%s month', '%s months', $months, 'simple-smtp' ), $months );
} else {
$years = round( $seconds / $year );
/* translators: %s: time to deletion in years. */
return sprintf( _n( '%s year', '%s years', $years, 'simple-smtp' ), $years );
}
}
}
2 changes: 1 addition & 1 deletion wp-simple-smtp.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function () {
$is_disabled = apply_filters( 'simple_smtp_disable_log_prune', false );
// 2629800 = 1 Month.
if ( ! $is_disabled ) {
( new LogService() )->prune_logs( 2629800 );
( new LogService() )->prune_logs( apply_filters( 'simple_smtp_log_expiry', 2629800 ) );
}
}
);
Expand Down

0 comments on commit b6a6573

Please sign in to comment.