本文整理汇总了PHP中wp_trash_comment函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_trash_comment函数的具体用法?PHP wp_trash_comment怎么用?PHP wp_trash_comment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_trash_comment函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: trash_wrapped_object
/**
* 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 trash_wrapped_object()
{
if (wp_trash_comment($this->container_id)) {
return true;
} else {
return new WP_Error('trash_failed', sprintf(__('Can\'t move comment %d to the trash', 'broken-link-checker'), $this->container_id));
}
}
示例2: trash
/**
* Trash a comment
*
* Example: wp comment trash 15
*
* @param array $args}
* @param array $assoc_args
*/
public function trash($args, $assoc_args)
{
$comment_id = WP_CLI::get_numeric_arg($args, 0, "Comment ID");
if (wp_trash_comment($comment_id)) {
WP_CLI::success("Trashed comment {$comment_id}.");
} else {
WP_CLI::error("Failed trashing comment {$comment_id}");
}
}
示例3: test_cache_is_cleared_when_comment_is_trashed
public function test_cache_is_cleared_when_comment_is_trashed()
{
$comment_1 = self::factory()->comment->create_and_get(array('comment_status' => 1, 'comment_date' => '1998-01-01 11:00:00', 'comment_date_gmt' => '1998-01-01 10:00:00'));
$comment_2 = self::factory()->comment->create_and_get(array('comment_status' => 1, 'comment_date' => '2000-01-02 11:00:00', 'comment_date_gmt' => '2000-01-02 10:00:00'));
get_lastcommentmodified();
$this->assertSame(strtotime('2000-01-02 10:00:00'), strtotime(wp_cache_get('lastcommentmodified:server', 'timeinfo')));
wp_trash_comment($comment_2->comment_ID);
$this->assertFalse(wp_cache_get('lastcommentmodified:server', 'timeinfo'));
$this->assertSame(strtotime('1998-01-01 10:00:00'), strtotime(get_lastcommentmodified()));
$this->assertSame(strtotime('1998-01-01 10:00:00'), strtotime(wp_cache_get('lastcommentmodified:server', 'timeinfo')));
}
示例4: test_wp_untrash_comment
public function test_wp_untrash_comment()
{
wp_trash_comment($this->comment->comment_ID);
$this->client->do_sync();
$this->assertEquals(0, $this->server_replica_storage->comment_count('approve'));
$this->assertEquals(1, $this->server_replica_storage->comment_count('trash'));
wp_untrash_comment($this->comment->comment_ID);
$this->client->do_sync();
$this->assertEquals(1, $this->server_replica_storage->comment_count('approve'));
$this->assertEquals(0, $this->server_replica_storage->comment_count('trash'));
}
示例5: bulk_comments
private function bulk_comments($doaction, $comment_ids)
{
global $wpdb;
$approved = $unapproved = $spammed = $unspammed = $trashed = $untrashed = $deleted = 0;
foreach ((array) $comment_ids as $comment_id) {
// Check the permissions on each
$_post_id = (int) $wpdb->get_var($wpdb->prepare("SELECT comment_post_ID FROM {$wpdb->comments} WHERE comment_ID = %d", $comment_id));
if (!current_user_can('edit_post', $_post_id)) {
continue;
}
switch ($doaction) {
case 'approve':
wp_set_comment_status($comment_id, 'approve');
$approved++;
break;
case 'unapprove':
wp_set_comment_status($comment_id, 'hold');
$unapproved++;
break;
case 'spam':
case 'markspam':
if (function_exists('wp_spam_coment')) {
wp_spam_comment($comment_id);
} else {
wp_set_comment_status($comment_id, 'spam');
}
$spammed++;
break;
case 'unspam':
if (function_exists('wp_unspam_comment')) {
wp_unspam_comment($comment_id);
$unspammed++;
}
break;
case 'trash':
if (function_exists('wp_trash_comment')) {
wp_trash_comment($comment_id);
$trashed++;
}
break;
case 'untrash':
if (function_exists('wp_untrash_comment')) {
wp_untrash_comment($comment_id);
$untrashed++;
}
break;
case 'delete':
if (function_exists('wp_delete_comment')) {
wp_delete_comment($comment_id);
} else {
wp_set_comment_status($comment_id, 'delete');
}
$deleted++;
break;
}
}
$redirect_to = $this->referer;
if (false === strpos($redirect_to, 'edit-comments.php')) {
$redirect_to = 'edit-comments.php';
}
if ($approved) {
$redirect_to = add_query_arg('approved', $approved, $redirect_to);
}
if ($unapproved) {
$redirect_to = add_query_arg('unapproved', $unapproved, $redirect_to);
}
if ($spammed) {
$redirect_to = add_query_arg('spammed', $spammed, $redirect_to);
}
if ($unspammed) {
$redirect_to = add_query_arg('unspammed', $unspammed, $redirect_to);
}
if ($trashed) {
$redirect_to = add_query_arg('trashed', $trashed, $redirect_to);
}
if ($untrashed) {
$redirect_to = add_query_arg('untrashed', $untrashed, $redirect_to);
}
if ($deleted) {
$redirect_to = add_query_arg('deleted', $deleted, $redirect_to);
}
if ($trashed || $spammed) {
$redirect_to = add_query_arg('ids', join(',', $comment_ids), $redirect_to);
}
if ($this->post_id > 0) {
$redirect_to = add_query_arg('p', $this->post_id, $redirect_to);
}
if (isset($_REQUEST['apage'])) {
$redirect_to = add_query_arg('apage', abs(intval($_REQUEST['apage'])), $redirect_to);
}
if (!empty($_REQUEST['mode'])) {
$redirect_to = add_query_arg('mode', $_REQUEST['mode'], $redirect_to);
}
if (!empty($_REQUEST['comment_status'])) {
$redirect_to = add_query_arg('comment_status', $_REQUEST['comment_status'], $redirect_to);
}
if (!empty($_REQUEST['s'])) {
$redirect_to = add_query_arg('s', $_REQUEST['s'], $redirect_to);
}
$this->admin->redirect($redirect_to);
//.........这里部分代码省略.........
示例6: wp_get_referer
$redir = wp_get_referer();
} elseif ('' != wp_get_original_referer() && !$noredir) {
$redir = wp_get_original_referer();
} elseif (in_array($action, array('approvecomment', 'unapprovecomment'))) {
$redir = admin_url('edit-comments.php?p=' . absint($comment->comment_post_ID));
} else {
$redir = admin_url('edit-comments.php');
}
$redir = remove_query_arg(array('spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids', 'approved', 'unapproved'), $redir);
switch ($action) {
case 'deletecomment':
wp_delete_comment($comment);
$redir = add_query_arg(array('deleted' => '1'), $redir);
break;
case 'trashcomment':
wp_trash_comment($comment);
$redir = add_query_arg(array('trashed' => '1', 'ids' => $comment_id), $redir);
break;
case 'untrashcomment':
wp_untrash_comment($comment);
$redir = add_query_arg(array('untrashed' => '1'), $redir);
break;
case 'spamcomment':
wp_spam_comment($comment);
$redir = add_query_arg(array('spammed' => '1', 'ids' => $comment_id), $redir);
break;
case 'unspamcomment':
wp_unspam_comment($comment);
$redir = add_query_arg(array('unspammed' => '1'), $redir);
break;
case 'approvecomment':
示例7: geodir_reviewrating_comment_action
/**
* Review Rating comment ajax actions.
*
* @since 1.0.0
* @package GeoDirectory_Review_Rating_Manager
*
* @param $request
* @return bool
*/
function geodir_reviewrating_comment_action($request)
{
global $wpdb;
$comment_ids = array();
if (isset($request['comment_ids']) && $request['comment_ids'] != '') {
$comment_ids = explode(',', $request['comment_ids']);
}
if (!empty($comment_ids) && $request['comment_ids'] != '') {
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'geodir_review_action_nonce')) {
return false;
}
foreach ($comment_ids as $comment_id) {
if ($comment_id != '') {
switch ($request['comment_action']) {
case 'deletecomment':
wp_delete_comment($comment_id);
break;
case 'trashcomment':
wp_trash_comment($comment_id);
break;
case 'untrashcomment':
wp_untrash_comment($comment_id);
break;
case 'spamcomment':
wp_spam_comment($comment_id);
break;
case 'unspamcomment':
wp_unspam_comment($comment_id);
break;
case 'approvecomment':
wp_set_comment_status($comment_id, 'approve');
break;
case 'unapprovecomment':
wp_set_comment_status($comment_id, 'hold');
break;
}
}
}
if (isset($request['geodir_comment_search'])) {
$geodir_commentsearch = $request['geodir_comment_search'];
}
if (isset($request['geodir_comment_posttype'])) {
$post_type = $request['geodir_comment_posttype'];
}
$status = $request['subtab'];
$orderby = 'comment_date_gmt';
$order = 'DESC';
if (isset($request['geodir_comment_sort'])) {
if ($request['geodir_comment_sort'] == 'oldest') {
$orderby = 'comment_date_gmt';
$order = 'ASC';
}
}
if (isset($request['paged']) && $request['paged'] != '') {
$paged = $request['paged'];
} else {
$paged = 1;
}
$show_post = $request['show_post'];
$defaults = array('paged' => $paged, 'show_post' => $show_post, 'orderby' => $orderby, 'order' => $order, 'post_type' => $post_type, 'comment_approved' => $status, 'user_id' => '', 'search' => $geodir_commentsearch);
$comments = geodir_reviewrating_get_comments($defaults);
geodir_reviewrating_show_comments($comments['comments']);
}
if (isset($request['gd_tab_head'])) {
geodir_reviewrating_show_tab_head($request['gd_tab_head']);
}
exit;
}
示例8: wp_delete_comment
/**
* Trashes or deletes a comment.
*
* The comment is moved to trash instead of permanently deleted unless trash is
* disabled, item is already in the trash, or $force_delete is true.
*
* The post comment count will be updated if the comment was approved and has a
* post ID available.
*
* @since 2.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object.
* @param bool $force_delete Whether to bypass trash and force deletion. Default is false.
* @return bool True on success, false on failure.
*/
function wp_delete_comment($comment_id, $force_delete = false)
{
global $wpdb;
if (!($comment = get_comment($comment_id))) {
return false;
}
if (!$force_delete && EMPTY_TRASH_DAYS && !in_array(wp_get_comment_status($comment), array('trash', 'spam'))) {
return wp_trash_comment($comment_id);
}
/**
* Fires immediately before a comment is deleted from the database.
*
* @since 1.2.0
*
* @param int $comment_id The comment ID.
*/
do_action('delete_comment', $comment->comment_ID);
// Move children up a level.
$children = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_parent = %d", $comment->comment_ID));
if (!empty($children)) {
$wpdb->update($wpdb->comments, array('comment_parent' => $comment->comment_parent), array('comment_parent' => $comment->comment_ID));
clean_comment_cache($children);
}
// Delete metadata
$meta_ids = $wpdb->get_col($wpdb->prepare("SELECT meta_id FROM {$wpdb->commentmeta} WHERE comment_id = %d", $comment->comment_ID));
foreach ($meta_ids as $mid) {
delete_metadata_by_mid('comment', $mid);
}
if (!$wpdb->delete($wpdb->comments, array('comment_ID' => $comment->comment_ID))) {
return false;
}
/**
* Fires immediately after a comment is deleted from the database.
*
* @since 2.9.0
*
* @param int $comment_id The comment ID.
*/
do_action('deleted_comment', $comment->comment_ID);
$post_id = $comment->comment_post_ID;
if ($post_id && $comment->comment_approved == 1) {
wp_update_comment_count($post_id);
}
clean_comment_cache($comment->comment_ID);
/** This action is documented in wp-includes/comment-functions.php */
do_action('wp_set_comment_status', $comment->comment_ID, 'delete');
wp_transition_comment_status('delete', $comment->comment_approved, $comment);
return true;
}
示例9: delete_item
/**
* Delete a product review.
*
* @param WP_REST_Request $request Full details about the request
* @return WP_Error|boolean
*/
public function delete_item($request)
{
$product_review_id = is_array($request['id']) ? $request['id']['id'] : $request['id'];
$force = isset($request['force']) ? (bool) $request['force'] : false;
$product_review = get_comment($product_review_id);
if (empty($product_review_id) || empty($product_review->comment_ID) || empty($product_review->comment_post_ID)) {
return new WP_Error('woocommerce_rest_product_review_invalid_id', __('Invalid product review ID.', 'woocommerce'), array('status' => 404));
}
/**
* Filter whether a product review is trashable.
*
* Return false to disable trash support for the product review.
*
* @param boolean $supports_trash Whether the object supports trashing.
* @param WP_Post $product_review The object being considered for trashing support.
*/
$supports_trash = apply_filters('rest_product_review_trashable', EMPTY_TRASH_DAYS > 0, $product_review);
$request->set_param('context', 'edit');
$response = $this->prepare_item_for_response($product_review, $request);
if ($force) {
$result = wp_delete_comment($product_review_id, true);
} else {
if (!$supports_trash) {
return new WP_Error('rest_trash_not_supported', __('The product review does not support trashing.', 'woocommerce'), array('status' => 501));
}
if ('trash' === $product_review->comment_approved) {
return new WP_Error('rest_already_trashed', __('The comment has already been trashed.', 'woocommerce'), array('status' => 410));
}
$result = wp_trash_comment($product_review->comment_ID);
}
if (!$result) {
return new WP_Error('rest_cannot_delete', __('The product review cannot be deleted.', 'woocommerce'), array('status' => 500));
}
/**
* Fires after a product review is deleted via the REST API.
*
* @param object $product_review The deleted item.
* @param WP_REST_Response $response The response data.
* @param WP_REST_Request $request The request sent to the API.
*/
do_action('rest_delete_product_review', $product_review, $response, $request);
return $response;
}
示例10: spc_manage_contest
function spc_manage_contest($contest_id = 0)
{
global $wpdb;
switch ($_POST['submit_task']) {
case 'Pubish':
if (count($_POST['pid']) > 0) {
foreach ($_POST['pid'] as $value) {
wp_update_comment(array('comment_ID' => $value, 'comment_approved' => 1));
}
}
break;
case 'UnPublish':
if (count($_POST['pid']) > 0) {
foreach ($_POST['pid'] as $value) {
wp_update_comment(array('comment_ID' => $value, 'comment_approved' => 0));
}
}
break;
case 'Delete':
if (count($_POST['pid']) > 0) {
foreach ($_POST['pid'] as $value) {
wp_trash_comment($value);
}
}
break;
default:
break;
}
$sql = "SELECT * FROM " . $wpdb->spc_contest . " WHERE " . $wpdb->spc_contest . ".contest_id <> 0 ";
if ($contest_id) {
$sql .= " AND " . $wpdb->spc_contest . ".contest_id = " . $contest_id;
}
$results = $wpdb->get_results($sql, ARRAY_A);
//spc_dg($results);
?>
<form name="listform" id="listform" action="admin.php?page=spc-manage-participant" method="POST">
<table class="widefat">
<thead>
<tr>
<td colspan="6">
<b>Action :</b>
<input class="button" type="submit" name="submit_task" value="Approve">
<input class="button" type="submit" name="submit_task" value="UnApprove">
<input class="button" type="submit" name="submit_task" value="Delete">
</td>
</tr>
<tr>
<th scope="col">Select</th>
<th scope="col">PostID</th>
<th scope="col">Desciption</th>
<th scope="col">Start-End Date</th>
<th scope="col">Upload End Date</th>
<th scope="col">Contest Status</th>
<th scope="col">Photo MaxUpload/user</th>
<th scope="col">Action</th>
<th scope="col"></th>
</tr>
</thead>
<tbody id="the-list">
<?php
$cnt = 0;
foreach ($results as $val) {
echo "<tr " . ($cnt % 2 == 0 ? ' class="alternate"' : '') . ">\n";
echo "<th scope=\"row\" style=\"text-align: center\"><input type=\"checkbox\" value=\"" . $val['contest_id'] . "\" name=\"pid[]\" id=\"cb" . $val['contest_id'] . "\"/></th>";
echo "<th scope=\"row\" style=\"text-align: center\">" . $val['contest_postid'] . "</th>\n";
echo "<th scope=\"row\">";
$temp = "<table border='0'>";
$temp .= "<tr><th colspan='2'>Title: " . $val['contest_title'] . "</th></tr>";
$temp .= "<tr><th valign='top'><p>" . $val['contest_description'] . "</p></th></tr>";
$temp .= "</table>";
echo $temp;
echo "</th>";
echo "<th scope=\"row\">" . $val['contest_startdate'] . " until " . $val['contest_enddate'] . "</th>";
echo "<th scope=\"row\">" . $val['contest_uploadenddate'] . "</th>";
echo "<th scope=\"row\">" . $val['contest_status'] . "</th>";
echo "<th scope=\"row\">" . $val['contest_maxupload'] . "</th>";
echo "<th scope=\"row\"><button class=\"button\" onclick=\"location.href='./admin.php?page=spc-addedit&contestID=" . $val['contest_id'] . "';\">EDIT</button></th>";
echo "</tr>\n";
}
?>
</tbody>
</table>
</form>
<?php
}
示例11: delete_comment
private function delete_comment($action)
{
$comment_id = intval($_REQUEST['c']);
check_admin_referer('delete-comment_' . $comment_id);
$noredir = isset($_REQUEST['noredir']);
if (!($comment = get_comment($comment_id))) {
$this->base->ks_die(__('Oops, no comment with this ID.') . sprintf(' <a href="%s">' . __('Go back') . '</a>!', 'edit-comments.php'), '', false);
//exit;
}
if (!current_user_can('edit_post', $comment->comment_post_ID)) {
$this->base->ks_die(__('You are not allowed to edit comments on this post.'));
}
$redir = $this->referer;
if (empty($redir) || $noredir || false !== strpos($redir, 'comment.php')) {
$redir = 'edit-comments.php';
}
switch ($action) {
case 'deletecomment':
wp_delete_comment($comment_id);
$redir = add_query_arg(array('deleted' => 1), $redir);
break;
case 'trashcomment':
if (function_exists('wp_trash_comment')) {
wp_trash_comment($comment_id);
$redir = add_query_arg(array('trashed' => '1', 'ids' => $comment_id), $redir);
}
break;
case 'untrashcomment':
if (function_exists('wp_untrash_comment')) {
wp_untrash_comment($comment_id);
$redir = add_query_arg(array('untrashed' => '1'), $redir);
}
break;
case 'spamcomment':
if (function_exists('wp_spam_comment')) {
wp_spam_comment($comment_id);
} else {
wp_set_comment_status($comment_id, 'spam');
}
$redir = add_query_arg(array('spammed' => '1', 'ids' => $comment_id), $redir);
break;
case 'unspamcomment':
if (function_exists('wp_spam_comment')) {
wp_unspam_comment($comment_id);
$redir = add_query_arg(array('unspammed' => '1'), $redir);
}
break;
}
$this->admin->redirect($redir);
exit;
}
示例12: test_wp_count_comments_cache
public function test_wp_count_comments_cache()
{
$post_id = self::factory()->post->create(array('post_status' => 'publish'));
$comment_id = self::factory()->comment->create(array('comment_approved' => '1', 'comment_post_ID' => $post_id));
$count1 = wp_count_comments($post_id);
$this->assertEquals(1, $count1->approved);
$this->assertEquals(0, $count1->moderated);
$this->assertEquals(0, $count1->spam);
$this->assertEquals(0, $count1->trash);
$this->assertEquals(0, $count1->{'post-trashed'});
$this->assertEquals(1, $count1->total_comments);
$this->assertEquals(1, $count1->all);
$all_count1 = wp_count_comments();
$this->assertEquals(1, $all_count1->approved);
$this->assertEquals(0, $all_count1->moderated);
$this->assertEquals(0, $all_count1->spam);
$this->assertEquals(0, $all_count1->trash);
$this->assertEquals(0, $all_count1->{'post-trashed'});
$this->assertEquals(1, $all_count1->total_comments);
$this->assertEquals(1, $all_count1->all);
wp_spam_comment($comment_id);
$count2 = wp_count_comments($post_id);
$this->assertEquals(0, $count2->approved);
$this->assertEquals(0, $count2->moderated);
$this->assertEquals(1, $count2->spam);
$this->assertEquals(0, $count2->trash);
$this->assertEquals(0, $count2->{'post-trashed'});
$this->assertEquals(1, $count2->total_comments);
$this->assertEquals(0, $count2->all);
$all_count2 = wp_count_comments();
$this->assertEquals(0, $all_count2->approved);
$this->assertEquals(0, $all_count2->moderated);
$this->assertEquals(1, $all_count2->spam);
$this->assertEquals(0, $all_count2->trash);
$this->assertEquals(0, $all_count2->{'post-trashed'});
$this->assertEquals(1, $all_count2->total_comments);
$this->assertEquals(0, $all_count2->all);
wp_trash_comment($comment_id);
$count3 = wp_count_comments($post_id);
$this->assertEquals(0, $count3->approved);
$this->assertEquals(0, $count3->moderated);
$this->assertEquals(0, $count3->spam);
$this->assertEquals(1, $count3->trash);
$this->assertEquals(0, $count3->{'post-trashed'});
$this->assertEquals(0, $count3->total_comments);
$this->assertEquals(0, $count3->all);
$all_count3 = wp_count_comments();
$this->assertEquals(0, $all_count3->approved);
$this->assertEquals(0, $all_count3->moderated);
$this->assertEquals(0, $all_count3->spam);
$this->assertEquals(1, $all_count3->trash);
$this->assertEquals(0, $all_count3->{'post-trashed'});
$this->assertEquals(0, $all_count3->total_comments);
$this->assertEquals(0, $all_count3->all);
wp_untrash_comment($comment_id);
$count4 = wp_count_comments($post_id);
$this->assertEquals(0, $count4->approved);
$this->assertEquals(0, $count4->moderated);
$this->assertEquals(1, $count4->spam);
$this->assertEquals(0, $count4->trash);
$this->assertEquals(0, $count4->{'post-trashed'});
$this->assertEquals(1, $count4->total_comments);
$this->assertEquals(0, $count4->all);
$all_count4 = wp_count_comments();
$this->assertEquals(0, $all_count4->approved);
$this->assertEquals(0, $all_count4->moderated);
$this->assertEquals(1, $all_count4->spam);
$this->assertEquals(0, $all_count4->trash);
$this->assertEquals(0, $all_count4->{'post-trashed'});
$this->assertEquals(1, $all_count4->total_comments);
$this->assertEquals(0, $all_count4->all);
}
示例13: test_bp_blogs_remove_comment_should_remove_spammed_activity_comment
/**
* @group bp_blogs_transition_activity_status
* @group bp_blogs_remove_comment
*/
public function test_bp_blogs_remove_comment_should_remove_spammed_activity_comment()
{
// save the current user and override logged-in user
$old_user = get_current_user_id();
$u = $this->factory->user->create();
$this->set_current_user($u);
$userdata = get_userdata($u);
// create the blog post
$post_id = $this->factory->post->create(array('post_status' => 'publish', 'post_type' => 'post', 'post_title' => 'First title'));
// let's use activity comments instead of single "new_blog_comment" activity items
add_filter('bp_disable_blogforum_comments', '__return_false');
$c1 = wp_new_comment(array('comment_post_ID' => $post_id, 'comment_author' => $userdata->user_nicename, 'comment_author_url' => 'http://buddypress.org', 'comment_author_email' => $userdata->user_email, 'comment_content' => 'this is a blog comment', 'comment_type' => '', 'comment_parent' => 0, 'user_id' => $u));
// save the corresponding activity comment ID
$a1 = bp_activity_get_activity_id(array('type' => 'activity_comment', 'display_comments' => 'stream', 'meta_query' => array(array('key' => 'bp_blogs_post_comment_id', 'value' => $c1))));
// trash the parent comment.
// corresponding activity comment should now be marked as spam
// @see bp_blogs_transition_activity_status()
wp_trash_comment($c1);
// now permanently delete the comment
wp_delete_comment($c1, true);
// activity comment should no longer exist
$a = bp_activity_get(array('in' => $a1, 'display_comments' => 'stream', 'spam' => 'all'));
// this is a convoluted way of testing if the activity comment still exists
$this->assertTrue(empty($a['activities'][0]));
// reset
$this->set_current_user($old_user);
remove_filter('bp_disable_blogforum_comments', '__return_false');
}
示例14: wp_delete_comment
/**
* Removes comment ID and maybe updates post comment count.
*
* The post comment count will be updated if the comment was approved and has a
* post ID available.
*
* @since 2.0.0
* @uses $wpdb
* @uses do_action() Calls 'delete_comment' hook on comment ID
* @uses do_action() Calls 'wp_set_comment_status' hook on comment ID with 'delete' set for the second parameter
* @uses wp_transition_comment_status() Passes new and old comment status along with $comment object
*
* @param int $comment_id Comment ID
* @return bool False if delete comment query failure, true on success.
*/
function wp_delete_comment($comment_id)
{
global $wpdb;
if (!($comment = get_comment($comment_id))) {
return false;
}
if (wp_get_comment_status($comment_id) != 'trash' && wp_get_comment_status($comment_id) != 'spam' && EMPTY_TRASH_DAYS > 0) {
return wp_trash_comment($comment_id);
}
do_action('delete_comment', $comment_id);
delete_comment_meta($comment_id, '_wp_trash_meta_status');
delete_comment_meta($comment_id, '_wp_trash_meta_time');
if (!$wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->comments} WHERE comment_ID = %d LIMIT 1", $comment_id))) {
return false;
}
// Move children up a level.
$children = $wpdb->get_col($wpdb->prepare("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_parent = %d", $comment_id));
if (!empty($children)) {
$wpdb->update($wpdb->comments, array('comment_parent' => $comment->comment_parent), array('comment_parent' => $comment_id));
clean_comment_cache($children);
}
$post_id = $comment->comment_post_ID;
if ($post_id && $comment->comment_approved == 1) {
wp_update_comment_count($post_id);
}
clean_comment_cache($comment_id);
do_action('wp_set_comment_status', $comment_id, 'delete');
wp_transition_comment_status('delete', $comment->comment_approved, $comment);
return true;
}
示例15: group_actions
//.........这里部分代码省略.........
* @uses WP_Idea_Stream_Group->remove_from_group() to remove one or more ideas from a group
* @uses wp_get_referer() to get the url the user came from
* @uses wp_spam_comment() to spam a comment made on an idea
* @uses wp_trash_comment() to trash a comment made on an idea
* @uses wp_idea_stream_add_message() to add a feedback to display to the user once redirected
* @uses bp_core_redirect() to safely redirect the user
*/
public function group_actions()
{
if (!bp_is_group()) {
return;
}
$group = groups_get_current_group();
// This part is to catch the group status before it might be updated
if ('group-settings' == bp_get_group_current_admin_tab() && bp_is_item_admin()) {
$this->group_update_ideas_stati = $group;
if (!empty($_POST['group-status']) && in_array($_POST['group-status'], array('public', 'private', 'hidden'))) {
$this->group_update_ideas_stati->new_status = $_POST['group-status'];
}
}
// This part is for ideastream moderation actions.
if (!(bp_is_current_action(wp_idea_stream_root_slug()) && wp_idea_stream_action_get_slug() == bp_action_variable(0) && bp_action_variable(1))) {
return;
}
$feedback = array();
// Default to group's home
$redirect = $this->group_ideas_archive_url($group, true);
switch (bp_action_variable(1)) {
case 'remove-idea':
check_admin_referer('group-remove-idea');
if (!bp_action_variable(2)) {
$feedback['type'] = 'error';
$feedback['content'] = __('Removing the idea failed.', 'wp-idea-stream');
break;
}
$idea_id = absint(bp_action_variable(2));
if (!wp_idea_stream_user_can('remove_group_ideas')) {
$feedback['type'] = 'error';
$feedback['content'] = __('Removing the idea failed. You do not have the capability to remove ideas.', 'wp-idea-stream');
break;
}
if (false === $this->remove_from_group($idea_id, $group->id)) {
$feedback['type'] = 'error';
$feedback['content'] = __('Removing the idea failed.', 'wp-idea-stream');
$redirect = wp_get_referer();
} else {
$feedback['type'] = 'success';
$feedback['content'] = __('The idea was successfully removed.', 'wp-idea-stream');
}
break;
case 'spam-comment':
check_admin_referer('group-spam-comment');
$redirect = wp_get_referer();
if (!bp_action_variable(2)) {
$feedback['type'] = 'error';
$feedback['content'] = __('Spamming the comment failed.', 'wp-idea-stream');
break;
}
$comment_id = absint(bp_action_variable(2));
if (!wp_idea_stream_user_can('spam_group_idea_comments')) {
$feedback['type'] = 'error';
$feedback['content'] = __('Spamming the comment failed. You do not have the capability to spam comments.', 'wp-idea-stream');
break;
}
if (false === wp_spam_comment($comment_id)) {
$feedback['type'] = 'error';
$feedback['content'] = __('Spamming the comment failed.', 'wp-idea-stream');
} else {
$feedback['type'] = 'success';
$feedback['content'] = __('The comment was successfully marked as spam.', 'wp-idea-stream');
}
break;
case 'trash-comment':
check_admin_referer('group-trash-comment');
$redirect = wp_get_referer();
if (!bp_action_variable(2)) {
$feedback['type'] = 'error';
$feedback['content'] = __('Deleting the comment failed.', 'wp-idea-stream');
break;
}
$comment_id = absint(bp_action_variable(2));
if (!wp_idea_stream_user_can('trash_group_idea_comments')) {
$feedback['type'] = 'error';
$feedback['content'] = __('Deleting the comment failed. You do not have the capability to delete comments.', 'wp-idea-stream');
break;
}
if (false === wp_trash_comment($comment_id)) {
$feedback['type'] = 'error';
$feedback['content'] = __('Deleting the comment failed.', 'wp-idea-stream');
} else {
$feedback['type'] = 'success';
$feedback['content'] = __('The comment was successfully deleted.', 'wp-idea-stream');
}
break;
}
if (!empty($feedback)) {
wp_idea_stream_add_message($feedback);
bp_core_redirect($redirect);
}
}