wp_new_comment example

if ( $parent && '0' === $parent->comment_approved && $parent->comment_post_ID == $comment_post_id ) {
            if ( ! current_user_can( 'edit_comment', $parent->comment_ID ) ) {
                wp_die( -1 );
            }

            if ( wp_set_comment_status( $parent, 'approve' ) ) {
                $comment_auto_approved = true;
            }
        }
    }

    $comment_id = wp_new_comment( $commentdata );

    if ( is_wp_error( $comment_id ) ) {
        wp_die( $comment_id->get_error_message() );
    }

    $comment = get_comment( $comment_id );

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

    

    $allow_empty_comment = apply_filters( 'allow_empty_comment', false, $commentdata );
    if ( '' === $comment_content && ! $allow_empty_comment ) {
        return new WP_Error( 'require_valid_comment', __( '<strong>Error:</strong> Please type your comment text.' ), 200 );
    }

    $check_max_lengths = wp_check_comment_data_max_lengths( $commentdata );
    if ( is_wp_error( $check_max_lengths ) ) {
        return $check_max_lengths;
    }

    $comment_id = wp_new_comment( wp_slash( $commentdata ), true );
    if ( is_wp_error( $comment_id ) ) {
        return $comment_id;
    }

    if ( ! $comment_id ) {
        return new WP_Error( 'comment_save_error', __( '<strong>Error:</strong> The comment could not be saved. Please try again later.' ), 500 );
    }

    return get_comment( $comment_id );
}

/** This filter is documented in wp-includes/comment.php */
        $allow_empty = apply_filters( 'allow_empty_comment', false, $comment );

        if ( ! $allow_empty && '' === $comment['comment_content'] ) {
            return new IXR_Error( 403, __( 'Comment is required.' ) );
        }

        /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
        do_action( 'xmlrpc_call', 'wp.newComment', $args$this );

        $comment_id = wp_new_comment( $comment, true );
        if ( is_wp_error( $comment_id ) ) {
            return new IXR_Error( 403, $comment_id->get_error_message() );
        }

        if ( ! $comment_id ) {
            return new IXR_Error( 403, __( 'Something went wrong.' ) );
        }

        /** * Fires after a new comment has been successfully created via XML-RPC. * * @since 3.4.0 * * @param int $comment_id ID of the new comment. * @param array $args An array of new comment arguments. */
'comment_post_ID' => $comment_post_id,
    );

    $commentdata += compact(
        'comment_author',
        'comment_author_email',
        'comment_author_url',
        'comment_content',
        'comment_type'
    );

    $result = wp_new_comment( $commentdata );

    if ( is_wp_error( $result ) ) {
        trackback_response( 1, $result->get_error_message() );
    }

    $trackback_id = $wpdb->insert_id;

    /** * Fires after a trackback is added to a post. * * @since 1.2.0 * * @param int $trackback_id Trackback ID. */
Home | Imprint | This part of the site doesn't use cookies.