<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[12128] trunk: Introduce get/set/delete_site_transient().</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12128">12128</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2009-10-29 21:53:57 +0000 (Thu, 29 Oct 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>Introduce get/set/delete_site_transient().  Make theme_roots a site transient.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesfunctionsphp">trunk/wp-includes/functions.php</a></li>
<li><a href="#trunkwpincludesthemephp">trunk/wp-includes/theme.php</a></li>
<li><a href="#trunkwpsettingsphp">trunk/wp-settings.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/functions.php (12127 => 12128)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/functions.php        2009-10-29 18:02:55 UTC (rev 12127)
+++ trunk/wp-includes/functions.php        2009-10-29 21:53:57 UTC (rev 12128)
</span><span class="lines">@@ -3190,6 +3190,12 @@
</span><span class="cx">         return $result;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+function delete_site_option( $key ) {
+        $result = delete_option($key);
+        do_action( &quot;delete_site_option_{$key}&quot;, $key );
+        return $result;
+}
+
</ins><span class="cx"> // expects $key, $value not to be SQL escaped
</span><span class="cx"> function update_site_option( $key, $value ) {
</span><span class="cx">         $oldvalue = get_site_option( $key );
</span><span class="lines">@@ -3200,6 +3206,100 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * Delete a site transient
+ *
+ * @since 2.890
+ * @package WordPress
+ * @subpackage Transient
+ *
+ * @param string $transient Transient name. Expected to not be SQL-escaped
+ * @return bool true if successful, false otherwise
+ */
+function delete_site_transient($transient) {
+        global $_wp_using_ext_object_cache, $wpdb;
+
+        if ( $_wp_using_ext_object_cache ) {
+                return wp_cache_delete($transient, 'site-transient');
+        } else {
+                $transient = '_site_transient_' . esc_sql($transient);
+                return delete_site_option($transient);
+        }
+}
+
+/**
+ * Get the value of a site transient
+ *
+ * If the transient does not exist or does not have a value, then the return value
+ * will be false.
+ * 
+ * @since 2.9.0
+ * @package WordPress
+ * @subpackage Transient
+ *
+ * @param string $transient Transient name. Expected to not be SQL-escaped
+ * @return mixed Value of transient
+ */
+function get_site_transient($transient) {
+        global $_wp_using_ext_object_cache, $wpdb;
+
+        $pre = apply_filters( 'pre_site_transient_' . $transient, false );
+        if ( false !== $pre )
+                return $pre;
+
+        if ( $_wp_using_ext_object_cache ) {
+                $value = wp_cache_get($transient, 'site-transient');
+        } else {
+                $transient_option = '_site_transient_' . esc_sql($transient);
+                $transient_timeout = '_site_transient_timeout_' . esc_sql($transient);
+                if ( get_site_option($transient_timeout) &lt; time() ) {
+                        delete_site_option($transient_option);
+                        delete_site_option($transient_timeout);
+                        return false;
+                }
+
+                $value = get_site_option($transient_option);
+        }
+
+        return apply_filters('site_transient_' . $transient, $value);
+}
+
+/**
+ * Set/update the value of a site transient
+ *
+ * You do not need to serialize values, if the value needs to be serialize, then
+ * it will be serialized before it is set.
+ *
+ * @since 2.9.0
+ * @package WordPress
+ * @subpackage Transient
+ *
+ * @param string $transient Transient name. Expected to not be SQL-escaped
+ * @param mixed $value Transient value.
+ * @param int $expiration Time until expiration in seconds, default 0
+ * @return bool False if value was not set and true if value was set.
+ */
+function set_site_transient($transient, $value, $expiration = 0) {
+        global $_wp_using_ext_object_cache, $wpdb;
+
+        if ( $_wp_using_ext_object_cache ) {
+                return wp_cache_set($transient, $value, 'site-transient', $expiration);
+        } else {
+                $transient_timeout = '_site_transient_timeout_' . $transient;
+                $transient = '_site_transient_' . $transient;
+                $safe_transient = esc_sql($transient);
+                if ( false === get_site_option( $safe_transient ) ) {
+                        if ( 0 != $expiration )
+                                add_site_option($transient_timeout, time() + $expiration);
+                        return add_site_option($transient, $value);
+                } else {
+                        if ( 0 != $expiration )
+                                update_site_option($transient_timeout, time() + $expiration);
+                        return update_site_option($transient, $value);
+                }
+        }
+}
+
+/**
</ins><span class="cx">  * gmt_offset modification for smart timezone handling
</span><span class="cx">  *
</span><span class="cx">  * Overrides the gmt_offset option if we have a timezone_string available
</span></span></pre></div>
<a id="trunkwpincludesthemephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/theme.php (12127 => 12128)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/theme.php        2009-10-29 18:02:55 UTC (rev 12127)
+++ trunk/wp-includes/theme.php        2009-10-29 21:53:57 UTC (rev 12128)
</span><span class="lines">@@ -398,8 +398,8 @@
</span><span class="cx">         $theme_names = array_keys( $themes );
</span><span class="cx"> 
</span><span class="cx">         /* Store theme roots in the DB */
</span><del>-        if ( get_transient( 'theme_roots' ) != $theme_roots )
-                set_transient( 'theme_roots', $theme_roots, 7200 ); // cache for two hours
</del><ins>+        if ( get_site_transient( 'theme_roots' ) != $theme_roots )
+                set_site_transient( 'theme_roots', $theme_roots, 7200 ); // cache for two hours
</ins><span class="cx"> 
</span><span class="cx">         foreach ( (array) $theme_names as $theme_name ) {
</span><span class="cx">                 $themes[$theme_name]['Parent Theme'] = '';
</span><span class="lines">@@ -426,10 +426,10 @@
</span><span class="cx">  * @return array Theme roots
</span><span class="cx">  */
</span><span class="cx"> function get_theme_roots() {
</span><del>-        $theme_roots = get_transient( 'theme_roots' );
</del><ins>+        $theme_roots = get_site_transient( 'theme_roots' );
</ins><span class="cx">         if ( false === $theme_roots ) {
</span><span class="cx">                 get_themes();
</span><del>-                $theme_roots = get_transient( 'theme_roots' ); // this is set in get_theme()
</del><ins>+                $theme_roots = get_site_transient( 'theme_roots' ); // this is set in get_theme()
</ins><span class="cx">         }
</span><span class="cx">         return $theme_roots;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkwpsettingsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-settings.php (12127 => 12128)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-settings.php        2009-10-29 18:02:55 UTC (rev 12127)
+++ trunk/wp-settings.php        2009-10-29 21:53:57 UTC (rev 12128)
</span><span class="lines">@@ -304,7 +304,7 @@
</span><span class="cx"> 
</span><span class="cx"> wp_cache_init();
</span><span class="cx"> if ( function_exists('wp_cache_add_global_groups') ) {
</span><del>-        wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta'));
</del><ins>+        wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta', 'site-transient'));
</ins><span class="cx">         wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>