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

目录

描述

译文

检查附件URI是否本地URI以及是否确实是附件类型

原文

Check if the attachment URI is local one and is really an attachment.

is_local_attachment() 描述

用法

<?php is_local_attachment$url ?>

is_local_attachment() 用法

参数

$url

(string) (必填) URL to check

默认值: None

is_local_attachment() 参数

返回值

(boolean) 

True on success, false on failure.

is_local_attachment() 返回值

历史

添加于 版本: 2.0.0

is_local_attachment() 历史

源文件

is_local_attachment() 函数的代码位于 wp-includes/post.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * 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;
}

is_local_attachment() 源文件

相关