Sorry if this is too simple but I am new with php.
I need to change the number of votes from my react native app. I have an endpoint in function.php but I don't know how to use wpdiscuz to add a like or dislike to comment. My code looks like this:
add_action( 'rest_api_init', function () { register_rest_route( 'wp/v2/comments_extended', '/change/(?P\d+)/(?P[a-z]+)', array( 'methods' => 'PUT', 'callback' => 'change_comment_votes' ) ); } ); function change_comment_votes( $request ) { global $wpdb; $commentId = $request['comment_id']; $voteType = $request['vote_type']; if (strcmp($voteType, 'like') === 0) { } else { } }
Or is there a different way to this if at all possible?
Hi @stevara,
We're really sorry, but there is no way for adding like/dislike via REST API.
You can view the "voteOnComment" method in the WpdiscuzHelperAjax class, it'll help you better understand how the wpDiscuz votes are realised.
I see that update_comment_meta function is being called where I guess comment_meta table is being updated. And also updateVoteType function in WPDiscuzDBManager.php where wc_users_voted table is updated.
Can I get the meta_value field from comment_meta in my endpoint, change it and then update the comment_meta database?
Also with the wc_users_voted table but I see that I will need to add new row there (although there is an UPDATE statement in updateVoteType). The user_id will then need to be an ip address of the user if I'm right? (I allow anonymous commenting and voting). And if id field in that table is somehow set to be auto filled..