/** * Update user meta of vote * @param integer $userid User ID who is voting. * @param string $type Vote type. * @param integer $actionid Post ID. * @param integer $receiving_userid User who is receiving vote. */ public function update_user_vote_casted_count($userid, $type, $actionid, $receiving_userid) { // Update total casted vote of user. update_user_meta($userid, '__up_vote_casted', ap_count_vote($userid, 'vote_up')); update_user_meta($userid, '__down_vote_casted', ap_count_vote($userid, 'vote_down')); // Update total received vote of user. update_user_meta($receiving_userid, '__up_vote_received', ap_count_vote(false, 'vote_up', false, $receiving_userid)); update_user_meta($receiving_userid, '__down_vote_received', ap_count_vote(false, 'vote_down', false, $receiving_userid)); }
public function ap_follow() { $args = $_POST['args']; if (wp_verify_nonce($args['nonce'], 'follow_' . $args['user'])) { $userid = (int) sanitize_text_field($args['user']); $user_following = ap_is_user_voted($userid, 'follow', get_current_user_id()); $user = get_userdata($userid); $user_name = $user->data->display_name; if (!$user_following) { $row = ap_add_vote(get_current_user_id(), 'follow', $userid); $action = 'follow'; $text = __('Unfollow', 'ap'); $title = sprintf(__('Unfollow %s', 'ap'), $user_name); $message = sprintf(__('You are now following %s', 'ap'), $user_name); } else { $row = ap_remove_vote('follow', get_current_user_id(), $userid); $action = 'unfollow'; $text = __('Follow', 'ap'); $title = sprintf(__('Follow %s', 'ap'), $user_name); $message = sprintf(__('You unfollowed %s', 'ap'), $user_name); } if ($row !== FALSE) { $followers = ap_count_vote(false, 'follow', $userid); $following = ap_count_vote(get_current_user_id(), 'follow'); update_user_meta($userid, AP_FOLLOWERS_META, $followers); update_user_meta(get_current_user_id(), AP_FOLLOWING_META, $following); $result = apply_filters('ap_follow_result', array('row' => $row, 'action' => $action, 'text' => $text, 'id' => $userid, 'title' => $title, 'message' => $message, 'following_count' => $following, 'followers_count' => $followers)); echo json_encode($result); } else { echo json_encode(array('action' => false, 'message' => _('Unable to process your request, please try again.', 'ap'))); } } else { echo json_encode(array('action' => false, 'message' => _('Something went wrong', 'ap'))); } die; }