Last active
March 4, 2021 20:20
-
-
Save Alimir/44ac0bb2117862d46b46e8af4acfffd2 to your computer and use it in GitHub Desktop.
How to add vote fields to WordPress comments API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'rest_api_init', function () { | |
register_rest_field( 'comment', 'votes', array( | |
'get_callback' => function( $comment_arr ) { | |
return array( | |
'like_amount' => wp_ulike_get_comment_likes( $comment_arr['id'], 'like' ), | |
'dislike_amount' => wp_ulike_get_comment_likes( $comment_arr['id'], 'dislike' ), | |
'likers_list' => wp_ulike_get_likers_list_per_post( 'ulike_comments', 'comment_id', $comment_arr['id'], NULL ) | |
); | |
} | |
) ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment