Opened 11 months ago
Last modified 9 months ago
#21330 new enhancement
Allow filtering of expiration in set_transient()
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Cache | Version: | |
| Severity: | normal | Keywords: | has-patch dev-feedback |
| Cc: | xoodrew@… |
Description
I recently needed to change an expiration of a transient and expected pre_set_site_transient_* filter to be able to do that. However, the filter only affects the value. I recommend adjusting this to affect both.
Attachments (6)
Change History (17)
comment:2
in reply to:
↑ 1
wpsmith
— 11 months ago
Replying to obenland:
AFAIK, filters are only supposed to filter the first supplied argument. So $expirationprobably should get its own filter.
Yes that's right. I knew that! Adjusted patch for one filter.
comment:3
follow-up:
↓ 4
nacin
— 11 months ago
extract( $options, EXTR_OVERWRITE ); is dangerous and not something we're likely going to do here, as it doesn't fit patterns found throughout. Please do not replace patches, we can't see what changed — I actually can't tell if this was the original patch, or a replacement.
comment:4
in reply to:
↑ 3
wpsmith
— 11 months ago
Replying to nacin:
extract( $options, EXTR_OVERWRITE ); is dangerous and not something we're likely going to do here, as it doesn't fit patterns found throughout. Please do not replace patches, we can't see what changed — I actually can't tell if this was the original patch, or a replacement.
My apologies. The first one was VERY much similiar to the one that's there now using extract. I've added a couple more options.
comment:5
follow-up:
↓ 6
nacin
— 11 months ago
I don't understand how 21330_opt2.patch would work in a plugin.
Could you go a bit more into your use case, perhaps some sample code?
comment:6
in reply to:
↑ 5
wpsmith
— 11 months ago
Replying to nacin:
I don't understand how 21330_opt2.patch would work in a plugin.
Could you go a bit more into your use case, perhaps some sample code?
The expiration time is always set (right? if not set, it's set to 0 by the time of the filter) and is always an integer. For example, wp_check_browser_version() has a set expiration that is known. So...assuming I knew the $key (93ce43dc55bd29ecc99e83ca12b5d7f4) in this example.
`
add_filter( 'pre_set_site_transient_browser_93ce43dc55bd29ecc99e83ca12b5d7f4', 'wps_change_browser_transient' );
function wps_change_browser_transient( $val ) {
if ( is_int( $val ) && 604800 == $val )
$val = 1209600;
return $val;
}
`
However, I am not convinced that this is the best solution...
comment:7
obenland
— 11 months ago
In 21330_opt4.patch, what do you need the option part for? Value and expiration are both filterable at this point.
comment:8
nacin
— 10 months ago
If we were to do this, it would probably look like 21330.diff.
comment:10
nacin
— 9 months ago
- Summary changed from Change pre_set_site_transient_* to affect $expiration to Allow filtering of expiration in set_transient()
comment:11
DrewAPicture
— 9 months ago
- Cc xoodrew@… added
AFAIK, filters are only supposed to filter the first supplied argument. So $expirationprobably should get its own filter.