function tptn_disp_count() { $id = intval($_GET['top_ten_id']); if ($id > 0) { $output = get_tptn_post_count($id); echo 'document.write("' . $output . '")'; } }
/** * Function to manually display count. * * @since 1.0 * @param int|boolean $echo Flag to echo the output? * @return string Formatted string if $echo is set to 0|false */ function echo_tptn_post_count($echo = 1) { global $post, $tptn_url, $tptn_path, $tptn_settings; $home_url = home_url('/'); /** * Filter the script URL of the counter. * * Create a filter function to overwrite the script URL to use the external top-10-counter.js.php * You can use $tptn_url . '/top-10-counter.js.php' as a source * $tptn_url is a global variable * * @since 2.0 */ $home_url = apply_filters('tptn_view_counter_script_url', $home_url); $id = intval($post->ID); $nonce_action = 'tptn-nonce-' . $id; $nonce = wp_create_nonce($nonce_action); if ($tptn_settings['dynamic_post_count']) { $output = '<div class="tptn_counter" id="tptn_counter_' . $id . '"><script type="text/javascript" data-cfasync="false" src="' . $home_url . '?top_ten_id=' . $id . '&view_counter=1&_wpnonce=' . $nonce . '"></script></div>'; } else { $output = '<div class="tptn_counter" id="tptn_counter_' . $id . '">' . get_tptn_post_count($id) . '</div>'; } /** * Filter the viewed count script * * @since 2.0.0 * * @param string $output Counter viewed count code */ $output = apply_filters('tptn_view_post_count', $output); if ($echo) { echo $output; } else { return $output; } }
/** * Function to manually display count. * * @access public * @param int|boolean $echo (default: 1) * @return string */ function echo_tptn_post_count($echo = 1) { global $post, $tptn_url, $tptn_path; global $tptn_settings; $id = intval($post->ID); $nonce_action = 'tptn-nonce-' . $id; $nonce = wp_create_nonce($nonce_action); if ($tptn_settings['dynamic_post_count']) { $output = '<div class="tptn_counter" id="tptn_counter_' . $id . '"><script type="text/javascript" data-cfasync="false" src="' . $tptn_url . '/top-10-counter.js.php?top_ten_id=' . $id . '&_wpnonce=' . $nonce . '"></script></div>'; } else { $output = '<div class="tptn_counter" id="tptn_counter_' . $id . '">' . get_tptn_post_count($id) . '</div>'; } if ($echo) { echo $output; } else { return $output; } }