/** * Save a visit to the post or page. * * @param WP_Post $postObject: The post being generated * @return null **/ function kp_saveVisit($postObject) { global $wp_query, $kp_firstPost; // Check that we are on a Page or Post // !is_single() -- Don't save the post when we aren't on a single post page // !is_page() -- Don't save the post when we aren't on a single page being // !$kp_firstPost -- Don't save the visit after the first post in the loop if (!is_single() && !is_page() && !$kp_firstPost) { return; } // TODO: Create a better way to check if the user is visiting the post // Check if we want to collect statistics if (get_option("kp_CollectStatistics", "true") == "false") { return; } // If we are in test mode and if the current user is an admin, don't collect their visit data if (get_option("kp_AdminTestMode", "false") == "true" && kp_isUserAdmin()) { return; } // At this point, a non-admin user's visit will be tracked even if we are in test mode $kp_firstPost = false; // Set this to false to short circuit when kp_saveVisit is called on the next $postObject in the loop // Get the user's data and save the visit $arr = kp_getUserData(); extract($arr); $recommender = new kp_recommender($ip, $ua); $recommender->saveVisit($wp_query->post->ID); return null; }
/** * Render the recommended posts, either using $this->template or the rendered posts * * @param string $template: The template to use to render (must contain {kp_recommendedPosts} to generate a list of posts) * @param Array $data: Data that should be used in rendering * @return string: The rendered Html **/ public function render($template = "", $data = array()) { return kp_recommender::renderPosts($this->posts, $template, $data); }