函数原型
is_local_attachment( string $url ): bool
函数描述
Determines whether an attachment URI is local and really an attachment.
是否弃用
未弃用
函数参数
-
$url
string
Required - URL to check
函数返回值
bool True on success, false on failure.
函数位置
File: wp-includes/post.php.
函数源码
function is_local_attachment( $url ) {
if ( strpos( $url, home_url() ) === false ) {
return false;
}
if ( strpos( $url, home_url( '/?attachment_id=' ) ) !== false ) {
return true;
}
$id = url_to_postid( $url );
if ( $id ) {
$post = get_post( $id );
if ( 'attachment' === $post->post_type ) {
return true;
}
}
return false;
}
源码链接
变更日志
| Version | Description |
|---|---|
| 2.0.0 | Introduced. |

