当前位置: 首页>>代码示例>>PHP>>正文


PHP wp_new_comment函数代码示例

本文整理汇总了PHP中wp_new_comment函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_new_comment函数的具体用法?PHP wp_new_comment怎么用?PHP wp_new_comment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wp_new_comment函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _rolo_save_contact_notes

/**
 * Notes Functions
 *
 * Save notes information to database
 *
 * @return int notes(comment) id
 *
 * @package RoloPress
 * @subpackage Functions
 */
function _rolo_save_contact_notes()
{
    global $wpdb;
    //TODO - Validate fields
    //TODO - Validate that the notes field is not empty
    //TODO - Apply a filter for notes
    $notes = trim($_POST['rolo_contact_notes']);
    $contact_id = (int) $_POST['rolo_contact_id'];
    $commentdata = array();
    $user = wp_get_current_user();
    if ($user->ID) {
        if (empty($user->display_name)) {
            $user->display_name = $user->user_login;
        }
        $commentdata['comment_author'] = $wpdb->escape($user->display_name);
        $commentdata['comment_author_url'] = $wpdb->escape($user->user_url);
        $commentdata['comment_author_email'] = $wpdb->escape($user->user_email);
    } else {
        // user is not logged in
        return false;
    }
    $commentdata['comment_post_ID'] = $contact_id;
    $commentdata['comment_content'] = $notes;
    $notes_id = wp_new_comment($commentdata);
    return $notes_id;
}
开发者ID:sudar,项目名称:rolopress-core,代码行数:36,代码来源:note-functions.php

示例2: add_comment

 /**
  * add new comment
  * @param int $id post id
  * @param string $comment  comment value
  * @param int $parent_id 父评论的ID
  */
 public function add_comment($id, $comment, $author = '', $email = '', $parent_id = 0, $type = 0)
 {
     if (empty($id) || empty($comment)) {
         json_error(BigAppErr::$comment['code'], "empty id or comment");
     }
     $user_id = get_current_user_id();
     $comment_type = bigapp_core::check_comment_status();
     if ($comment_type == 2 && $user_id == 0) {
         if ($author == '' or $email == '') {
             json_error(BigAppErr::$comment['code'], 'need email or author');
         }
         if (false == check_email($email)) {
             json_error(BigAppErr::$comment['code'], 'email format is wrong');
         }
     }
     if ($comment_type == 3) {
         if ($user_id == 0) {
             json_error(BigAppErr::$login['code'], 'need login');
         }
     }
     $commentdata = array("comment_post_ID" => $id, 'comment_content' => $comment, 'comment_approved' => 1, 'comment_author' => $author, 'comment_author_email' => $email, 'comment_parent' => $parent_id, "user_ID" => $user_id);
     $result = wp_new_comment($commentdata);
     if (!$result) {
         json_error(BigAppErr::$comment['code'], "creat new comment failed");
     }
     return array('id' => $result);
 }
开发者ID:Mushan3420,项目名称:BigApp-PHP7,代码行数:33,代码来源:class-wp-json-comments.php

示例3: custom_save_comment_wp

function custom_save_comment_wp($postID, $userID, $author, $email, $comment, $ratingvalue)
{
    remove_all_actions('comment_post', 1);
    $_POST['crfp-rating'] = $ratingvalue;
    $commentdata = array('comment_post_ID' => $postID, 'comment_author' => $author, 'comment_author_email' => $email, 'comment_content' => $comment, 'comment_type' => '', 'comment_parent' => 0, 'user_id' => $userID);
    /*Graba el comentario y me da el ID*/
    $commentID = wp_new_comment($commentdata);
    /*Añade el meta con el rating*/
    add_comment_meta($commentID, 'crfp-rating', $ratingvalue, true);
    //add_comment_meta($commentID, 'crfp-rating', 4, true);
    /*Actualiza el total y el promedio del rating*/
    $comments = get_comments(array('post_id' => $postID, 'status' => 'approve'));
    $totalRating = 0;
    $totalRatings = 0;
    $averageRating = 0;
    if (is_array($comments) and count($comments) > 0) {
        foreach ($comments as $comment) {
            $rating = get_comment_meta($comment->comment_ID, 'crfp-rating', true);
            if ($rating > 0) {
                $totalRatings++;
                $totalRating += $rating;
            }
        }
        $averageRating = ($totalRatings == 0 or $totalRating == 0) ? 0 : round($totalRating / $totalRatings, 0);
    }
    update_post_meta($postID, 'crfp-total-ratings', $totalRatings);
    update_post_meta($postID, 'crfp-average-rating', $averageRating);
    return true;
}
开发者ID:Rempty,项目名称:supch,代码行数:29,代码来源:save_comment.php

示例4: tzs_add_feedback_callback

function tzs_add_feedback_callback()
{
    $user_id = get_current_user_id();
    $id = isset($_POST['id']) && is_valid_num($_POST['id']) ? intval($_POST['id']) : 0;
    $tp = isset($_POST['type']) && is_valid_num_zero($_POST['type']) ? intval($_POST['type']) : 1;
    if ($tp > 2) {
        $tp = 2;
    }
    $cont = isset($_POST['cont']) ? trim($_POST['cont']) : "";
    global $wpdb;
    if ($user_id == 0 || $id == 0) {
        echo 'Пользователь не найден';
    } else {
        if (strlen($cont) < TZS_FEEDBACK_MIN_LEN) {
            echo 'Слишком короткий отзыв';
        } else {
            $cont = $tp . $cont;
            $u_comment = $wpdb->get_row($wpdb->prepare("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_post_ID = %d AND user_id = %d", $id, $user_id));
            if (count($u_comment) > 0) {
                $commentdata = array('comment_ID' => $u_comment->comment_ID, 'comment_date' => current_time('mysql'), 'comment_content' => $cont);
                wp_update_comment($commentdata);
                echo 1;
            } else {
                $commentdata = array('comment_post_ID' => $id, 'comment_content' => $cont, 'comment_type' => '', 'user_id' => $user_id);
                $comment_id = wp_new_comment($commentdata);
                echo 1;
            }
        }
    }
    die;
}
开发者ID:serker72,项目名称:T3S,代码行数:31,代码来源:tzs.feedback.php

示例5: test_comment_content_length

	public function test_comment_content_length() {
		// `wp_new_comment()` checks REMOTE_ADDR, so we fake it to avoid PHP notices.
		if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
			$remote_addr = $_SERVER['REMOTE_ADDR'];
		} else {
			$_SERVER['REMOTE_ADDR'] = '';
		}

		$u = $this->factory->user->create();
		$post_id = $this->factory->post->create( array( 'post_author' => $u ) );

		$data = array(
			'comment_post_ID' => $post_id,
			'comment_author' => rand_str(),
			'comment_author_url' => '',
			'comment_author_email' => '',
			'comment_type' => '',
			'comment_content' => str_repeat( 'A', 65536 ),
			'comment_date' => '2011-01-01 10:00:00',
			'comment_date_gmt' => '2011-01-01 10:00:00',
		);

		add_filter( 'pre_option_moderation_notify', '__return_zero' );
		$id = wp_new_comment( $data );
		remove_filter( 'pre_option_moderation_notify', '__return_zero' );

		$this->assertEmpty( $id );

		// Cleanup.
		if ( isset( $remote_addr ) ) {
			$_SERVER['REMOTE_ADDR'] = $remote_addr;
		} else {
			unset( $_SERVER['REMOTE_ADDR'] );
		}
	}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:35,代码来源:comment.php

示例6: create_comment

 public static function create_comment($entry_id, $form_id)
 {
     $comment_post_ID = isset($_POST['comment_post_ID']) ? (int) $_POST['comment_post_ID'] : 0;
     $post = get_post($comment_post_ID);
     if (empty($post->comment_status)) {
         return;
     }
     // get_post_status() will get the parent status for attachments.
     $status = get_post_status($post);
     $status_obj = get_post_status_object($status);
     if (!comments_open($comment_post_ID)) {
         do_action('comment_closed', $comment_post_ID);
         //wp_die( __( 'Sorry, comments are closed for this item.') );
         return;
     } else {
         if ('trash' == $status) {
             do_action('comment_on_trash', $comment_post_ID);
             return;
         } else {
             if (!$status_obj->public && !$status_obj->private) {
                 do_action('comment_on_draft', $comment_post_ID);
                 return;
             } else {
                 if (post_password_required($comment_post_ID)) {
                     do_action('comment_on_password_protected', $comment_post_ID);
                     return;
                 } else {
                     do_action('pre_comment_on_post', $comment_post_ID);
                 }
             }
         }
     }
     $comment_content = isset($_POST['comment']) ? trim($_POST['comment']) : '';
     // If the user is logged in
     $user_ID = get_current_user_id();
     if ($user_ID) {
         global $current_user;
         $display_name = !empty($current_user->display_name) ? $current_user->display_name : $current_user->user_login;
         $comment_author = $display_name;
         $comment_author_email = '';
         //get email from field
         $comment_author_url = $current_user->user_url;
     } else {
         $comment_author = isset($_POST['author']) ? trim(strip_tags($_POST['author'])) : '';
         $comment_author_email = isset($_POST['email']) ? trim($_POST['email']) : '';
         $comment_author_url = isset($_POST['url']) ? trim($_POST['url']) : '';
     }
     $comment_type = '';
     if (!$user_ID && get_option('require_name_email') && (6 > strlen($comment_author_email) || $comment_author == '')) {
         return;
     }
     if ($comment_content == '') {
         return;
     }
     $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID');
     wp_new_comment($commentdata);
 }
开发者ID:swc-dng,项目名称:swcsandbox,代码行数:57,代码来源:FrmProComment.php

示例7: new_comment

 public function new_comment()
 {
     $words = array('Ok', 'Cool', 'wow', 'Yeah Right!', 'Ha Ha', 'Tacos', 'Burritos', 'Maybe', 'Tonight', 'Fun');
     $i1 = array_rand($words);
     $i2 = array_rand($words);
     $num = range(0, 10);
     $comment_id = wp_new_comment(array('comment_type' => 'comment', 'comment_post_ID' => 1, 'comment_author_url' => '', 'comment_author_email' => 'person' . $num[array_rand($num)] . '@people.com', 'comment_author' => 'person' . $num[array_rand($num)], 'comment_content' => join(' ', array($words[$i1], $words[$i2]))));
     get_comment($comment_id);
     wp_cache_delete('comments-1', 'counts');
     exit(1);
 }
开发者ID:staylor,项目名称:comments-redux,代码行数:11,代码来源:Comments_Redux_Plugin.php

示例8: comment

 function comment($id, $data)
 {
     global $wp_json_posts;
     if (!is_user_logged_in()) {
         return new WP_Error('bikeit_user_cannot_comment', __('Sorry, you must be logged in to comment.', 'bikeit'), array('status' => 401));
     }
     $user_id = get_current_user_id();
     $comment_content = $data['comment_content'];
     $comment_data = array('comment_post_ID' => $id, 'user_ID' => $user_id, 'comment_content' => $comment_content);
     $comment_id = wp_new_comment($comment_data);
     $response = json_ensure_response($wp_json_posts->comments->get_comment($comment_id));
     $response->set_status(201);
     return $response;
 }
开发者ID:tiagofassoni,项目名称:bikeit,代码行数:14,代码来源:comment.php

示例9: create

 /**
  * @throws ShoutemApiException
  */
 public function create($record)
 {
     $commentdata = array('comment_author' => $record['author'], 'comment_author_email' => $record['author_email'], 'comment_author_url' => $record['author_url'], 'user_id' => (int) $record['user_id'], 'comment_content' => $record['message'], 'comment_post_ID' => (int) $record['post_id'], 'comment_type' => '');
     add_action('comment_duplicate_trigger', 'shoutem_api_comment_duplicate_trigger');
     add_action('comment_flood_trigger', 'shoutem_api_comment_flood_trigger');
     $comment_id = wp_new_comment($commentdata);
     $comment = false;
     if ($comment_id !== false) {
         $comment = get_comment($comment_id);
     }
     if ($comment !== false) {
         return $this->get_comment($comment, $record);
     } else {
         throw new ShoutemApiException('comment_create_error');
     }
 }
开发者ID:gopinathshiva,项目名称:wordpress-vip-plugins,代码行数:19,代码来源:class-shoutem-posts-comments-dao.php

示例10: test_wp_new_comment

 /**
  * Tests the extended model function that expects slashed data
  *
  */
 function test_wp_new_comment()
 {
     $post_id = self::factory()->post->create();
     // not testing comment_author_email or comment_author_url
     // as slashes are not permitted in that data
     $data = array('comment_post_ID' => $post_id, 'comment_author' => $this->slash_1, 'comment_author_url' => '', 'comment_author_email' => '', 'comment_type' => '', 'comment_content' => $this->slash_7);
     $id = wp_new_comment($data);
     $comment = get_comment($id);
     $this->assertEquals(wp_unslash($this->slash_1), $comment->comment_author);
     $this->assertEquals(wp_unslash($this->slash_7), $comment->comment_content);
     $data = array('comment_post_ID' => $post_id, 'comment_author' => $this->slash_2, 'comment_author_url' => '', 'comment_author_email' => '', 'comment_type' => '', 'comment_content' => $this->slash_4);
     $id = wp_new_comment($data);
     $comment = get_comment($id);
     $this->assertEquals(wp_unslash($this->slash_2), $comment->comment_author);
     $this->assertEquals(wp_unslash($this->slash_4), $comment->comment_content);
 }
开发者ID:boonebgorges,项目名称:develop.wordpress,代码行数:20,代码来源:slashes.php

示例11: extra_add_post_rating

function extra_add_post_rating($post_id, $rating)
{
    if (extra_get_user_post_rating($post_id)) {
        return array();
    }
    $commentdata = array('comment_type' => EXTRA_RATING_COMMENT_TYPE, 'comment_author' => '', 'comment_author_url' => '', 'comment_author_email' => '', 'comment_post_ID' => absint($post_id), 'comment_content' => abs(floatval($rating)));
    $user = wp_get_current_user();
    if ($user->exists()) {
        $commentdata['comment_author'] = wp_slash($user->display_name);
        $commentdata['user_ID'] = $user->ID;
    }
    // prevent notifications
    add_filter('extra_rating_notify_intercept', '__return_zero');
    wp_new_comment($commentdata);
    return array('rating' => $rating, 'average' => extra_set_post_rating_average($post_id));
}
开发者ID:rthburke,项目名称:fltHub,代码行数:16,代码来源:ratings.php

示例12: add_vote_for_post

 /**
  * Inserts a comment in the database for a given post.
  *
  * @param int    $post_id
  * @param string $content
  *
  * @return false|int Either the inserted comment `comment_id` or `false` on failure.
  */
 public function add_vote_for_post($post_id, $content)
 {
     if (empty(get_post($post_id))) {
         return false;
     }
     if (empty($content)) {
         return false;
     }
     $comments = $this->get_post_comments($post_id);
     $comment_data = array('comment_post_ID' => $post_id, 'comment_author' => 'Anonymous', 'comment_author_url' => get_post_permalink($post_id), 'comment_author_email' => 'idlikethis@' . home_url(), 'comment_content' => count($comments) . ' - ' . $content, 'comment_type' => 'idlikethis', 'user_id' => get_current_user_id(), 'comment_approved' => 1);
     try {
         return wp_new_comment($comment_data);
     } catch (WPDieException $e) {
         return false;
     }
 }
开发者ID:lucatume,项目名称:idlikethis,代码行数:24,代码来源:CommentsRepository.php

示例13: insertComment

 private function insertComment($message)
 {
     global $wpdb;
     $comment_table = $wpdb->prefix . "comments";
     $post_table = $wpdb->prefix . "posts";
     $comment_date = date("Y-m-d H:i:s", $message->timestamp);
     $post_id = url_to_postid($message->conversation_url);
     $comment_id = $wpdb->get_var("SELECT comment_ID FROM `{$comment_table}` WHERE comment_post_ID = {$post_id} AND comment_date = '{$comment_date}' LIMIT 1");
     if (!$comment_id) {
         $post = $wpdb->get_var("SELECT ID FROM `{$post_table}` WHERE ID = {$post_id} LIMIT 1");
         if ($post) {
             $data = array('comment_post_ID' => $post_id, 'comment_author' => $message->display_name, 'comment_content' => $message->content[0]->text, 'comment_type' => $message->content[0]->type, 'comment_date_gmt' => $comment_date, 'comment_date' => $comment_date, 'comment_approved' => 1, 'comment_author_IP' => '', 'comment_agent' => '');
             $new_comment_id = wp_new_comment($data);
             if ($new_comment_id) {
                 return true;
             }
         }
     }
     return false;
 }
开发者ID:SpinMedia,项目名称:spotim-wp-comments,代码行数:20,代码来源:class-spotim-update-comment.php

示例14: ajax_comment

function ajax_comment()
{
    global $wpdb;
    $comment_post_ID = isset($_POST['comment_post_ID']) ? (int) $_POST['comment_post_ID'] : 0;
    $post = get_post($comment_post_ID);
    if (empty($post->comment_status)) {
        do_action('comment_id_not_found', $comment_post_ID);
        ajax_comment_err(__('Invalid comment status.'));
    }
    $status = get_post_status($post);
    $status_obj = get_post_status_object($status);
    if (!comments_open($comment_post_ID)) {
        do_action('comment_closed', $comment_post_ID);
        ajax_comment_err(__('Sorry, comments are closed for this item.'));
    } elseif ('trash' == $status) {
        do_action('comment_on_trash', $comment_post_ID);
        ajax_comment_err(__('Invalid comment status.'));
    } elseif (!$status_obj->public && !$status_obj->private) {
        do_action('comment_on_draft', $comment_post_ID);
        ajax_comment_err(__('Invalid comment status.'));
    } elseif (post_password_required($comment_post_ID)) {
        do_action('comment_on_password_protected', $comment_post_ID);
        ajax_comment_err(__('Password Protected'));
    } else {
        do_action('pre_comment_on_post', $comment_post_ID);
    }
    $comment_author = isset($_POST['author']) ? trim(strip_tags($_POST['author'])) : null;
    $comment_author_email = isset($_POST['email']) ? trim($_POST['email']) : null;
    $comment_author_url = isset($_POST['url']) ? trim($_POST['url']) : null;
    $comment_content = isset($_POST['comment']) ? trim($_POST['comment']) : null;
    $user = wp_get_current_user();
    if ($user->exists()) {
        if (empty($user->display_name)) {
            $user->display_name = $user->user_login;
        }
        $comment_author = $wpdb->escape($user->display_name);
        $comment_author_email = $wpdb->escape($user->user_email);
        $comment_author_url = $wpdb->escape($user->user_url);
        $user_ID = $wpdb->escape($user->ID);
        if (current_user_can('unfiltered_html')) {
            if (wp_create_nonce('unfiltered-html-comment_' . $comment_post_ID) != $_POST['_wp_unfiltered_html_comment']) {
                kses_remove_filters();
                kses_init_filters();
            }
        }
    } else {
        if (get_option('comment_registration') || 'private' == $status) {
            ajax_comment_err('对不起,您必须登录后才能进行评论');
        }
    }
    $comment_type = '';
    if (get_option('require_name_email') && !$user->exists()) {
        if (6 > strlen($comment_author_email) || '' == $comment_author) {
            ajax_comment_err('错误: 请填写如下信息 (姓名, 电子邮件)');
        } elseif (!is_email($comment_author_email)) {
            ajax_comment_err('错误: 请输入正确的邮件地址');
        }
    }
    if ('' == $comment_content) {
        ajax_comment_err('请输入回复内容');
    }
    $dupe = "SELECT comment_ID FROM {$wpdb->comments} WHERE comment_post_ID = '{$comment_post_ID}' AND ( comment_author = '{$comment_author}' ";
    if ($comment_author_email) {
        $dupe .= "OR comment_author_email = '{$comment_author_email}' ";
    }
    $dupe .= ") AND comment_content = '{$comment_content}' LIMIT 1";
    if ($wpdb->get_var($dupe)) {
        ajax_comment_err('重复回复,貌似您已经回复过该信息');
    }
    if ($lasttime = $wpdb->get_var($wpdb->prepare("SELECT comment_date_gmt FROM {$wpdb->comments} WHERE comment_author = %s ORDER BY comment_date DESC LIMIT 1", $comment_author))) {
        $time_lastcomment = mysql2date('U', $lasttime, false);
        $time_newcomment = mysql2date('U', current_time('mysql', 1), false);
        $flood_die = apply_filters('comment_flood_filter', false, $time_lastcomment, $time_newcomment);
        if ($flood_die) {
            ajax_comment_err('您回复速度太快了,请稍后在进行回复');
        }
    }
    $comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0;
    $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
    $comment_id = wp_new_comment($commentdata);
    $comment = get_comment($comment_id);
    do_action('set_comment_cookies', $comment, $user);
    $comment_depth = 1;
    $tmp_c = $comment;
    while ($tmp_c->comment_parent != 0) {
        $comment_depth++;
        $tmp_c = get_comment($tmp_c->comment_parent);
    }
    $GLOBALS['comment'] = $comment;
    //your comments here	edit start
    ?>
<li class="comments" <?php 
    comment_class(empty($args['has_children']) ? '' : 'parent');
    ?>
 id="li-comment-<?php 
    comment_ID();
    ?>
">
    <div id="comment-<?php 
    comment_ID();
//.........这里部分代码省略.........
开发者ID:qq361168780,项目名称:9IPHP,代码行数:101,代码来源:functions.php

示例15: pingback_ping


//.........这里部分代码省略.........
     }
     // Check if pings are on
     if (!pings_open($post)) {
         return $this->pingback_error(33, __('The specified target URL cannot be used as a target. It either doesn&#8217;t exist, or it is not a pingback-enabled resource.'));
     }
     // Let's check that the remote site didn't already pingback this entry
     if ($wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->comments} WHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom))) {
         return $this->pingback_error(48, __('The pingback has already been registered.'));
     }
     // very stupid, but gives time to the 'from' server to publish !
     sleep(1);
     $remote_ip = preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']);
     /** This filter is documented in wp-includes/class-http.php */
     $user_agent = apply_filters('http_headers_useragent', 'WordPress/' . $GLOBALS['wp_version'] . '; ' . get_bloginfo('url'));
     // Let's check the remote site
     $http_api_args = array('timeout' => 10, 'redirection' => 0, 'limit_response_size' => 153600, 'user-agent' => "{$user_agent}; verifying pingback from {$remote_ip}", 'headers' => array('X-Pingback-Forwarded-For' => $remote_ip));
     $request = wp_safe_remote_get($pagelinkedfrom, $http_api_args);
     $linea = wp_remote_retrieve_body($request);
     if (!$linea) {
         return $this->pingback_error(16, __('The source URL does not exist.'));
     }
     /**
      * Filter the pingback remote source.
      *
      * @since 2.5.0
      *
      * @param string $linea        Response object for the page linked from.
      * @param string $pagelinkedto URL of the page linked to.
      */
     $linea = apply_filters('pre_remote_source', $linea, $pagelinkedto);
     // Work around bug in strip_tags():
     $linea = str_replace('<!DOC', '<DOC', $linea);
     $linea = preg_replace('/[\\r\\n\\t ]+/', ' ', $linea);
     // normalize spaces
     $linea = preg_replace("/<\\/*(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/", "\n\n", $linea);
     preg_match('|<title>([^<]*?)</title>|is', $linea, $matchtitle);
     $title = $matchtitle[1];
     if (empty($title)) {
         return $this->pingback_error(32, __('We cannot find a title on that page.'));
     }
     $linea = strip_tags($linea, '<a>');
     // just keep the tag we need
     $p = explode("\n\n", $linea);
     $preg_target = preg_quote($pagelinkedto, '|');
     foreach ($p as $para) {
         if (strpos($para, $pagelinkedto) !== false) {
             // it exists, but is it a link?
             preg_match("|<a[^>]+?" . $preg_target . "[^>]*>([^>]+?)</a>|", $para, $context);
             // If the URL isn't in a link context, keep looking
             if (empty($context)) {
                 continue;
             }
             // We're going to use this fake tag to mark the context in a bit
             // the marker is needed in case the link text appears more than once in the paragraph
             $excerpt = preg_replace('|\\</?wpcontext\\>|', '', $para);
             // prevent really long link text
             if (strlen($context[1]) > 100) {
                 $context[1] = substr($context[1], 0, 100) . '&#8230;';
             }
             $marker = '<wpcontext>' . $context[1] . '</wpcontext>';
             // set up our marker
             $excerpt = str_replace($context[0], $marker, $excerpt);
             // swap out the link for our marker
             $excerpt = strip_tags($excerpt, '<wpcontext>');
             // strip all tags but our context marker
             $excerpt = trim($excerpt);
             $preg_marker = preg_quote($marker, '|');
             $excerpt = preg_replace("|.*?\\s(.{0,100}{$preg_marker}.{0,100})\\s.*|s", '$1', $excerpt);
             $excerpt = strip_tags($excerpt);
             // YES, again, to remove the marker wrapper
             break;
         }
     }
     if (empty($context)) {
         // Link to target not found
         return $this->pingback_error(17, __('The source URL does not contain a link to the target URL, and so cannot be used as a source.'));
     }
     $pagelinkedfrom = str_replace('&', '&amp;', $pagelinkedfrom);
     $context = '[&#8230;] ' . esc_html($excerpt) . ' [&#8230;]';
     $pagelinkedfrom = $this->escape($pagelinkedfrom);
     $comment_post_ID = (int) $post_ID;
     $comment_author = $title;
     $comment_author_email = '';
     $this->escape($comment_author);
     $comment_author_url = $pagelinkedfrom;
     $comment_content = $context;
     $this->escape($comment_content);
     $comment_type = 'pingback';
     $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_content', 'comment_type');
     $comment_ID = wp_new_comment($commentdata);
     /**
      * Fires after a post pingback has been sent.
      *
      * @since 0.71
      *
      * @param int $comment_ID Comment ID.
      */
     do_action('pingback_post', $comment_ID);
     return sprintf(__('Pingback from %1$s to %2$s registered. Keep the web talking! :-)'), $pagelinkedfrom, $pagelinkedto);
 }
开发者ID:sb-xs,项目名称:que-pour-elle,代码行数:101,代码来源:class-wp-xmlrpc-server.php


注:本文中的wp_new_comment函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。