Make WordPress Core


Ignore:
Timestamp:
02/05/2009 08:46:39 PM (18 years ago)
Author:
ryan
Message:

HTTP API updates and fixes. Props sivel. see #8702

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r10504 r10507  
    623623        }
    624624        return true;
     625}
     626
     627/**
     628 * Delete a transient
     629 *
     630 * @since 2.8.0
     631 * @package WordPress
     632 * @subpackage Transient
     633 *
     634 * @param string $transient Transient name. Expected to not be SQL-escaped
     635 * @return bool true if successful, false otherwise
     636 */
     637function delete_transient($transient) {
     638        global $_wp_using_ext_object_cache, $wpdb;
     639
     640        if ( $_wp_using_ext_object_cache ) {
     641                return wp_cache_delete($transient, 'transient');
     642        } else {
     643                $transient = $wpdb->escape($transient);
     644                return delete_option($transient);
     645        }
     646}
     647
     648/**
     649 * Get the value of a transient
     650 *
     651 * If the transient does not exist or does not have a value, then the return value
     652 * will be false.
     653 *
     654 * @since 2.8.0
     655 * @package WordPress
     656 * @subpackage Transient
     657 *
     658 * @param string $transient Transient name. Expected to not be SQL-escaped
     659 * @return mixed Value of transient
     660 */
     661function get_transient($transient) {
     662        global $_wp_using_ext_object_cache, $wpdb;
     663
     664        if ( $_wp_using_ext_object_cache ) {
     665                return wp_cache_get($transient, 'transient');
     666        } else {
     667                $transient = $wpdb->escape($transient);
     668                return get_option($transient);
     669        }
     670}
     671
     672/**
     673 * Set/update the value of a transient
     674 *
     675 * You do not need to serialize values, if the value needs to be serialize, then
     676 * it will be serialized before it is set.
     677 *
     678 * @since 2.8.0
     679 * @package WordPress
     680 * @subpackage Transient
     681 *
     682 * @param string $transient Transient name. Expected to not be SQL-escaped
     683 * @param mixed $value Transient value.
     684 * @return bool False if value was not set and true if value was set.
     685 */
     686function set_transient($transient, $value) {
     687        global $_wp_using_ext_object_cache, $wpdb;
     688
     689        if ( $_wp_using_ext_object_cache ) {
     690                return wp_cache_set($transient, $value, 'transient');
     691        } else {
     692                $safe_transient = $wpdb->escape($transient);
     693                if ( false === get_option( $safe_transient ) )
     694                        return add_option($transient, $value, '', 'no');
     695                else
     696                        return update_option($transient, $value);
     697        }
    625698}
    626699
Note: See TracChangeset for help on using the changeset viewer.