Transients: Allow a non-expiring transient to be updated with an expiry.

props shahpranaf, sandyr.
fixes #22807.

Built from https://develop.svn.wordpress.org/trunk@27719


git-svn-id: http://core.svn.wordpress.org/trunk@27557 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2014-03-25 18:23:14 +00:00
parent 5a873ec0c6
commit d63fbed03d
1 changed files with 16 additions and 3 deletions

View File

@ -642,9 +642,22 @@ function set_transient( $transient, $value, $expiration = 0 ) {
}
$result = add_option( $transient, $value, '', $autoload );
} else {
if ( $expiration )
update_option( $transient_timeout, time() + $expiration );
$result = update_option( $transient, $value );
// If expiration is requested, but the transient has no timeout option,
// delete, then re-create transient rather than update.
$update = true;
if ( $expiration ) {
if ( false === get_option( $transient_timeout ) ) {
delete_option( $transient );
add_option( $transient_timeout, time() + $expiration, '', 'no' );
$result = add_option( $transient, $value, '', 'no' );
$update = false;
} else {
update_option( $transient_timeout, time() + $expiration );
}
}
if ( $update ) {
$result = update_option( $transient, $value );
}
}
}