do_enclose()
do_enclose( string $content = null, int|WP_Post $post )…
do_enclose( string $content = null, int|WP_Post $post )
检查要作为附件添加的视频和音频链接的内容。
Check content for video and audio links to add as enclosures.
目录锚点:#说明#参数#返回#源码
说明(Description)
将不添加已添加的存储模块,并将删除不再位于日志中的存储模块。这称为pingback和trackback。
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$content | (string) | 可选 | 发布内容。如果为空,则使用$post中的post_内容字段。 |
$post | (int | WP_Post) | 必需 | Post ID或Post对象。 |
返回(Return)
(null|bool)如果未找到post,则返回false。
源码(Source)
/** * 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 " ); } } } } }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
5.3.0 | wp-includes/functions.php:834 | 1 function | 13 |
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!