Introduce get/set/delete_site_transient(). Make theme_roots a site transient.
git-svn-id: http://svn.automattic.com/wordpress/trunk@12128 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
dd4b5f01c0
commit
9ee06eaec7
|
@ -3190,6 +3190,12 @@ function add_site_option( $key, $value ) {
|
|||
return $result;
|
||||
}
|
||||
|
||||
function delete_site_option( $key ) {
|
||||
$result = delete_option($key);
|
||||
do_action( "delete_site_option_{$key}", $key );
|
||||
return $result;
|
||||
}
|
||||
|
||||
// expects $key, $value not to be SQL escaped
|
||||
function update_site_option( $key, $value ) {
|
||||
$oldvalue = get_site_option( $key );
|
||||
|
@ -3199,6 +3205,100 @@ function update_site_option( $key, $value ) {
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) < 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gmt_offset modification for smart timezone handling
|
||||
*
|
||||
|
|
|
@ -398,8 +398,8 @@ function get_themes() {
|
|||
$theme_names = array_keys( $themes );
|
||||
|
||||
/* Store theme roots in the DB */
|
||||
if ( get_transient( 'theme_roots' ) != $theme_roots )
|
||||
set_transient( 'theme_roots', $theme_roots, 7200 ); // cache for two hours
|
||||
if ( get_site_transient( 'theme_roots' ) != $theme_roots )
|
||||
set_site_transient( 'theme_roots', $theme_roots, 7200 ); // cache for two hours
|
||||
|
||||
foreach ( (array) $theme_names as $theme_name ) {
|
||||
$themes[$theme_name]['Parent Theme'] = '';
|
||||
|
@ -426,10 +426,10 @@ function get_themes() {
|
|||
* @return array Theme roots
|
||||
*/
|
||||
function get_theme_roots() {
|
||||
$theme_roots = get_transient( 'theme_roots' );
|
||||
$theme_roots = get_site_transient( 'theme_roots' );
|
||||
if ( false === $theme_roots ) {
|
||||
get_themes();
|
||||
$theme_roots = get_transient( 'theme_roots' ); // this is set in get_theme()
|
||||
$theme_roots = get_site_transient( 'theme_roots' ); // this is set in get_theme()
|
||||
}
|
||||
return $theme_roots;
|
||||
}
|
||||
|
|
|
@ -304,7 +304,7 @@ if ( file_exists(WP_CONTENT_DIR . '/object-cache.php') ) {
|
|||
|
||||
wp_cache_init();
|
||||
if ( function_exists('wp_cache_add_global_groups') ) {
|
||||
wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta'));
|
||||
wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta', 'site-transient'));
|
||||
wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue