wp_update_comment example

return $result_counts;
    }

    // Adds an 'x' link next to author URLs, clicking will remove the author URL and show an undo link     public static function remove_comment_author_url() {
        if ( !empty( $_POST['id'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) {
            $comment_id = intval( $_POST['id'] );
            $comment = get_comment( $comment_id, ARRAY_A );
            if ( $comment && current_user_can( 'edit_comment', $comment['comment_ID'] ) ) {
                $comment['comment_author_url'] = '';
                do_action( 'comment_remove_author_url' );
                print( wp_update_comment( $comment ) );
                die();
            }
        }
    }

    public static function add_comment_author_url() {
        if ( !empty( $_POST['id'] ) && !empty( $_POST['url'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) {
            $comment_id = intval( $_POST['id'] );
            $comment = get_comment( $comment_id, ARRAY_A );
            if ( $comment && current_user_can( 'edit_comment', $comment['comment_ID'] ) ) {
                $comment['comment_author_url'] = esc_url( $_POST['url'] );
                
$comment['comment_author'] = $content_struct['author'];
        }

        if ( isset( $content_struct['author_url'] ) ) {
            $comment['comment_author_url'] = $content_struct['author_url'];
        }

        if ( isset( $content_struct['author_email'] ) ) {
            $comment['comment_author_email'] = $content_struct['author_email'];
        }

        $result = wp_update_comment( $comment, true );
        if ( is_wp_error( $result ) ) {
            return new IXR_Error( 500, $result->get_error_message() );
        }

        if ( ! $result ) {
            return new IXR_Error( 500, __( 'Sorry, the comment could not be updated.' ) );
        }

        /** * Fires after a comment has been successfully updated via XML-RPC. * * @since 3.4.0 * * @param int $comment_id ID of the updated comment. * @param array $args An array of arguments to update the comment. */
$check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_args );

            if ( is_wp_error( $check_comment_lengths ) ) {
                $error_code = $check_comment_lengths->get_error_code();
                return new WP_Error(
                    $error_code,
                    __( 'Comment field exceeds maximum length allowed.' ),
                    array( 'status' => 400 )
                );
            }

            $updated = wp_update_comment( wp_slash( (array) $prepared_args ), true );

            if ( is_wp_error( $updated ) ) {
                return new WP_Error(
                    'rest_comment_failed_edit',
                    __( 'Updating comment failed.' ),
                    array( 'status' => 500 )
                );
            }

            if ( isset( $request['status'] ) ) {
                $this->handle_status_param( $request['status']$id );
            }
$hh = $_POST['hh'];
        $mn = $_POST['mn'];
        $ss = $_POST['ss'];
        $jj = ( $jj > 31 ) ? 31 : $jj;
        $hh = ( $hh > 23 ) ? $hh - 24 : $hh;
        $mn = ( $mn > 59 ) ? $mn - 60 : $mn;
        $ss = ( $ss > 59 ) ? $ss - 60 : $ss;

        $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
    }

    return wp_update_comment( $_POST, true );
}

/** * Returns a WP_Comment object based on comment ID. * * @since 2.0.0 * * @param int $id ID of comment to retrieve. * @return WP_Comment|false Comment if found. False on failure. */
function get_comment_to_edit( $id ) {
    
Home | Imprint | This part of the site doesn't use cookies.