Skip to content

Commit cced4c2

Browse files
committed
[garbage-collector] [configuration] Make garbage collector expiration time configurable.
1 parent 4725e27 commit cced4c2

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

includes/class-freemius.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,8 +1357,8 @@ function _plugins_loaded() {
13571357
}
13581358

13591359
function _run_garbage_collector() {
1360-
// @todo - Remove this check once the garbage collector is ready.
1361-
if ( ! defined( 'WP_FS__ENABLE_GARBAGE_COLLECTOR' ) || true !== WP_FS__ENABLE_GARBAGE_COLLECTOR ) {
1360+
// @todo - Remove this check once the garbage collector is ready to be out of beta.
1361+
if ( true !== fs_get_optional_constant( 'WP_FS__ENABLE_GARBAGE_COLLECTOR', false ) ) {
13621362
return;
13631363
}
13641364

includes/class-fs-garbage-collector.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ private function is_product_active( $slug ) {
195195
}
196196
}
197197

198-
if ( $this->get_last_load_timestamp( $slug ) > ( time() - ( WP_FS__TIME_WEEK_IN_SEC * 4 ) ) ) {
198+
$expiration_time = fs_get_optional_constant( 'WP_FS__GARBAGE_COLLECTOR_EXPIRATION_TIME_SECS', ( WP_FS__TIME_WEEK_IN_SEC * 4 ) );
199+
200+
if ( $this->get_last_load_timestamp( $slug ) > ( time() - $expiration_time ) ) {
199201
// Last activation was within the last 4 weeks.
200202
return true;
201203
}

includes/fs-core-functions.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,4 +1485,21 @@ function fs_apply_filter( $module_unique_affix, $tag, $value ) {
14851485
array_slice( $args, 2 ) )
14861486
);
14871487
}
1488+
}
1489+
1490+
if ( ! function_exists( 'fs_get_optional_constant' ) ) {
1491+
/**
1492+
* Gets the value of an optional constant. If the constant is not defined, the default value will be returned.
1493+
*
1494+
* @author Swashata Ghosh (@swashata)
1495+
* @since 2.5.12.5
1496+
*
1497+
* @param string $constant_name
1498+
* @param mixed $default_value
1499+
*
1500+
* @return mixed
1501+
*/
1502+
function fs_get_optional_constant( $constant_name, $default_value = null ) {
1503+
return defined( $constant_name ) ? constant( $constant_name ) : $default_value;
1504+
}
14881505
}

0 commit comments

Comments
 (0)