_wp_relative_upload_path
Return relative path to an uploaded file.
Description
(string) _wp_relative_upload_path( (string) $path );
The path is relative to the current upload dir.
Returns (string)
Relative path on success, unchanged path on failure.
Parameters (1)
- 0. $path (string)
- Full path to the file.
Usage
if ( !function_exists( '_wp_relative_upload_path' ) ) { require_once ABSPATH . WPINC . '/post.php'; } // Full path to the file. $path = ''; // NOTICE! Understand what this does before running. $result = _wp_relative_upload_path($path);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/post.php
- 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 );
- }