Add constant to handle Patreon user data expiration

And reduce the time to one week per default.
This commit is contained in:
Tetrakern 2024-04-27 12:52:25 +02:00
parent bdb4f565e1
commit 4dec87b117
4 changed files with 10 additions and 4 deletions

View File

@ -1441,6 +1441,7 @@ define( 'CONSTANT_NAME', value );
| FICTIONEER_REQUESTS_PER_MINUTE | integer | Maximum requests per minute and action if the rate limit is enabled. Default `5`.
| FICTIONEER_QUERY_ID_ARRAY_LIMIT | integer | Maximum allowed IDs in 'post__{not}_in' query arguments. Default `100`.
| FICTIONEER_OLD_POST_THRESHOLD | integer | Age of published post that is considered "old" in seconds. Default `30`.
| FICTIONEER_PATREON_EXPIRATION_TIME | integer | Time until a users Patreon data expires in seconds. Default `WEEK_IN_SECONDS`.
| FICTIONEER_CACHE_PURGE_ASSIST | boolean | Whether to call the cache purge assist function on post updates. Default `true`.
| FICTIONEER_RELATIONSHIP_PURGE_ASSIST | boolean | Whether to purge related post caches. Default `true`.
| FICTIONEER_CHAPTER_LIST_TRANSIENTS | boolean | Whether to cache chapter lists on story pages as Transients. Default `true`.

View File

@ -271,6 +271,11 @@ if ( ! defined( 'FICTIONEER_OLD_POST_THRESHOLD' ) ) {
define( 'FICTIONEER_OLD_POST_THRESHOLD', 30 );
}
// Integer: Time until a user's Patreon data expires in seconds
if ( ! defined( 'FICTIONEER_PATREON_EXPIRATION_TIME' ) ) {
define( 'FICTIONEER_PATREON_EXPIRATION_TIME', WEEK_IN_SECONDS );
}
/*
* Booleans
*/

View File

@ -713,8 +713,8 @@ if ( ! function_exists( 'fictioneer_get_patreon_badge' ) ) {
$patreon_tiers = get_user_meta( $user->ID, 'fictioneer_patreon_tiers', true );
$last_updated = is_array( $patreon_tiers ) ? ( $patreon_tiers[0]['timestamp'] ?? 0 ) : 0;
// Check if still valid (two weeks since last login) if not empty
if ( time() <= $last_updated + WEEK_IN_SECONDS * 2 ) {
// Check if still valid if not empty
if ( time() <= $last_updated + FICTIONEER_PATREON_EXPIRATION_TIME ) {
$label = get_option( 'fictioneer_patreon_label' );
return empty( $label ) ? _x( 'Patron', 'Default Patreon supporter badge label.', 'fictioneer' ) : $label;
}

View File

@ -28,7 +28,7 @@ if ( ! get_option( 'fictioneer_enable_oauth' ) ) {
$current_user = $args['user'];
$patreon_tiers = get_user_meta( $current_user->ID, 'fictioneer_patreon_tiers', true );
$patreon_timestamp = is_array( $patreon_tiers ) ? ( $patreon_tiers[0]['timestamp'] ?? 0 ) : 0;
$patreon_expired = $patreon_timestamp + WEEK_IN_SECONDS * 2 < time();
$patreon_expired = $patreon_timestamp + FICTIONEER_PATREON_EXPIRATION_TIME < time();
$oauth_providers = [
['discord', 'Discord'],
['twitch', 'Twitch'],
@ -56,7 +56,7 @@ $unset_oauth_prompt = sprintf(
<ul class="profile__admin-notes">
<li>
<i class="fa-solid fa-hourglass-end"></i>
<span><?php _e( '<b>Patreon:</b> Data expires after two weeks. Log in with Patreon again to refresh.', 'fictioneer' ); ?></span>
<span><?php _e( '<b>Patreon:</b> Data expired. Log in with Patreon again to refresh.', 'fictioneer' ); ?></span>
</li>
</ul>
<?php endif; ?>