Make WordPress Core

Ticket #43233: 43233.2.diff

File 43233.2.diff, 12.2 KB (added by spacedmonkey, 6 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 ) {
     1714
     1715        if ( $network_id && ! is_numeric( $network_id ) ) {
     1716                return false;
     1717        }
     1718
     1719        $network_id = (int) $network_id;
     1720
     1721        // Fallback to the current network if a network ID is not specified.
     1722        if ( ! $network_id ) {
     1723                $network_id = get_current_network_id();
     1724        }
    16591725
    16601726        /**
    16611727         * Fires immediately before a specific site transient is deleted.
     
    16631729         * The dynamic portion of the hook name, `$transient`, refers to the transient name.
    16641730         *
    16651731         * @since 3.0.0
     1732         * @since 5.0.0 The `$network_id` parameter was added.
    16661733         *
    16671734         * @param string $transient Transient name.
     1735         * @param int    $network_id ID of the network.
    16681736         */
    1669         do_action( "delete_site_transient_{$transient}", $transient );
     1737        do_action( "delete_site_transient_{$transient}", $transient, $network_id );
    16701738
    16711739        if ( wp_using_ext_object_cache() ) {
    1672                 $result = wp_cache_delete( $transient, 'site-transient' );
     1740                $cache_key = "$network_id:$transient";
     1741                $result    = wp_cache_delete( $cache_key, 'site-transient' );
    16731742        } else {
    16741743                $option_timeout = '_site_transient_timeout_' . $transient;
    16751744                $option         = '_site_transient_' . $transient;
    1676                 $result         = delete_site_option( $option );
     1745                $result         = delete_network_option( $network_id, $option );
    16771746                if ( $result ) {
    1678                         delete_site_option( $option_timeout );
     1747                        delete_network_option( $network_id, $option_timeout );
    16791748                }
    16801749        }
    16811750        if ( $result ) {
     
    16861755                 * @since 3.0.0
    16871756                 *
    16881757                 * @param string $transient Deleted transient name.
     1758                 * @param int    $network_id ID of the network.
    16891759                 */
    1690                 do_action( 'deleted_site_transient', $transient );
     1760                do_action( 'deleted_site_transient', $transient, $network_id );
    16911761        }
    16921762
    16931763        return $result;
    16941764}
    16951765
    16961766/**
    1697  * Get the value of a site transient.
     1767 * Get the value of a network transient.
    16981768 *
    16991769 * If the transient does not exist, does not have a value, or has expired,
    17001770 * then the return value will be false.
    17011771 *
    1702  * @since 2.9.0
     1772 * @since 5.0.0
    17031773 *
    17041774 * @see get_transient()
    1705  *
     1775
     1776 * @param int    $network_id ID of the network.
    17061777 * @param string $transient Transient name. Expected to not be SQL-escaped.
    17071778 * @return mixed Value of transient.
    17081779 */
    1709 function get_site_transient( $transient ) {
     1780function get_network_transient( $network_id, $transient ) {
     1781
     1782        if ( $network_id && ! is_numeric( $network_id ) ) {
     1783                return false;
     1784        }
     1785
     1786        $network_id = (int) $network_id;
     1787
     1788        // Fallback to the current network if a network ID is not specified.
     1789        if ( ! $network_id ) {
     1790                $network_id = get_current_network_id();
     1791        }
    17101792
    17111793        /**
    1712          * Filters the value of an existing site transient.
     1794         * Filters the value of an existing network transient.
    17131795         *
    17141796         * The dynamic portion of the hook name, `$transient`, refers to the transient name.
    17151797         *
     
    17181800         *
    17191801         * @since 2.9.0
    17201802         * @since 4.4.0 The `$transient` parameter was added.
     1803         * @since 5.0.0 The `$network_id` parameter was added.
    17211804         *
    17221805         * @param mixed  $pre_site_transient The default value to return if the site transient does not exist.
    17231806         *                                   Any value other than false will short-circuit the retrieval
    17241807         *                                   of the transient, and return the returned value.
    17251808         * @param string $transient          Transient name.
     1809         * @param int    $network_id ID of the network.
    17261810         */
    1727         $pre = apply_filters( "pre_site_transient_{$transient}", false, $transient );
     1811        $pre = apply_filters( "pre_site_transient_{$transient}", false, $transient, $network_id );
    17281812
    17291813        if ( false !== $pre ) {
    17301814                return $pre;
    17311815        }
    17321816
    17331817        if ( wp_using_ext_object_cache() ) {
    1734                 $value = wp_cache_get( $transient, 'site-transient' );
     1818                $cache_key = "$network_id:$transient";
     1819                $value = wp_cache_get( $cache_key, 'site-transient' );
    17351820        } else {
    17361821                // Core transients that do not have a timeout. Listed here so querying timeouts can be avoided.
    17371822                $no_timeout       = array( 'update_core', 'update_plugins', 'update_themes' );
    17381823                $transient_option = '_site_transient_' . $transient;
    17391824                if ( ! in_array( $transient, $no_timeout ) ) {
    17401825                        $transient_timeout = '_site_transient_timeout_' . $transient;
    1741                         $timeout           = get_site_option( $transient_timeout );
     1826                        $timeout           = get_network_option( $network_id, $transient_timeout );
    17421827                        if ( false !== $timeout && $timeout < time() ) {
    1743                                 delete_site_option( $transient_option );
    1744                                 delete_site_option( $transient_timeout );
     1828                                delete_network_option( $network_id, $transient_option );
     1829                                delete_network_option( $network_id, $transient_timeout );
    17451830                                $value = false;
    17461831                        }
    17471832                }
    17481833
    17491834                if ( ! isset( $value ) ) {
    1750                         $value = get_site_option( $transient_option );
     1835                        $value = get_network_option( $network_id, $transient_option );
    17511836                }
    17521837        }
    17531838
     
    17581843         *
    17591844         * @since 2.9.0
    17601845         * @since 4.4.0 The `$transient` parameter was added.
     1846         * @since 5.0.0 The `$network_id` parameter was added.
    17611847         *
    17621848         * @param mixed  $value     Value of site transient.
    17631849         * @param string $transient Transient name.
     1850         * @param int    $network_id ID of the network.
    17641851         */
    1765         return apply_filters( "site_transient_{$transient}", $value, $transient );
     1852        return apply_filters( "site_transient_{$transient}", $value, $transient, $network_id );
    17661853}
    17671854
    17681855/**
    1769  * Set/update the value of a site transient.
     1856 * Set/update the value of a network transient.
    17701857 *
    17711858 * You do not need to serialize values, if the value needs to be serialize, then
    17721859 * it will be serialized before it is set.
    17731860 *
    1774  * @since 2.9.0
     1861 * @since 5.0.0
    17751862 *
    17761863 * @see set_transient()
    17771864 *
     
    17811868 * @param int    $expiration Optional. Time until expiration in seconds. Default 0 (no expiration).
    17821869 * @return bool False if value was not set and true if value was set.
    17831870 */
    1784 function set_site_transient( $transient, $value, $expiration = 0 ) {
     1871function set_network_transient( $network_id, $transient, $value, $expiration = 0 ) {
     1872
     1873        if ( $network_id && ! is_numeric( $network_id ) ) {
     1874                return false;
     1875        }
     1876
     1877        $network_id = (int) $network_id;
     1878
     1879        // Fallback to the current network if a network ID is not specified.
     1880        if ( ! $network_id ) {
     1881                $network_id = get_current_network_id();
     1882        }
    17851883
    17861884        /**
    1787          * Filters the value of a specific site transient before it is set.
     1885         * Filters the value of a specific network transient before it is set.
    17881886         *
    17891887         * The dynamic portion of the hook name, `$transient`, refers to the transient name.
    17901888         *
    17911889         * @since 3.0.0
    17921890         * @since 4.4.0 The `$transient` parameter was added.
     1891         * @since 5.0.0 The `$network_id` parameter was added.
    17931892         *
    17941893         * @param mixed  $value     New value of site transient.
    17951894         * @param string $transient Transient name.
     1895         * @param int    $network_id ID of the network.
    17961896         */
    1797         $value = apply_filters( "pre_set_site_transient_{$transient}", $value, $transient );
     1897        $value = apply_filters( "pre_set_site_transient_{$transient}", $value, $transient, $network_id );
    17981898
    17991899        $expiration = (int) $expiration;
    18001900
    18011901        /**
    1802          * Filters the expiration for a site transient before its value is set.
     1902         * Filters the expiration for a network transient before its value is set.
    18031903         *
    18041904         * The dynamic portion of the hook name, `$transient`, refers to the transient name.
    18051905         *
    18061906         * @since 4.4.0
     1907         * @since 5.0.0 The `$network_id` parameter was added.
    18071908         *
    18081909         * @param int    $expiration Time until expiration in seconds. Use 0 for no expiration.
    18091910         * @param mixed  $value      New value of site transient.
    18101911         * @param string $transient  Transient name.
     1912         * @param int    $network_id ID of the network.
    18111913         */
    1812         $expiration = apply_filters( "expiration_of_site_transient_{$transient}", $expiration, $value, $transient );
     1914        $expiration = apply_filters( "expiration_of_site_transient_{$transient}", $expiration, $value, $transient, $network_id );
    18131915
    18141916        if ( wp_using_ext_object_cache() ) {
    1815                 $result = wp_cache_set( $transient, $value, 'site-transient', $expiration );
     1917                $cache_key = "$network_id:$transient";
     1918                $result = wp_cache_set( $cache_key, $value, 'site-transient', $expiration );
    18161919        } else {
    18171920                $transient_timeout = '_site_transient_timeout_' . $transient;
    18181921                $option            = '_site_transient_' . $transient;
    1819                 if ( false === get_site_option( $option ) ) {
     1922                if ( false === get_network_option( $network_id, $option ) ) {
    18201923                        if ( $expiration ) {
    1821                                 add_site_option( $transient_timeout, time() + $expiration );
     1924                                add_network_option( $network_id, $transient_timeout, time() + $expiration );
    18221925                        }
    1823                         $result = add_site_option( $option, $value );
     1926                        $result = add_network_option( $network_id, $option, $value );
    18241927                } else {
    18251928                        if ( $expiration ) {
    1826                                 update_site_option( $transient_timeout, time() + $expiration );
     1929                                update_network_option( $network_id, $transient_timeout, time() + $expiration );
    18271930                        }
    1828                         $result = update_site_option( $option, $value );
     1931                        $result = update_network_option( $network_id, $option, $value );
    18291932                }
    18301933        }
    18311934        if ( $result ) {
    18321935
    18331936                /**
    1834                  * Fires after the value for a specific site transient has been set.
     1937                 * Fires after the value for a specific network transient has been set.
    18351938                 *
    18361939                 * The dynamic portion of the hook name, `$transient`, refers to the transient name.
    18371940                 *
    18381941                 * @since 3.0.0
    18391942                 * @since 4.4.0 The `$transient` parameter was added
     1943                 * @since 5.0.0 The `$network_id` parameter was added.
    18401944                 *
    18411945                 * @param mixed  $value      Site transient value.
    18421946                 * @param int    $expiration Time until expiration in seconds.
    18431947                 * @param string $transient  Transient name.
     1948                 * @param int    $network_id ID of the network.
    18441949                 */
    1845                 do_action( "set_site_transient_{$transient}", $value, $expiration, $transient );
     1950                do_action( "set_site_transient_{$transient}", $value, $expiration, $transient, $network_id );
    18461951
    18471952                /**
    1848                  * Fires after the value for a site transient has been set.
     1953                 * Fires after the value for a network transient has been set.
    18491954                 *
    18501955                 * @since 3.0.0
     1956                 * @since 5.0.0 The `$network_id` parameter was added.
    18511957                 *
    18521958                 * @param string $transient  The name of the site transient.
    18531959                 * @param mixed  $value      Site transient value.
    18541960                 * @param int    $expiration Time until expiration in seconds.
     1961                 * @param int    $network_id ID of the network.
    18551962                 */
    1856                 do_action( 'setted_site_transient', $transient, $value, $expiration );
     1963                do_action( 'setted_site_transient', $transient, $value, $expiration, $network_id );
    18571964        }
    18581965        return $result;
    18591966}