Skip to content

Commit ef813e2

Browse files
Fix orphaned transient timeout cleanup
1 parent 888f0d9 commit ef813e2

3 files changed

Lines changed: 46 additions & 6 deletions

File tree

‎src/wp-includes/option.php‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,9 +1397,7 @@ function delete_transient( $transient ) {
13971397
$option = '_transient_' . $transient;
13981398
$result = delete_option( $option );
13991399

1400-
if ( $result ) {
1401-
delete_option( $option_timeout );
1402-
}
1400+
delete_option( $option_timeout );
14031401
}
14041402

14051403
if ( $result ) {
@@ -2528,9 +2526,7 @@ function delete_site_transient( $transient ) {
25282526
$option = '_site_transient_' . $transient;
25292527
$result = delete_site_option( $option );
25302528

2531-
if ( $result ) {
2532-
delete_site_option( $option_timeout );
2533-
}
2529+
delete_site_option( $option_timeout );
25342530
}
25352531

25362532
if ( $result ) {

‎tests/phpunit/tests/option/siteTransient.php‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,26 @@ public function test_site_transients_not_stored_in_options_table_on_ms() {
155155

156156
$this->assertNull( $option, 'Querying option table should not return transient on multisite.' );
157157
}
158+
159+
/**
160+
* Tests that delete_site_transient() removes an orphaned timeout row.
161+
*
162+
* @ticket 65863
163+
*/
164+
public function test_delete_site_transient_removes_orphaned_timeout() {
165+
$key = 'orphaned_timeout';
166+
167+
set_site_transient( $key, 'value', 3600 );
168+
169+
// Remove the value row, leaving only the timeout row.
170+
delete_site_option( '_site_transient_' . $key );
171+
172+
$this->assertFalse( get_site_option( '_site_transient_' . $key ) );
173+
$this->assertNotFalse( get_site_option( '_site_transient_timeout_' . $key ) );
174+
175+
delete_site_transient( $key );
176+
177+
$this->assertFalse( get_site_option( '_site_transient_' . $key ) );
178+
$this->assertFalse( get_site_option( '_site_transient_timeout_' . $key ) );
179+
}
158180
}

‎tests/phpunit/tests/option/transient.php‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,26 @@ public function test_nonexistent_key_old_timeout() {
265265
);
266266
$this->assertSame( $expected, $a->get_events() );
267267
}
268+
269+
/**
270+
* Tests that delete_transient() removes an orphaned timeout row.
271+
*
272+
* @ticket 65863
273+
*/
274+
public function test_delete_transient_removes_orphaned_timeout() {
275+
$key = 'orphaned_timeout';
276+
277+
set_transient( $key, 'value', 3600 );
278+
279+
// Remove the value row, leaving only the timeout row.
280+
delete_option( '_transient_' . $key );
281+
282+
$this->assertFalse( get_option( '_transient_' . $key ) );
283+
$this->assertNotFalse( get_option( '_transient_timeout_' . $key ) );
284+
285+
delete_transient( $key );
286+
287+
$this->assertFalse( get_option( '_transient_' . $key ) );
288+
$this->assertFalse( get_option( '_transient_timeout_' . $key ) );
289+
}
268290
}

0 commit comments

Comments
 (0)