返回上传文件的相对路径。

原型

_wp_relative_upload_path( string $path )

描述

该路径相对于当前上载目录。

参数

$path (string) (Required) 文件的完整路径。

返回值

(string)  成功的相对路径,失败的路径不变。

源文件

路径:wp-includes/post.php

<?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 );
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/_wp_relative_upload_path/