_wp_relative_upload_path

The timeline below displays how wordpress function _wp_relative_upload_path has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Returns relative path to an uploaded file.
 *
 * The path is relative to the current upload dir.
 *
 * @since 2.9.0
 * @access private
 *
 * @param string $path Full path to the file.
 * @return string Relative path on success, unchanged path on failure.
 */
function _wp_relative_upload_path($path)
{
    $new_path = $path;
    $uploads = wp_get_upload_dir();
    if (str_starts_with($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);
}

WordPress Version: 6.1

/**
 * Returns relative path to an uploaded file.
 *
 * The path is relative to the current upload dir.
 *
 * @since 2.9.0
 * @access private
 *
 * @param string $path Full path to the file.
 * @return string Relative path on success, unchanged path on failure.
 */
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);
}

WordPress Version: 5.1

/**
 * Return relative path to an uploaded file.
 *
 * The path is relative to the current upload dir.
 *
 * @since 2.9.0
 * @access private
 *
 * @param string $path Full path to the file.
 * @return string Relative path on success, unchanged path on failure.
 */
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);
}

WordPress Version: 4.6

/**
 * Return relative path to an uploaded file.
 *
 * The path is relative to the current upload dir.
 *
 * @since 2.9.0
 *
 * @param string $path Full path to the file.
 * @return string Relative path on success, unchanged path on failure.
 */
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);
}

WordPress Version: 4.5

/**
 * Return relative path to an uploaded file.
 *
 * The path is relative to the current upload dir.
 *
 * @since 2.9.0
 *
 * @param string $path Full path to the file.
 * @return string Relative path on success, unchanged path on failure.
 */
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, '/');
    }
    /**
     * Filter 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);
}

WordPress Version: 4.0

/**
 * Return relative path to an uploaded file.
 *
 * The path is relative to the current upload dir.
 *
 * @since 2.9.0
 *
 * @param string $path Full path to the file.
 * @return string Relative path on success, unchanged path on failure.
 */
function _wp_relative_upload_path($path)
{
    $new_path = $path;
    $uploads = wp_upload_dir();
    if (0 === strpos($new_path, $uploads['basedir'])) {
        $new_path = str_replace($uploads['basedir'], '', $new_path);
        $new_path = ltrim($new_path, '/');
    }
    /**
     * Filter 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);
}

WordPress Version: 3.9

/**
 * Return relative path to an uploaded file.
 *
 * The path is relative to the current upload dir.
 *
 * @since 2.9.0
 *
 * @param string $path Full path to the file
 * @return string relative path on success, unchanged path on failure.
 */
function _wp_relative_upload_path($path)
{
    $new_path = $path;
    $uploads = wp_upload_dir();
    if (0 === strpos($new_path, $uploads['basedir'])) {
        $new_path = str_replace($uploads['basedir'], '', $new_path);
        $new_path = ltrim($new_path, '/');
    }
    /**
     * Filter 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);
}

WordPress Version: 3.7

/**
 * Return relative path to an uploaded file.
 *
 * The path is relative to the current upload dir.
 *
 * @since 2.9.0
 * @uses apply_filters() Calls '_wp_relative_upload_path' on file path.
 *
 * @param string $path Full path to the file
 * @return string relative path on success, unchanged path on failure.
 */
function _wp_relative_upload_path($path)
{
    $new_path = $path;
    $uploads = wp_upload_dir();
    if (0 === strpos($new_path, $uploads['basedir'])) {
        $new_path = str_replace($uploads['basedir'], '', $new_path);
        $new_path = ltrim($new_path, '/');
    }
    return apply_filters('_wp_relative_upload_path', $new_path, $path);
}