wpseek.com
WordPress开发者和主题制作者的搜索引擎



_wp_get_attachment_relative_path › WordPress Function

Since4.4.1
已弃用n/a
› _wp_get_attachment_relative_path ( $file )
访问:
  • private
参数:
  • (string) $file Attachment file name.
    Required: Yes
返回:
  • (string) Attachment path relative to the upload directory.
定义在:
文档:

Gets the attachment path relative to the upload directory.



源码

function _wp_get_attachment_relative_path( $file ) {
	$dirname = dirname( $file );

	if ( '.' === $dirname ) {
		return '';
	}

	if ( str_contains( $dirname, 'wp-content/uploads' ) ) {
		// Get the directory name relative to the upload directory (back compat for pre-2.7 uploads).
		$dirname = substr( $dirname, strpos( $dirname, 'wp-content/uploads' ) + 18 );
		$dirname = ltrim( $dirname, '/' );
	}

	return $dirname;
}