Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 63 additions & 6 deletions src/wp-includes/option.php
Original file line number Diff line number Diff line change
Expand Up @@ -1372,9 +1372,19 @@ function wp_filter_default_autoload_value_via_option_size( $autoload, $option, $
/**
* Deletes a transient.
*
* If an orphaned transient timeout option exists without a corresponding transient
* option, the timeout option is deleted, but the function returns false because
* no transient value option existed to be deleted.
*
* @since 2.8.0
*
* @param string $transient Transient name. Expected to not be SQL-escaped.
* Note: If only an orphaned timeout row exists, it will be deleted, but the function
* will return false because the transient value option did not exist to be deleted.
*
* Note: If only an orphaned timeout row exists, it will be deleted, but the function
* will return false because the transient value option did not exist to be deleted.
*
* @return bool True if the transient was deleted, false otherwise.
*/
function delete_transient( $transient ) {
Expand All @@ -1397,9 +1407,7 @@ function delete_transient( $transient ) {
$option = '_transient_' . $transient;
$result = delete_option( $option );

if ( $result ) {
delete_option( $option_timeout );
}
delete_option( $option_timeout );
}

if ( $result ) {
Expand Down Expand Up @@ -1655,6 +1663,19 @@ function delete_expired_transients( $force_db = false ) {
)
);

$wpdb->query(
$wpdb->prepare(
"DELETE a FROM {$wpdb->options} a
LEFT JOIN {$wpdb->options} b
ON b.option_name = CONCAT( '_transient_', SUBSTRING( a.option_name, 20 ) )
WHERE a.option_name LIKE %s
AND a.option_value < %d
AND b.option_id IS NULL",
$wpdb->esc_like( '_transient_timeout_' ) . '%',
time()
)
);

if ( ! is_multisite() ) {
// Single site stores site transients in the options table.
$wpdb->query(
Expand All @@ -1669,6 +1690,19 @@ function delete_expired_transients( $force_db = false ) {
time()
)
);

$wpdb->query(
$wpdb->prepare(
"DELETE a FROM {$wpdb->options} a
LEFT JOIN {$wpdb->options} b
ON b.option_name = CONCAT( '_site_transient_', SUBSTRING( a.option_name, 25 ) )
WHERE a.option_name LIKE %s
AND a.option_value < %d
AND b.option_id IS NULL",
$wpdb->esc_like( '_site_transient_timeout_' ) . '%',
time()
)
);
} elseif ( is_main_site() && is_main_network() ) {
// Multisite stores site transients in the sitemeta table.
$wpdb->query(
Expand All @@ -1677,12 +1711,27 @@ function delete_expired_transients( $force_db = false ) {
WHERE a.meta_key LIKE %s
AND a.meta_key NOT LIKE %s
AND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) )
AND b.site_id = a.site_id
AND b.meta_value < %d",
$wpdb->esc_like( '_site_transient_' ) . '%',
$wpdb->esc_like( '_site_transient_timeout_' ) . '%',
time()
)
);

$wpdb->query(
$wpdb->prepare(
"DELETE a FROM {$wpdb->sitemeta} a
LEFT JOIN {$wpdb->sitemeta} b
ON b.meta_key = CONCAT( '_site_transient_', SUBSTRING( a.meta_key, 25 ) )
AND b.site_id = a.site_id
WHERE a.meta_key LIKE %s
AND a.meta_value < %d
AND b.meta_id IS NULL",
$wpdb->esc_like( '_site_transient_timeout_' ) . '%',
time()
)
);
}
}

Expand Down Expand Up @@ -2503,9 +2552,19 @@ function update_network_option( $network_id, $option, $value ) {
/**
* Deletes a site transient.
*
* If an orphaned site transient timeout option exists without a corresponding transient
* option, the timeout option is deleted, but the function returns false because
* no transient value option existed to be deleted.
*
* @since 2.9.0
*
* @param string $transient Transient name. Expected to not be SQL-escaped.
* Note: If only an orphaned timeout row exists, it will be deleted, but the function
* will return false because the transient value option did not exist to be deleted.
*
* Note: If only an orphaned timeout row exists, it will be deleted, but the function
* will return false because the transient value option did not exist to be deleted.
*
* @return bool True if the transient was deleted, false otherwise.
*/
function delete_site_transient( $transient ) {
Expand All @@ -2528,9 +2587,7 @@ function delete_site_transient( $transient ) {
$option = '_site_transient_' . $transient;
$result = delete_site_option( $option );

if ( $result ) {
delete_site_option( $option_timeout );
}
delete_site_option( $option_timeout );
}

if ( $result ) {
Expand Down
Loading
Loading