Index: wp-includes/option.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- wp-includes/option.php	(revision )
+++ wp-includes/option.php	(revision )
@@ -596,6 +596,39 @@
 }
 
 /**
+ * Determines if a transient is valid.
+ *
+ * If the transient does not exist, does not have a value, or has expired,
+ * then the return value will be false.
+ *
+ * @since 4.7.0
+ *
+ * @param string $transient Transient name. Expected to not be SQL-escaped.
+ *
+ * @return bool
+ */
+function valid_transient( $transient ) {
+
+	$transient_timeout = '_transient_timeout_' . $transient;
+	$timeout           = get_option( $transient_timeout );
+
+	// No transient found.
+	if ( false === $timeout ) {
+		return false;
+	}
+	// Expired transient detected.
+	elseif ( false !== $timeout && $timeout < time() ) {
+		delete_option( '_transient_' . $transient );
+		delete_option( $transient_timeout );
+
+		return false;
+	}
+
+	// Transient is valid.
+	return true;
+}
+
+/**
  * Get the value of a transient.
  *
  * If the transient does not exist, does not have a value, or has expired,
@@ -635,16 +668,10 @@
 		if ( ! wp_installing() ) {
 			// If option is not in alloptions, it is not autoloaded and thus has a timeout
 			$alloptions = wp_load_alloptions();
-			if ( !isset( $alloptions[$transient_option] ) ) {
-				$transient_timeout = '_transient_timeout_' . $transient;
-				$timeout = get_option( $transient_timeout );
-				if ( false !== $timeout && $timeout < time() ) {
-					delete_option( $transient_option  );
-					delete_option( $transient_timeout );
+			if ( !isset( $alloptions[$transient_option] ) && ! valid_transient( $transient ) ) {
-					$value = false;
-				}
-			}
+				$value = false;
+			}
+		}
-		}
 
 		if ( ! isset( $value ) )
 			$value = get_option( $transient_option );
@@ -1527,6 +1554,39 @@
 }
 
 /**
+ * Determines if a site transient is valid.
+ *
+ * If the transient does not exist, does not have a value, or has expired,
+ * then the return value will be false.
+ *
+ * @since 4.7.0
+ *
+ * @param string $transient Transient name. Expected to not be SQL-escaped.
+ *
+ * @return bool
+ */
+function valid_site_transient( $transient ) {
+
+	$transient_timeout = '_site_transient_timeout_' . $transient;
+	$timeout = get_site_option( $transient_timeout );
+
+	// No transient found.
+	if ( false === $timeout ) {
+		return false;
+	}
+	// Expired transient detected.
+	elseif ( false !== $timeout && $timeout < time() ) {
+		delete_site_option( '_site_transient_' . $transient );
+		delete_site_option( $transient_timeout );
+
+		return false;
+	}
+
+	// Transient is valid.
+	return true;
+}
+
+/**
  * Get the value of a site transient.
  *
  * If the transient does not exist, does not have a value, or has expired,
@@ -1567,19 +1627,12 @@
 	} else {
 		// Core transients that do not have a timeout. Listed here so querying timeouts can be avoided.
 		$no_timeout = array('update_core', 'update_plugins', 'update_themes');
-		$transient_option = '_site_transient_' . $transient;
-		if ( ! in_array( $transient, $no_timeout ) ) {
-			$transient_timeout = '_site_transient_timeout_' . $transient;
-			$timeout = get_site_option( $transient_timeout );
-			if ( false !== $timeout && $timeout < time() ) {
-				delete_site_option( $transient_option  );
-				delete_site_option( $transient_timeout );
+		if ( ! in_array( $transient, $no_timeout ) && ! valid_site_transient( $transient ) ) {
-				$value = false;
-			}
+			$value = false;
+		}
-		}
 
 		if ( ! isset( $value ) )
-			$value = get_site_option( $transient_option );
+			$value = get_site_option( '_site_transient_' . $transient );
 	}
 
 	/**
