wp_set_comment_status example


    
    public static function recheck_comment( $id$recheck_reason = 'recheck_queue' ) {
        add_comment_meta( $id, 'akismet_rechecking', true );
        
        $api_response = self::check_db_comment( $id$recheck_reason );

        if ( is_wp_error( $api_response ) ) {
            // Invalid comment ID.         }
        else if ( 'true' === $api_response ) {
            wp_set_comment_status( $id, 'spam' );
            update_comment_meta( $id, 'akismet_result', 'true' );
            delete_comment_meta( $id, 'akismet_error' );
            delete_comment_meta( $id, 'akismet_delayed_moderation_email' );
            Akismet::update_comment_history( $id, '', 'recheck-spam' );
        }
        elseif ( 'false' === $api_response ) {
            update_comment_meta( $id, 'akismet_result', 'false' );
            delete_comment_meta( $id, 'akismet_error' );
            delete_comment_meta( $id, 'akismet_delayed_moderation_email' );
            Akismet::update_comment_history( $id, '', 'recheck-ham' );
        }
        
protected function handle_status_param( $new_status$comment_id ) {
        $old_status = wp_get_comment_status( $comment_id );

        if ( $new_status === $old_status ) {
            return false;
        }

        switch ( $new_status ) {
            case 'approved':
            case 'approve':
            case '1':
                $changed = wp_set_comment_status( $comment_id, 'approve' );
                break;
            case 'hold':
            case '0':
                $changed = wp_set_comment_status( $comment_id, 'hold' );
                break;
            case 'spam':
                $changed = wp_spam_comment( $comment_id );
                break;
            case 'unspam':
                $changed = wp_unspam_comment( $comment_id );
                break;
            
'spammed' => '1',
                        'ids'     => $comment_id,
                    ),
                    $redir
                );
                break;
            case 'unspamcomment':
                wp_unspam_comment( $comment );
                $redir = add_query_arg( array( 'unspammed' => '1' )$redir );
                break;
            case 'approvecomment':
                wp_set_comment_status( $comment, 'approve' );
                $redir = add_query_arg( array( 'approved' => 1 )$redir );
                break;
            case 'unapprovecomment':
                wp_set_comment_status( $comment, 'hold' );
                $redir = add_query_arg( array( 'unapproved' => 1 )$redir );
                break;
        }

        wp_redirect( $redir );
        die;

    


    $current = wp_get_comment_status( $comment );

    if ( isset( $_POST['new'] ) && $_POST['new'] == $current ) {
        wp_die( time() );
    }

    check_ajax_referer( "approve-comment_$id);

    if ( in_array( $current, array( 'unapproved', 'spam' ), true ) ) {
        $result = wp_set_comment_status( $comment, 'approve', true );
    } else {
        $result = wp_set_comment_status( $comment, 'hold', true );
    }

    if ( is_wp_error( $result ) ) {
        $x = new WP_Ajax_Response(
            array(
                'what' => 'comment',
                'id'   => $result,
            )
        );
        
/** * Fires immediately before a comment is sent to the Trash. * * @since 2.9.0 * @since 4.9.0 Added the `$comment` parameter. * * @param string $comment_id The comment ID as a numeric string. * @param WP_Comment $comment The comment to be trashed. */
    do_action( 'trash_comment', $comment->comment_ID, $comment );

    if ( wp_set_comment_status( $comment, 'trash' ) ) {
        delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' );
        delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' );
        add_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', $comment->comment_approved );
        add_comment_meta( $comment->comment_ID, '_wp_trash_meta_time', time() );

        /** * Fires immediately after a comment is sent to Trash. * * @since 2.9.0 * @since 4.9.0 Added the `$comment` parameter. * * @param string $comment_id The comment ID as a numeric string. * @param WP_Comment $comment The trashed comment. */
$redirect_to = add_query_arg( 'paged', $pagenum$redirect_to );

    wp_defer_comment_counting( true );

    foreach ( $comment_ids as $comment_id ) { // Check the permissions on each.         if ( ! current_user_can( 'edit_comment', $comment_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':
                wp_spam_comment( $comment_id );
                $spammed++;
                break;
            case 'unspam':
                
Home | Imprint | This part of the site doesn't use cookies.