_wp_relative_upload_path

函数
_wp_relative_upload_path ( $path )
Access
Private
参数
  • (string) $path Full path to the file.
    Required:
返回值
  • (string) Relative path on success, unchanged path on failure.
定义位置
相关方法
_wp_translate_postdatawp_resolve_post_date_wp_handle_uploadwp_get_upload_dir_wp_get_attachment_relative_path
引入
2.9.0
弃用
-

_wp_relative_upload_path: 这个函数返回WordPress安装的上传目录的相对路径。它用于在wp-config.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 );
}

常见问题

FAQs
查看更多 >