调用do_trackbacks的hook钩子
描述
执行trackbacks
用法
<?php do_trackbacks( $post_id ) ?>
参数
$post_id
(integer) (必填) Post ID to do trackbacks on.
默认值: None
返回值
(void)
This function does not return a value.
注意
See Reads from and may update the _posts table from the database.
使用到 global: (object) $wpdb
使用到: get_to_ping()
使用到: get_pung()
使用到: wp_html_excerpt()
使用到: apply_filters() on ‘the_content’ on ‘post_content’
使用到: apply_filters() on ‘the_excerpt’ on ‘post_excerpt’
使用到: apply_filters() on ‘the_title’ on ‘post_title’
使用到: trackback()
历史
添加于 版本: 1.5.0
源文件
do_trackbacks() 函数的代码位于 wp-includes/comment.php
.
/**
* Perform trackbacks.
*
* @since 1.5.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param int $post_id Post ID to do trackbacks on.
*/
function do_trackbacks($post_id) {
global $wpdb;
$post = get_post( $post_id );
$to_ping = get_to_ping($post_id);
$pinged = get_pung($post_id);
if ( empty($to_ping) ) {
$wpdb->update($wpdb->posts, array(‘to_ping’ => ”), array(‘ID’ => $post_id) );
return;
}
if ( empty($post->post_excerpt) ) {
/** This filter is documented in wp-includes/post-template.php */
$excerpt = apply_filters( ‘the_content’, $post->post_content, $post->ID );
} else {
/** This filter is documented in wp-includes/post-template.php */
$excerpt = apply_filters( ‘the_excerpt’, $post->post_excerpt );
}
$excerpt = str_replace(‘]]>’, ‘]]>’, $excerpt);
$excerpt = wp_html_excerpt($excerpt, 252, ‘…’);
/** This filter is documented in wp-includes/post-template.php */
$post_title = apply_filters( ‘the_title’, $post->post_title, $post->ID );
$post_title = strip_tags($post_title);
if ( $to_ping ) {
foreach ( (array) $to_ping as $tb_ping ) {
$tb_ping = trim($tb_ping);
if ( !in_array($tb_ping, $pinged) ) {
trackback($tb_ping, $post_title, $excerpt, $post_id);
$pinged[] = $tb_ping;
} else {
$wpdb->query( $wpdb->prepare(“UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, ”)) WHERE ID = %d”, $tb_ping, $post_id) );
}
}
}
}