wp_get_comment_status example


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. */
$comment = get_comment( $id );

    if ( ! $comment ) {
        wp_die( time() );
    }

    if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
        wp_die( -1 );
    }

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


            if ( 'view' === $action && '1' !== $comment->comment_approved ) {
                $action .= ' hidden';
            }

            $actions_string .= "<span class='$action'>{$separator}{$link}</span>";
        }
    }
    ?> <li id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status( $comment ) )$comment ); ?>> <?php             $comment_row_class = '';

            if ( get_option( 'show_avatars' ) ) {
                echo get_avatar( $comment, 50, 'mystery' );
                $comment_row_class .= ' has-avatar';
            }
            ?> <?php if ( ! $comment->comment_type || 'comment' === $comment->comment_type ) : ?>


            // 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( $event ) ) {
                delete_comment_meta( $comment_id, 'akismet_error' );
                self::update_comment_history( $comment_id, '', $event );
                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 if ( get_comment_meta( $comment_id, 'akismet_delayed_moderation_email', true ) )
                            wp_notify_moderator( $comment_id );
                    }
                }
                
                

do_action( 'set_comment_cookies', $comment$user$cookies_consent );

$location = empty( $_POST['redirect_to'] ) ? get_comment_link( $comment ) : $_POST['redirect_to'] . '#comment-' . $comment->comment_ID;

// If user didn't consent to cookies, add specific query arguments to display the awaiting moderation message. if ( ! $cookies_consent && 'unapproved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_author_email ) ) {
    $location = add_query_arg(
        array(
            'unapproved'      => $comment->comment_ID,
            'moderation-hash' => wp_hash( $comment->comment_date_gmt ),
        ),
        $location
    );
}

/** * Filters the location URI to send the commenter after posting. * * @since 2.0.5 * * @param string $location The 'redirect_to' URI sent via $_POST. * @param WP_Comment $comment Comment object. */
<div class="wrap"> <h1><?php _e( 'Edit Comment' ); ?></h1> <div id="poststuff"> <input type="hidden" name="action" value="editedcomment" /> <input type="hidden" name="comment_ID" value="<?php echo esc_attr( $comment->comment_ID ); ?>" /> <input type="hidden" name="comment_post_ID" value="<?php echo esc_attr( $comment->comment_post_ID ); ?>" /> <div id="post-body" class="metabox-holder columns-2"> <div id="post-body-content" class="edit-form-section edit-comment-section"> <?php if ( 'approved' === wp_get_comment_status( $comment ) && $comment->comment_post_ID > 0 ) :
    $comment_link = get_comment_link( $comment );
    ?> <div class="inside"> <div id="comment-link-box"> <strong><?php _ex( 'Permalink:', 'comment' ); ?></strong> <span id="sample-permalink"> <a href="<?php echo esc_url( $comment_link ); ?>"> <?php echo esc_html( $comment_link ); ?> </a> </span> </div> </div>
do_action( 'comment_add_author_url' );
                print( wp_update_comment( $comment ) );
                die();
            }
        }
    }

    public static function comment_row_action( $a$comment ) {
        $akismet_result = get_comment_meta( $comment->comment_ID, 'akismet_result', true );
        $akismet_error  = get_comment_meta( $comment->comment_ID, 'akismet_error', true );
        $user_result    = get_comment_meta( $comment->comment_ID, 'akismet_user_result', true);
        $comment_status = wp_get_comment_status( $comment->comment_ID );
        $desc = null;
        if ( $akismet_error ) {
            $desc = __( 'Awaiting spam check' , 'akismet');
        } elseif ( !$user_result || $user_result == $akismet_result ) {
            // Show the original Akismet result if the user hasn't overridden it, or if their decision was the same             if ( $akismet_result == 'true' && $comment_status != 'spam' && $comment_status != 'trash' )
                $desc = __( 'Flagged as spam by Akismet' , 'akismet');
            elseif ( $akismet_result == 'false' && $comment_status == 'spam' )
                $desc = __( 'Cleared by Akismet' , 'akismet');
        } else {
            $who = get_comment_meta( $comment->comment_ID, 'akismet_user', true );
            
/** * Sets the comment_status of a given comment object when creating or updating a comment. * * @since 4.7.0 * * @param string|int $new_status New comment status. * @param int $comment_id Comment ID. * @return bool Whether the status was changed. */
    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;
            
/** * @global WP_Post $post Global post object. * @global WP_Comment $comment Global comment object. * * @param WP_Comment $item */
    public function single_row( $item ) {
        global $post$comment;

        $comment = $item;

        $the_comment_class = wp_get_comment_status( $comment );

        if ( ! $the_comment_class ) {
            $the_comment_class = '';
        }

        $the_comment_class = implode( ' ', get_comment_class( $the_comment_class$comment$comment->comment_post_ID ) );

        if ( $comment->comment_post_ID > 0 ) {
            $post = get_post( $comment->comment_post_ID );
        }

        
<?php _e( 'Submitted on' ); ?></th> <td> <?php         $submitted = sprintf(
            /* translators: 1: Comment date, 2: Comment time. */
            __( '%1$s at %2$s' ),
            /* translators: Comment date format. See https://www.php.net/manual/datetime.format.php */
            get_comment_date( __( 'Y/m/d' )$comment ),
            /* translators: Comment time format. See https://www.php.net/manual/datetime.format.php */
            get_comment_date( __( 'g:i a' )$comment )
        );
        if ( 'approved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_post_ID ) ) {
            echo '<a href="' . esc_url( get_comment_link( $comment ) ) . '">' . $submitted . '</a>';
        } else {
            echo $submitted;
        }
        ?> </td> </tr> <tr> <th scope="row"><?php /* translators: Field name in comment form. */ _ex( 'Comment', 'noun' ); ?></th> <td class="comment-content"> <?php comment_text( $comment ); ?>
Home | Imprint | This part of the site doesn't use cookies.