Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.
This repository was archived by the owner on Sep 24, 2018. It is now read-only.

Add endpoints to create, update and delete comments #86

@royboy789

Description

@royboy789

This is a bit specific to my case, but figured it would be worth sharing how I added in new comments into the API.

public function newComment( $id, $data ) {
        $time = current_time('mysql');
        $data = array(
            'comment_post_ID' => $data['id'],
            'comment_author' => $data['author'],
            'comment_author_email' => $data['comment_author_email'],
            'comment_content' => $data['content'],
            'comment_date' => $time,
            'comment_approved' => 1
        );
        $newComment = wp_insert_comment($data);
        return $newComment;
}

I pass the ID into $data, but can easily just be grabbed from $id.

I will eventually be adding in logged in vs. not logged in, but I think that will primarily just be front end to retain as much of this API function as possible for either use case.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions