diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php index 0280d5375880a..5d6b04392c2c5 100644 --- a/src/wp-includes/option.php +++ b/src/wp-includes/option.php @@ -1636,56 +1636,107 @@ function set_transient( $transient, $value, $expiration = 0 ) { * @param bool $force_db Optional. Force cleanup to run against the database even when an external object cache is used. */ function delete_expired_transients( $force_db = false ) { - global $wpdb; - - if ( ! $force_db && wp_using_ext_object_cache() ) { - return; - } - - $wpdb->query( - $wpdb->prepare( - "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b - WHERE a.option_name LIKE %s - AND a.option_name NOT LIKE %s - AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) ) - AND b.option_value < %d", - $wpdb->esc_like( '_transient_' ) . '%', - $wpdb->esc_like( '_transient_timeout_' ) . '%', - time() - ) - ); - - if ( ! is_multisite() ) { - // Single site stores site transients in the options table. - $wpdb->query( - $wpdb->prepare( - "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b - WHERE a.option_name LIKE %s - AND a.option_name NOT LIKE %s - AND b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) ) - AND b.option_value < %d", - $wpdb->esc_like( '_site_transient_' ) . '%', - $wpdb->esc_like( '_site_transient_timeout_' ) . '%', - time() - ) - ); - } elseif ( is_multisite() && is_main_site() && is_main_network() ) { - // Multisite stores site transients in the sitemeta table. - $wpdb->query( - $wpdb->prepare( - "DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b - 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.meta_value < %d", - $wpdb->esc_like( '_site_transient_' ) . '%', - $wpdb->esc_like( '_site_transient_timeout_' ) . '%', - time() - ) - ); - } + global $wpdb; + + if ( ! $force_db && wp_using_ext_object_cache() ) { + return; + } + + $version_comment = $wpdb->get_var("SELECT @@global.version_comment"); + + if (strpos($version_comment, 'OceanBase') !== false) { + //OceanBase connection identified + $wpdb->query( + $wpdb->prepare( + "DELETE from wp_options where option_id in + (select a.option_id FROM {$wpdb->options} a, {$wpdb->options} b + WHERE a.option_name LIKE %s + AND a.option_name NOT LIKE %s + AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) ) + AND b.option_value < %d)", + $wpdb->esc_like( '_transient_' ) . '%', + $wpdb->esc_like( '_transient_timeout_' ) . '%', + time() + ) + ); + + if ( ! is_multisite() ) { + // Single site stores site transients in the options table. + $wpdb->query( + $wpdb->prepare( + "DELETE from wp_options where option_id in + (select a.option_id FROM {$wpdb->options} a, {$wpdb->options} b + WHERE a.option_name LIKE %s + AND a.option_name NOT LIKE %s + AND b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) ) + AND b.option_value < %d)", + $wpdb->esc_like( '_site_transient_' ) . '%', + $wpdb->esc_like( '_site_transient_timeout_' ) . '%', + time() + ) + ); + } elseif ( is_multisite() && is_main_site() && is_main_network() ) { + // Multisite stores site transients in the sitemeta table. + $wpdb->query( + $wpdb->prepare( + "DELETE from wp_options where option_id in + (select a.option_id FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b + 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.meta_value < %d)", + $wpdb->esc_like( '_site_transient_' ) . '%', + $wpdb->esc_like( '_site_transient_timeout_' ) . '%', + time() + ) + ); + } + } else { + // MySQL connection identified + $wpdb->query( + $wpdb->prepare( + "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b + WHERE a.option_name LIKE %s + AND a.option_name NOT LIKE %s + AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) ) + AND b.option_value < %d", + $wpdb->esc_like( '_transient_' ) . '%', + $wpdb->esc_like( '_transient_timeout_' ) . '%', + time() + ) + ); + + if ( ! is_multisite() ) { + // Single site stores site transients in the options table. + $wpdb->query( + $wpdb->prepare( + "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b + WHERE a.option_name LIKE %s + AND a.option_name NOT LIKE %s + AND b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) ) + AND b.option_value < %d", + $wpdb->esc_like( '_site_transient_' ) . '%', + $wpdb->esc_like( '_site_transient_timeout_' ) . '%', + time() + ) + ); + } elseif ( is_multisite() && is_main_site() && is_main_network() ) { + // Multisite stores site transients in the sitemeta table. + $wpdb->query( + $wpdb->prepare( + "DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b + 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.meta_value < %d", + $wpdb->esc_like( '_site_transient_' ) . '%', + $wpdb->esc_like( '_site_transient_timeout_' ) . '%', + time() + ) + ); + } + } } - /** * Saves and restores user interface settings stored in a cookie. *