/** * Update article usefulness * @param (Int) $post_id The post id */ function ht_voting_update_article_usefulness($post_id) { $usefulness = 0; //get all votes $votes = ht_voting_get_post_votes($post_id); foreach ($votes as $key => $vote) { //update the helpfulness if (is_a($vote, 'HT_Vote_Up')) { $usefulness++; } elseif (is_a($vote, 'HT_Vote_Down')) { $usefulness--; } } //update the usefulness update_post_meta($post_id, HT_USEFULNESS_KEY, $usefulness); }
function render_article_votes($post) { $post_id = $post->ID; //get votes echo '<table class="ht-voting-backend-vote-list wp-list-table widefat fixed striped">'; echo '<thead>'; echo '<tr>'; echo '<th>' . __('Rating', 'ht-knowledge-base') . '</th>'; echo '<th>' . __('Date', 'ht-knowledge-base') . '</th>'; echo '<th>' . __('User/IP', 'ht-knowledge-base') . '</th>'; echo '<th>' . __('Comments', 'ht-knowledge-base') . '</th>'; echo '<th>' . __('Options', 'ht-knowledge-base') . '</th>'; echo '</tr>'; echo '</thead>'; //upgrade check $votes = ht_voting_get_post_votes($post_id); foreach ($votes as $key => $vote) { if (property_exists($vote, 'key') && $vote->key) { //no upgrade required } else { //perform upgrade HT_Voting::ht_kb_voting_upgrade_votes($post_id); break; } } //reassign $votes = ht_voting_get_post_votes($post_id); foreach ($votes as $key => $vote) { if (property_exists($vote, 'key') && $vote->key) { $key = $vote->key; } else { delete_post_meta($post_id, HT_VOTING_KEY, $vote); $vote = $this->upgrade_vote($key, $post_id, $vote); $key = $vote->key; } $key = $vote->key; $rating = $vote->magnitude; $delete_link = admin_url('post.php?post=' . $post->ID . '&action=edit'); $delete_href = '<button class="ht-voting-delete-vote button" data-vote-key="' . $key . '" data-post-id="' . $post_id . '" href="' . $delete_link . '">' . __('Delete This Vote', 'ht-knowledge-base') . '</button>'; if ($rating == 10) { $rating = __('Up', 'ht-knowledge-base'); } else { $rating = __('Down', 'ht-knowledge-base'); } $date_order = $vote->time; $date = date('H:i d/m/Y', $vote->time); $user_id = $vote->user_id; $user = $vote->ip; if ('' != $user_id) { $user_info = get_userdata($user_id); $user_name = $user_info->user_login; $user = '******' . get_edit_user_link($user_id) . '" target="_blank">' . $user_name . '</a>'; } $comments = ''; if (property_exists($vote, 'comments') && $vote->comments) { $comments = $vote->comments; } echo '<tr>'; echo '<td>' . $rating . '</td>'; echo '<td data-order="' . $date_order . '">' . $date . '</td>'; echo '<td>' . $user . '</td>'; echo '<td>' . $comments . '</td>'; echo '<td>' . $delete_href . '</td>'; echo '</tr>'; } echo '</table>'; }