_wp_relative_upload_path() WP 2.9.0
Return relative path to an uploaded file.
The path is relative to the current upload dir.
This is an internal function for using it by WP core itself. It's not recommended to use this function in your code.
Hooks from the function
Return
String
. Relative path on success, unchanged path on failure.
Usage
_wp_relative_upload_path( $path );
- $path(string) (required)
- Full path to the file.
Changelog
Since 2.9.0 | Introduced. |
Code of _wp_relative_upload_path() wp relative upload path WP 5.7.1
function _wp_relative_upload_path( $path ) {
$new_path = $path;
$uploads = wp_get_upload_dir();
if ( 0 === strpos( $new_path, $uploads['basedir'] ) ) {
$new_path = str_replace( $uploads['basedir'], '', $new_path );
$new_path = ltrim( $new_path, '/' );
}
/**
* Filters the relative path to an uploaded file.
*
* @since 2.9.0
*
* @param string $new_path Relative path to the file.
* @param string $path Full path to the file.
*/
return apply_filters( '_wp_relative_upload_path', $new_path, $path );
}