wp_trash_comment example


            }

            if ( 'trash' === $comment->comment_approved ) {
                return new WP_Error(
                    'rest_already_trashed',
                    __( 'The comment has already been trashed.' ),
                    array( 'status' => 410 )
                );
            }

            $result   = wp_trash_comment( $comment->comment_ID );
            $comment  = get_comment( $comment->comment_ID );
            $response = $this->prepare_item_for_response( $comment$request );
        }

        if ( ! $result ) {
            return new WP_Error(
                'rest_cannot_delete',
                __( 'The comment cannot be deleted.' ),
                array( 'status' => 500 )
            );
        }

        


    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 );

        // Undo trash, not in Trash.         if ( ! isset( $_POST['comment_status'] ) || 'trash' !== $_POST['comment_status'] ) {
            $delta = 1;
        }
    }
$unapproved++;
                break;
            case 'spam':
                wp_spam_comment( $comment_id );
                $spammed++;
                break;
            case 'unspam':
                wp_unspam_comment( $comment_id );
                $unspammed++;
                break;
            case 'trash':
                wp_trash_comment( $comment_id );
                $trashed++;
                break;
            case 'untrash':
                wp_untrash_comment( $comment_id );
                $untrashed++;
                break;
            case 'delete':
                wp_delete_comment( $comment_id );
                $deleted++;
                break;
        }
    }
$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 );
                

function wp_delete_comment( $comment_id$force_delete = false ) {
    global $wpdb;

    $comment = get_comment( $comment_id );
    if ( ! $comment ) {
        return false;
    }

    if ( ! $force_delete && EMPTY_TRASH_DAYS && ! in_array( wp_get_comment_status( $comment ), array( 'trash', 'spam' ), true ) ) {
        return wp_trash_comment( $comment_id );
    }

    /** * Fires immediately before a comment is deleted from the database. * * @since 1.2.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 deleted. */
    
Home | Imprint | This part of the site doesn't use cookies.