diff --git src/wp-includes/option.php src/wp-includes/option.php
index e1ad731..f20e7bf 100644
|
|
|
function set_transient( $transient, $value, $expiration = 0 ) { |
| 642 | 642 | } |
| 643 | 643 | $result = add_option( $transient, $value, '', $autoload ); |
| 644 | 644 | } else { |
| 645 | | if ( $expiration ) |
| 646 | | update_option( $transient_timeout, time() + $expiration ); |
| 647 | | $result = update_option( $transient, $value ); |
| | 645 | /** |
| | 646 | * If expiration is requested, but the transient has no timeout option, |
| | 647 | * delete, then re-create transient rather than update. |
| | 648 | */ |
| | 649 | $skipupdate = false; |
| | 650 | if ( $expiration ) { |
| | 651 | if ( false === get_option( $transient_timeout ) ) { |
| | 652 | delete_option( $transient ); |
| | 653 | add_option( $transient_timeout, time() + $expiration, '', 'no' ); |
| | 654 | $result = add_option( $transient, $value, '', 'no' ); |
| | 655 | $skipupdate = true; |
| | 656 | } else { |
| | 657 | update_option( $transient_timeout, time() + $expiration ); |
| | 658 | } |
| | 659 | } |
| | 660 | if ( false === $skipupdate ) { |
| | 661 | $result = update_option( $transient, $value ); |
| | 662 | } |
| 648 | 663 | } |
| 649 | 664 | } |
| 650 | 665 | |
diff --git tests/phpunit/tests/option/transient.php tests/phpunit/tests/option/transient.php
index 1d9c64f..c7eeb1b 100644
|
|
|
class Tests_Option_Transient extends WP_UnitTestCase { |
| 33 | 33 | $this->assertEquals( $value, get_transient( $key ) ); |
| 34 | 34 | $this->assertTrue( delete_transient( $key ) ); |
| 35 | 35 | } |
| | 36 | |
| | 37 | function test_transient_data_with_timeout() { |
| | 38 | $key = rand_str(); |
| | 39 | $value = rand_str(); |
| | 40 | $value2 = rand_str(); |
| | 41 | |
| | 42 | $this->assertTrue( set_transient( $key, $value, 1 ) ); |
| | 43 | sleep( 2 ); |
| | 44 | $this->assertFalse( get_transient( $key ) ); |
| | 45 | } |
| | 46 | |
| | 47 | /** |
| | 48 | * @ticket 22807 |
| | 49 | */ |
| | 50 | function test_transient_add_timeout() { |
| | 51 | $key = rand_str(); |
| | 52 | $value = rand_str(); |
| | 53 | $value2 = rand_str(); |
| | 54 | $this->assertTrue( set_transient( $key, $value) ); |
| | 55 | $this->assertEquals($value, get_transient( $key) ); |
| | 56 | |
| | 57 | // Add timeout to existing timeout-less transient. |
| | 58 | $this->assertTrue( set_transient( $key, $value2, 1 ) ); |
| | 59 | sleep( 2 ); |
| | 60 | $this->assertFalse( get_transient( $key ) ); |
| | 61 | } |
| 36 | 62 | } |