Changeset 36565 for trunk/src/wp-includes/functions.php
- Timestamp:
- 02/17/2016 10:51:01 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.php
r36541 r36565 1801 1801 1802 1802 /** 1803 * Get uploads directory information. 1804 * 1805 * Same as wp_upload_dir() but "light weight" as it doesn't attempt to create the uploads directory. 1806 * Intended for use in themes, when only 'basedir' and 'baseurl' are needed, generally in all cases when not uploading files. 1807 * 1808 * @since 4.5.0 1809 * 1810 * @return array See wp_upload_dir() for description. 1811 */ 1812 function wp_get_upload_dir() { 1813 return wp_upload_dir( null, false ); 1814 } 1815 1816 /** 1803 1817 * Get an array containing the current upload directory's path and url. 1804 1818 * … … 1825 1839 * 'basedir' - path without subdir. 1826 1840 * 'baseurl' - URL path without subdir. 1827 * 'error' - set to false.1841 * 'error' - false or error message. 1828 1842 * 1829 1843 * @since 2.0.0 1844 * @uses _wp_upload_dir() 1830 1845 * 1831 1846 * @param string $time Optional. Time formatted in 'yyyy/mm'. Default null. 1847 * @param bool $create_dir Optional. Whether to check and create the uploads directory. Default true (backwards compatible). 1848 * @param bool $refresh_cache Optional. Whether to refresh the cache. Default false. 1832 1849 * @return array See above for description. 1833 1850 */ 1834 function wp_upload_dir( $time = null ) { 1851 function wp_upload_dir( $time = null, $create_dir = true, $refresh_cache = false ) { 1852 static $cache = array(); 1853 1854 $key = sprintf( '%d-%s', get_current_blog_id(), (string) $time ); 1855 1856 if ( $refresh_cache || empty( $cache[ $key ] ) ) { 1857 $cache[ $key ] = _wp_upload_dir( $time ); 1858 } 1859 1860 /** 1861 * Filter the uploads directory data. 1862 * 1863 * @since 2.0.0 1864 * 1865 * @param array $uploads Array of upload directory data with keys of 'path', 1866 * 'url', 'subdir, 'basedir', and 'error'. 1867 */ 1868 $uploads = apply_filters( 'upload_dir', $cache[ $key ] ); 1869 1870 if ( $create_dir ) { 1871 $path = $uploads['path']; 1872 $tested_paths = wp_cache_get( 'upload_dir_tested_paths' ); 1873 1874 if ( ! is_array( $tested_paths ) ) { 1875 $tested_paths = array(); 1876 } 1877 1878 if ( array_key_exists( $path, $tested_paths ) ) { 1879 $uploads['error'] = $tested_paths[ $path ]; 1880 } else { 1881 if ( ! wp_mkdir_p( $path ) ) { 1882 if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) { 1883 $error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir']; 1884 } else { 1885 $error_path = basename( $uploads['basedir'] ) . $uploads['subdir']; 1886 } 1887 1888 $uploads['error'] = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $error_path ); 1889 } 1890 1891 $tested_paths[ $path ] = $uploads['error']; 1892 wp_cache_set( 'upload_dir_tested_paths', $tested_paths ); 1893 } 1894 } 1895 1896 return $uploads; 1897 } 1898 1899 /** 1900 * A non-filtered, non-cached version of wp_upload_dir() that doesn't check the path. 1901 * 1902 * @access private 1903 * 1904 * @param string $time Optional. Time formatted in 'yyyy/mm'. Default null. 1905 * @return array See wp_upload_dir() 1906 */ 1907 function _wp_upload_dir( $time = null ) { 1835 1908 $siteurl = get_option( 'siteurl' ); 1836 1909 $upload_path = trim( get_option( 'upload_path' ) ); … … 1921 1994 $url .= $subdir; 1922 1995 1923 /** 1924 * Filter the uploads directory data. 1925 * 1926 * @since 2.0.0 1927 * 1928 * @param array $uploads Array of upload directory data with keys of 'path', 1929 * 'url', 'subdir, 'basedir', and 'error'. 1930 */ 1931 $uploads = apply_filters( 'upload_dir', 1932 array( 1933 'path' => $dir, 1934 'url' => $url, 1935 'subdir' => $subdir, 1936 'basedir' => $basedir, 1937 'baseurl' => $baseurl, 1938 'error' => false, 1939 ) ); 1940 1941 // Make sure we have an uploads directory. 1942 if ( ! wp_mkdir_p( $uploads['path'] ) ) { 1943 if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) 1944 $error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir']; 1945 else 1946 $error_path = basename( $uploads['basedir'] ) . $uploads['subdir']; 1947 1948 $message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $error_path ); 1949 $uploads['error'] = $message; 1950 } 1951 1952 return $uploads; 1996 return array( 1997 'path' => $dir, 1998 'url' => $url, 1999 'subdir' => $subdir, 2000 'basedir' => $basedir, 2001 'baseurl' => $baseurl, 2002 'error' => false, 2003 ); 1953 2004 } 1954 2005
Note: See TracChangeset
for help on using the changeset viewer.