/** * Displays the post comments sorted by weight/karma DESC. * * @param array $args */ function hmn_cp_the_sorted_comments($args = array()) { if (class_exists('CommentPopularity\\HMN_Comment_Popularity')) { $hmn_cp_obj = CommentPopularity\HMN_Comment_Popularity::get_instance(); global $post; if (!array_key_exists('post_id', $args)) { $args['post_id'] = $post->ID; } if (!array_key_exists('callback', $args)) { $args['callback'] = array($hmn_cp_obj, 'comment_callback'); } echo $hmn_cp_obj->get_comments_sorted_by_weight(true, $args); } }
function hmn_cp_init() { $comment_popularity = CommentPopularity\HMN_Comment_Popularity::get_instance(); if (is_user_logged_in()) { $visitor = new CommentPopularity\HMN_CP_Visitor_Member(get_current_user_id()); } elseif ($comment_popularity->is_guest_voting_allowed()) { $visitor = new CommentPopularity\HMN_CP_Visitor_Guest($_SERVER['REMOTE_ADDR']); } else { return; } if (!$comment_popularity->get_visitor() instanceof CommentPopularity\HMN_CP_Visitor) { $comment_popularity->set_visitor($visitor); } }
// Remove User meta $args = array('meta_query' => array(array('key' => $wpdb->get_blog_prefix() . 'hmn_user_expert_status', 'compare' => 'EXISTS')), 'fields' => 'all'); // Delete user expert status $user_query = new WP_User_Query($args); if (!empty($user_query->results)) { foreach ($user_query->results as $user) { delete_user_meta($user->ID, 'hmn_user_expert_status'); delete_user_option($user->ID, 'hmn_user_expert_status'); } } $args = array('meta_query' => array(array('key' => $wpdb->get_blog_prefix() . 'hmn_user_karma', 'compare' => 'EXISTS')), 'fields' => 'all'); $user_query = new WP_User_Query($args); if (!empty($user_query->results)) { foreach ($user_query->results as $user) { delete_user_meta($user->ID, 'hmn_user_karma'); delete_user_option($user->ID, 'hmn_user_karma'); } } $args = array('meta_query' => array(array('key' => $wpdb->get_blog_prefix() . 'hmn_comments_voted_on', 'compare' => 'EXISTS')), 'fields' => 'all'); $user_query = new WP_User_Query($args); if (!empty($user_query->results)) { foreach ($user_query->results as $user) { delete_user_option($user->ID, 'hmn_comments_voted_on'); } } // Select all comments with karma > 0, and reset value to zero. $wpdb->query($wpdb->prepare("UPDATE wp_comments SET comment_karma=0 WHERE comment_karma > %d", 0)); // Remove custom capabilities require_once plugin_dir_path(__FILE__) . 'inc/class-comment-popularity.php'; $cp_plugin = CommentPopularity\HMN_Comment_Popularity::get_instance();