Make WordPress Core

Ticket #43233: 43233.diff

File 43233.diff, 11.4 KB (added by spacedmonkey, 8 years ago)
  • src/wp-includes/option.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    16521652 *
    16531653 * @since 2.9.0
    16541654 *
     1655 * @see delete_network_transient
     1656 *
    16551657 * @param string $transient Transient name. Expected to not be SQL-escaped.
     1658 *
    16561659 * @return bool True if successful, false otherwise
    16571660 */
    16581661function delete_site_transient( $transient ) {
     1662        return delete_network_transient( null, $transient );
     1663}
     1664
     1665/**
     1666 * Get the value of a site transient.
     1667 *
     1668 * If the transient does not exist, does not have a value, or has expired,
     1669 * then the return value will be false.
     1670 *
     1671 * @since 2.9.0
     1672 *
     1673 * @see get_network_transient()
     1674 *
     1675 * @param string $transient Transient name. Expected to not be SQL-escaped.
     1676 *
     1677 * @return mixed Value of transient.
     1678 */
     1679function get_site_transient( $transient ) {
     1680        return get_network_transient( null, $transient );
     1681}
     1682
     1683/**
     1684 * Set/update the value of a site transient.
     1685 *
     1686 * You do not need to serialize values, if the value needs to be serialize, then
     1687 * it will be serialized before it is set.
     1688 *
     1689 * @since 2.9.0
     1690 *
     1691 * @see set_network_transient()
     1692 *
     1693 * @param string $transient Transient name. Expected to not be SQL-escaped. Must be
     1694 *                           167 characters or fewer in length.
     1695 * @param mixed $value Transient value. Expected to not be SQL-escaped.
     1696 * @param int $expiration Optional. Time until expiration in seconds. Default 0 (no expiration).
     1697 *
     1698 * @return bool False if value was not set and true if value was set.
     1699 */
     1700function set_site_transient( $transient, $value, $expiration = 0 ) {
     1701        return set_network_transient( null, $value, $expiration = 0 );
     1702}
     1703
     1704/**
     1705 * Delete a network transient.
     1706 *
     1707 * @since 5.0.0
     1708 *
     1709 * @param string $transient Transient name. Expected to not be SQL-escaped.
     1710 * @return bool True if successful, false otherwise
     1711 * @param int    $network_id ID of the network.
     1712 */
     1713function delete_network_transient( $network_id, $transient ) {
    16591714
    16601715        /**
    16611716         * Fires immediately before a specific site transient is deleted.
     
    16631718         * The dynamic portion of the hook name, `$transient`, refers to the transient name.
    16641719         *
    16651720         * @since 3.0.0
     1721         * @since 5.0.0 The `$network_id` parameter was added.
    16661722         *
    16671723         * @param string $transient Transient name.
     1724         * @param int    $network_id ID of the network.
    16681725         */
    1669         do_action( "delete_site_transient_{$transient}", $transient );
     1726        do_action( "delete_site_transient_{$transient}", $transient, $network_id );
    16701727
    16711728        if ( wp_using_ext_object_cache() ) {
    1672                 $result = wp_cache_delete( $transient, 'site-transient' );
     1729                $cache_key = "$network_id:$transient";
     1730                $result    = wp_cache_delete( $cache_key, 'site-transient' );
    16731731        } else {
    16741732                $option_timeout = '_site_transient_timeout_' . $transient;
    16751733                $option         = '_site_transient_' . $transient;
    1676                 $result         = delete_site_option( $option );
     1734                $result         = delete_network_option( $network_id, $option );
    16771735                if ( $result ) {
    1678                         delete_site_option( $option_timeout );
     1736                        delete_network_option( $network_id, $option_timeout );
    16791737                }
    16801738        }
    16811739        if ( $result ) {
     
    16861744                 * @since 3.0.0
    16871745                 *
    16881746                 * @param string $transient Deleted transient name.
     1747                 * @param int    $network_id ID of the network.
    16891748                 */
    1690                 do_action( 'deleted_site_transient', $transient );
     1749                do_action( 'deleted_site_transient', $transient, $network_id );
    16911750        }
    16921751
    16931752        return $result;
    16941753}
    16951754
    16961755/**
    1697  * Get the value of a site transient.
     1756 * Get the value of a network transient.
    16981757 *
    16991758 * If the transient does not exist, does not have a value, or has expired,
    17001759 * then the return value will be false.
    17011760 *
    1702  * @since 2.9.0
     1761 * @since 5.0.0
    17031762 *
    17041763 * @see get_transient()
    1705  *
     1764
     1765 * @param int    $network_id ID of the network.
    17061766 * @param string $transient Transient name. Expected to not be SQL-escaped.
    17071767 * @return mixed Value of transient.
    17081768 */
    1709 function get_site_transient( $transient ) {
     1769function get_network_transient( $network_id, $transient ) {
    17101770
    17111771        /**
    1712          * Filters the value of an existing site transient.
     1772         * Filters the value of an existing network transient.
    17131773         *
    17141774         * The dynamic portion of the hook name, `$transient`, refers to the transient name.
    17151775         *
     
    17181778         *
    17191779         * @since 2.9.0
    17201780         * @since 4.4.0 The `$transient` parameter was added.
     1781         * @since 5.0.0 The `$network_id` parameter was added.
    17211782         *
    17221783         * @param mixed  $pre_site_transient The default value to return if the site transient does not exist.
    17231784         *                                   Any value other than false will short-circuit the retrieval
    17241785         *                                   of the transient, and return the returned value.
    17251786         * @param string $transient          Transient name.
     1787         * @param int    $network_id ID of the network.
    17261788         */
    1727         $pre = apply_filters( "pre_site_transient_{$transient}", false, $transient );
     1789        $pre = apply_filters( "pre_site_transient_{$transient}", false, $transient, $network_id );
    17281790
    17291791        if ( false !== $pre ) {
    17301792                return $pre;
    17311793        }
    17321794
    17331795        if ( wp_using_ext_object_cache() ) {
    1734                 $value = wp_cache_get( $transient, 'site-transient' );
     1796                $cache_key = "$network_id:$transient";
     1797                $value = wp_cache_get( $cache_key, 'site-transient' );
    17351798        } else {
    17361799                // Core transients that do not have a timeout. Listed here so querying timeouts can be avoided.
    17371800                $no_timeout       = array( 'update_core', 'update_plugins', 'update_themes' );
    17381801                $transient_option = '_site_transient_' . $transient;
    17391802                if ( ! in_array( $transient, $no_timeout ) ) {
    17401803                        $transient_timeout = '_site_transient_timeout_' . $transient;
    1741                         $timeout           = get_site_option( $transient_timeout );
     1804                        $timeout           = get_network_option( $network_id, $transient_timeout );
    17421805                        if ( false !== $timeout && $timeout < time() ) {
    1743                                 delete_site_option( $transient_option );
    1744                                 delete_site_option( $transient_timeout );
     1806                                delete_network_option( $network_id, $transient_option );
     1807                                delete_network_option( $network_id, $transient_timeout );
    17451808                                $value = false;
    17461809                        }
    17471810                }
    17481811
    17491812                if ( ! isset( $value ) ) {
    1750                         $value = get_site_option( $transient_option );
     1813                        $value = get_network_option( $network_id, $transient_option );
    17511814                }
    17521815        }
    17531816
     
    17581821         *
    17591822         * @since 2.9.0
    17601823         * @since 4.4.0 The `$transient` parameter was added.
     1824         * @since 5.0.0 The `$network_id` parameter was added.
    17611825         *
    17621826         * @param mixed  $value     Value of site transient.
    17631827         * @param string $transient Transient name.
     1828         * @param int    $network_id ID of the network.
    17641829         */
    1765         return apply_filters( "site_transient_{$transient}", $value, $transient );
     1830        return apply_filters( "site_transient_{$transient}", $value, $transient, $network_id );
    17661831}
    17671832
    17681833/**
    1769  * Set/update the value of a site transient.
     1834 * Set/update the value of a network transient.
    17701835 *
    17711836 * You do not need to serialize values, if the value needs to be serialize, then
    17721837 * it will be serialized before it is set.
    17731838 *
    1774  * @since 2.9.0
     1839 * @since 5.0.0
    17751840 *
    17761841 * @see set_transient()
    17771842 *
     
    17811846 * @param int    $expiration Optional. Time until expiration in seconds. Default 0 (no expiration).
    17821847 * @return bool False if value was not set and true if value was set.
    17831848 */
    1784 function set_site_transient( $transient, $value, $expiration = 0 ) {
     1849function set_network_transient( $network_id, $transient, $value, $expiration = 0 ) {
    17851850
    17861851        /**
    1787          * Filters the value of a specific site transient before it is set.
     1852         * Filters the value of a specific network transient before it is set.
    17881853         *
    17891854         * The dynamic portion of the hook name, `$transient`, refers to the transient name.
    17901855         *
    17911856         * @since 3.0.0
    17921857         * @since 4.4.0 The `$transient` parameter was added.
     1858         * @since 5.0.0 The `$network_id` parameter was added.
    17931859         *
    17941860         * @param mixed  $value     New value of site transient.
    17951861         * @param string $transient Transient name.
     1862         * @param int    $network_id ID of the network.
    17961863         */
    1797         $value = apply_filters( "pre_set_site_transient_{$transient}", $value, $transient );
     1864        $value = apply_filters( "pre_set_site_transient_{$transient}", $value, $transient, $network_id );
    17981865
    17991866        $expiration = (int) $expiration;
    18001867
    18011868        /**
    1802          * Filters the expiration for a site transient before its value is set.
     1869         * Filters the expiration for a network transient before its value is set.
    18031870         *
    18041871         * The dynamic portion of the hook name, `$transient`, refers to the transient name.
    18051872         *
    18061873         * @since 4.4.0
     1874         * @since 5.0.0 The `$network_id` parameter was added.
    18071875         *
    18081876         * @param int    $expiration Time until expiration in seconds. Use 0 for no expiration.
    18091877         * @param mixed  $value      New value of site transient.
    18101878         * @param string $transient  Transient name.
     1879         * @param int    $network_id ID of the network.
    18111880         */
    1812         $expiration = apply_filters( "expiration_of_site_transient_{$transient}", $expiration, $value, $transient );
     1881        $expiration = apply_filters( "expiration_of_site_transient_{$transient}", $expiration, $value, $transient, $network_id );
    18131882
    18141883        if ( wp_using_ext_object_cache() ) {
    1815                 $result = wp_cache_set( $transient, $value, 'site-transient', $expiration );
     1884                $cache_key = "$network_id:$transient";
     1885                $result = wp_cache_set( $cache_key, $value, 'site-transient', $expiration );
    18161886        } else {
    18171887                $transient_timeout = '_site_transient_timeout_' . $transient;
    18181888                $option            = '_site_transient_' . $transient;
    1819                 if ( false === get_site_option( $option ) ) {
     1889                if ( false === get_network_option( $network_id, $option ) ) {
    18201890                        if ( $expiration ) {
    1821                                 add_site_option( $transient_timeout, time() + $expiration );
     1891                                add_network_option( $network_id, $transient_timeout, time() + $expiration );
    18221892                        }
    1823                         $result = add_site_option( $option, $value );
     1893                        $result = add_network_option( $network_id, $option, $value );
    18241894                } else {
    18251895                        if ( $expiration ) {
    1826                                 update_site_option( $transient_timeout, time() + $expiration );
     1896                                update_network_option( $network_id, $transient_timeout, time() + $expiration );
    18271897                        }
    1828                         $result = update_site_option( $option, $value );
     1898                        $result = update_network_option( $network_id, $option, $value );
    18291899                }
    18301900        }
    18311901        if ( $result ) {
    18321902
    18331903                /**
    1834                  * Fires after the value for a specific site transient has been set.
     1904                 * Fires after the value for a specific network transient has been set.
    18351905                 *
    18361906                 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
    18371907                 *
    18381908                 * @since 3.0.0
    18391909                 * @since 4.4.0 The `$transient` parameter was added
     1910                 * @since 5.0.0 The `$network_id` parameter was added.
    18401911                 *
    18411912                 * @param mixed  $value      Site transient value.
    18421913                 * @param int    $expiration Time until expiration in seconds.
    18431914                 * @param string $transient  Transient name.
     1915                 * @param int    $network_id ID of the network.
    18441916                 */
    1845                 do_action( "set_site_transient_{$transient}", $value, $expiration, $transient );
     1917                do_action( "set_site_transient_{$transient}", $value, $expiration, $transient, $network_id );
    18461918
    18471919                /**
    1848                  * Fires after the value for a site transient has been set.
     1920                 * Fires after the value for a network transient has been set.
    18491921                 *
    18501922                 * @since 3.0.0
     1923                 * @since 5.0.0 The `$network_id` parameter was added.
    18511924                 *
    18521925                 * @param string $transient  The name of the site transient.
    18531926                 * @param mixed  $value      Site transient value.
    18541927                 * @param int    $expiration Time until expiration in seconds.
     1928                 * @param int    $network_id ID of the network.
    18551929                 */
    1856                 do_action( 'setted_site_transient', $transient, $value, $expiration );
     1930                do_action( 'setted_site_transient', $transient, $value, $expiration, $network_id );
    18571931        }
    18581932        return $result;
    18591933}