-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rest-api endpoint #90
Comments
Nope, I have no time to add that in. Feel free to fork it and add it in =) |
Ok ! |
FYI, you will find that here in the -dev branch I split to code to permit the use of a REST API |
@lesterchan any hope/plan to see -dev merged? |
@drzraf nope. It is still too huge a change and I have not look through the code yet. We also need more testers. If you really need it out in the public urgently, why not fork the plugin release the plugin as your own? Maybe like WP-PostRatings Plus or WP-PostRatings Adv. |
For the record, this the code of my API endpoint (where comment are submitted through REST and can have an optional /*
Copyright (C) 2017, Raphaël Droz
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
*/
class WP_REST_Vote_Comments_Field {
static function rest_api_init_additional_fields() {
register_rest_field( 'comment',
'vote',
array(
'get_callback' => [__CLASS__, 'comment_get_vote'],
'update_callback' => [__CLASS__, 'comment_set_vote'],
'schema' => array(
'description' => __( 'Rate associated with the comment.' ),
'type' => 'integer',
'minimum' => 0,
'maximum' => intval(get_option('postratings_max'))
),
)
);
}
static function comment_get_vote( $object, $field_name, $request ) {
if ( ( $rate_id = get_comment_meta( $object['id'], 'postratings_id', true ) ) ) {
if (intval($rate_id)) {
global $wpdb;
$rate = $wpdb->get_var( $wpdb->prepare( "SELECT rating_rating FROM {$wpdb->ratings} WHERE rating_id = %d", intval($rate_id)) );
return $rate ? intval($rate) : false;
}
}
return false;
}
static function comment_set_vote( $value, $object, $field_name ) {
if ( ! $value || ! is_numeric( $value ) || $field_name == 'vote' ) {
return;
}
if ( ! is_plugin_active('wp-postratings/wp-postratings.php') ||
! function_exists('process_ratings_from_rest_API')) {
return ;
}
$vote_from_API = process_ratings_from_rest_API($object, intval($value));
if ($vote_from_API === true ) {
return $rate;
}
// WP_Error || false
return $vote_from_API;
}
} |
Hi !
I begin to use this nice plugin, but I need to have a API endpoint.
It's planned ?
Thank you !
The text was updated successfully, but these errors were encountered: