Make WordPress Core

Ticket #37040: valid_transients.patch

File valid_transients.patch, 3.7 KB (added by danieliser, 9 years ago)

Adds 2 new functions valid_transient & valid_site_transient. Modifies get_transient & get_site_transient to use these new functions.

  • wp-includes/option.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    596596}
    597597
    598598/**
     599 * Determines if a transient is valid.
     600 *
     601 * If the transient does not exist, does not have a value, or has expired,
     602 * then the return value will be false.
     603 *
     604 * @since 4.7.0
     605 *
     606 * @param string $transient Transient name. Expected to not be SQL-escaped.
     607 *
     608 * @return bool
     609 */
     610function valid_transient( $transient ) {
     611
     612        $transient_timeout = '_transient_timeout_' . $transient;
     613        $timeout           = get_option( $transient_timeout );
     614
     615        // No transient found.
     616        if ( false === $timeout ) {
     617                return false;
     618        }
     619        // Expired transient detected.
     620        elseif ( false !== $timeout && $timeout < time() ) {
     621                delete_option( '_transient_' . $transient );
     622                delete_option( $transient_timeout );
     623
     624                return false;
     625        }
     626
     627        // Transient is valid.
     628        return true;
     629}
     630
     631/**
    599632 * Get the value of a transient.
    600633 *
    601634 * If the transient does not exist, does not have a value, or has expired,
     
    635668                if ( ! wp_installing() ) {
    636669                        // If option is not in alloptions, it is not autoloaded and thus has a timeout
    637670                        $alloptions = wp_load_alloptions();
    638                         if ( !isset( $alloptions[$transient_option] ) ) {
    639                                 $transient_timeout = '_transient_timeout_' . $transient;
    640                                 $timeout = get_option( $transient_timeout );
    641                                 if ( false !== $timeout && $timeout < time() ) {
    642                                         delete_option( $transient_option  );
    643                                         delete_option( $transient_timeout );
    644                                         $value = false;
    645                                 }
    646                         }
    647                 }
     671                        if ( !isset( $alloptions[$transient_option] ) && ! valid_transient( $transient ) ) {
     672                                $value = false;
     673                        }
     674                }
    648675
    649676                if ( ! isset( $value ) )
    650677                        $value = get_option( $transient_option );
     
    15271554}
    15281555
    15291556/**
     1557 * Determines if a site transient is valid.
     1558 *
     1559 * If the transient does not exist, does not have a value, or has expired,
     1560 * then the return value will be false.
     1561 *
     1562 * @since 4.7.0
     1563 *
     1564 * @param string $transient Transient name. Expected to not be SQL-escaped.
     1565 *
     1566 * @return bool
     1567 */
     1568function valid_site_transient( $transient ) {
     1569
     1570        $transient_timeout = '_site_transient_timeout_' . $transient;
     1571        $timeout = get_site_option( $transient_timeout );
     1572
     1573        // No transient found.
     1574        if ( false === $timeout ) {
     1575                return false;
     1576        }
     1577        // Expired transient detected.
     1578        elseif ( false !== $timeout && $timeout < time() ) {
     1579                delete_site_option( '_site_transient_' . $transient );
     1580                delete_site_option( $transient_timeout );
     1581
     1582                return false;
     1583        }
     1584
     1585        // Transient is valid.
     1586        return true;
     1587}
     1588
     1589/**
    15301590 * Get the value of a site transient.
    15311591 *
    15321592 * If the transient does not exist, does not have a value, or has expired,
     
    15671627        } else {
    15681628                // Core transients that do not have a timeout. Listed here so querying timeouts can be avoided.
    15691629                $no_timeout = array('update_core', 'update_plugins', 'update_themes');
    1570                 $transient_option = '_site_transient_' . $transient;
    1571                 if ( ! in_array( $transient, $no_timeout ) ) {
    1572                         $transient_timeout = '_site_transient_timeout_' . $transient;
    1573                         $timeout = get_site_option( $transient_timeout );
    1574                         if ( false !== $timeout && $timeout < time() ) {
    1575                                 delete_site_option( $transient_option  );
    1576                                 delete_site_option( $transient_timeout );
    1577                                 $value = false;
    1578                         }
    1579                 }
     1630                if ( ! in_array( $transient, $no_timeout ) && ! valid_site_transient( $transient ) ) {
     1631                        $value = false;
     1632                }
    15801633
    15811634                if ( ! isset( $value ) )
    1582                         $value = get_site_option( $transient_option );
     1635                        $value = get_site_option( '_site_transient_' . $transient );
    15831636        }
    15841637
    15851638        /**