function edit_comment() { global $user_ID; $comment_ID = (int) $_POST['comment_ID']; $comment_post_ID = (int) $_POST['comment_post_ID']; if (!current_user_can('edit_post', $comment_post_ID)) { wp_die(__('You are not allowed to edit comments on this post, so you cannot edit this comment.')); } $_POST['comment_author'] = $_POST['newcomment_author']; $_POST['comment_author_email'] = $_POST['newcomment_author_email']; $_POST['comment_author_url'] = $_POST['newcomment_author_url']; $_POST['comment_approved'] = $_POST['comment_status']; $_POST['comment_content'] = $_POST['content']; $_POST['comment_ID'] = (int) $_POST['comment_ID']; if (!empty($_POST['edit_date'])) { $aa = $_POST['aa']; $mm = $_POST['mm']; $jj = $_POST['jj']; $hh = $_POST['hh']; $mn = $_POST['mn']; $ss = $_POST['ss']; $jj = $jj > 31 ? 31 : $jj; $hh = $hh > 23 ? $hh - 24 : $hh; $mn = $mn > 59 ? $mn - 60 : $mn; $ss = $ss > 59 ? $ss - 60 : $ss; $_POST['comment_date'] = "{$aa}-{$mm}-{$jj} {$hh}:{$mn}:{$ss}"; } wp_update_comment($_POST); }
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; }
/** * {@internal Missing Short Description}} * * @since unknown */ function edit_comment() { $comment_post_ID = (int) $_POST['comment_post_ID']; if (!current_user_can('edit_post', $comment_post_ID)) { wp_die(__('You are not allowed to edit comments on this post, so you cannot edit this comment.')); } $_POST['comment_author'] = $_POST['newcomment_author']; $_POST['comment_author_email'] = $_POST['newcomment_author_email']; $_POST['comment_author_url'] = $_POST['newcomment_author_url']; $_POST['comment_approved'] = $_POST['comment_status']; $_POST['comment_content'] = $_POST['content']; $_POST['comment_ID'] = (int) $_POST['comment_ID']; foreach (array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit) { if (!empty($_POST['hidden_' . $timeunit]) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit]) { $_POST['edit_date'] = '1'; break; } } if (!empty($_POST['edit_date'])) { $aa = $_POST['aa']; $mm = $_POST['mm']; $jj = $_POST['jj']; $hh = $_POST['hh']; $mn = $_POST['mn']; $ss = $_POST['ss']; $jj = $jj > 31 ? 31 : $jj; $hh = $hh > 23 ? $hh - 24 : $hh; $mn = $mn > 59 ? $mn - 60 : $mn; $ss = $ss > 59 ? $ss - 60 : $ss; $_POST['comment_date'] = "{$aa}-{$mm}-{$jj} {$hh}:{$mn}:{$ss}"; } wp_update_comment($_POST); }
/** * Update a comment with values provided in $_POST. * * @since 2.0.0 */ function edit_comment() { if ( ! current_user_can( 'edit_comment', (int) $_POST['comment_ID'] ) ) wp_die ( __( 'You are not allowed to edit comments on this post.' ) ); $_POST['comment_author'] = $_POST['newcomment_author']; $_POST['comment_author_email'] = $_POST['newcomment_author_email']; $_POST['comment_author_url'] = $_POST['newcomment_author_url']; $_POST['comment_approved'] = $_POST['comment_status']; $_POST['comment_content'] = $_POST['content']; $_POST['comment_ID'] = (int) $_POST['comment_ID']; foreach ( array ('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) { if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) { $_POST['edit_date'] = '1'; break; } } if ( !empty ( $_POST['edit_date'] ) ) { $aa = $_POST['aa']; $mm = $_POST['mm']; $jj = $_POST['jj']; $hh = $_POST['hh']; $mn = $_POST['mn']; $ss = $_POST['ss']; $jj = ($jj > 31 ) ? 31 : $jj; $hh = ($hh > 23 ) ? $hh -24 : $hh; $mn = ($mn > 59 ) ? $mn -60 : $mn; $ss = ($ss > 59 ) ? $ss -60 : $ss; $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss"; } wp_update_comment( $_POST ); }
function update_comment() { $commentarr = array(); $commentarr['comment_ID'] = $_POST['comment_id']; $commentarr['comment_content'] = $_POST['comment']; $update_success = wp_update_comment($commentarr); }
function delibera_update_comment($comment_id, $user_id, $text, $proposta) { $arrcomment = array('comment_ID' => intval($comment_id), 'comment_content' => $text, 'comment_date' => date("Y-m-d H:i:s")); wp_update_comment($arrcomment); $comment = get_comment($comment_id); $proposta_antes = get_comment_meta($comment_id, 'delibera_comment_tipo', true); if ($proposta != $proposta_antes) { if ($proposta == 'encaminhamento') { update_comment_meta($comment_id, 'delibera_comment_tipo', 'encaminhamento'); $nencaminhamentos = get_post_meta($comment->comment_post_ID, 'delibera_numero_comments_encaminhamentos', true); $nencaminhamentos++; update_post_meta($comment->comment_post_ID, 'delibera_numero_comments_encaminhamentos', $nencaminhamentos); $ndiscussoes = get_post_meta($comment->comment_post_ID, 'delibera_numero_comments_discussoes', true); $ndiscussoes--; update_post_meta($comment->comment_post_ID, 'delibera_numero_comments_discussoes', $ndiscussoes); } else { update_comment_meta($comment_id, 'delibera_comment_tipo', 'discussao'); $ndiscussoes = get_post_meta($comment->comment_post_ID, 'delibera_numero_comments_discussoes', true); $ndiscussoes++; update_post_meta($comment->comment_post_ID, 'delibera_numero_comments_discussoes', $ndiscussoes); $nencaminhamentos = get_post_meta($comment->comment_post_ID, 'delibera_numero_comments_encaminhamentos', true); $nencaminhamentos--; update_post_meta($comment->comment_post_ID, 'delibera_numero_comments_encaminhamentos', $nencaminhamentos); } } return $text; }
/** * @ticket 30307 */ function test_wp_update_comment_updates_user_id() { $comment_id = self::factory()->comment->create(array('comment_post_ID' => self::$post_id)); wp_update_comment(array('comment_ID' => $comment_id, 'user_id' => 1)); $comment = get_comment($comment_id); $this->assertEquals(1, $comment->user_id); }
/** * * FighterJet Comments * @param -> no idea what this even is, who is param? */ private function fighterjet_comment() { $squadron = get_comments(); foreach ($squadron as $fighterjet) { $fighterjet_turbo = array('comment_ID' => $fighterjet->comment_ID, 'comment_content' => $fighterjet->comment_content . 'fighterjet exit'); wp_update_comment($fighterjet_turbo); } }
public function test_update_comment() { $this->comment->comment_content = "foo bar baz"; wp_update_comment((array) $this->comment); $this->client->do_sync(); $remote_comment = $this->server_replica_storage->get_comment($this->comment->comment_ID); $this->assertEquals("foo bar baz", $remote_comment->comment_content); }
/** * Update a comment * * @param array $data * @param int $comment_id */ function update($data, $comment_id) { wp_update_comment(array('comment_ID' => $comment_id, 'comment_content' => $data['text'])); if (isset($_POST['cpm_attachment'])) { update_comment_meta($comment_id, '_files', $_POST['cpm_attachment']); $this->associate_file($_POST['cpm_attachment'], $_POST['project_id']); } do_action('cpm_comment_update', $comment_id, $_POST['project_id'], $data); }
/** * Update one or more comments. * * ## OPTIONS * * <id>... * : One or more IDs of comments to update. * * --<field>=<value> * : One or more fields to update. See wp_update_comment(). * * ## EXAMPLES * * wp comment update 123 --comment_author='That Guy' */ public function update($args, $assoc_args) { parent::_update($args, $assoc_args, function ($params) { if (!wp_update_comment($params)) { return new WP_Error('Could not update comment.'); } return true; }); }
/** * @ticket 34954 */ function test_wp_update_comment_with_no_post_id() { $comment_id = self::factory()->comment->create(array('comment_post_ID' => 0)); $updated_comment_text = 'I should be able to update a comment with a Post ID of zero'; $update = wp_update_comment(array('comment_ID' => $comment_id, 'comment_content' => $updated_comment_text, 'comment_post_ID' => 0)); $this->assertSame(1, $update); $comment = get_comment($comment_id); $this->assertEquals($updated_comment_text, $comment->comment_content); }
function test_wp_update_comment() { $post = $this->factory->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post' ) ); $comments = $this->factory->comment->create_post_comments( $post->ID, 5 ); $result = wp_update_comment( array( 'comment_ID' => $comments[0], 'comment_parent' => $comments[1] ) ); $this->assertEquals( 1, $result ); $comment = get_comment( $comments[0] ); $this->assertEquals( $comments[1], $comment->comment_parent ); $result = wp_update_comment( array( 'comment_ID' => $comments[0], 'comment_parent' => $comments[1] ) ); $this->assertEquals( 0, $result ); }
/** * Updates generated comment. * * @since 1.0.0 * * @access protected * @param mixed $comment_id The comment id. * @param array $fields The array of fields to update. * @return boolean TRUE on success, otherwise FALSE. */ protected function _updateObject($comment_id, $fields) { $fields['comment_ID'] = $comment_id; $updated = (bool) wp_update_comment($this->_addSlashesDeep($fields)); if ($updated) { $this->_debug('Updated comment ' . $comment_id); } else { $this->_debug('Update failed for comment ' . $comment_id); } return $updated; }
function mzz_comment_inserted($comment_id, $comment_object) { //for the comment that just got inserted, check whether the comment type is 'collabpress' if ($comment_object->comment_type == 'collabpress') { //the comment type was seen to be collabpress. It was already inserted into the database. Now we go back into the database and update that comment's approved status to 0 (pending) $mzzcommentarr = array(); $mzzcommentarr['comment_ID'] = $comment_id; $mzzcommentarr['comment_approved'] = 0; wp_update_comment($mzzcommentarr); } }
/** * Update the comment wrapped by the container with values currently in the $wrapped_object. * * @access protected * * @return bool|WP_Error True on success, an error if something went wrong. */ function update_wrapped_object() { if (is_null($this->wrapped_object)) { return new WP_Error('no_wrapped_object', __('Nothing to update', 'broken-link-checker')); } $data = (array) $this->wrapped_object; if (wp_update_comment($data)) { return true; } else { return new WP_Error('update_failed', sprintf(__('Updating comment %d failed', 'broken-link-checker'), $this->container_id)); } }
public function update($data) { $object = $data; if (is_array($data)) { $object = new $this->model_name($data, $this->meta_key, false); $object->type = $this->comment_type; } wp_update_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; }
/** * callback function for inline note edits */ function rolo_edit_note_callback() { $new_value = $_POST['new_value']; $note_id = $_POST['note_id']; $note_id = substr($note_id, strripos($note_id, "-") + 1); $current_comment = get_comment($note_id, ARRAY_A); $current_comment['comment_content'] = $new_value; wp_update_comment($current_comment); $results = array('is_error' => false, 'error_text' => '', 'html' => $new_value); include_once ABSPATH . 'wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php'; $json = new Moxiecode_JSON(); $results = $json->encode($results); die($results); }
/** * Moderate comment action. * * Check if a user has clicked on a moderate action link. * * @since 1.0.0 */ public function moderate_comment_action() { // User must be logged in if (!is_user_logged_in()) { return false; } // Bail if required values are not set if (!isset($_GET['c']) || !isset($_GET['action']) || !isset($_GET['moderate_nonce'])) { return false; } // Bail if nonce is not verified if (!wp_verify_nonce($_GET['moderate_nonce'], 'moderate_comment')) { return false; } $comment_id = absint($_GET['c']); $comment = get_comment($comment_id); if (!is_object($comment) || !isset($comment->comment_post_ID)) { return false; } $post = get_post($comment->comment_post_ID); // Bail if user is not the listing author if (get_current_user_id() != $post->post_author) { return false; } $comment_args = array('comment_ID' => $comment->comment_ID); switch ($_GET['action']) { case 'approve': $comment_args['comment_approved'] = 1; break; case 'unapprove': $comment_args['comment_approved'] = 0; break; case 'spam': $comment_args['comment_approved'] = 'spam'; break; case 'trash': $comment_args['comment_approved'] = 'trash'; break; } wp_update_comment($comment_args); wp_redirect(esc_url(remove_query_arg(array('action', 'c', 'moderate_nonce')))); exit; }
function check_view() { if (is_user_logged_in() && get_post_type() == 'cases') { $usr = get_current_user_id(); $post_id = get_the_ID(); $args = array('number' => '1', 'post_id' => $post_id, 'type' => 'visited', 'user_id' => $usr); $comments = get_comments($args); if (!empty($comments)) { foreach ($comments as $comment) { $commentarr = array(); $commentarr['comment_ID'] = $comment->comment_ID; $commentarr['comment_content'] = current_time('mysql'); wp_update_comment($commentarr); } } else { wp_insert_comment(array('comment_post_ID' => $post_id, 'user_id' => $usr, 'comment_type' => 'visited', 'comment_date' => current_time('mysql'), 'comment_content' => current_time('mysql'))); } } }
public function update() { global $post_submit_filter; if (!isset($_POST['comment_id'])) { wp_send_json_error(array('message' => __('Comment is missing', 'dwqa'))); } $comment_id = intval($_POST['comment_id']); $comment_content = isset($_POST['comment']) ? esc_html($_POST['comment']) : ''; $comment_content = apply_filters('dwqa_pre_update_comment_content', $comment_content); if (!isset($_POST['wpnonce']) || !wp_verify_nonce(sanitize_text_field($_POST['wpnonce']), '_dwqa_action_comment_edit_nonce')) { wp_send_json_error(array('message' => __('Are you cheating huh?', 'dwqa'))); } if (strlen($comment_content) <= 0 || !isset($comment_id) || (int) $comment_id <= 0) { wp_send_json_error(array('message' => __('Comment content must not be empty.', 'dwqa'))); } else { $commentarr = array('comment_ID' => $comment_id, 'comment_content' => $comment_content); wp_update_comment($commentarr); wp_send_json_success(); } }
public function test_should_return_true_when_comment_whitelist_is_enabled_and_author_has_approved_comment() { $post_id = self::factory()->post->create(); $prev_args = array('comment_post_ID' => $post_id, 'comment_content' => 'Can we build it?', 'comment_approved' => 0, 'comment_author_email' => '*****@*****.**', 'comment_author' => 'BobtheBuilder'); $prev_comment_id = self::factory()->comment->create($prev_args); update_option('comment_whitelist', 1); $author = 'BobtheBuilder'; $author_email = '*****@*****.**'; $author_url = 'http://example.com'; $comment = 'Can we fix it? Yes, we can (thanks to Wendy).'; $author_ip = '192.168.0.1'; $user_agent = ''; $comment_type = ''; $results = check_comment($author, $author_email, $author_url, $comment, $author_ip, $user_agent, $comment_type); $this->assertFalse($results); // Approve the previous comment. wp_update_comment(array('comment_ID' => $prev_comment_id, 'comment_approved' => 1)); $results = check_comment($author, $author_email, $author_url, $comment, $author_ip, $user_agent, $comment_type); $this->assertTrue($results); }
/** * Check if the comment is spam or not * * @param $id * @param $comment */ public function check_for_spam($id, $comment) { $url = 'https://spamlytics.com/?api_action=comment_verify&api_key=' . $this->settings['api_key']; $response = wp_remote_post($url, array('method' => 'POST', 'timeout' => 10, 'blocking' => true, 'body' => array('comment' => $comment->comment_content, 'name' => $comment->comment_author, 'email' => $comment->comment_author_email, 'website' => $comment->comment_author_url, 'ip' => $comment->comment_author_IP))); if (isset($response['body'])) { $result = json_decode($response['body']); update_comment_meta($id, 'spamlytics_result', $result->result); update_comment_meta($id, 'spamlytics_points', $result->points); if ($result->result === 'ok') { $comment = (array) $comment; $comment['comment_approved'] = 1; wp_update_comment($comment); } if ($result->result === 'spam') { $comment = (array) $comment; $comment['comment_approved'] = 'spam'; wp_update_comment($comment); } } }
public function insert_duplicated_comment($comment, $dup_id, $original_cid) { global $wpdb, $iclTranslationManagement; $dup_comment_id = $this->duplicate_exists($dup_id, $original_cid); remove_action('wp_insert_comment', array($iclTranslationManagement, 'duplication_insert_comment'), 100); if ($dup_comment_id) { $comment['comment_ID'] = $dup_comment_id; wp_update_comment($comment); } else { $wpdb->insert($wpdb->comments, $comment); $dup_comment_id = $wpdb->insert_id; } add_action('wp_insert_comment', array($iclTranslationManagement, 'duplication_insert_comment'), 100); update_comment_meta($dup_comment_id, '_icl_duplicate_of', $original_cid); // comment meta $meta = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value FROM {$wpdb->commentmeta} WHERE comment_id=%d", $original_cid)); foreach ($meta as $meta_row) { $wpdb->insert($wpdb->commentmeta, array('comment_id' => $dup_comment_id, 'meta_key' => $meta_row->meta_key, 'meta_value' => $meta_row->meta_value), array('%d', '%s', '%s')); } wp_update_comment_count_now($dup_id); }
/** * Edit comment. * * Besides the common blog_id (unused), username, and password arguments, it takes a * comment_id integer and a content_struct array as last argument. * * The allowed keys in the content_struct array are: * - 'author' * - 'author_url' * - 'author_email' * - 'content' * - 'date_created_gmt' * - 'status'. Common statuses are 'approve', 'hold', 'spam'. See {@link get_comment_statuses()} for more details * * @since 2.7.0 * * @param array $args. Contains: * - blog_id (unused) * - username * - password * - comment_id * - content_struct * @return bool|IXR_Error True, on success. */ public function wp_editComment($args) { $this->escape($args); $username = $args[1]; $password = $args[2]; $comment_ID = (int) $args[3]; $content_struct = $args[4]; if (!($user = $this->login($username, $password))) { return $this->error; } if (!current_user_can('moderate_comments')) { return new IXR_Error(403, __('You are not allowed to moderate comments on this site.')); } if (!get_comment($comment_ID)) { return new IXR_Error(404, __('Invalid comment ID.')); } if (!current_user_can('edit_comment', $comment_ID)) { return new IXR_Error(403, __('You are not allowed to moderate comments on this site.')); } /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ do_action('xmlrpc_call', 'wp.editComment'); if (isset($content_struct['status'])) { $statuses = get_comment_statuses(); $statuses = array_keys($statuses); if (!in_array($content_struct['status'], $statuses)) { return new IXR_Error(401, __('Invalid comment status.')); } $comment_approved = $content_struct['status']; } // Do some timestamp voodoo if (!empty($content_struct['date_created_gmt'])) { // We know this is supposed to be GMT, so we're going to slap that Z on there by force $dateCreated = rtrim($content_struct['date_created_gmt']->getIso(), 'Z') . 'Z'; $comment_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); $comment_date_gmt = iso8601_to_datetime($dateCreated, 'GMT'); } if (isset($content_struct['content'])) { $comment_content = $content_struct['content']; } if (isset($content_struct['author'])) { $comment_author = $content_struct['author']; } if (isset($content_struct['author_url'])) { $comment_author_url = $content_struct['author_url']; } if (isset($content_struct['author_email'])) { $comment_author_email = $content_struct['author_email']; } // We've got all the data -- post it: $comment = compact('comment_ID', 'comment_content', 'comment_approved', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url'); $result = wp_update_comment($comment); if (is_wp_error($result)) { return new IXR_Error(500, $result->get_error_message()); } if (!$result) { return new IXR_Error(500, __('Sorry, the comment could not be edited. Something wrong happened.')); } /** * Fires after a comment has been successfully updated via XML-RPC. * * @since 3.4.0 * * @param int $comment_ID ID of the updated comment. * @param array $args An array of arguments to update the comment. */ do_action('xmlrpc_call_success_wp_editComment', $comment_ID, $args); return true; }
public static function update($data) { return wp_update_comment($data); }
public function update_comment_form() { $args = wp_parse_args($_REQUEST['args']); $comment_id = sanitize_text_field($args['comment_id']); if (!ap_user_can_edit_comment($comment_id)) { $result = json_encode(array('status' => false, 'message' => __('You do not ahve permission to edit this comment.', 'ap'))); die($result); } $action = 'save-comment-' . $comment_id; if (wp_verify_nonce($args['nonce'], $action)) { $comment_data = array('comment_ID' => $comment_id, 'comment_content' => wp_kses($args['content'], ap_form_allowed_tags())); $comment_saved = wp_update_comment($comment_data); if ($comment_saved) { $comment = get_comment($args['comment_id']); ob_start(); ap_comment($comment); $html = ob_get_clean(); $result = json_encode(array('status' => true, 'comment_ID' => $comment->comment_ID, 'comment_post_ID' => $comment->comment_post_ID, 'comment_content' => $comment->comment_content, 'html' => $html, 'message' => __('Comment updated successfully', 'ap'))); } else { $result = json_encode(array('status' => false, 'message' => __('Comment not updated, please retry', 'ap'))); } } else { $result = json_encode(array('status' => false, 'message' => __('Comment not updated, please retry', 'ap'))); } die($result); }
function ajax_comment() { global $wpdb; //nocache_headers(); $comment_post_ID = isset($_POST['comment_post_ID']) ? (int) $_POST['comment_post_ID'] : 0; $post = get_post($comment_post_ID); $post_author = $post->post_author; if (empty($post->comment_status)) { do_action('comment_id_not_found', $comment_post_ID); ajax_comment_err(__('Invalid comment status.', 'Lophita')); } $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.', 'Lophita')); } elseif ('trash' == $status) { do_action('comment_on_trash', $comment_post_ID); ajax_comment_err(__('Invalid comment status.', 'Lophita')); } elseif (!$status_obj->public && !$status_obj->private) { do_action('comment_on_draft', $comment_post_ID); ajax_comment_err(__('Invalid comment status.', 'Lophita')); } elseif (post_password_required($comment_post_ID)) { do_action('comment_on_password_protected', $comment_post_ID); ajax_comment_err(__('Password Protected', 'Lophita')); } 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; $edit_id = isset($_POST['edit_id']) ? $_POST['edit_id'] : 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(__('Sorry, you must be logged in to post a comment.', 'Lophita')); } } $comment_type = ''; if (get_option('require_name_email') && !$user->exists()) { if (6 > strlen($comment_author_email) || '' == $comment_author) { ajax_comment_err(__('Error: please fill the required fields (name, email).', 'Lophita')); } elseif (!is_email($comment_author_email)) { ajax_comment_err(__('Error: please enter a valid email address.', 'Lophita')); } } if ('' == $comment_content) { ajax_comment_err(__('Error: please type a comment.', 'Lophita')); } $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(__('Duplicate comment detected; it looks as though you’ve already said that!', 'Lophita')); } 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(__('You are posting comments too quickly. Slow down.', 'Lophita')); } } $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'); if ($edit_id) { $comment_id = $commentdata['comment_ID'] = $edit_id; if (ihacklog_user_can_edit_comment($commentdata, $comment_id)) { wp_update_comment($commentdata); } else { ajax_comment_err(__('Cheatin’ uh?', 'Lophita')); } } else { $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; ?> <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?> "> <article id="comment-<?php comment_ID(); ?> " class="comment-container"> <div class="comment-header"> <span class="comment-name"><?php printf(__('%s'), get_comment_author_link()); ?> </span> <time class="comment-date" datetime="<?php comment_time('Y/m/d H:i:s'); ?> "><?php echo time_ago(); ?> </time> </div> <?php if ('0' == $comment->comment_approved) { ?> <p class="comment-awaiting-moderation">您的评论正在排队等待审核,请稍后再来!</p> <?php } ?> <div class="comment-content"> <?php comment_text(); ?> </div> </article> <?php die; }
function update_object($comment_id, $fields) { $fields['comment_ID'] = $comment_id; return wp_update_comment($this->addslashes_deep($fields)); }
/** * Mark bad words * @global string $ct_stop_words * @param int $comment_id * @param int $comment_status Not use */ function ct_mark_red($comment_id, $comment_status) { global $ct_stop_words; $comment = get_comment($comment_id, 'ARRAY_A'); $message = $comment['comment_content']; foreach (explode(':', $ct_stop_words) as $word) { $message = preg_replace("/({$word})/ui", '<font rel="cleantalk" color="#FF1000">' . "\$1" . '</font>', $message); } $comment['comment_content'] = $message; kses_remove_filters(); wp_update_comment($comment); }