gdrts_core_user_rating

This class is initialized with the user ID. Using the provided method you can check if the user voted for specific rating item, return the last vote, or all user votes for given item.

Public Methods

Methods can be split into several groups.

Has Voted

has_voted
has_voted($args, $method = 'stars-rating', $series = null)

Check if the user has voted for the item supplied in the $args, for the provided $method and $series. Array $args contains following elements:

  • entity: item entity
  • name: item type name
  • id: item real ID
  • item_id: internal ID of the item, if this is provided, other elements are ignored
has_voted_for_item
has_voted_for_item($item_id, $method = 'stars-rating', $series = null)

Check if the user has voted for the item with $item_id, for the provided $method and $series.

has_voted_for_post
has_voted_for_post($post_id, $method = 'stars-rating', $series = null)

Check if the user has voted for the post with $post_id, for the provided $method and $series. This method works for any post type.

has_voted_in_loop
has_voted_in_loop($method = 'stars-rating', $series = null)

Check if the user has voted for the current post in the loop.

Get the Vote

get_the_vote
get_the_vote($args, $method = 'stars-rating', $series = null)

Get the last vote from the user for the item supplied in the $args, for the provided $method and $series. Array $args contains following elements:

  • entity: item entity
  • name: item type name
  • id: item real ID
  • item_id: internal ID of the item, if this is provided, other elements are ignored
get_the_vote_for_item
get_the_vote_for_item($item_id, $method = 'stars-rating', $series = null)

Get the last vote from the user for the item with $item_id, for the provided $method and $series.

get_the_vote_for_post
get_the_vote_for_post($post_id, $method = 'stars-rating', $series = null)

Get the last vote from the user for the post with $post_id, for the provided $method and $series. This method works for any post type.

get_the_vote_in_loop
get_the_vote_in_loop($method = 'stars-rating', $series = null)

Get the last vote from the user for the post in the loop.

Get all Votes

get_all_votes
get_all_votes($args, $method = 'stars-rating', $series = null)

Get all the votes (active and replaced) from the user for the item supplied in the $args, for the provided $method and $series. Array $args contains following elements:

  • entity: item entity
  • name: item type name
  • id: item real ID
  • item_id: internal ID of the item, if this is provided, other elements are ignored
get_all_votes_for_item
get_all_votes_for_item($item_id, $method = 'stars-rating', $series = null)

Get all the votes (active and replaced) from the user for the item with $item_id, for the provided $method and $series.

get_all_votes_for_post
get_all_votes_for_post($post_id, $method = 'stars-rating', $series = null)

Get all the votes (active and replaced) from the user for the post with $post_id, for the provided $method and $series. This method works for any post type.

get_all_votes_in_loop
get_all_votes_in_loop($method = 'stars-rating', $series = null)

Get all the votes (active and replaced) from the user for the post in the loop.

Public Properties

There are few public properties you can access:

  • $user_id: object user ID

Returned results

Methods to get the last vote and all the votes will return single vote or array of votes. Each vote is an object with properties including rating item, method, date and other things. It has the property called $meta where vote value is stored (along with some other things, depending on the rating method).

How to use it?

To initialize the object from this class, it is recomended to use gdrts_get_user_rating() or gdrts_get_current_user_rating() functions. Here are few examples:

// check if current user voted for post in the loop with
// Like This method. If yes, print the vote object
$user = gdrts_get_current_user_rating();
if ($user->has_voted_in_loop('like-this')) {
  print_r($user->get_the_vote_in_loop('like-this'));
}
// check if current user voted for post in the loop with
// Emote This method. If yes, print the vote object voted value
$user = gdrts_get_current_user_rating();
if ($user->has_voted_in_loop('emote-this', 'default')) {
  echo $user->get_the_vote_in_loop('like-this', 'default')->meta['vote'];
}
0
0
24
Rate this reference

You are not allowed to rate this post.

Comments

Leave a Reply