• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wp_new_comment函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_comment_as_logged_out_user_success

 /**
  * @group comments
  */
 public function test_comment_as_logged_out_user_success()
 {
     $old_current_user = get_current_user_id();
     $this->set_current_user(0);
     $d = $this->factory->doc->create();
     $d_settings = bp_docs_get_doc_settings($d);
     $d_settings['post_comments'] = 'anyone';
     update_post_meta($d, 'bp_docs_settings', $d_settings);
     $c_args = array('comment_post_ID' => $d, 'comment_content' => 'Test', 'comment_author' => 'foo', 'comment_author_url' => '', 'comment_author_email' => '[email protected]', 'comment_type' => '');
     // Gah
     add_filter('pre_option_moderation_notify', '__return_zero');
     $c = wp_new_comment($c_args);
     remove_filter('pre_option_moderation_notify', '__return_zero');
     $this->set_current_user($old_current_user);
     $comment = get_comment($c);
     $this->assertEquals(1, $comment->comment_approved);
 }
开发者ID:igniterealtime,项目名称:community-plugins,代码行数:20,代码来源:test-bp-docs.php


示例17: new_comment

 function new_comment()
 {
     if (empty($_POST['action']) || $_POST['action'] != 'new_comment') {
         die;
     }
     check_ajax_referer('ajaxnonce', '_ajax_post');
     $comment_content = isset($_POST['comment']) ? trim($_POST['comment']) : null;
     $comment_post_ID = isset($_POST['comment_post_ID']) ? trim($_POST['comment_post_ID']) : null;
     $user = wp_get_current_user();
     if (is_user_logged_in()) {
         if (empty($user->display_name)) {
             $user->display_name = $user->user_login;
         }
         $comment_author = $user->display_name;
         $comment_author_email = $user->user_email;
         $comment_author_url = $user->user_url;
         $user_ID = $user->ID;
     } else {
         if (get_option('comment_registration')) {
             die('<p>' . __('Error: you must be logged in to post a comment.', 'p2') . '</p>');
         }
         $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_type = '';
     if (get_option('require_name_email') && !$user->ID) {
         if (strlen($comment_author_email) < 6 || '' == $comment_author) {
             die('<p>' . __('Error: please fill the required fields (name, email).', 'p2') . '</p>');
         } elseif (!is_email($comment_author_email)) {
             die('<p>' . __('Error: please enter a valid email address.', 'p2') . '</p>');
         }
     }
     if ('' == $comment_content) {
         die('<p>' . __('Error: Please type a comment.', 'p2') . '</p>');
     }
     $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);
     if (!$user->ID) {
         setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
         setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
         setcookie('comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
     }
     if ($comment) {
         echo $comment_id;
     } else {
         echo __("Error: Unknown error occurred. Comment not posted.", 'p2');
     }
 }
开发者ID:rajbot,项目名称:tikirobot_p2,代码行数:51,代码来源:ajax.php


示例18: test_wp_update_comment_author_id_and_agent

 /**
  * @ticket 35276
  */
 public function test_wp_update_comment_author_id_and_agent()
 {
     $default_data = array('comment_post_ID' => self::$post_id, 'comment_author' => rand_str(), 'comment_author_IP' => '192.168.0.1', 'comment_agent' => 'WRONG_AGENT', 'comment_author_url' => '', 'comment_author_email' => '', 'comment_type' => '', 'comment_content' => rand_str());
     $comment_id = wp_new_comment($default_data);
     // Confirm that the IP and Agent are correct on initial save.
     $save = get_comment($comment_id);
     $this->assertSame($default_data['comment_author_IP'], $save->comment_author_IP);
     $this->assertSame($default_data['comment_agent'], $save->comment_agent);
     // Update the comment.
     wp_update_comment(array('comment_ID' => $comment_id, 'comment_author_IP' => '111.111.1.1', 'comment_agent' => 'SHIELD_AGENT'));
     // Retrieve and check the new values.
     $updated = get_comment($comment_id);
     $this->assertSame('111.111.1.1', $updated->comment_author_IP);
     $this->assertSame('SHIELD_AGENT', $updated->comment_agent);
 }
开发者ID:aaronjorbin,项目名称:WordPress,代码行数:18,代码来源:comment.php


示例19: post_comment

 /** 
  * Transparent inline login and commenting.
  * The comment text is in the session.
  * Post it and redirect to the permalink.
  */
 function post_comment(&$oid_user_data)
 {
     $comment = $this->get_comment();
     $comment_content = $comment['comment_content'];
     $this->clear_comment();
     if ('' == trim($comment_content)) {
         die(__('Error: please type a comment.'));
     }
     $this->core->log->debug('OpenIDConsumer: action=commentopenid  redirect_to=' . $redirect_to);
     $this->core->log->debug('OpenIDConsumer: comment_content = ' . $comment_content);
     nocache_headers();
     // Do essentially the same thing as wp-comments-post.php
     global $wpdb;
     $comment_post_ID = (int) $_REQUEST['wordpressid'];
     $status = $wpdb->get_row("SELECT post_status, comment_status FROM {$wpdb->posts} " . "WHERE ID = '{$comment_post_ID}'");
     if (empty($status->comment_status)) {
         do_action('comment_id_not_found', $comment_post_ID);
         exit;
     } elseif ('closed' == $status->comment_status) {
         do_action('comment_closed', $comment_post_ID);
         die(__('Sorry, comments are closed for this item.'));
     } elseif ('draft' == $status->post_status) {
         do_action('comment_on_draft', $comment_post_ID);
         exit;
     }
     $comment_author = $wpdb->escape($oid_user_data['display_name']);
     $comment_author_email = $wpdb->escape($oid_user_data['user_email']);
     $comment_author_url = $wpdb->escape($oid_user_data['user_url']);
     $user_ID = $oid_user_data['ID'];
     $this->flag_doing_openid_comment = true;
     $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID');
     if (!$user_id) {
         setcookie('comment_author_' . COOKIEHASH, $comment['comment_author'], time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
         setcookie('comment_author_email_' . COOKIEHASH, $comment['comment_author_email'], time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
         setcookie('comment_author_url_' . COOKIEHASH, clean_url($comment['comment_author_url']), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
         // save openid url in a separate cookie so wordpress doesn't muck with it when we
         // read it back in later
         setcookie('comment_author_openid_' . COOKIEHASH, $comment['comment_author_openid'], time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
     }
     // comment approval
     if (get_option('oid_enable_approval')) {
         add_filter('pre_comment_approved', array($this, 'comment_approval'));
     }
     $comment_ID = wp_new_comment($commentdata);
     $this->set_comment_openid($comment_ID);
     return $comment_ID;
 }
开发者ID:versvs,项目名称:pressmark,代码行数:52,代码来源:logic.php


示例20: try_sending_author_notification

 /**
  * Helper function to test sending author notifications.
  *
  * @since 4.4.0
  * @access public
  */
 public function try_sending_author_notification($comment, $post)
 {
     // Approve comments, triggering notifications.
     add_filter('pre_comment_approved', '__return_true');
     // Post authors possibly notified when a comment is approved on their post.
     wp_set_comment_status($comment, 'approve');
     // Check to see if a notification email was sent to the post author `[email protected]`.
     if (isset($GLOBALS['phpmailer']->mock_sent) && !empty($GLOBALS['phpmailer']->mock_sent) && '[email protected]' == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]) {
         $email_sent_when_comment_approved = true;
     } else {
         $email_sent_when_comment_approved = false;
     }
     unset($GLOBALS['phpmailer']->mock_sent);
     // Post authors are notified when a new comment is added to their post.
     $data = array('comment_post_ID' => $post, 'comment_author' => rand_str(), 'comment_author_url' => '', 'comment_author_email' => '', 'comment_type' => '', 'comment_content' => rand_str());
     wp_new_comment($data);
     // Check to see if a notification email was sent to the post author `[email protected]`.
     if (isset($GLOBALS['phpmailer']->mock_sent) && !empty($GLOBALS['phpmailer']->mock_sent) && '[email protected]' == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]) {
         $email_sent_when_comment_added = true;
         unset($GLOBALS['phpmailer']->mock_sent);
     } else {
         $email_sent_when_comment_added = false;
     }
     return $email_sent_when_comment_approved || $email_sent_when_comment_added;
 }
开发者ID:nkeat12,项目名称:dv,代码行数:31,代码来源:comment.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wp_new_user_notification函数代码示例发布时间:2022-05-23
下一篇:
PHP wp_new_blog_notification函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap