Edit File by line
/home/barbar84/www/wp-inclu...
File: functions.php
$target_parent = dirname( $target );
[2000] Fix | Delete
while ( '.' !== $target_parent && ! is_dir( $target_parent ) && dirname( $target_parent ) !== $target_parent ) {
[2001] Fix | Delete
$target_parent = dirname( $target_parent );
[2002] Fix | Delete
}
[2003] Fix | Delete
[2004] Fix | Delete
// Get the permission bits.
[2005] Fix | Delete
$stat = @stat( $target_parent );
[2006] Fix | Delete
if ( $stat ) {
[2007] Fix | Delete
$dir_perms = $stat['mode'] & 0007777;
[2008] Fix | Delete
} else {
[2009] Fix | Delete
$dir_perms = 0777;
[2010] Fix | Delete
}
[2011] Fix | Delete
[2012] Fix | Delete
if ( @mkdir( $target, $dir_perms, true ) ) {
[2013] Fix | Delete
[2014] Fix | Delete
/*
[2015] Fix | Delete
* If a umask is set that modifies $dir_perms, we'll have to re-set
[2016] Fix | Delete
* the $dir_perms correctly with chmod()
[2017] Fix | Delete
*/
[2018] Fix | Delete
if ( ( $dir_perms & ~umask() ) != $dir_perms ) {
[2019] Fix | Delete
$folder_parts = explode( '/', substr( $target, strlen( $target_parent ) + 1 ) );
[2020] Fix | Delete
for ( $i = 1, $c = count( $folder_parts ); $i <= $c; $i++ ) {
[2021] Fix | Delete
chmod( $target_parent . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms );
[2022] Fix | Delete
}
[2023] Fix | Delete
}
[2024] Fix | Delete
[2025] Fix | Delete
return true;
[2026] Fix | Delete
}
[2027] Fix | Delete
[2028] Fix | Delete
return false;
[2029] Fix | Delete
}
[2030] Fix | Delete
[2031] Fix | Delete
/**
[2032] Fix | Delete
* Test if a given filesystem path is absolute.
[2033] Fix | Delete
*
[2034] Fix | Delete
* For example, '/foo/bar', or 'c:\windows'.
[2035] Fix | Delete
*
[2036] Fix | Delete
* @since 2.5.0
[2037] Fix | Delete
*
[2038] Fix | Delete
* @param string $path File path.
[2039] Fix | Delete
* @return bool True if path is absolute, false is not absolute.
[2040] Fix | Delete
*/
[2041] Fix | Delete
function path_is_absolute( $path ) {
[2042] Fix | Delete
/*
[2043] Fix | Delete
* Check to see if the path is a stream and check to see if its an actual
[2044] Fix | Delete
* path or file as realpath() does not support stream wrappers.
[2045] Fix | Delete
*/
[2046] Fix | Delete
if ( wp_is_stream( $path ) && ( is_dir( $path ) || is_file( $path ) ) ) {
[2047] Fix | Delete
return true;
[2048] Fix | Delete
}
[2049] Fix | Delete
[2050] Fix | Delete
/*
[2051] Fix | Delete
* This is definitive if true but fails if $path does not exist or contains
[2052] Fix | Delete
* a symbolic link.
[2053] Fix | Delete
*/
[2054] Fix | Delete
if ( realpath( $path ) == $path ) {
[2055] Fix | Delete
return true;
[2056] Fix | Delete
}
[2057] Fix | Delete
[2058] Fix | Delete
if ( strlen( $path ) == 0 || '.' === $path[0] ) {
[2059] Fix | Delete
return false;
[2060] Fix | Delete
}
[2061] Fix | Delete
[2062] Fix | Delete
// Windows allows absolute paths like this.
[2063] Fix | Delete
if ( preg_match( '#^[a-zA-Z]:\\\\#', $path ) ) {
[2064] Fix | Delete
return true;
[2065] Fix | Delete
}
[2066] Fix | Delete
[2067] Fix | Delete
// A path starting with / or \ is absolute; anything else is relative.
[2068] Fix | Delete
return ( '/' === $path[0] || '\\' === $path[0] );
[2069] Fix | Delete
}
[2070] Fix | Delete
[2071] Fix | Delete
/**
[2072] Fix | Delete
* Join two filesystem paths together.
[2073] Fix | Delete
*
[2074] Fix | Delete
* For example, 'give me $path relative to $base'. If the $path is absolute,
[2075] Fix | Delete
* then it the full path is returned.
[2076] Fix | Delete
*
[2077] Fix | Delete
* @since 2.5.0
[2078] Fix | Delete
*
[2079] Fix | Delete
* @param string $base Base path.
[2080] Fix | Delete
* @param string $path Path relative to $base.
[2081] Fix | Delete
* @return string The path with the base or absolute path.
[2082] Fix | Delete
*/
[2083] Fix | Delete
function path_join( $base, $path ) {
[2084] Fix | Delete
if ( path_is_absolute( $path ) ) {
[2085] Fix | Delete
return $path;
[2086] Fix | Delete
}
[2087] Fix | Delete
[2088] Fix | Delete
return rtrim( $base, '/' ) . '/' . ltrim( $path, '/' );
[2089] Fix | Delete
}
[2090] Fix | Delete
[2091] Fix | Delete
/**
[2092] Fix | Delete
* Normalize a filesystem path.
[2093] Fix | Delete
*
[2094] Fix | Delete
* On windows systems, replaces backslashes with forward slashes
[2095] Fix | Delete
* and forces upper-case drive letters.
[2096] Fix | Delete
* Allows for two leading slashes for Windows network shares, but
[2097] Fix | Delete
* ensures that all other duplicate slashes are reduced to a single.
[2098] Fix | Delete
*
[2099] Fix | Delete
* @since 3.9.0
[2100] Fix | Delete
* @since 4.4.0 Ensures upper-case drive letters on Windows systems.
[2101] Fix | Delete
* @since 4.5.0 Allows for Windows network shares.
[2102] Fix | Delete
* @since 4.9.7 Allows for PHP file wrappers.
[2103] Fix | Delete
*
[2104] Fix | Delete
* @param string $path Path to normalize.
[2105] Fix | Delete
* @return string Normalized path.
[2106] Fix | Delete
*/
[2107] Fix | Delete
function wp_normalize_path( $path ) {
[2108] Fix | Delete
$wrapper = '';
[2109] Fix | Delete
[2110] Fix | Delete
if ( wp_is_stream( $path ) ) {
[2111] Fix | Delete
list( $wrapper, $path ) = explode( '://', $path, 2 );
[2112] Fix | Delete
[2113] Fix | Delete
$wrapper .= '://';
[2114] Fix | Delete
}
[2115] Fix | Delete
[2116] Fix | Delete
// Standardise all paths to use '/'.
[2117] Fix | Delete
$path = str_replace( '\\', '/', $path );
[2118] Fix | Delete
[2119] Fix | Delete
// Replace multiple slashes down to a singular, allowing for network shares having two slashes.
[2120] Fix | Delete
$path = preg_replace( '|(?<=.)/+|', '/', $path );
[2121] Fix | Delete
[2122] Fix | Delete
// Windows paths should uppercase the drive letter.
[2123] Fix | Delete
if ( ':' === substr( $path, 1, 1 ) ) {
[2124] Fix | Delete
$path = ucfirst( $path );
[2125] Fix | Delete
}
[2126] Fix | Delete
[2127] Fix | Delete
return $wrapper . $path;
[2128] Fix | Delete
}
[2129] Fix | Delete
[2130] Fix | Delete
/**
[2131] Fix | Delete
* Determine a writable directory for temporary files.
[2132] Fix | Delete
*
[2133] Fix | Delete
* Function's preference is the return value of sys_get_temp_dir(),
[2134] Fix | Delete
* followed by your PHP temporary upload directory, followed by WP_CONTENT_DIR,
[2135] Fix | Delete
* before finally defaulting to /tmp/
[2136] Fix | Delete
*
[2137] Fix | Delete
* In the event that this function does not find a writable location,
[2138] Fix | Delete
* It may be overridden by the WP_TEMP_DIR constant in your wp-config.php file.
[2139] Fix | Delete
*
[2140] Fix | Delete
* @since 2.5.0
[2141] Fix | Delete
*
[2142] Fix | Delete
* @return string Writable temporary directory.
[2143] Fix | Delete
*/
[2144] Fix | Delete
function get_temp_dir() {
[2145] Fix | Delete
static $temp = '';
[2146] Fix | Delete
if ( defined( 'WP_TEMP_DIR' ) ) {
[2147] Fix | Delete
return trailingslashit( WP_TEMP_DIR );
[2148] Fix | Delete
}
[2149] Fix | Delete
[2150] Fix | Delete
if ( $temp ) {
[2151] Fix | Delete
return trailingslashit( $temp );
[2152] Fix | Delete
}
[2153] Fix | Delete
[2154] Fix | Delete
if ( function_exists( 'sys_get_temp_dir' ) ) {
[2155] Fix | Delete
$temp = sys_get_temp_dir();
[2156] Fix | Delete
if ( @is_dir( $temp ) && wp_is_writable( $temp ) ) {
[2157] Fix | Delete
return trailingslashit( $temp );
[2158] Fix | Delete
}
[2159] Fix | Delete
}
[2160] Fix | Delete
[2161] Fix | Delete
$temp = ini_get( 'upload_tmp_dir' );
[2162] Fix | Delete
if ( @is_dir( $temp ) && wp_is_writable( $temp ) ) {
[2163] Fix | Delete
return trailingslashit( $temp );
[2164] Fix | Delete
}
[2165] Fix | Delete
[2166] Fix | Delete
$temp = WP_CONTENT_DIR . '/';
[2167] Fix | Delete
if ( is_dir( $temp ) && wp_is_writable( $temp ) ) {
[2168] Fix | Delete
return $temp;
[2169] Fix | Delete
}
[2170] Fix | Delete
[2171] Fix | Delete
return '/tmp/';
[2172] Fix | Delete
}
[2173] Fix | Delete
[2174] Fix | Delete
/**
[2175] Fix | Delete
* Determine if a directory is writable.
[2176] Fix | Delete
*
[2177] Fix | Delete
* This function is used to work around certain ACL issues in PHP primarily
[2178] Fix | Delete
* affecting Windows Servers.
[2179] Fix | Delete
*
[2180] Fix | Delete
* @since 3.6.0
[2181] Fix | Delete
*
[2182] Fix | Delete
* @see win_is_writable()
[2183] Fix | Delete
*
[2184] Fix | Delete
* @param string $path Path to check for write-ability.
[2185] Fix | Delete
* @return bool Whether the path is writable.
[2186] Fix | Delete
*/
[2187] Fix | Delete
function wp_is_writable( $path ) {
[2188] Fix | Delete
if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) ) {
[2189] Fix | Delete
return win_is_writable( $path );
[2190] Fix | Delete
} else {
[2191] Fix | Delete
return @is_writable( $path );
[2192] Fix | Delete
}
[2193] Fix | Delete
}
[2194] Fix | Delete
[2195] Fix | Delete
/**
[2196] Fix | Delete
* Workaround for Windows bug in is_writable() function
[2197] Fix | Delete
*
[2198] Fix | Delete
* PHP has issues with Windows ACL's for determine if a
[2199] Fix | Delete
* directory is writable or not, this works around them by
[2200] Fix | Delete
* checking the ability to open files rather than relying
[2201] Fix | Delete
* upon PHP to interprate the OS ACL.
[2202] Fix | Delete
*
[2203] Fix | Delete
* @since 2.8.0
[2204] Fix | Delete
*
[2205] Fix | Delete
* @see https://bugs.php.net/bug.php?id=27609
[2206] Fix | Delete
* @see https://bugs.php.net/bug.php?id=30931
[2207] Fix | Delete
*
[2208] Fix | Delete
* @param string $path Windows path to check for write-ability.
[2209] Fix | Delete
* @return bool Whether the path is writable.
[2210] Fix | Delete
*/
[2211] Fix | Delete
function win_is_writable( $path ) {
[2212] Fix | Delete
if ( '/' === $path[ strlen( $path ) - 1 ] ) {
[2213] Fix | Delete
// If it looks like a directory, check a random file within the directory.
[2214] Fix | Delete
return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp' );
[2215] Fix | Delete
} elseif ( is_dir( $path ) ) {
[2216] Fix | Delete
// If it's a directory (and not a file), check a random file within the directory.
[2217] Fix | Delete
return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' );
[2218] Fix | Delete
}
[2219] Fix | Delete
[2220] Fix | Delete
// Check tmp file for read/write capabilities.
[2221] Fix | Delete
$should_delete_tmp_file = ! file_exists( $path );
[2222] Fix | Delete
[2223] Fix | Delete
$f = @fopen( $path, 'a' );
[2224] Fix | Delete
if ( false === $f ) {
[2225] Fix | Delete
return false;
[2226] Fix | Delete
}
[2227] Fix | Delete
fclose( $f );
[2228] Fix | Delete
[2229] Fix | Delete
if ( $should_delete_tmp_file ) {
[2230] Fix | Delete
unlink( $path );
[2231] Fix | Delete
}
[2232] Fix | Delete
[2233] Fix | Delete
return true;
[2234] Fix | Delete
}
[2235] Fix | Delete
[2236] Fix | Delete
/**
[2237] Fix | Delete
* Retrieves uploads directory information.
[2238] Fix | Delete
*
[2239] Fix | Delete
* Same as wp_upload_dir() but "light weight" as it doesn't attempt to create the uploads directory.
[2240] Fix | Delete
* Intended for use in themes, when only 'basedir' and 'baseurl' are needed, generally in all cases
[2241] Fix | Delete
* when not uploading files.
[2242] Fix | Delete
*
[2243] Fix | Delete
* @since 4.5.0
[2244] Fix | Delete
*
[2245] Fix | Delete
* @see wp_upload_dir()
[2246] Fix | Delete
*
[2247] Fix | Delete
* @return array See wp_upload_dir() for description.
[2248] Fix | Delete
*/
[2249] Fix | Delete
function wp_get_upload_dir() {
[2250] Fix | Delete
return wp_upload_dir( null, false );
[2251] Fix | Delete
}
[2252] Fix | Delete
[2253] Fix | Delete
/**
[2254] Fix | Delete
* Returns an array containing the current upload directory's path and URL.
[2255] Fix | Delete
*
[2256] Fix | Delete
* Checks the 'upload_path' option, which should be from the web root folder,
[2257] Fix | Delete
* and if it isn't empty it will be used. If it is empty, then the path will be
[2258] Fix | Delete
* 'WP_CONTENT_DIR/uploads'. If the 'UPLOADS' constant is defined, then it will
[2259] Fix | Delete
* override the 'upload_path' option and 'WP_CONTENT_DIR/uploads' path.
[2260] Fix | Delete
*
[2261] Fix | Delete
* The upload URL path is set either by the 'upload_url_path' option or by using
[2262] Fix | Delete
* the 'WP_CONTENT_URL' constant and appending '/uploads' to the path.
[2263] Fix | Delete
*
[2264] Fix | Delete
* If the 'uploads_use_yearmonth_folders' is set to true (checkbox if checked in
[2265] Fix | Delete
* the administration settings panel), then the time will be used. The format
[2266] Fix | Delete
* will be year first and then month.
[2267] Fix | Delete
*
[2268] Fix | Delete
* If the path couldn't be created, then an error will be returned with the key
[2269] Fix | Delete
* 'error' containing the error message. The error suggests that the parent
[2270] Fix | Delete
* directory is not writable by the server.
[2271] Fix | Delete
*
[2272] Fix | Delete
* @since 2.0.0
[2273] Fix | Delete
* @uses _wp_upload_dir()
[2274] Fix | Delete
*
[2275] Fix | Delete
* @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
[2276] Fix | Delete
* @param bool $create_dir Optional. Whether to check and create the uploads directory.
[2277] Fix | Delete
* Default true for backward compatibility.
[2278] Fix | Delete
* @param bool $refresh_cache Optional. Whether to refresh the cache. Default false.
[2279] Fix | Delete
* @return array {
[2280] Fix | Delete
* Array of information about the upload directory.
[2281] Fix | Delete
*
[2282] Fix | Delete
* @type string $path Base directory and subdirectory or full path to upload directory.
[2283] Fix | Delete
* @type string $url Base URL and subdirectory or absolute URL to upload directory.
[2284] Fix | Delete
* @type string $subdir Subdirectory if uploads use year/month folders option is on.
[2285] Fix | Delete
* @type string $basedir Path without subdir.
[2286] Fix | Delete
* @type string $baseurl URL path without subdir.
[2287] Fix | Delete
* @type string|false $error False or error message.
[2288] Fix | Delete
* }
[2289] Fix | Delete
*/
[2290] Fix | Delete
function wp_upload_dir( $time = null, $create_dir = true, $refresh_cache = false ) {
[2291] Fix | Delete
static $cache = array(), $tested_paths = array();
[2292] Fix | Delete
[2293] Fix | Delete
$key = sprintf( '%d-%s', get_current_blog_id(), (string) $time );
[2294] Fix | Delete
[2295] Fix | Delete
if ( $refresh_cache || empty( $cache[ $key ] ) ) {
[2296] Fix | Delete
$cache[ $key ] = _wp_upload_dir( $time );
[2297] Fix | Delete
}
[2298] Fix | Delete
[2299] Fix | Delete
/**
[2300] Fix | Delete
* Filters the uploads directory data.
[2301] Fix | Delete
*
[2302] Fix | Delete
* @since 2.0.0
[2303] Fix | Delete
*
[2304] Fix | Delete
* @param array $uploads {
[2305] Fix | Delete
* Array of information about the upload directory.
[2306] Fix | Delete
*
[2307] Fix | Delete
* @type string $path Base directory and subdirectory or full path to upload directory.
[2308] Fix | Delete
* @type string $url Base URL and subdirectory or absolute URL to upload directory.
[2309] Fix | Delete
* @type string $subdir Subdirectory if uploads use year/month folders option is on.
[2310] Fix | Delete
* @type string $basedir Path without subdir.
[2311] Fix | Delete
* @type string $baseurl URL path without subdir.
[2312] Fix | Delete
* @type string|false $error False or error message.
[2313] Fix | Delete
* }
[2314] Fix | Delete
*/
[2315] Fix | Delete
$uploads = apply_filters( 'upload_dir', $cache[ $key ] );
[2316] Fix | Delete
[2317] Fix | Delete
if ( $create_dir ) {
[2318] Fix | Delete
$path = $uploads['path'];
[2319] Fix | Delete
[2320] Fix | Delete
if ( array_key_exists( $path, $tested_paths ) ) {
[2321] Fix | Delete
$uploads['error'] = $tested_paths[ $path ];
[2322] Fix | Delete
} else {
[2323] Fix | Delete
if ( ! wp_mkdir_p( $path ) ) {
[2324] Fix | Delete
if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) {
[2325] Fix | Delete
$error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir'];
[2326] Fix | Delete
} else {
[2327] Fix | Delete
$error_path = wp_basename( $uploads['basedir'] ) . $uploads['subdir'];
[2328] Fix | Delete
}
[2329] Fix | Delete
[2330] Fix | Delete
$uploads['error'] = sprintf(
[2331] Fix | Delete
/* translators: %s: Directory path. */
[2332] Fix | Delete
__( 'Unable to create directory %s. Is its parent directory writable by the server?' ),
[2333] Fix | Delete
esc_html( $error_path )
[2334] Fix | Delete
);
[2335] Fix | Delete
}
[2336] Fix | Delete
[2337] Fix | Delete
$tested_paths[ $path ] = $uploads['error'];
[2338] Fix | Delete
}
[2339] Fix | Delete
}
[2340] Fix | Delete
[2341] Fix | Delete
return $uploads;
[2342] Fix | Delete
}
[2343] Fix | Delete
[2344] Fix | Delete
/**
[2345] Fix | Delete
* A non-filtered, non-cached version of wp_upload_dir() that doesn't check the path.
[2346] Fix | Delete
*
[2347] Fix | Delete
* @since 4.5.0
[2348] Fix | Delete
* @access private
[2349] Fix | Delete
*
[2350] Fix | Delete
* @param string $time Optional. Time formatted in 'yyyy/mm'. Default null.
[2351] Fix | Delete
* @return array See wp_upload_dir()
[2352] Fix | Delete
*/
[2353] Fix | Delete
function _wp_upload_dir( $time = null ) {
[2354] Fix | Delete
$siteurl = get_option( 'siteurl' );
[2355] Fix | Delete
$upload_path = trim( get_option( 'upload_path' ) );
[2356] Fix | Delete
[2357] Fix | Delete
if ( empty( $upload_path ) || 'wp-content/uploads' === $upload_path ) {
[2358] Fix | Delete
$dir = WP_CONTENT_DIR . '/uploads';
[2359] Fix | Delete
} elseif ( 0 !== strpos( $upload_path, ABSPATH ) ) {
[2360] Fix | Delete
// $dir is absolute, $upload_path is (maybe) relative to ABSPATH.
[2361] Fix | Delete
$dir = path_join( ABSPATH, $upload_path );
[2362] Fix | Delete
} else {
[2363] Fix | Delete
$dir = $upload_path;
[2364] Fix | Delete
}
[2365] Fix | Delete
[2366] Fix | Delete
$url = get_option( 'upload_url_path' );
[2367] Fix | Delete
if ( ! $url ) {
[2368] Fix | Delete
if ( empty( $upload_path ) || ( 'wp-content/uploads' === $upload_path ) || ( $upload_path == $dir ) ) {
[2369] Fix | Delete
$url = WP_CONTENT_URL . '/uploads';
[2370] Fix | Delete
} else {
[2371] Fix | Delete
$url = trailingslashit( $siteurl ) . $upload_path;
[2372] Fix | Delete
}
[2373] Fix | Delete
}
[2374] Fix | Delete
[2375] Fix | Delete
/*
[2376] Fix | Delete
* Honor the value of UPLOADS. This happens as long as ms-files rewriting is disabled.
[2377] Fix | Delete
* We also sometimes obey UPLOADS when rewriting is enabled -- see the next block.
[2378] Fix | Delete
*/
[2379] Fix | Delete
if ( defined( 'UPLOADS' ) && ! ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) ) {
[2380] Fix | Delete
$dir = ABSPATH . UPLOADS;
[2381] Fix | Delete
$url = trailingslashit( $siteurl ) . UPLOADS;
[2382] Fix | Delete
}
[2383] Fix | Delete
[2384] Fix | Delete
// If multisite (and if not the main site in a post-MU network).
[2385] Fix | Delete
if ( is_multisite() && ! ( is_main_network() && is_main_site() && defined( 'MULTISITE' ) ) ) {
[2386] Fix | Delete
[2387] Fix | Delete
if ( ! get_site_option( 'ms_files_rewriting' ) ) {
[2388] Fix | Delete
/*
[2389] Fix | Delete
* If ms-files rewriting is disabled (networks created post-3.5), it is fairly
[2390] Fix | Delete
* straightforward: Append sites/%d if we're not on the main site (for post-MU
[2391] Fix | Delete
* networks). (The extra directory prevents a four-digit ID from conflicting with
[2392] Fix | Delete
* a year-based directory for the main site. But if a MU-era network has disabled
[2393] Fix | Delete
* ms-files rewriting manually, they don't need the extra directory, as they never
[2394] Fix | Delete
* had wp-content/uploads for the main site.)
[2395] Fix | Delete
*/
[2396] Fix | Delete
[2397] Fix | Delete
if ( defined( 'MULTISITE' ) ) {
[2398] Fix | Delete
$ms_dir = '/sites/' . get_current_blog_id();
[2399] Fix | Delete
} else {
[2400] Fix | Delete
$ms_dir = '/' . get_current_blog_id();
[2401] Fix | Delete
}
[2402] Fix | Delete
[2403] Fix | Delete
$dir .= $ms_dir;
[2404] Fix | Delete
$url .= $ms_dir;
[2405] Fix | Delete
[2406] Fix | Delete
} elseif ( defined( 'UPLOADS' ) && ! ms_is_switched() ) {
[2407] Fix | Delete
/*
[2408] Fix | Delete
* Handle the old-form ms-files.php rewriting if the network still has that enabled.
[2409] Fix | Delete
* When ms-files rewriting is enabled, then we only listen to UPLOADS when:
[2410] Fix | Delete
* 1) We are not on the main site in a post-MU network, as wp-content/uploads is used
[2411] Fix | Delete
* there, and
[2412] Fix | Delete
* 2) We are not switched, as ms_upload_constants() hardcodes these constants to reflect
[2413] Fix | Delete
* the original blog ID.
[2414] Fix | Delete
*
[2415] Fix | Delete
* Rather than UPLOADS, we actually use BLOGUPLOADDIR if it is set, as it is absolute.
[2416] Fix | Delete
* (And it will be set, see ms_upload_constants().) Otherwise, UPLOADS can be used, as
[2417] Fix | Delete
* as it is relative to ABSPATH. For the final piece: when UPLOADS is used with ms-files
[2418] Fix | Delete
* rewriting in multisite, the resulting URL is /files. (#WP22702 for background.)
[2419] Fix | Delete
*/
[2420] Fix | Delete
[2421] Fix | Delete
if ( defined( 'BLOGUPLOADDIR' ) ) {
[2422] Fix | Delete
$dir = untrailingslashit( BLOGUPLOADDIR );
[2423] Fix | Delete
} else {
[2424] Fix | Delete
$dir = ABSPATH . UPLOADS;
[2425] Fix | Delete
}
[2426] Fix | Delete
$url = trailingslashit( $siteurl ) . 'files';
[2427] Fix | Delete
}
[2428] Fix | Delete
}
[2429] Fix | Delete
[2430] Fix | Delete
$basedir = $dir;
[2431] Fix | Delete
$baseurl = $url;
[2432] Fix | Delete
[2433] Fix | Delete
$subdir = '';
[2434] Fix | Delete
if ( get_option( 'uploads_use_yearmonth_folders' ) ) {
[2435] Fix | Delete
// Generate the yearly and monthly directories.
[2436] Fix | Delete
if ( ! $time ) {
[2437] Fix | Delete
$time = current_time( 'mysql' );
[2438] Fix | Delete
}
[2439] Fix | Delete
$y = substr( $time, 0, 4 );
[2440] Fix | Delete
$m = substr( $time, 5, 2 );
[2441] Fix | Delete
$subdir = "/$y/$m";
[2442] Fix | Delete
}
[2443] Fix | Delete
[2444] Fix | Delete
$dir .= $subdir;
[2445] Fix | Delete
$url .= $subdir;
[2446] Fix | Delete
[2447] Fix | Delete
return array(
[2448] Fix | Delete
'path' => $dir,
[2449] Fix | Delete
'url' => $url,
[2450] Fix | Delete
'subdir' => $subdir,
[2451] Fix | Delete
'basedir' => $basedir,
[2452] Fix | Delete
'baseurl' => $baseurl,
[2453] Fix | Delete
'error' => false,
[2454] Fix | Delete
);
[2455] Fix | Delete
}
[2456] Fix | Delete
[2457] Fix | Delete
/**
[2458] Fix | Delete
* Get a filename that is sanitized and unique for the given directory.
[2459] Fix | Delete
*
[2460] Fix | Delete
* If the filename is not unique, then a number will be added to the filename
[2461] Fix | Delete
* before the extension, and will continue adding numbers until the filename
[2462] Fix | Delete
* is unique.
[2463] Fix | Delete
*
[2464] Fix | Delete
* The callback function allows the caller to use their own method to create
[2465] Fix | Delete
* unique file names. If defined, the callback should take three arguments:
[2466] Fix | Delete
* - directory, base filename, and extension - and return a unique filename.
[2467] Fix | Delete
*
[2468] Fix | Delete
* @since 2.5.0
[2469] Fix | Delete
*
[2470] Fix | Delete
* @param string $dir Directory.
[2471] Fix | Delete
* @param string $filename File name.
[2472] Fix | Delete
* @param callable $unique_filename_callback Callback. Default null.
[2473] Fix | Delete
* @return string New filename, if given wasn't unique.
[2474] Fix | Delete
*/
[2475] Fix | Delete
function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) {
[2476] Fix | Delete
// Sanitize the file name before we begin processing.
[2477] Fix | Delete
$filename = sanitize_file_name( $filename );
[2478] Fix | Delete
$ext2 = null;
[2479] Fix | Delete
[2480] Fix | Delete
// Separate the filename into a name and extension.
[2481] Fix | Delete
$ext = pathinfo( $filename, PATHINFO_EXTENSION );
[2482] Fix | Delete
$name = pathinfo( $filename, PATHINFO_BASENAME );
[2483] Fix | Delete
[2484] Fix | Delete
if ( $ext ) {
[2485] Fix | Delete
$ext = '.' . $ext;
[2486] Fix | Delete
}
[2487] Fix | Delete
[2488] Fix | Delete
// Edge case: if file is named '.ext', treat as an empty name.
[2489] Fix | Delete
if ( $name === $ext ) {
[2490] Fix | Delete
$name = '';
[2491] Fix | Delete
}
[2492] Fix | Delete
[2493] Fix | Delete
/*
[2494] Fix | Delete
* Increment the file number until we have a unique file to save in $dir.
[2495] Fix | Delete
* Use callback if supplied.
[2496] Fix | Delete
*/
[2497] Fix | Delete
if ( $unique_filename_callback && is_callable( $unique_filename_callback ) ) {
[2498] Fix | Delete
$filename = call_user_func( $unique_filename_callback, $dir, $name, $ext );
[2499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function