do_enclose()

调用do_enclose的hook钩子

描述

检查视频音频链接的内容,将内容作为enclosures加入。

已经添加的enclosure将不再重新加入。

用法

<?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.

/**
* 星空站长网 xingkongweb.com 整理收集
* 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

“ );

}

}

}

}

}
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索