Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_wp_relative_upload_path() WordPress Function

The wp_relative_upload_path() function is used to generate a relative path for an uploaded file. This is useful when you want to move or rename an uploaded file without changing its URL.

_wp_relative_upload_path( string $path ) #

Return relative path to an uploaded file.


Description

The path is relative to the current upload dir.


Top ↑

Parameters

$path

(string)(Required)Full path to the file.


Top ↑

Return

(string) Relative path on success, unchanged path on failure.


Top ↑

Source

File: 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 );
}


Top ↑

Changelog

Changelog
VersionDescription
2.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More