WordPress开发功能函数atom_enclosure()

WordPress开发功能函数atom_enclosure(),显示当前帖子的atom外壳。

用法:

atom_enclosure()

描述

使用全局$post检查文章是否需要密码,以及用户是否有文章的密码。如果没有,那么它将在显示之前返回。

还使用函数get_post_custom()来获取帖子的‘enclosure’元数据字段,并解析值以显示框。附件由带有URI和其他属性的链接HTML标记组成。

来源:

文件: wp-includes/feed.php

function atom_enclosure() {

if ( post_password_required() ) {

return;

}

foreach ( (array) get_post_custom() as $key => $val ) {

if ( ‘enclosure’ === $key ) {

foreach ( (array) $val as $enc ) {

$enclosure = explode( “\n”, $enc );

$url = ”;

$type = ”;

$length = 0;

$mimes = get_allowed_mime_types();

// Parse URL.

if ( isset( $enclosure[0] ) && is_string( $enclosure[0] ) ) {

$url = trim( $enclosure[0] );

}

// Parse length and type.

for ( $i = 1; $i <= 2; $i++ ) {

if ( isset( $enclosure[ $i ] ) ) {

if ( is_numeric( $enclosure[ $i ] ) ) {

$length = trim( $enclosure[ $i ] );

} elseif ( in_array( $enclosure[ $i ], $mimes, true ) ) {

$type = trim( $enclosure[ $i ] );

}

}

}

$html_link_tag = sprintf(

“<link href=\”%s\” rel=\”enclosure\” length=\”%d\” type=\”%s\” />\n”,

esc_url( $url ),

esc_attr( $length ),

esc_attr( $type )

);

/**

* Filters the atom enclosure HTML link tag for the current post.

*

* @since 2.2.0

*

* @param string $html_link_tag The HTML link tag with a URI and other attributes.

*/

echo apply_filters( ‘atom_enclosure’, $html_link_tag );

}

}

}

}

更新日志:

WordPress开发功能函数atom_enclosure() (https://www.wp-admin.cn/) WordPress开发教程 第1张

相关推荐

发表回复

房先生
我们将24小时内回复。
2024-07-14 18:43:25
您好,有任何疑问请与我们联系!
您的工单我们已经收到,我们将会尽快跟您联系!
[QQ客服]
2781198
加我微信
[电话联系]
13585372227
[电子邮件]
chaoneo@163.com
取消

选择聊天工具: