检索附件附件的路径或URL。
原型
_load_image_to_edit_path( string $attachment_id, string $size = 'full' )
描述
如果附加文件不存在于本地文件系统上(通常是由于复制插件),则如果支持url fopen,则返回文件的url。
参数
$attachment_id
(string)
(Required)
附件ID。
$size
(string)
(Optional)
图像大小,默认为“完整”。
返回值
(string|false)
成功时文件路径或URL,失败时为false。
源文件
路径:wp-admin/includes/image.php
<?php
...
function _load_image_to_edit_path( $attachment_id, $size = 'full' ) {
$filepath = get_attached_file( $attachment_id );
if ( $filepath && file_exists( $filepath ) ) {
if ( 'full' != $size && ( $data = image_get_intermediate_size( $attachment_id, $size ) ) ) {
/**
* Filters the path to the current image.
*
* The filter is evaluated for all image sizes except 'full'.
*
* @since 3.1.0
*
* @param string $path Path to the current image.
* @param string $attachment_id Attachment ID.
* @param string $size Size of the image.
*/
$filepath = apply_filters( 'load_image_to_edit_filesystempath', path_join( dirname( $filepath ), $data['file'] ), $attachment_id, $size );
}
} elseif ( function_exists( 'fopen' ) && true == ini_get( 'allow_url_fopen' ) ) {
/**
* Filters the image URL if not in the local filesystem.
*
* The filter is only evaluated if fopen is enabled on the server.
*
* @since 3.1.0
*
* @param string $image_url Current image URL.
* @param string $attachment_id Attachment ID.
* @param string $size Size of the image.
*/
$filepath = apply_filters( 'load_image_to_edit_attachmenturl', wp_get_attachment_url( $attachment_id ), $attachment_id, $size );
}
/**
* Filters the returned path or URL of the current image.
*
* @since 2.9.0
*
* @param string|bool $filepath File path or URL to current image, or false.
* @param string $attachment_id Attachment ID.
* @param string $size Size of the image.
*/
return apply_filters( 'load_image_to_edit_path', $filepath, $attachment_id, $size );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/_load_image_to_edit_path/