Ticket #43233: 43233.2.diff
File 43233.2.diff, 12.2 KB (added by , 6 years ago) |
---|
-
src/wp-includes/option.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
1652 1652 * 1653 1653 * @since 2.9.0 1654 1654 * 1655 * @see delete_network_transient 1656 * 1655 1657 * @param string $transient Transient name. Expected to not be SQL-escaped. 1658 * 1656 1659 * @return bool True if successful, false otherwise 1657 1660 */ 1658 1661 function 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 */ 1679 function 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 */ 1700 function 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 */ 1713 function 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 } 1659 1725 1660 1726 /** 1661 1727 * Fires immediately before a specific site transient is deleted. … … 1663 1729 * The dynamic portion of the hook name, `$transient`, refers to the transient name. 1664 1730 * 1665 1731 * @since 3.0.0 1732 * @since 5.0.0 The `$network_id` parameter was added. 1666 1733 * 1667 1734 * @param string $transient Transient name. 1735 * @param int $network_id ID of the network. 1668 1736 */ 1669 do_action( "delete_site_transient_{$transient}", $transient );1737 do_action( "delete_site_transient_{$transient}", $transient, $network_id ); 1670 1738 1671 1739 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' ); 1673 1742 } else { 1674 1743 $option_timeout = '_site_transient_timeout_' . $transient; 1675 1744 $option = '_site_transient_' . $transient; 1676 $result = delete_ site_option($option );1745 $result = delete_network_option( $network_id, $option ); 1677 1746 if ( $result ) { 1678 delete_ site_option($option_timeout );1747 delete_network_option( $network_id, $option_timeout ); 1679 1748 } 1680 1749 } 1681 1750 if ( $result ) { … … 1686 1755 * @since 3.0.0 1687 1756 * 1688 1757 * @param string $transient Deleted transient name. 1758 * @param int $network_id ID of the network. 1689 1759 */ 1690 do_action( 'deleted_site_transient', $transient );1760 do_action( 'deleted_site_transient', $transient, $network_id ); 1691 1761 } 1692 1762 1693 1763 return $result; 1694 1764 } 1695 1765 1696 1766 /** 1697 * Get the value of a sitetransient.1767 * Get the value of a network transient. 1698 1768 * 1699 1769 * If the transient does not exist, does not have a value, or has expired, 1700 1770 * then the return value will be false. 1701 1771 * 1702 * @since 2.9.01772 * @since 5.0.0 1703 1773 * 1704 1774 * @see get_transient() 1705 * 1775 1776 * @param int $network_id ID of the network. 1706 1777 * @param string $transient Transient name. Expected to not be SQL-escaped. 1707 1778 * @return mixed Value of transient. 1708 1779 */ 1709 function get_site_transient( $transient ) { 1780 function 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 } 1710 1792 1711 1793 /** 1712 * Filters the value of an existing sitetransient.1794 * Filters the value of an existing network transient. 1713 1795 * 1714 1796 * The dynamic portion of the hook name, `$transient`, refers to the transient name. 1715 1797 * … … 1718 1800 * 1719 1801 * @since 2.9.0 1720 1802 * @since 4.4.0 The `$transient` parameter was added. 1803 * @since 5.0.0 The `$network_id` parameter was added. 1721 1804 * 1722 1805 * @param mixed $pre_site_transient The default value to return if the site transient does not exist. 1723 1806 * Any value other than false will short-circuit the retrieval 1724 1807 * of the transient, and return the returned value. 1725 1808 * @param string $transient Transient name. 1809 * @param int $network_id ID of the network. 1726 1810 */ 1727 $pre = apply_filters( "pre_site_transient_{$transient}", false, $transient );1811 $pre = apply_filters( "pre_site_transient_{$transient}", false, $transient, $network_id ); 1728 1812 1729 1813 if ( false !== $pre ) { 1730 1814 return $pre; 1731 1815 } 1732 1816 1733 1817 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' ); 1735 1820 } else { 1736 1821 // Core transients that do not have a timeout. Listed here so querying timeouts can be avoided. 1737 1822 $no_timeout = array( 'update_core', 'update_plugins', 'update_themes' ); 1738 1823 $transient_option = '_site_transient_' . $transient; 1739 1824 if ( ! in_array( $transient, $no_timeout ) ) { 1740 1825 $transient_timeout = '_site_transient_timeout_' . $transient; 1741 $timeout = get_ site_option($transient_timeout );1826 $timeout = get_network_option( $network_id, $transient_timeout ); 1742 1827 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 ); 1745 1830 $value = false; 1746 1831 } 1747 1832 } 1748 1833 1749 1834 if ( ! isset( $value ) ) { 1750 $value = get_ site_option($transient_option );1835 $value = get_network_option( $network_id, $transient_option ); 1751 1836 } 1752 1837 } 1753 1838 … … 1758 1843 * 1759 1844 * @since 2.9.0 1760 1845 * @since 4.4.0 The `$transient` parameter was added. 1846 * @since 5.0.0 The `$network_id` parameter was added. 1761 1847 * 1762 1848 * @param mixed $value Value of site transient. 1763 1849 * @param string $transient Transient name. 1850 * @param int $network_id ID of the network. 1764 1851 */ 1765 return apply_filters( "site_transient_{$transient}", $value, $transient );1852 return apply_filters( "site_transient_{$transient}", $value, $transient, $network_id ); 1766 1853 } 1767 1854 1768 1855 /** 1769 * Set/update the value of a sitetransient.1856 * Set/update the value of a network transient. 1770 1857 * 1771 1858 * You do not need to serialize values, if the value needs to be serialize, then 1772 1859 * it will be serialized before it is set. 1773 1860 * 1774 * @since 2.9.01861 * @since 5.0.0 1775 1862 * 1776 1863 * @see set_transient() 1777 1864 * … … 1781 1868 * @param int $expiration Optional. Time until expiration in seconds. Default 0 (no expiration). 1782 1869 * @return bool False if value was not set and true if value was set. 1783 1870 */ 1784 function set_site_transient( $transient, $value, $expiration = 0 ) { 1871 function 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 } 1785 1883 1786 1884 /** 1787 * Filters the value of a specific sitetransient before it is set.1885 * Filters the value of a specific network transient before it is set. 1788 1886 * 1789 1887 * The dynamic portion of the hook name, `$transient`, refers to the transient name. 1790 1888 * 1791 1889 * @since 3.0.0 1792 1890 * @since 4.4.0 The `$transient` parameter was added. 1891 * @since 5.0.0 The `$network_id` parameter was added. 1793 1892 * 1794 1893 * @param mixed $value New value of site transient. 1795 1894 * @param string $transient Transient name. 1895 * @param int $network_id ID of the network. 1796 1896 */ 1797 $value = apply_filters( "pre_set_site_transient_{$transient}", $value, $transient );1897 $value = apply_filters( "pre_set_site_transient_{$transient}", $value, $transient, $network_id ); 1798 1898 1799 1899 $expiration = (int) $expiration; 1800 1900 1801 1901 /** 1802 * Filters the expiration for a sitetransient before its value is set.1902 * Filters the expiration for a network transient before its value is set. 1803 1903 * 1804 1904 * The dynamic portion of the hook name, `$transient`, refers to the transient name. 1805 1905 * 1806 1906 * @since 4.4.0 1907 * @since 5.0.0 The `$network_id` parameter was added. 1807 1908 * 1808 1909 * @param int $expiration Time until expiration in seconds. Use 0 for no expiration. 1809 1910 * @param mixed $value New value of site transient. 1810 1911 * @param string $transient Transient name. 1912 * @param int $network_id ID of the network. 1811 1913 */ 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 ); 1813 1915 1814 1916 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 ); 1816 1919 } else { 1817 1920 $transient_timeout = '_site_transient_timeout_' . $transient; 1818 1921 $option = '_site_transient_' . $transient; 1819 if ( false === get_ site_option($option ) ) {1922 if ( false === get_network_option( $network_id, $option ) ) { 1820 1923 if ( $expiration ) { 1821 add_ site_option($transient_timeout, time() + $expiration );1924 add_network_option( $network_id, $transient_timeout, time() + $expiration ); 1822 1925 } 1823 $result = add_ site_option($option, $value );1926 $result = add_network_option( $network_id, $option, $value ); 1824 1927 } else { 1825 1928 if ( $expiration ) { 1826 update_ site_option($transient_timeout, time() + $expiration );1929 update_network_option( $network_id, $transient_timeout, time() + $expiration ); 1827 1930 } 1828 $result = update_ site_option($option, $value );1931 $result = update_network_option( $network_id, $option, $value ); 1829 1932 } 1830 1933 } 1831 1934 if ( $result ) { 1832 1935 1833 1936 /** 1834 * Fires after the value for a specific sitetransient has been set.1937 * Fires after the value for a specific network transient has been set. 1835 1938 * 1836 1939 * The dynamic portion of the hook name, `$transient`, refers to the transient name. 1837 1940 * 1838 1941 * @since 3.0.0 1839 1942 * @since 4.4.0 The `$transient` parameter was added 1943 * @since 5.0.0 The `$network_id` parameter was added. 1840 1944 * 1841 1945 * @param mixed $value Site transient value. 1842 1946 * @param int $expiration Time until expiration in seconds. 1843 1947 * @param string $transient Transient name. 1948 * @param int $network_id ID of the network. 1844 1949 */ 1845 do_action( "set_site_transient_{$transient}", $value, $expiration, $transient );1950 do_action( "set_site_transient_{$transient}", $value, $expiration, $transient, $network_id ); 1846 1951 1847 1952 /** 1848 * Fires after the value for a sitetransient has been set.1953 * Fires after the value for a network transient has been set. 1849 1954 * 1850 1955 * @since 3.0.0 1956 * @since 5.0.0 The `$network_id` parameter was added. 1851 1957 * 1852 1958 * @param string $transient The name of the site transient. 1853 1959 * @param mixed $value Site transient value. 1854 1960 * @param int $expiration Time until expiration in seconds. 1961 * @param int $network_id ID of the network. 1855 1962 */ 1856 do_action( 'setted_site_transient', $transient, $value, $expiration );1963 do_action( 'setted_site_transient', $transient, $value, $expiration, $network_id ); 1857 1964 } 1858 1965 return $result; 1859 1966 }