function evc_comments_add_comment($comment, $post_id, $widget_api_id, $comment_parent = null) { if (isset($comment['cid'])) { $comment['id'] = $comment['cid']; } $vk_item_id = 'app' . $widget_api_id . '_' . $comment['id']; $comment_wp_id = evc_get_wpid_by_vkid($vk_item_id, 'comment'); if ($comment_wp_id && isset($comment_wp_id[$vk_item_id])) { return $comment_wp_id[$vk_item_id]; } if (isset($comment['user']) && !empty($comment['user'])) { $user_wp_id = evc_get_wpid_by_vkid($comment['user']['id'], 'user'); if (!$user_wp_id) { $user_wp_id = evc_add_user($comment['user']); if (!$user_wp_id) { return false; } } else { $user_wp_id = $user_wp_id[$comment['user']['id']]; } } else { return false; } $args = array('comment_post_ID' => $post_id, 'comment_content' => $comment['text'], 'user_id' => $user_wp_id, 'comment_date' => date('Y-m-d H:i:s', $comment['date'] + get_option('gmt_offset') * 3600), 'comment_approved' => 1, 'comment_author_IP' => preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']), 'comment_agent' => substr($_SERVER['HTTP_USER_AGENT'], 0, 254)); if (isset($comment_parent) && !empty($comment_parent)) { $args['comment_parent'] = $comment_parent; } $args = apply_filters('evc_comments_add_comment_args', $args, $comment); //print__r($args); // $comment_wp_id = wp_insert_comment($args); if ($comment_wp_id) { update_comment_meta($comment_wp_id, 'vk_item_id', $vk_item_id); } return $comment_wp_id; }
function p_ssc_process($commentdata) { // if this is a trackback or pingback return if ($commentdata['comment_type'] != '') { return $commentdata; } global $post; // Quick fix: $post no more available since WordPress 4.4 if (is_null($post)) { //global $wpdb; //$_postid = $wpdb->last_result[0]->ID; // better, thanks to https://twitter.com/nosegraze $_postid = $commentdata['comment_post_ID']; } else { $_postid = $post->ID; } $key = p_ssc_generateKey($_postid); // if comment has key field return if (isset($_POST['ssc_key_' . $key[0]]) && $_POST['ssc_key_' . $key[0]] == $key[1]) { return $commentdata; } elseif (strpos($commentdata['comment_content'], $key[1] . $key[0]) !== false) { $commentdata['comment_content'] = str_replace($key[1] . $key[0], '', $commentdata['comment_content']); return $commentdata; } else { do_action('stop_spam_comments_found_spam', $commentdata); if (get_option('p_ssc_keepspam')) { $commentdata['comment_approved'] = 'spam'; wp_insert_comment($commentdata); } wp_die(__('Notice: It seems you have Javascript disabled in your Browser. In order to submit a comment to this post, please write the code below the form along with your comment.', 'stop-spam-comments')); } }
public function customer_note_added($data) { global $wpdb; $post = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE id = %d", $data['order_id'])); if ($post && $post->post_type == 'order_shipment') { $parent_id = $post->post_parent; $is_customer_note = intval(1); if (isset($_SERVER['HTTP_HOST'])) { $comment_author_email = sanitize_email(strtolower(__('WooCommerce', 'woocommerce')) . '@' . str_replace('www.', '', $_SERVER['HTTP_HOST'])); } else { $comment_author_email = sanitize_email(strtolower(__('WooCommerce', 'woocommerce')) . '@noreply.com'); } $comment_post_ID = $parent_id; $comment_author = __('WooCommerce', 'woocommerce'); $comment_author_url = ''; $comment_content = $data['customer_note']; $comment_agent = 'WooCommerce'; $comment_type = 'order_note'; $comment_parent = 0; $comment_approved = 1; $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_agent', 'comment_type', 'comment_parent', 'comment_approved'); $comment_id = wp_insert_comment($commentdata); add_comment_meta($comment_id, 'is_customer_note', $is_customer_note); } }
function import() { $comment_author = $this->author; $comment_author_url = $this->authoruri; $comment_author_email = $this->authoremail; $comment_date = $this->updated; $comment_content = $this->content; $comment_post_ID = $this->post_ID; $comment_author_IP = '127.0.0.1'; //Blogger does not supply the IP so default this // Clean up content // Simplepie does some cleaning but does not do these. $comment_content = str_replace('<br>', '<br />', $comment_content); $comment_content = str_replace('<hr>', '<hr />', $comment_content); $comment_parent = isset($this->parentcommentid) ? $this->parentcommentid : 0; $comment = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email','comment_author_IP','comment_date', 'comment_content', 'comment_parent'); $comment = wp_filter_comment($comment); $comment_id = wp_insert_comment($comment); //links of the form /feeds/417730729915399755/8397846992898424746/comments/default/7732208643735403000 add_comment_meta($comment_id, 'blogger_internal', $this->self, true); return $comment_id; }
function wp_new_comment($commentdata) { $commentdata = apply_filters('preprocess_comment', $commentdata); $commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID']; $commentdata['user_ID'] = (int) $commentdata['user_ID']; $commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR']; $commentdata['comment_agent'] = $_SERVER['HTTP_USER_AGENT']; $commentdata['comment_date'] = current_time('mysql'); $commentdata['comment_date_gmt'] = current_time('mysql', 1); $commentdata = wp_filter_comment($commentdata); $commentdata['comment_approved'] = wp_allow_comment($commentdata); $comment_ID = wp_insert_comment($commentdata); do_action('comment_post', $comment_ID, $commentdata['comment_approved']); if ('spam' !== $commentdata['comment_approved']) { // If it's spam save it silently for later crunching if ('0' == $commentdata['comment_approved']) { wp_notify_moderator($comment_ID); } $post =& get_post($commentdata['comment_post_ID']); // Don't notify if it's your own comment if (get_settings('comments_notify') && $commentdata['comment_approved'] && $post->post_author != $commentdata['user_ID']) { wp_notify_postauthor($comment_ID, $commentdata['comment_type']); } } return $comment_ID; }
function jobman_store_comment() { global $current_user; get_currentuserinfo(); $comment = array('comment_post_ID' => $_REQUEST['interview'], 'comment_content' => $_REQUEST['comment'], 'user_id' => $current_user->ID); wp_insert_comment($comment); }
function process_comments($post_id, $item_id) { if (empty($post_id)) { return; } if (!is_numeric($post_id)) { return; } $comments = $this->model->get_item_comments($item_id); if (!$comments || !isset($comments['data'])) { return; } $comments = $comments['data']; if (!count($comments)) { return false; } foreach ($comments as $comment) { if ($this->model->comment_already_imported($comment['id'])) { continue; } // We already have this comment, continue. $data = array('comment_post_ID' => $post_id, 'comment_date_gmt' => date('Y-m-d H:i:s', strtotime($comment['created_time'])), 'comment_author' => $comment['from']['name'], 'comment_author_url' => 'http://www.facebook.com/profile.php?id=' . $comment['from']['id'], 'comment_content' => $comment['message']); $meta = array('fb_comment_id' => $comment['id'], 'fb_author_id' => $comment['from']['id']); $data = wp_filter_comment($data); $comment_id = wp_insert_comment($data); add_comment_meta($comment_id, 'wdfb_comment', $meta); if ($this->model->data->get_option('wdfb_comments', 'notify_authors')) { wp_notify_postauthor($comment_id, 'comment'); } } }
/** * Import comments from Instagram and load as WP comments for an image and post * * @param $access_token * @param $comments * @param $image_id * @param $post_id * @param $id * @param bool $sync */ public function import_comments($access_token, $comments, $image_id, $post_id, $id, $sync = false) { global $wpdb; if ($comments == '') { $comments = instagrate_pro()->accounts->get_comments($access_token, $image_id); $data = array('comments' => isset($comments) ? base64_encode(serialize($comments)) : array()); $where = array('id' => $id); $wpdb->update(instagrate_pro()->images->get_table_name(), $data, $where); } $meta_table = $wpdb->prefix . 'commentmeta'; if (!is_array($comments)) { return; } foreach ($comments as $comment) { $querystr = "\tSELECT count(*)\n\t\t\t\t\t\t\tFROM {$meta_table} m\n\t\t\t\t\t\t\tWHERE m.meta_key = '_igp_comment_id'\n\t\t\t\t\t\t\tAND m.meta_value = '{$comment->id}'\t"; $exists = $wpdb->get_var($querystr); if ($exists > 0) { continue; } // set comment data $data = array('comment_post_ID' => $post_id, 'comment_author' => $comment->from->username, 'comment_author_email' => '@instagram_igp', 'comment_author_url' => 'http://instagram.com/' . $comment->from->username, 'comment_content' => instagrate_pro()->helper->clean_caption($comment->text), 'comment_type' => '', 'comment_parent' => 0, 'user_id' => 0, 'comment_author_IP' => '127.0.0.1', 'comment_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)', 'comment_date' => date('Y-m-d H:i:s', $comment->created_time), 'comment_approved' => Instagrate_Pro_Helper::setting('igpsettings_comments_auto-approve', '0')); $comment_id = wp_insert_comment($data); //set comment meta ig comment id add_comment_meta($comment_id, '_igp_comment_id', $comment->id, true); //set comment meta with user image url add_comment_meta($comment_id, '_igp_comment_avatar', $comment->from->profile_picture, true); } }
function smamo_status_post() { $response = array(); // Check om bruger er logget ind if (!is_user_logged_in()) { $response['code'] = '403'; $response['error'] = 'Du skal være logget ind for at kunne kommentere.'; wp_die(json_encode($response)); } // Fang nuværende bruger $user = wp_get_current_user(); $response['user'] = array('ID' => $user->ID, 'name' => $user->user_login); // Fang tekst $msg = esc_textarea($_POST['msg']); $response['msg'] = $msg; // fang ID på spørgsmål $post_id = wp_strip_all_tags($_POST['post_id']); // Opret ny kommmentar $time = current_time('mysql'); $data = array('comment_post_ID' => $post_id, 'comment_author' => $user->user_login, 'comment_content' => $msg, 'user_id' => $user->ID, 'comment_date' => $time, 'comment_approved' => 1); $new = wp_insert_comment($data); if (is_wp_error($new)) { $response['code'] = '503'; $response['error'] = $new->get_error_message(); wp_die(json_encode($response)); } // Send succes tilbage $response['code'] = 200; $response['success'] = 'Successfully posted'; wp_die(json_encode($response)); }
/** * create a comment with type fre_invite * @param int $user_id * @param int $project * @return int $invite_id * @since 1.3.1 * @author Dakachi */ function fre_create_invite($user_id, $project_id) { global $user_ID, $current_user; $invite_id = wp_insert_comment(array('comment_post_ID' => $project_id, 'comment_author' => $current_user->data->user_login, 'comment_author_email' => $current_user->data->user_email, 'comment_content' => sprintf(__("Invite %s to bid project", 'invites-backend'), get_the_author_meta('display_name', $user_id)), 'comment_type' => 'fre_invite', 'user_id' => $user_ID, 'comment_approved' => 1)); update_comment_meta($invite_id, 'invite', $user_id); return $invite_id; }
protected function create_wp_comment($action_id, $message, DateTime $date) { $comment_date_gmt = $date->format('Y-m-d H:i:s'); $date->setTimezone(ActionScheduler_TimezoneHelper::get_local_timezone()); $comment_data = array('comment_post_ID' => $action_id, 'comment_date' => $date->format('Y-m-d H:i:s'), 'comment_date_gmt' => $comment_date_gmt, 'comment_author' => self::AGENT, 'comment_content' => $message, 'comment_agent' => self::AGENT, 'comment_type' => self::TYPE); return wp_insert_comment($comment_data); }
public static function wpSetUpBeforeClass(WP_UnitTest_Factory $factory) { self::$post_id = $factory->post->create(); self::$parent_comment_data = array('comment_post_ID' => self::$post_id, 'comment_author' => 'Test commenter', 'comment_author_url' => 'http://example.com/', 'comment_author_email' => '*****@*****.**', 'comment_content' => rand_str(100)); self::$parent_comment_id = wp_insert_comment(self::$parent_comment_data); self::$child_comment_data = array('comment_post_ID' => self::$post_id, 'comment_author' => 'Test commenter 2', 'comment_author_url' => 'http://example.org/', 'comment_author_email' => '*****@*****.**', 'comment_parent' => self::$parent_comment_id, 'comment_content' => rand_str(100)); self::$child_comment_id = wp_insert_comment(self::$child_comment_data); }
public function test_erroneous_entry_id() { $comment = wp_insert_comment(array('comment_post_ID' => 1, 'comment_author' => 'test', 'comment_content' => 'this is not a log entry')); $logger = ActionScheduler::logger(); $entry = $logger->get_entry($comment); $this->assertEquals('', $entry->get_action_id()); $this->assertEquals('', $entry->get_message()); }
function setUp() { parent::setUp(); $this->post_id = $this->factory->post->create(); $this->parent_comment_data = array('comment_post_ID' => $this->post_id, 'comment_author' => 'Test commenter', 'comment_author_url' => 'http://example.com/', 'comment_author_email' => '*****@*****.**', 'comment_content' => rand_str(100)); $this->parent_comment_id = wp_insert_comment($this->parent_comment_data); $this->child_comment_data = array('comment_post_ID' => $this->post_id, 'comment_author' => 'Test commenter 2', 'comment_author_url' => 'http://example.org/', 'comment_author_email' => '*****@*****.**', 'comment_parent' => $this->parent_comment_id, 'comment_content' => rand_str(100)); $this->child_comment_id = wp_insert_comment($this->child_comment_data); }
/** * Create a data comment with data for a potential new subscriber. * * @since 1.0.0 * * @param Prompt_Interface_Subscribable[]|Prompt_Interface_Subscribable $lists * @param string $email * @param array $user_data */ public function save_subscription_data($lists, $email, $user_data = array()) { $remote_address = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $comment_id = wp_insert_comment(array('comment_author_email' => $email, 'comment_author_IP' => preg_replace('/[^0-9a-fA-F:., ]/', '', $remote_address), 'comment_agent' => 'Postmatic/' . Prompt_Core::version(), 'comment_content' => serialize($lists), 'comment_type' => self::$comment_type, 'comment_approved' => 'Postmatic')); if (!empty($user_data)) { add_comment_meta($comment_id, self::$user_data_meta_key, $user_data); } $this->keys = array($comment_id); }
function theme_comment_form() { $result = array(); $result["isOk"] = true; if ($_POST["name"] != "" && $_POST["email"] != "" && preg_match("#^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*(\\.[a-zA-Z]{2,4})\$#", $_POST["email"]) && $_POST["message"] != "") { $values = array("name" => $_POST["name"], "email" => $_POST["email"], "website" => $_POST["website"], "message" => $_POST["message"]); if ((bool) ini_get("magic_quotes_gpc")) { $values = array_map("stripslashes", $values); } $values = array_map("htmlspecialchars", $values); $time = current_time('mysql'); $data = array('comment_post_ID' => (int) $_POST['post_id'], 'comment_author' => $values['name'], 'comment_author_email' => $values['email'], 'comment_author_url' => $values['website'] != __("Website (optional)", 'medicenter') ? $values['website'] : "", 'comment_content' => $values['message'], 'comment_parent' => (int) $_POST['parent_comment_id'], 'comment_date' => $time, 'comment_approved' => (int) get_option('comment_moderation') ? 0 : 1, 'comment_parent' => (int) $_POST['comment_parent_id']); if ($comment_id = wp_insert_comment($data)) { $result["submit_message"] = __("Your comment has been added", 'medicenter'); if (get_option('comments_notify')) { wp_notify_postauthor($comment_id); } //get post comments //post query_posts("p=" . (int) $_POST['post_id'] . "&post_type=" . $_POST["post_type"]); if (have_posts()) { the_post(); ob_start(); $result['comment_id'] = $comment_id; if ((int) $_POST['comment_parent_id'] == 0) { global $wpdb; $query = "SELECT COUNT(*) AS count FROM {$wpdb->comments} WHERE comment_approved = 1 AND comment_post_ID = " . get_the_ID() . " AND comment_parent = 0"; $parents = $wpdb->get_row($query); $_GET["paged"] = ceil($parents->count / 5); $result["change_url"] = "#page-" . $_GET["paged"]; } else { $_GET["paged"] = (int) $_POST["paged"]; } comments_template(); $result['html'] = ob_get_contents(); ob_end_clean(); } } else { $result["isOk"] = false; $result["submit_message"] = __("Error while adding comment", 'medicenter'); } } else { $result["isOk"] = false; if ($_POST["name"] == "" || $_POST["name"] == __("Your name", 'medicenter')) { $result["error_name"] = __("Please enter your name", 'medicenter'); } if ($_POST["email"] == "" || $_POST["email"] == __("Your email", 'medicenter') || !preg_match("#^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*(\\.[a-zA-Z]{2,4})\$#", $_POST["email"])) { $result["error_email"] = __("Please enter valid e-mail", 'medicenter'); } if ($_POST["message"] == "" || $_POST["message"] == __("Message", 'medicenter')) { $result["error_message"] = __("Please enter your message", 'medicenter'); } } echo @json_encode($result); exit; }
public function do_save($return_val, $data, $module) { $comment_id = wp_insert_comment($data); if (!is_numeric($comment_id)) { return false; } // Flag the Object as FakerPress update_post_meta($comment_id, self::$flag, 1); return $comment_id; }
function test_trash_comment() { $this->make_user_by_role('administrator'); $post_id = self::factory()->post->create(); $comment_data = array('comment_post_ID' => $post_id, 'comment_author' => 'Test commenter', 'comment_author_url' => 'http://example.com/', 'comment_author_email' => '*****@*****.**', 'comment_content' => rand_str(100), 'comment_approved' => '1'); $comment_id = wp_insert_comment($comment_data); $this->assertEquals('1', get_comment($comment_id)->comment_approved); $this->myxmlrpcserver->wp_editComment(array(1, 'administrator', 'administrator', $comment_id, array('status' => 'trash'))); $this->assertEquals('trash', get_comment($comment_id)->comment_approved); }
public function do_save($return_val, $params, $metas, $module) { $comment_id = wp_insert_comment($params); if (!is_numeric($comment_id)) { return false; } foreach ($metas as $key => $value) { update_comment_meta($comment_id, $key, $value); } return $comment_id; }
protected function _insertTestData() { $post_id_a = wp_insert_post(array('post_status' => 'publish', 'post_type' => 'post', 'post_author' => 1, 'post_parent' => 0, 'menu_order' => 0, 'post_content_filtered' => '', 'post_excerpt' => 'This is the excerpt.', 'post_content' => 'This is the content.', 'post_title' => 'Hello World A!', 'post_date' => '2013-04-30 20:33:36', 'post_date_gmt' => '2013-04-30 20:33:36', 'comment_status' => 'open')); $post_id_b = wp_insert_post(array('post_status' => 'publish', 'post_type' => 'post', 'post_author' => 1, 'post_parent' => 0, 'menu_order' => 0, 'post_content_filtered' => '', 'post_excerpt' => 'This is the excerpt 2.', 'post_content' => 'This is the content 2.', 'post_title' => 'Hello World A!', 'post_date' => '2013-04-30 20:33:36', 'post_date_gmt' => '2013-04-30 20:33:36', 'comment_status' => 'open')); $comment_approved_minus_10 = wp_insert_comment(array('comment_post_ID' => $post_id_a, 'comment_author' => 'Some Guy', 'comment_author_email' => '*****@*****.**', 'comment_content' => 'This is my comment text', 'user_id' => 1, 'comment_date' => gmdate('Y-m-d H:i:s', time() - 10 * MINUTE_IN_SECONDS + get_option('gmt_offset') * HOUR_IN_SECONDS), 'comment_date_gmt' => gmdate('Y-m-d H:i:s', time() - 10 * MINUTE_IN_SECONDS), 'comment_approved' => 1)); $comment_approved_minus_20 = wp_insert_comment(array('comment_post_ID' => $post_id_a, 'comment_author' => 'Some Guy', 'comment_author_email' => '*****@*****.**', 'comment_content' => 'This is my earlier comment text', 'user_id' => 1, 'comment_date' => gmdate('Y-m-d H:i:s', time() - 20 * MINUTE_IN_SECONDS + get_option('gmt_offset') * HOUR_IN_SECONDS), 'comment_date_gmt' => gmdate('Y-m-d H:i:s', time() - 20 * MINUTE_IN_SECONDS), 'comment_approved' => 1)); $comment_approved_no_user = wp_insert_comment(array('comment_post_ID' => $post_id_a, 'comment_author' => 'Some Guy 3', 'comment_author_email' => '*****@*****.**', 'comment_content' => 'This is another comment text', 'user_id' => 1, 'comment_date' => gmdate('Y-m-d H:i:s', time() - 20 * MINUTE_IN_SECONDS + get_option('gmt_offset') * HOUR_IN_SECONDS), 'comment_date_gmt' => gmdate('Y-m-d H:i:s', time() - 20 * MINUTE_IN_SECONDS), 'comment_approved' => 1)); $comment_pending_minus_20 = wp_insert_comment(array('comment_post_ID' => $post_id_a, 'comment_author' => 'Some Guy 2', 'comment_author_email' => '*****@*****.**', 'comment_content' => 'This is my pending comment text', 'user_id' => null, 'comment_date' => gmdate('Y-m-d H:i:s', time() - 20 * MINUTE_IN_SECONDS + get_option('gmt_offset') * HOUR_IN_SECONDS), 'comment_date_gmt' => gmdate('Y-m-d H:i:s', time() - 20 * MINUTE_IN_SECONDS), 'comment_approved' => 0)); $comment_approved_post_b = wp_insert_comment(array('comment_post_ID' => $post_id_b, 'comment_author' => 'Some Guy 2', 'comment_author_email' => '*****@*****.**', 'comment_content' => 'This is my pending comment text', 'user_id' => null, 'comment_date' => gmdate('Y-m-d H:i:s', time() - 20 * MINUTE_IN_SECONDS + get_option('gmt_offset') * HOUR_IN_SECONDS), 'comment_date_gmt' => gmdate('Y-m-d H:i:s', time() - 20 * MINUTE_IN_SECONDS), 'comment_approved' => 1)); return compact('post_id_a', 'post_id_b', 'comment_approved_minus_10', 'comment_approved_minus_20', 'comment_pending_minus_20', 'comment_approved_post_b'); }
/** * Extract the updates from $_POST and save in post meta. */ public function save_post_meta($post_id) { if (isset($_POST['add-bulk-comments'])) { $n = intval($_POST['add-bulk-comments']); $data = array('comment_post_ID' => $post_id, 'comment_author' => 'Bulk Comment', 'comment_content' => 'Content', 'comment_approved' => 1); for ($i = 0; $i < $n; $i += 1) { $data['comment_content'] = wp_generate_password(12, false); wp_insert_comment($data); } } }
/** * @param Rating $rating * * @return bool */ public function save_rating(Rating $rating) { // save rating $id = wp_insert_comment($rating->to_comment()); if ($id) { $rating->comment_ID = $id; add_comment_meta($id, '_wpkb_rating', $rating->rating, true); return true; } return false; }
/** * Generates a new comment. * * @since 1.0.0 * * @access protected * @param array $args The array of arguments to use during a new comment creation. * @return int|boolean The newly created comment's ID on success, otherwise FALSE. */ protected function _createObject($args) { $comment_id = wp_insert_comment($this->_addSlashesDeep($args)); if ($comment_id && !is_wp_error($comment_id)) { $this->_debug('Generated comment ID: ' . $comment_id); } elseif (is_wp_error($comment_id)) { $this->_debug('Comment generation failed with message [%s] %s', $comment_id->get_error_code(), $comment_id->get_error_messages()); } else { $this->_debug('Comment generation failed'); } return $comment_id; }
private static function add_new_comment($sp_message, $sp_users, $post_id) { $comment_created = false; $message = new SpotIM_Message('new', $sp_message, $sp_users, $post_id); if (!$message->is_comment_exists()) { $comment_id = wp_insert_comment($message->get_comment_data()); if ($comment_id) { $comment_created = $message->update_messages_map($comment_id); } } else { $comment_created = self::update_comment($sp_message, $sp_users, $post_id); } return !!$comment_created; }
function filter_handler($data) { global $wpdb; $sql = "SELECT * FROM {$wpdb->comments} WHERE comment_author_email = '{$data['comment_author_email']}' AND comment_author = '{$data['comment_author']}' AND comment_approved = 1"; $comment_list = $wpdb->get_results($sql, ARRAY_A); if ($data['comment_author_url'] != '' and empty($comment_list)) { $data['comment_approved'] = 'spam'; $data['comment_content'] = $data['comment_content'] . '.'; wp_insert_comment($data); wp_die(__('<strong>Sorry</strong>, You Are Not Permitted To Submit A Website Address In Blog Comments On Your Very First Comment In This Blog. Click Your Back Button, Delete The Website In The Website Field And Submit Your Comment For Approval.')); } else { return $data; } }
public function create($data) { $object = $data; if (is_array($data)) { $object = new $this->model_name($data, $this->meta_key, false); $object->type = $this->comment_type; } $object->id = wp_insert_comment($object->do_wp_object()); /** On insert ou on met à jour les meta */ if (!empty($object->option)) { $object->save_meta_data($object, 'update_comment_meta', $this->meta_key); } return $object; }
static function ajax_save() { if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], sprintf('%s-save', Kanban::$instance->settings->basename)) || !is_user_logged_in()) { wp_send_json_error(); } do_action(sprintf('%s_before_%s_ajax_save', Kanban::$instance->settings->basename, self::$slug)); $current_user_id = get_current_user_id(); $data = array('comment_type' => Kanban_Utils::format_key($_POST['post_type'], 'comment'), 'comment_author' => Kanban::$instance->settings->pretty_name, 'comment_post_ID' => $_POST['id'], 'comment_content' => sanitize_text_field(str_replace("\n", '', $_POST['comment_content'])), 'user_id' => $current_user_id, 'comment_approved' => 1); $comment_id = wp_insert_comment($data); // $comment_type = Kanban_Utils::format_key ($_POST['post_type'], 'comment'); // update_comment_meta( $comment_id, 'comment_type', $comment_type); do_action(sprintf('%s_after_%s_ajax_save', Kanban::$instance->settings->basename, self::$slug)); wp_send_json_success(array('message' => sprintf('%s saved', $comment_type))); }
/** * Project finished update * * @param int $post_id */ function orbis_project_invoice_number_update($post_id, $invoice_number_old, $invoice_number_new) { // Date update_post_meta($post_id, '_orbis_project_invoice_number_modified', time()); // Comment $user = wp_get_current_user(); $text = $invoice_number_new; $invoice_link = orbis_get_invoice_link($invoice_number_new); if (!empty($invoice_link)) { $text = sprintf('<a href="%s">%s</a>', esc_attr($invoice_link), $invoice_number_new); } $comment_content = sprintf(__("Invoice Number '%s' was registered on this project by %s.", 'orbis_finance'), $text, $user->display_name); $data = array('comment_post_ID' => $post_id, 'comment_content' => $comment_content, 'comment_author' => 'Orbis', 'comment_type' => 'orbis_comment'); $comment_id = wp_insert_comment($data); }
function add_comment_new_case_cp($post_ID, $post) { $user_ID = get_current_user_id(); //$post_ID = get_the_ID(); if ('cases' != get_post_type()) { return; } $comment_check = get_comments(array('post_id' => $post_ID, 'post_type' => 'cases', 'type' => 'event_case_added')); if (empty($comment_check)) { // создаем массив данных нового комментария $commentdata = array('comment_post_ID' => $post_ID, 'comment_author' => 'CasePress', 'comment_content' => 'Добавлено дело', 'comment_type' => 'event_case_added', 'user_ID' => $user_ID); // добавляем данные в Базу Данных wp_insert_comment($commentdata); } }
/** * Insert a new comment * * @param array $commentdata * @param array $files * @return int */ function create($commentdata, $files = array()) { $user = wp_get_current_user(); $commentdata['comment_author_IP'] = preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']); $commentdata['comment_agent'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 254); $commentdata['comment_author'] = $user->display_name; $commentdata['comment_author_email'] = $user->user_email; $comment_id = wp_insert_comment($commentdata); if ($comment_id) { add_comment_meta($comment_id, '_files', $files); $this->associate_file($files, $commentdata['comment_post_ID'], $_POST['project_id']); } do_action('cpm_comment_new', $comment_id, $_POST['project_id'], $commentdata); return $comment_id; }