/** * Use this method to prevent excluding something that was not configured by FakerPress * * @param array|int|\WP_Comment $comment The ID for the Post or the Object * @return bool */ public static function delete($comment) { if (is_array($comment)) { $deleted = array(); foreach ($comment as $id) { $id = $id instanceof \WP_Comment ? $id->comment_ID : $id; if (!is_numeric($id)) { continue; } $deleted[$id] = self::delete($id); } return $deleted; } if (is_numeric($comment)) { $comment = \WP_Comment::get_instance($comment); } if (!$comment instanceof \WP_Comment) { return false; } $flag = (bool) get_comment_meta($comment->comment_ID, self::$flag, true); if (true !== $flag) { return false; } return wp_delete_comment($comment->comment_ID, true); }
public function delete_comment() { $args = $args = explode('-', sanitize_text_field($_REQUEST['args'])); if (!ap_user_can_delete_comment($args[0])) { $result = array('status' => false, 'message' => __('You do not have permission to delete this comment', 'ap')); die(json_encode($result)); } $action = 'delete-comment-' . $args[0]; if (wp_verify_nonce($args[1], $action)) { $comment = get_comment($args[0]); $delete = wp_delete_comment($args[0], true); if ($delete) { $post_type = get_post_type($comment->comment_post_ID); do_action('ap_after_delete_comment', $comment, $post_type); if ($post_type == 'question') { ap_do_event('delete_comment', $comment, 'question'); } elseif ($post_type == 'answer') { ap_do_event('delete_comment', $comment, 'answer'); } } $result = array('status' => true, 'message' => __('Comment deleted successfully', 'ap')); die(json_encode($result)); } die; }
function rotary_set_default_pages() { wp_delete_post(1); //delete sample post wp_delete_comment(1); //delete sample comment wp_delete_post(2); //delete sample page if (!get_page_by_title('Member Information')) { $args = array('post_name' => 'member-information', 'post_title' => 'Member Information', 'post_type' => 'page', 'post_status' => 'publish'); wp_insert_post($args); } if (!get_page_by_title('About')) { $args = array('post_name' => 'about', 'post_title' => 'About', 'post_type' => 'page', 'post_status' => 'publish'); wp_insert_post($args); } if (!get_page_by_title('Home')) { $args = array('post_name' => 'home', 'post_title' => 'Home', 'post_type' => 'page', 'post_status' => 'publish'); wp_insert_post($args); } if (!get_page_by_title('Posts')) { $args = array('post_name' => 'posts', 'post_title' => 'Posts', 'post_type' => 'page', 'post_status' => 'publish'); wp_insert_post($args); } }
function bp_groupblog_blog_defaults($blog_id) { global $bp, $wp_rewrite; // only apply defaults to groupblog blogs if (bp_is_groups_component()) { switch_to_blog($blog_id); // get the site options $options = get_site_option('bp_groupblog_blog_defaults_options'); foreach ((array) $options as $key => $value) { update_option($key, $value); } // override default themes if (!empty($options['theme'])) { // we want something other than the default theme $values = explode("|", $options['theme']); switch_theme($values[0], $values[1]); } // groupblog bonus options if (strlen($options['default_cat_name']) > 0) { global $wpdb; $cat = $options['default_cat_name']; $slug = str_replace(' ', '-', strtolower($cat)); $results = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->terms} SET name = %s, slug = %s WHERE term_id = 1", $cat, $slug)); } if (strlen($options['default_link_cat']) > 0) { global $wpdb; $cat = $options['default_link_cat']; $slug = str_replace(' ', '-', strtolower($cat)); $results = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->terms} SET name = %s, slug = %s WHERE term_id = 2", $cat, $slug)); } if (isset($options['delete_first_post']) && $options['delete_first_post'] == 1) { global $wpdb; $statement = "UPDATE {$wpdb->posts} SET post_status = 'draft' WHERE id = 1"; $results = $wpdb->query($statement); } if (isset($options['delete_first_comment']) && $options['delete_first_comment'] == 1) { wp_delete_comment(1); } if ($options['delete_blogroll_links'] == 1) { wp_delete_link(1); //delete Wordpress.com blogroll link wp_delete_link(2); //delete Wordpress.org blogroll link } if ($options['redirectblog'] == 2) { $blog_page = array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_status' => 'publish', 'post_name' => $options['pageslug'], 'post_title' => $options['pagetitle'], 'post_type' => 'page', 'post_content' => __('<p><strong>This page has been created automatically by the BuddyPress GroupBlog plugin.</strong></p><p>Please contact the site admin if you see this message instead of your blog posts. Possible solution: please advise your site admin to create the <a href="http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates">page template</a> needed for the BuddyPress GroupBlog plugin.<p>', 'groupblog')); $blog_page_id = wp_insert_post($blog_page); if ($blog_page_id) { add_post_meta($blog_page_id, '_wp_page_template', 'blog.php'); } add_post_meta($blog_page_id, 'created_by_groupblog_dont_change', '1'); // Set the Blog Reading Settings to load the template page as front page if ($options['deep_group_integration'] == 1) { update_option('show_on_front', 'page'); update_option('page_on_front', $blog_page_id); } } restore_current_blog(); } }
public static function wpTearDownAfterClass() { foreach (self::$comments as $c) { wp_delete_comment($c, true); } wp_delete_post(self::$p, true); }
/** * Delete the comment corresponding to this container. * This will actually move the comment to the trash in newer versions of WP. * * @return bool|WP_error */ function delete_wrapped_object() { if (wp_delete_comment($this->container_id)) { return true; } else { return new WP_Error('delete_failed', sprintf(__('Failed to delete comment %d', 'broken-link-checker'), $this->container_id)); } }
function delete_comment_sync($activity_id, $comment_id) { global $wpdb; $comment_id = $wpdb->get_var($wpdb->prepare("select comment_id from {$wpdb->commentmeta} where meta_key = 'activity_id' and meta_value=%s", $comment_id)); if ($comment_id) { wp_delete_comment($comment_id, true); } }
public static function wpTearDownAfterClass() { foreach (self::$comment_ids as $comment_id) { wp_delete_comment($comment_id, true); } wp_delete_post(self::$comment_post->ID, true); wp_delete_post(self::$draft_post->ID, true); }
public function test_delete_comment_deletes_data() { $this->assertEquals(1, $this->server_replica_storage->comment_count('approve')); wp_delete_comment($this->comment->comment_ID, true); $this->client->do_sync(); // there should be no comments at all $this->assertEquals(0, $this->server_replica_storage->comment_count('approve')); }
/** * Delete a comment. * * @synopsis <id> [--force] */ public function delete($args, $assoc_args) { list($comment_id) = $args; if (wp_delete_comment($comment_id, isset($assoc_args['force']))) { WP_CLI::success("Deleted comment {$comment_id}."); } else { WP_CLI::error("Failed deleting comment {$comment_id}"); } }
/** * Set default options */ function set_defaults() { // Update options to wpdp foreach ($this->default_options as $name => $value) { update_option($name, $value); } // Delete default post & comment wp_delete_post(1, true); wp_delete_comment(1); }
/** * Delete a comment * * Example: wp comment delete 15 --force * * @param array $args} * @param array $assoc_args */ public function delete($args, $assoc_args) { $comment_id = WP_CLI::get_numeric_arg($args, 0, "Comment ID"); // Boolean $force parameter to bypass trash and really delete $force = isset($assoc_args['force']) ? true : false; if (wp_delete_comment($comment_id, $force)) { WP_CLI::success("Deleted comment {$comment_id}."); } else { WP_CLI::error("Failed deleting comment {$comment_id}"); } }
function ecs_delete_comment() { $return_val = 'false'; if (is_numeric($_POST['comment_id'])) { $delete_comment = wp_delete_comment($_POST['comment_id'], true); if ($delete_comment) { $return_val = 'true'; } } echo $return_val; die; }
/** * Delete a comment * * @param int $comment_id * @param bool $force_delete */ function delete($comment_id, $force_delete = false) { do_action('cpm_comment_delete', $comment_id, $force_delete); //delete any file attached to it $files = get_comment_meta($comment_id, '_files', true); if ($files) { foreach ($files as $file_id) { $this->delete_file($file_id); } } //now delete the comment wp_delete_comment($comment_id, $force_delete); }
/** * Add query string to the comment redirect location * * @param $location string location to redirect to after comment * @param $comment object comment object * * @return string */ public static function redirect_fail_captcha_comment($location, $comment) { if (!empty(self::$captcha_error)) { // delete the failed captcha comment wp_delete_comment(absint($comment->comment_ID)); // add failed query string for @parent::display_captcha to display error message $location = add_query_arg('captcha', 'failed', $location); // remove the obnoxious comment string i.e comment-15 $deleted_comment_id = strstr($location, '#'); $location = str_replace($deleted_comment_id, '#comments', $location); } return $location; }
public function delete_comment() { if (!isset($_GET['_wpnonce']) || !wp_verify_nonce(sanitize_text_field($_GET['_wpnonce']), '_dwqa_delete_comment')) { wp_die(__('Are you cheating huh?', 'dwqa')); } if (!dwqa_current_user_can('delete_comment')) { wp_die(__('You do not have permission to edit comment.', 'dwqa')); } if (!isset($_GET['comment_id'])) { wp_die(__('Comment ID must be showed.', 'dwqa')); } wp_delete_comment(intval($_GET['comment_id'])); $comment = get_comment($_GET['comment_id']); exit(wp_safe_redirect(dwqa_get_question_link($comment->comment_post_ID))); }
function rotary_delete_announcement() { $comment_id = $_REQUEST['comment_id']; //check again if I can delete this comment $user_can_delete = current_user_can('delete_others_announcements') || get_current_user_id() == $announcement->user_id || current_user_can('manage_options'); if (!$user_can_delete) { $error = array('error' => 'You do not have permission to delete this announcment!'); echo json_encode($error); die; } if (wp_delete_comment($comment_id)) { echo json_encode(array('success' => 'Comment ' . $_REQUEST['comment_id'] . ' deleted')); die; } else { echo json_encode(array('error' => 'Comment ' . $_REQUEST['comment_id'] . ' could not be deleted')); die; } }
/** * Clean up shared fixtures. * * @since 4.1.0 */ public static function delete_shared_fixtures() { self::delete_user(self::$author_id); foreach (self::$post_ids as $pid) { wp_delete_post($pid, true); } foreach (self::$comment_ids as $cid) { wp_delete_comment($cid, true); } foreach (self::$term_ids as $tid => $tax) { wp_delete_term($tid, $tax); } self::$author_id = null; self::$post_ids = array(); self::$comment_ids = array(); self::$term_ids = array(); self::$terms = array(); }
public function kkb_comment_delete($cid, $inputpwd) { $comment = get_comment($cid); $entry_id = $comment->comment_post_ID; $controller = new kkbController(); $post_id = $controller->getMeta($entry_id, 'guid'); $board_id = $controller->getMeta($entry_id, 'board_id'); if (is_user_logged_in()) { $user = wp_get_current_user(); if ($controller->actionCommentPermission($board_id, $cid, 'delete') == true) { $status = wp_delete_comment($cid); if (!is_wp_error($status)) { $result['status'] = 'success'; } else { $result['status'] = 'failed'; $result['message'] = __('삭제에 문제가 발생하였습니다.', 'kingkongboard'); } } else { $result['status'] = 'failed'; $result['message'] = __('본인 댓글이 아닙니다.', 'kingkongboard'); } } else { if (!is_user_logged_in() && $inputpwd != null) { $pwd = get_comment_meta($cid, 'kkb_comment_password', true); if ($controller->actionCommentPermission($board_id, $cid, 'delete') == true && $pwd == md5($inputpwd)) { $status = wp_delete_comment($cid); if (!is_wp_error($status)) { $result['status'] = 'success'; $result['url'] = add_query_arg(array('view' => 'read', 'id' => $entry_id), get_the_permalink($post_id)); } else { $result['status'] = 'failed'; $result['message'] = __('삭제에 문제가 발생하였습니다.', 'kingkongboard'); } } else { $result['status'] = 'failed'; $result['message'] = __('비밀번호가 일치하지 않습니다.', 'kingkongboard'); } } else { $result['status'] = 'check'; $result['url'] = add_query_arg(array('view' => 'cmtcheck', 'cid' => $cid, 'id' => $comment->comment_post_ID, 'mod' => 'delete'), get_the_permalink($post_id)); } } return $result; }
function ing_theme_setup() { // First we check to see if our default theme settings have been applied. $the_theme_status = get_option('theme_setup_status'); // If the theme has not yet been used we want to run our default settings. if ($the_theme_status !== '1') { // Delete dummy post, page and comment. wp_delete_post(1, true); wp_delete_post(2, true); wp_delete_comment(1); // Create pages $home_page = array('post_title' => 'Home', 'post_content' => 'Home Page Content.', 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'page'); $blog_page = array('post_title' => 'Blog', 'post_content' => '', 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'page'); $about_page = array('post_title' => 'About us', 'post_content' => 'Home Page Content.', 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'page'); // Insert the pages into the database $home = wp_insert_post($home_page); $blog = wp_insert_post($blog_page); $about = wp_insert_post($about_page); // Setup Default WordPress settings $core_settings = array('avatar_default' => 'mystery', 'avatar_rating' => 'G', 'default_role' => 'subscriber', 'show_on_front' => 'page', 'page_on_front' => $home, 'page_for_posts' => $blog); foreach ($core_settings as $k => $v) { update_option($k, $v); } ////////////////////////////////////////////////////////////////////// ////////////////////// WRAP UP // Once done, we register our setting to make sure we don't duplicate everytime we activate. update_option('theme_setup_status', '1'); // Lets let the admin know whats going on. $msg = ' <div class="error"> <p>The ' . get_option('current_theme') . 'theme has changed your WordPress default <a href="' . admin_url('options-general.php') . '" title="See Settings">settings</a> and deleted default posts & comments.</p> </div>'; add_action('admin_notices', $c = create_function('', 'echo "' . addcslashes($msg, '"') . '";')); } elseif ($the_theme_status === '1' and isset($_GET['activated'])) { $msg = ' <div class="updated"> <p>The ' . get_option('current_theme') . ' theme was successfully re-activated.</p> </div>'; add_action('admin_notices', $c = create_function('', 'echo "' . addcslashes($msg, '"') . '";')); } }
function kt_delete_comment_callback() { check_ajax_referer('_kt_ajax_check_nonce', 'nonce_field', TRUE); if (isset($_GET['post'])) { $comment_id = sanitize_text_field($_GET['post']); $user_id = get_current_user_id(); $comment = get_comment($comment_id); if ($comment->user_id == $user_id) { if (wp_delete_comment($comment_id)) { $result = 'deleted'; } else { $result = 'delete goes wrong'; } } else { $result = 'User do not match'; } echo $result; } wp_die(); // this is required to terminate immediately and return a proper response }
function wpse_set_defaults($blog_id) { global $json_api; switch_to_blog($blog_id); $id = 'json_api_controllers'; $required_controllers = explode(",", "categories,posts,user,projects,attachments"); $available_controllers = $json_api->get_controllers(); $active_controllers = explode(',', get_option($id, 'core')); $action = "activate"; foreach ($required_controllers as $controller) { if (in_array($controller, $available_controllers)) { if ($action == 'activate' && !in_array($controller, $active_controllers)) { $active_controllers[] = $controller; } else { if ($action == 'deactivate') { $index = array_search($controller, $active_controllers); if ($index !== false) { unset($active_controllers[$index]); } } } } } $value = implode(',', $active_controllers); $option_exists = get_option($id, null) !== null; if ($option_exists) { update_option($id, $value); } else { add_option($id, $value); } // Remove the default post & page wp_delete_post(1, true); wp_delete_post(2, true); // Remove the first comment wp_delete_comment(1, true); // add default categories wp_create_category("Project"); wp_create_category("Document"); restore_current_blog(); }
private static function delete_comment($sp_message, $sp_users, $post_id) { $comment_deleted = false; $message_deleted_from_map = false; $message = new SpotIM_Message('delete', $sp_message, $sp_users, $post_id); if ($message->get_comment_id()) { $messages_ids = $message->get_message_and_children_ids_map(); foreach ($messages_ids as $message_id => $comment_id) { $comment_deleted = wp_delete_comment($comment_id, true); if ($comment_deleted) { $message_deleted_from_map = $message->delete_from_messages_map($message_id); if (!!$message_deleted_from_map) { break; } } else { break; } } } else { $comment_deleted = true; $message_deleted_from_map = true; } return !!$comment_deleted && !!$message_deleted_from_map; }
/** * Delete a comment. * * @uses wp_delete_comment * @param int $id Post ID * @param int $comment Comment ID * @param boolean $force Skip trash * @return array */ public function delete_comment($id, $comment, $force = false) { $comment = (int) $comment; if (empty($comment)) { return new WP_Error('json_comment_invalid_id', __('Invalid comment ID.'), array('status' => 404)); } $comment_array = get_comment($comment, ARRAY_A); if (empty($comment_array)) { return new WP_Error('json_comment_invalid_id', __('Invalid comment ID.'), array('status' => 404)); } if (!current_user_can('edit_comment', $comment_array['comment_ID'])) { return new WP_Error('json_user_cannot_delete_comment', __('Sorry, you are not allowed to delete this comment.'), array('status' => 401)); } $result = wp_delete_comment($comment_array['comment_ID'], $force); if (!$result) { return new WP_Error('json_cannot_delete', __('The comment cannot be deleted.'), array('status' => 500)); } if ($force) { return array('message' => __('Permanently deleted comment')); } else { // TODO: return a HTTP 202 here instead return array('message' => __('Deleted comment')); } }
/** * Delete a comment. * * @uses wp_delete_comment * @param int $id Post ID * @param int $comment Comment ID * @param boolean $force Skip trash * @return array */ public function delete_comment($comment, $force = false) { $comment = (int) $comment; if (empty($comment)) { json_error(BigAppErr::$comment['code'], BigAppErr::$comment['msg'], __lan("comment id invalid")); } $comment_array = get_comment($comment, ARRAY_A); if (empty($comment_array)) { json_error(BigAppErr::$comment['code'], BigAppErr::$comment['msg'], __lan("comment id invalid")); } $user_id = get_current_user_id(); if ($user_id == 0) { //未登录用户,不能删除评论 json_error(BigAppErr::$login['code'], BigAppErr::$login['msg'], __lan("need login")); } if (!current_user_can('edit_comment', $comment_array['comment_ID']) && $user_id != $comment_array['user_id']) { json_error(BigAppErr::$comment['code'], BigAppErr::$comment['msg'], __lan("no auth to delete comment ")); } $result = wp_delete_comment($comment_array['comment_ID'], $force); if (!$result) { json_error(BigAppErr::$comment['code'], BigAppErr::$comment['msg'], __lan("delete comment failed")); } return array('message' => __('Deleted comment'), 'id' => $comment); }
/** * Trashes or deletes an attachment. * * When an attachment is permanently deleted, the file will also be removed. * Deletion removes all post meta fields, taxonomy, comments, etc. associated * with the attachment (except the main post). * * The attachment is moved to the trash instead of permanently deleted unless trash * for media is disabled, item is already in the trash, or $force_delete is true. * * @since 2.0.0 * @uses $wpdb * @uses do_action() Calls 'delete_attachment' hook on Attachment ID. * * @param int $post_id Attachment ID. * @param bool $force_delete Whether to bypass trash and force deletion. Defaults to false. * @return mixed False on failure. Post data on success. */ function wp_delete_attachment($post_id, $force_delete = false) { global $wpdb; if (!($post = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE ID = %d", $post_id)))) { return $post; } if ('attachment' != $post->post_type) { return false; } if (!$force_delete && EMPTY_TRASH_DAYS && MEDIA_TRASH && 'trash' != $post->post_status) { return wp_trash_post($post_id); } delete_post_meta($post_id, '_wp_trash_meta_status'); delete_post_meta($post_id, '_wp_trash_meta_time'); $meta = wp_get_attachment_metadata($post_id); $backup_sizes = get_post_meta($post->ID, '_wp_attachment_backup_sizes', true); $file = get_attached_file($post_id); if (is_multisite()) { delete_transient('dirsize_cache'); } do_action('delete_attachment', $post_id); wp_delete_object_term_relationships($post_id, array('category', 'post_tag')); wp_delete_object_term_relationships($post_id, get_object_taxonomies($post->post_type)); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_key = '_thumbnail_id' AND meta_value = %d", $post_id)); $comment_ids = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_post_ID = %d", $post_id)); if (!empty($comment_ids)) { do_action('delete_comment', $comment_ids); foreach ($comment_ids as $comment_id) { wp_delete_comment($comment_id, true); } do_action('deleted_comment', $comment_ids); } $post_meta_ids = $wpdb->get_col($wpdb->prepare("SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = %d ", $post_id)); if (!empty($post_meta_ids)) { do_action('delete_postmeta', $post_meta_ids); $in_post_meta_ids = "'" . implode("', '", $post_meta_ids) . "'"; $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE meta_id IN({$in_post_meta_ids})"); do_action('deleted_postmeta', $post_meta_ids); } do_action('delete_post', $post_id); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->posts} WHERE ID = %d", $post_id)); do_action('deleted_post', $post_id); $uploadpath = wp_upload_dir(); if (!empty($meta['thumb'])) { // Don't delete the thumb if another attachment uses it if (!$wpdb->get_row($wpdb->prepare("SELECT meta_id FROM {$wpdb->postmeta} WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $meta['thumb'] . '%', $post_id))) { $thumbfile = str_replace(basename($file), $meta['thumb'], $file); $thumbfile = apply_filters('wp_delete_file', $thumbfile); @unlink(path_join($uploadpath['basedir'], $thumbfile)); } } // remove intermediate and backup images if there are any foreach (get_intermediate_image_sizes() as $size) { if ($intermediate = image_get_intermediate_size($post_id, $size)) { $intermediate_file = apply_filters('wp_delete_file', $intermediate['path']); @unlink(path_join($uploadpath['basedir'], $intermediate_file)); } } if (is_array($backup_sizes)) { foreach ($backup_sizes as $size) { $del_file = path_join(dirname($meta['file']), $size['file']); $del_file = apply_filters('wp_delete_file', $del_file); @unlink(path_join($uploadpath['basedir'], $del_file)); } } $file = apply_filters('wp_delete_file', $file); if (!empty($file)) { @unlink($file); } clean_post_cache($post_id); return $post; }
/** * Delete a comment. * * By default, the comment will be moved to the trash instead of deleted. * See {@link wp_delete_comment()} for more information on * this behavior. * * @since 2.7.0 * * @param array $args Method parameters. Contains: * - blog_id (unused) * - username * - password * - comment_id * @return bool|IXR_Error {@link wp_delete_comment()} */ public function wp_deleteComment($args) { $this->escape($args); $username = $args[1]; $password = $args[2]; $comment_ID = (int) $args[3]; 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.deleteComment'); $status = wp_delete_comment($comment_ID); if (true == $status) { /** * Fires after a comment has been successfully deleted via XML-RPC. * * @since 3.4.0 * * @param int $comment_ID ID of the deleted comment. * @param array $args An array of arguments to delete the comment. */ do_action('xmlrpc_call_success_wp_deleteComment', $comment_ID, $args); } return $status; }
/** * Ajax handler for deleting a comment. * * @since 3.1.0 */ function wp_ajax_delete_comment() { $id = isset($_POST['id']) ? (int) $_POST['id'] : 0; if (!($comment = get_comment($id))) { wp_die(time()); } if (!current_user_can('edit_comment', $comment->comment_ID)) { wp_die(-1); } check_ajax_referer("delete-comment_{$id}"); $status = wp_get_comment_status($comment); $delta = -1; if (isset($_POST['trash']) && 1 == $_POST['trash']) { if ('trash' == $status) { wp_die(time()); } $r = wp_trash_comment($comment); } elseif (isset($_POST['untrash']) && 1 == $_POST['untrash']) { if ('trash' != $status) { wp_die(time()); } $r = wp_untrash_comment($comment); if (!isset($_POST['comment_status']) || $_POST['comment_status'] != 'trash') { // undo trash, not in trash $delta = 1; } } elseif (isset($_POST['spam']) && 1 == $_POST['spam']) { if ('spam' == $status) { wp_die(time()); } $r = wp_spam_comment($comment); } elseif (isset($_POST['unspam']) && 1 == $_POST['unspam']) { if ('spam' != $status) { wp_die(time()); } $r = wp_unspam_comment($comment); if (!isset($_POST['comment_status']) || $_POST['comment_status'] != 'spam') { // undo spam, not in spam $delta = 1; } } elseif (isset($_POST['delete']) && 1 == $_POST['delete']) { $r = wp_delete_comment($comment); } else { wp_die(-1); } if ($r) { // Decide if we need to send back '1' or a more complicated response including page links and comment counts _wp_ajax_delete_comment_response($comment->comment_ID, $delta); } wp_die(0); }
function duplication_delete_comment($comment_id) { global $wpdb; $original_comment = (bool) get_comment_meta($comment_id, '_icl_duplicate_of', true) === false; if ($original_comment) { $duplicates = $wpdb->get_col($wpdb->prepare("SELECT comment_id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t FROM {$wpdb->commentmeta}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t WHERE meta_key='_icl_duplicate_of'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t AND meta_value=%d", $comment_id)); foreach ($duplicates as $dup) { wp_delete_comment($dup, true); } } }
/** * Delete a answer and child answers * @param int $id * @param bool $force_delete * @return bool $success */ public static function delete($id, $force_delete = false) { $instance = self::get_instance(); $answer = get_post($id); $question = get_post($answer->post_parent); $answer = QA_Answers::convert($answer); $question = QA_Questions::convert($question); /* also delete question likes */ $comments = get_comments(array('post_id' => $id, 'parent' => 0, 'status' => 'approve', 'post_status' => 'publish')); if (is_array($comments) && count($comments) > 0) { foreach ($comments as $comment) { wp_delete_comment($comment->comment_ID, $force_delete); } } $success = $instance->_delete($id, $force_delete); if ($success) { //update answer count $count = et_count_user_posts($answer->post_author, 'answer'); update_user_meta($answer->post_author, 'et_answer_count', $count); //update status answered for question: $is_best_answer = get_post_meta($id, 'et_is_best_answer', true); if ($is_best_answer) { delete_post_meta($question->ID, 'et_best_answer'); } } return $success; }