wp/wp-trackback.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
    80 
    80 
    81 if ( is_single() || is_page() )
    81 if ( is_single() || is_page() )
    82 	$tb_id = $posts[0]->ID;
    82 	$tb_id = $posts[0]->ID;
    83 
    83 
    84 if ( !isset($tb_id) || !intval( $tb_id ) )
    84 if ( !isset($tb_id) || !intval( $tb_id ) )
    85 	trackback_response(1, 'I really need an ID for this to work.');
    85 	trackback_response( 1, __( 'I really need an ID for this to work.' ) );
    86 
    86 
    87 if (empty($title) && empty($tb_url) && empty($blog_name)) {
    87 if (empty($title) && empty($tb_url) && empty($blog_name)) {
    88 	// If it doesn't look like a trackback at all.
    88 	// If it doesn't look like a trackback at all.
    89 	wp_redirect(get_permalink($tb_id));
    89 	wp_redirect(get_permalink($tb_id));
    90 	exit;
    90 	exit;
    91 }
    91 }
    92 
    92 
    93 if ( !empty($tb_url) && !empty($title) ) {
    93 if ( !empty($tb_url) && !empty($title) ) {
       
    94 	/**
       
    95 	* Fires before the trackback is added to a post.
       
    96 	*
       
    97 	* @since 4.7.0
       
    98 	*
       
    99 	* @param int    $tb_id     Post ID related to the trackback.
       
   100 	* @param string $tb_url    Trackback URL.
       
   101 	* @param string $charset   Character Set.
       
   102 	* @param string $title     Trackback Title.
       
   103 	* @param string $excerpt   Trackback Excerpt.
       
   104 	* @param string $blog_name Blog Name.
       
   105 	*/
       
   106 	do_action( 'pre_trackback_post', $tb_id, $tb_url, $charset, $title, $excerpt, $blog_name );
       
   107 
    94 	header('Content-Type: text/xml; charset=' . get_option('blog_charset') );
   108 	header('Content-Type: text/xml; charset=' . get_option('blog_charset') );
    95 
   109 
    96 	if ( !pings_open($tb_id) )
   110 	if ( !pings_open($tb_id) )
    97 		trackback_response(1, 'Sorry, trackbacks are closed for this item.');
   111 		trackback_response( 1, __( 'Sorry, trackbacks are closed for this item.' ) );
    98 
   112 
    99 	$title =  wp_html_excerpt( $title, 250, '…' );
   113 	$title =  wp_html_excerpt( $title, 250, '…' );
   100 	$excerpt = wp_html_excerpt( $excerpt, 252, '…' );
   114 	$excerpt = wp_html_excerpt( $excerpt, 252, '…' );
   101 
   115 
   102 	$comment_post_ID = (int) $tb_id;
   116 	$comment_post_ID = (int) $tb_id;
   106 	$comment_content = "<strong>$title</strong>\n\n$excerpt";
   120 	$comment_content = "<strong>$title</strong>\n\n$excerpt";
   107 	$comment_type = 'trackback';
   121 	$comment_type = 'trackback';
   108 
   122 
   109 	$dupe = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $comment_post_ID, $comment_author_url) );
   123 	$dupe = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $comment_post_ID, $comment_author_url) );
   110 	if ( $dupe )
   124 	if ( $dupe )
   111 		trackback_response(1, 'We already have a ping from that URL for this post.');
   125 		trackback_response( 1, __( 'We already have a ping from that URL for this post.' ) );
   112 
   126 
   113 	$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type');
   127 	$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type');
   114 
   128 
   115 	wp_new_comment($commentdata);
   129 	$result = wp_new_comment( $commentdata );
       
   130 
       
   131 	if ( is_wp_error( $result ) ) {
       
   132 		trackback_response( 1, $result->get_error_message() );
       
   133 	}
       
   134 
   116 	$trackback_id = $wpdb->insert_id;
   135 	$trackback_id = $wpdb->insert_id;
   117 
   136 
   118 	/**
   137 	/**
   119 	 * Fires after a trackback is added to a post.
   138 	 * Fires after a trackback is added to a post.
   120 	 *
   139 	 *