Make WordPress Core


Ignore:
Timestamp:
03/25/2014 06:22:49 PM (11 years ago)
Author:
nacin
Message:

Transients: Allow a non-expiring transient to be updated with an expiry.

props shahpranaf, sandyr.
fixes #22807.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/option.php

    r27365 r27719  
    643643            $result = add_option( $transient, $value, '', $autoload );
    644644        } else {
    645             if ( $expiration )
    646                 update_option( $transient_timeout, time() + $expiration );
    647             $result = update_option( $transient, $value );
     645            // If expiration is requested, but the transient has no timeout option,
     646            // delete, then re-create transient rather than update.
     647            $update = true;
     648            if ( $expiration ) {
     649                if ( false === get_option( $transient_timeout ) ) {
     650                    delete_option( $transient );
     651                    add_option( $transient_timeout, time() + $expiration, '', 'no' );
     652                    $result = add_option( $transient, $value, '', 'no' );
     653                    $update = false;
     654                } else {
     655                    update_option( $transient_timeout, time() + $expiration );
     656                }
     657            }
     658            if ( $update ) {
     659                $result = update_option( $transient, $value );
     660            }
    648661        }
    649662    }
Note: See TracChangeset for help on using the changeset viewer.