本文整理汇总了PHP中wp_set_comment_status函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_set_comment_status函数的具体用法?PHP wp_set_comment_status怎么用?PHP wp_set_comment_status使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_set_comment_status函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set_status
private function set_status($args, $status, $success)
{
list($comment_id) = $args;
$r = wp_set_comment_status($comment_id, 'approve', true);
if (is_wp_error($r)) {
WP_CLI::error($r);
} else {
WP_CLI::success("{$success} comment {$comment_id}");
}
}
示例2: set_comment_status
function set_comment_status($comment_id, $comment_status)
{
if ($comment_status == '1') {
wp_set_comment_status($comment_id, 'approve');
} elseif ($comment_status == '0') {
wp_set_comment_status($comment_id, 'hold');
} else {
wp_set_comment_status($comment_id, 'spam');
}
}
示例3: sent_comment_to_spam
function sent_comment_to_spam($comment_id)
{
$wpad_flaging_threshold = get_option('wpad_flaging_threshold');
if (empty($wpad_flaging_threshold)) {
return;
}
$no_of_flags = get_comment_meta($comment_id, 'no_of_flags', true);
if ($no_of_flags >= $wpad_flaging_threshold) {
wp_set_comment_status($comment_id, 'hold');
}
}
示例4: remove_comment
/**
* Remove a single comment from the anth_library_item
*
* For technical reasons having to do with the markup created in the project organizer JS,
* this function takes the *original comment ID* as a parameter, NOT the ID of the copied
* comment on the anth_library_item. This function then deletes ALL instances of comments
* on the anth_library_item that correspond to the original comment.
*
* @package Anthologize
* @since 0.6
*
* @uses apply_filters() Filter anthologize_remove_comment_status to change the default
* behavior from trashing to true deletion
* @param int $comment_id The ID of the *original* comment corresponding to the comments
* you want to delete
*/
public function remove_comment($comment_id)
{
// Just to be safe, we remove all instances of comments on the library item that
// correspond to the original comment in question
$comments_to_remove = array_keys($this->included_comments, $comment_id);
foreach ((array) $comments_to_remove as $ctr) {
// We'll trash the comment instead of deleting it
wp_set_comment_status($ctr, apply_filters('anthologize_remove_comment_status', 'trash'));
unset($this->included_comments[$ctr]);
}
}
示例5: test_sends_highlander_comment_meta_with_comment
public function test_sends_highlander_comment_meta_with_comment()
{
$wpcom_user_id = 101;
$sig = 'abcd1234';
$comment_ID = $this->comment->comment_ID;
add_comment_meta($comment_ID, 'hc_post_as', 'wordpress', true);
add_comment_meta($comment_ID, 'hc_wpcom_id_sig', $sig, true);
add_comment_meta($comment_ID, 'hc_foreign_user_id', $wpcom_user_id, true);
// re-save the comment
wp_set_comment_status($comment_ID, 'hold');
$this->client->do_sync();
$this->client->do_sync();
$event = $this->server_event_storage->get_most_recent_event();
$synced_comment = $event->args[1];
$this->assertObjectHasAttribute('meta', $synced_comment);
$this->assertEquals('wordpress', $synced_comment->meta['hc_post_as']);
$this->assertEquals('abcd1234', $synced_comment->meta['hc_wpcom_id_sig']);
$this->assertEquals(101, $synced_comment->meta['hc_foreign_user_id']);
}
示例6: test_custom_pagination_should_allow_ones_own_unapproved_comments
/**
* @ticket 37048
*/
public function test_custom_pagination_should_allow_ones_own_unapproved_comments()
{
$p = self::factory()->post->create();
$u = self::factory()->user->create();
$comments = array();
$now = time();
for ($i = 0; $i <= 5; $i++) {
$comments[] = self::factory()->comment->create(array('comment_post_ID' => $p, 'comment_date_gmt' => date('Y-m-d H:i:s', $now - $i), 'comment_author' => 'Commenter ' . $i, 'user_id' => $u));
}
// Only 2 and 5 are approved.
wp_set_comment_status($comments[0], '0');
wp_set_comment_status($comments[1], '0');
wp_set_comment_status($comments[3], '0');
wp_set_comment_status($comments[4], '0');
update_option('page_comments', true);
update_option('comments_per_page', 2);
wp_set_current_user($u);
$this->go_to(get_permalink($p));
// comments_template() populates $wp_query->comments
get_echo('comments_template');
$found = wp_list_comments(array('echo' => false, 'per_page' => 1, 'page' => 2));
preg_match_all('|id="comment\\-([0-9]+)"|', $found, $matches);
$this->assertSame(array($comments[4]), array_map('intval', $matches[1]));
}
示例7: akismet_cron_recheck
function akismet_cron_recheck()
{
global $wpdb;
$status = akismet_verify_key(akismet_get_key());
if (get_option('akismet_alert_code') || $status == 'invalid') {
// since there is currently a problem with the key, reschedule a check for 6 hours hence
wp_schedule_single_event(time() + 21600, 'akismet_schedule_cron_recheck');
return false;
}
delete_option('akismet_available_servers');
$comment_errors = $wpdb->get_col("\n\t\tSELECT comment_id\n\t\tFROM {$wpdb->prefix}commentmeta\n\t\tWHERE meta_key = 'akismet_error'\n\t\tLIMIT 100\n\t");
foreach ((array) $comment_errors as $comment_id) {
// if the comment no longer exists, or is too old, remove the meta entry from the queue to avoid getting stuck
$comment = get_comment($comment_id);
if (!$comment || strtotime($comment->comment_date_gmt) < strtotime("-15 days")) {
delete_comment_meta($comment_id, 'akismet_error');
continue;
}
add_comment_meta($comment_id, 'akismet_rechecking', true);
$status = akismet_check_db_comment($comment_id, 'retry');
$msg = '';
if ($status == 'true') {
$msg = __('Akismet caught this comment as spam during an automatic retry.');
} elseif ($status == 'false') {
$msg = __('Akismet cleared this comment during an automatic retry.');
}
// If we got back a legit response then update the comment history
// other wise just bail now and try again later. No point in
// re-trying all the comments once we hit one failure.
if (!empty($msg)) {
delete_comment_meta($comment_id, 'akismet_error');
akismet_update_comment_history($comment_id, $msg, 'cron-retry');
update_comment_meta($comment_id, 'akismet_result', $status);
// make sure the comment status is still pending. if it isn't, that means the user has already moved it elsewhere.
$comment = get_comment($comment_id);
if ($comment && 'unapproved' == wp_get_comment_status($comment_id)) {
if ($status == 'true') {
wp_spam_comment($comment_id);
} elseif ($status == 'false') {
// comment is good, but it's still in the pending queue. depending on the moderation settings
// we may need to change it to approved.
if (check_comment($comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent, $comment->comment_type)) {
wp_set_comment_status($comment_id, 1);
}
}
}
} else {
delete_comment_meta($comment_id, 'akismet_rechecking');
wp_schedule_single_event(time() + 1200, 'akismet_schedule_cron_recheck');
return;
}
delete_comment_meta($comment_id, 'akismet_rechecking');
}
$remaining = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->commentmeta} WHERE meta_key = 'akismet_error'");
if ($remaining && !wp_next_scheduled('akismet_schedule_cron_recheck')) {
wp_schedule_single_event(time() + 1200, 'akismet_schedule_cron_recheck');
}
}
示例8: duplication_status_comment
function duplication_status_comment($comment_id, $comment_status)
{
global $wpdb;
static $_avoid_8_loop;
if (isset($_avoid_8_loop)) {
return;
}
$_avoid_8_loop = true;
$original_comment = get_comment_meta($comment_id, '_icl_duplicate_of', true);
if ($original_comment) {
$duplicates = $wpdb->get_col($wpdb->prepare("SELECT comment_id FROM {$wpdb->commentmeta} WHERE meta_key='_icl_duplicate_of' AND meta_value=%d", $original_comment));
$duplicates = array($original_comment) + array_diff($duplicates, array($comment_id));
} else {
$duplicates = $wpdb->get_col($wpdb->prepare("SELECT comment_id FROM {$wpdb->commentmeta} WHERE meta_key='_icl_duplicate_of' AND meta_value=%d", $comment_id));
}
if (!empty($duplicates)) {
foreach ($duplicates as $duplicate) {
wp_set_comment_status($duplicate, $comment_status);
}
}
unset($_avoid_8_loop);
}
示例9: WP_Ajax_Response
if (!($comment = get_comment($id))) {
$x = new WP_Ajax_Response(array('what' => 'comment', 'id' => new WP_Error('invalid_comment', sprintf(__('Comment %d does not exist'), $id))));
$x->send();
}
if (!current_user_can('edit_post', $comment->comment_post_ID) && !current_user_can('moderate_comments')) {
die('-1');
}
$current = wp_get_comment_status($comment->comment_ID);
if ($_POST['new'] == $current) {
die((string) time());
}
check_ajax_referer("approve-comment_{$id}");
if (in_array($current, array('unapproved', 'spam'))) {
$result = wp_set_comment_status($comment->comment_ID, 'approve', true);
} else {
$result = wp_set_comment_status($comment->comment_ID, 'hold', true);
}
if (is_wp_error($result)) {
$x = new WP_Ajax_Response(array('what' => 'comment', 'id' => $result));
$x->send();
}
// 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);
die('0');
break;
case 'add-category':
// On the Fly
check_ajax_referer($action);
if (!current_user_can('manage_categories')) {
die('-1');
}
示例10: set_status
private function set_status($args, $status, $success)
{
$comment = $this->fetcher->get_check($args);
$r = wp_set_comment_status($comment->comment_ID, $status, true);
if (is_wp_error($r)) {
WP_CLI::error($r);
} else {
WP_CLI::success("{$success} comment {$comment->comment_ID}.");
}
}
示例11: akismet_recheck_queue
function akismet_recheck_queue()
{
global $wpdb, $akismet_api_host, $akismet_api_port;
if (!(isset($_GET['recheckqueue']) || isset($_REQUEST['action']) && 'akismet_recheck_queue' == $_REQUEST['action'])) {
return;
}
$moderation = $wpdb->get_results("SELECT * FROM {$wpdb->comments} WHERE comment_approved = '0'", ARRAY_A);
foreach ((array) $moderation as $c) {
$c['user_ip'] = $c['comment_author_IP'];
$c['user_agent'] = $c['comment_agent'];
$c['referrer'] = '';
$c['blog'] = get_option('home');
$c['blog_lang'] = get_locale();
$c['blog_charset'] = get_option('blog_charset');
$c['permalink'] = get_permalink($c['comment_post_ID']);
$c['user_role'] = '';
if (isset($c['user_ID'])) {
$c['user_role'] = akismet_get_user_roles($c['user_ID']);
}
$id = (int) $c['comment_ID'];
$query_string = '';
foreach ($c as $key => $data) {
$query_string .= $key . '=' . urlencode(stripslashes($data)) . '&';
}
$response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
if ('true' == $response[1]) {
if (function_exists('wp_set_comment_status')) {
wp_set_comment_status($id, 'spam');
} else {
$wpdb->query("UPDATE {$wpdb->comments} SET comment_approved = 'spam' WHERE comment_ID = {$id}");
}
}
}
wp_redirect($_SERVER['HTTP_REFERER']);
exit;
}
示例12: recheck_queue
public static function recheck_queue()
{
global $wpdb;
Akismet::fix_scheduled_recheck();
if (!(isset($_GET['recheckqueue']) || isset($_REQUEST['action']) && 'akismet_recheck_queue' == $_REQUEST['action'])) {
return;
}
$paginate = '';
if (isset($_POST['limit']) && isset($_POST['offset'])) {
$paginate = $wpdb->prepare(" LIMIT %d OFFSET %d", array($_POST['limit'], $_POST['offset']));
}
$moderation = $wpdb->get_results("SELECT * FROM {$wpdb->comments} WHERE comment_approved = '0'{$paginate}", ARRAY_A);
foreach ((array) $moderation as $c) {
$c['user_ip'] = $c['comment_author_IP'];
$c['user_agent'] = $c['comment_agent'];
$c['referrer'] = '';
$c['blog'] = get_bloginfo('url');
$c['blog_lang'] = get_locale();
$c['blog_charset'] = get_option('blog_charset');
$c['permalink'] = get_permalink($c['comment_post_ID']);
$c['user_role'] = '';
if (isset($c['user_ID'])) {
$c['user_role'] = Akismet::get_user_roles($c['user_ID']);
}
if (Akismet::is_test_mode()) {
$c['is_test'] = 'true';
}
add_comment_meta($c['comment_ID'], 'akismet_rechecking', true);
$response = Akismet::http_post(http_build_query($c), 'comment-check');
if ('true' == $response[1]) {
wp_set_comment_status($c['comment_ID'], 'spam');
update_comment_meta($c['comment_ID'], 'akismet_result', 'true');
delete_comment_meta($c['comment_ID'], 'akismet_error');
delete_comment_meta($c['comment_ID'], 'akismet_delayed_moderation_email');
Akismet::update_comment_history($c['comment_ID'], __('Akismet re-checked and caught this comment as spam', 'akismet'), 'check-spam');
} elseif ('false' == $response[1]) {
update_comment_meta($c['comment_ID'], 'akismet_result', 'false');
delete_comment_meta($c['comment_ID'], 'akismet_error');
delete_comment_meta($c['comment_ID'], 'akismet_delayed_moderation_email');
Akismet::update_comment_history($c['comment_ID'], __('Akismet re-checked and cleared this comment', 'akismet'), 'check-ham');
// abnormal result: error
} else {
update_comment_meta($c['comment_ID'], 'akismet_result', 'error');
Akismet::update_comment_history($c['comment_ID'], sprintf(__('Akismet was unable to re-check this comment (response: %s)', 'akismet'), substr($response[1], 0, 50)), 'check-error');
}
delete_comment_meta($c['comment_ID'], 'akismet_rechecking');
}
if (defined('DOING_AJAX') && DOING_AJAX) {
wp_send_json(array('processed' => count((array) $moderation)));
} else {
$redirect_to = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : admin_url('edit-comments.php');
wp_safe_redirect($redirect_to);
exit;
}
}
示例13: wp_unspam_comment
/**
* Removes a comment from the Spam
*
* @since 2.9.0
*
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object.
* @return bool True on success, false on failure.
*/
function wp_unspam_comment($comment_id)
{
$comment = get_comment($comment_id);
if (!$comment) {
return false;
}
/**
* Fires immediately before a comment is unmarked as Spam.
*
* @since 2.9.0
*
* @param int $comment_id The comment ID.
*/
do_action('unspam_comment', $comment->comment_ID);
$status = (string) get_comment_meta($comment->comment_ID, '_wp_trash_meta_status', true);
if (empty($status)) {
$status = '0';
}
if (wp_set_comment_status($comment, $status)) {
delete_comment_meta($comment->comment_ID, '_wp_trash_meta_status');
delete_comment_meta($comment->comment_ID, '_wp_trash_meta_time');
/**
* Fires immediately after a comment is unmarked as Spam.
*
* @since 2.9.0
*
* @param int $comment_id The comment ID.
*/
do_action('unspammed_comment', $comment->comment_ID);
return true;
}
return false;
}
示例14: elseif
foreach ($_REQUEST['delete_comments'] as $comment) : // Check the permissions on each
$comment = (int) $comment;
$post_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = %d", $comment) );
if ( !current_user_can('edit_post', $post_id) )
continue;
if ( !empty( $_REQUEST['spamit'] ) ) {
wp_set_comment_status($comment, 'spam');
$comments_spammed++;
} elseif ( !empty( $_REQUEST['deleteit'] ) ) {
wp_set_comment_status($comment, 'delete');
$comments_deleted++;
} elseif ( !empty( $_REQUEST['approveit'] ) ) {
wp_set_comment_status($comment, 'approve');
$comments_approved++;
} elseif ( !empty( $_REQUEST['unapproveit'] ) ) {
wp_set_comment_status($comment, 'hold');
$comments_unapproved++;
}
endforeach;
$redirect_to = basename( __FILE__ ) . '?deleted=' . $comments_deleted . '&approved=' . $comments_approved . '&spam=' . $comments_spammed . '&unapproved=' . $comments_unapproved;
if ( isset($_REQUEST['apage']) )
$redirect_to = add_query_arg( 'apage', absint($_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);
wp_redirect( $redirect_to );
} elseif ( !empty($_GET['_wp_http_referer']) ) {
wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
示例15: comment_bulk_action
function comment_bulk_action()
{
//Read form data
$action = $_POST['action'];
$commentIds = explode(',', $_POST['ids']);
$information['success'] = 0;
foreach ($commentIds as $commentId) {
if ($commentId) {
$information['success']++;
if ('approve' === $action) {
wp_set_comment_status($commentId, 'approve');
} else {
if ('unapprove' === $action) {
wp_set_comment_status($commentId, 'hold');
} else {
if ('spam' === $action) {
wp_spam_comment($commentId);
} else {
if ('unspam' === $action) {
wp_unspam_comment($commentId);
} else {
if ('trash' === $action) {
wp_trash_comment($commentId);
} else {
if ('restore' === $action) {
wp_untrash_comment($commentId);
} else {
if ('delete' === $action) {
wp_delete_comment($commentId, true);
} else {
$information['success']--;
}
}
}
}
}
}
}
}
}
MainWP_Helper::write($information);
}