Пример #1
0
function akismet_transition_comment_status($new_status, $old_status, $comment)
{
    if ($new_status == $old_status) {
        return;
    }
    if ($new_status == 'spam') {
        akismet_submit_spam_comment($comment->comment_ID);
    } elseif ($old_status == 'spam' && ($new_status == 'approved' || $new_status == 'unapproved')) {
        akismet_submit_nonspam_comment($comment->comment_ID);
    }
}
Пример #2
0
function akismet_transition_comment_status($new_status, $old_status, $comment)
{
    if ($new_status == $old_status) {
        return;
    }
    # we don't need to record a history item for deleted comments
    if ($new_status == 'delete') {
        return;
    }
    if (!is_admin()) {
        return;
    }
    if (!current_user_can('edit_post', $comment->comment_post_ID) && !current_user_can('moderate_comments')) {
        return;
    }
    if (defined('WP_IMPORTING') && WP_IMPORTING == true) {
        return;
    }
    // if this is present, it means the status has been changed by a re-check, not an explicit user action
    if (get_comment_meta($comment->comment_ID, 'akismet_rechecking')) {
        return;
    }
    global $current_user;
    $reporter = '';
    if (is_object($current_user)) {
        $reporter = $current_user->user_login;
    }
    // Assumption alert:
    // We want to submit comments to Akismet only when a moderator explicitly spams or approves it - not if the status
    // is changed automatically by another plugin.  Unfortunately WordPress doesn't provide an unambiguous way to
    // determine why the transition_comment_status action was triggered.  And there are several different ways by which
    // to spam and unspam comments: bulk actions, ajax, links in moderation emails, the dashboard, and perhaps others.
    // We'll assume that this is an explicit user action if POST or GET has an 'action' key.
    if (isset($_POST['action']) || isset($_GET['action'])) {
        if ($new_status == 'spam' && ($old_status == 'approved' || $old_status == 'unapproved' || !$old_status)) {
            return akismet_submit_spam_comment($comment->comment_ID);
        } elseif ($old_status == 'spam' && ($new_status == 'approved' || $new_status == 'unapproved')) {
            return akismet_submit_nonspam_comment($comment->comment_ID);
        }
    }
    akismet_update_comment_history($comment->comment_ID, sprintf(__('%s changed the comment status to %s'), $reporter, $new_status), 'status-' . $new_status);
}