WordPress函数文档do_enclose()
调用do_enclose的hook钩子 描述 译文 检查视频音频链接的内容,将内容作为enclosures加入…
调用do_enclose的hook钩子
描述
译文
检查视频音频链接的内容,将内容作为enclosures加入。
已经添加的enclosure将不再重新加入。
原文
Check content for video and audio links to add as enclosures.
Will not add enclosures that have already been added.
用法
<?php do_enclose( $content, $post_ID ) ?>
参数
$content
(string) (必填) Post Content
默认值: None
$post_ID
(integer) (必填) Post ID
默认值: None
返回值
(void)
This function does not return a value.
注意
- 使用到 global: (object) $wpdb to read and condtionally insert records on _postmeta table in the database.
- 使用到: debug_fopen() to open ‘enclosures.log’ file.
- 使用到: debug_fwrite() to write to ‘enclosures.log’ file.
- 使用到: get_enclosed()
- 使用到: wp_get_http_headers()
历史
添加于 版本: 1.5.0
源文件
do_enclose() 函数的代码位于 wp-includes/functions.php
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
/**
* Check content for video and audio links to add as enclosures.
*
* Will not add enclosures that have already been added and will
* remove enclosures that are no longer in the post. This is called as
* pingbacks and trackbacks.
*
* @since 1.5.0
*
* @global wpdb $wpdb
*
* @param string $content Post Content.
* @param int $post_ID Post ID.
*/
function do_enclose( $content, $post_ID ) {
global $wpdb;
//TODO: Tidy this ghetto code up and make the debug code optional
include_once( ABSPATH . WPINC . ‘/class-IXR.php’ );
$post_links = array();
$pung = get_enclosed( $post_ID );
$post_links_temp = wp_extract_urls( $content );
foreach ( $pung as $link_test ) {
if ( ! in_array( $link_test, $post_links_temp ) ) { // link no longer in post
$mids = $wpdb->get_col( $wpdb->prepare(“SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = ‘enclosure’ AND meta_value LIKE %s”, $post_ID, $wpdb->esc_like( $link_test ) . ‘%’) );
foreach ( $mids as $mid )
delete_metadata_by_mid( ‘post’, $mid );
}
}
foreach ( (array) $post_links_temp as $link_test ) {
if ( !in_array( $link_test, $pung ) ) { // If we haven’t pung it already
$test = @parse_url( $link_test );
if ( false === $test )
continue;
if ( isset( $test[‘query’] ) )
$post_links[] = $link_test;
elseif ( isset($test[‘path’]) && ( $test[‘path’] != ‘/’ ) && ($test[‘path’] != ” ) )
$post_links[] = $link_test;
}
}
foreach ( (array) $post_links as $url ) {
if ( $url != ” && !$wpdb->get_var( $wpdb->prepare( “SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = ‘enclosure’ AND meta_value LIKE %s”, $post_ID, $wpdb->esc_like( $url ) . ‘%’ ) ) ) {
if ( $headers = wp_get_http_headers( $url) ) {
$len = isset( $headers[‘content-length’] ) ? (int) $headers[‘content-length’] : 0;
$type = isset( $headers[‘content-type’] ) ? $headers[‘content-type’] : ”;
$allowed_types = array( ‘video’, ‘audio’ );
// Check to see if we can figure out the mime type from
// the extension
$url_parts = @parse_url( $url );
if ( false !== $url_parts ) {
$extension = pathinfo( $url_parts[‘path’], PATHINFO_EXTENSION );
if ( !empty( $extension ) ) {
foreach ( wp_get_mime_types() as $exts => $mime ) {
if ( preg_match( ‘!^(‘ . $exts . ‘)$!i’, $extension ) ) {
$type = $mime;
break;
}
}
}
}
if ( in_array( substr( $type, 0, strpos( $type, “/” ) ), $allowed_types ) ) {
add_post_meta( $post_ID, ‘enclosure’, “$url
$len
$mime
“ );
}
}
}
}
}
|
- 原文:http://codex.wordpress.org/Function_Reference/do_enclose
类别:WordPress函数文档、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
评论功能已经关闭!