is_local_attachment()
最后更新于:2021-11-27 08:49:45
is_local_attachment( string$url)Determines whether an attachment URI is local and really an attachment.
参数
- $url
-
(string) (Required) URL to check
响应
(bool) True on success, false on failure.
源文件
文件: gc-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;
}