WordPress函数is_local_attachment()检查附件URI是否本地URI,及是否为附件类型

描述:

检查附件URI是否本地URI,及是否为附件类型

用法:

<?php is_local_attachment( $url ) ?>

参数:

$url

(string) (必填) 要检查的URL

默认值: None

源文件:

/**
 * Check if the attachment URI is local one and is really an attachment.
 *
 * @since 2.0.0
 *
 * @param string $url URL to check
 * @return bool True on success, false on failure.
 */
function is_local_attachment($url) {
	if (strpos($url, home_url()) === false)
		return false;
	if (strpos($url, home_url('/?attachment_id=')) !== false)
		return true;
	if ( $id = url_to_postid($url) ) {
		$post = get_post($id);
		if ( 'attachment' == $post->post_type )
			return true;
	}
	return false;
}