forked from wpgeeks/wp-most-popular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-most-popular.php
82 lines (67 loc) · 2.83 KB
/
wp-most-popular.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/*
Plugin Name: WP Most Popular
Plugin URI: http://mattgeri.com/projects/
Description: Flexible plugin to show most popular posts based on views
Version: 0.2
Author: Matt Geri
Author URI: http://mattgeri.com
License: GPL2
Copyright 2011 Matt Geri (email: [email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
if ( phpversion() > 5 ) {
// Setup our path
define( 'WMP_PATH', dirname(__FILE__) . '/' );
// Setup activation and deactivation
register_activation_hook( WP_PLUGIN_DIR . '/wp-most-popular/wp-most-popular.php', 'WMP_system::install' );
register_deactivation_hook( WP_PLUGIN_DIR . '/wp-most-popular/wp-most-popular.php', 'WMP_system::uninstall' );
// Include our helpers
include_once( WMP_PATH . 'system/helpers.php' );
// Class for installation and uninstallation
class WMP_system{
public static function actions() {
// Check for token
if ( ! wp_verify_nonce( $_POST['token'], 'wmp_token' ) ) die();
include_once( WMP_PATH . 'system/track.php' );
$track = new WMP_track( intval( $_POST['id'] ) );
}
public static function install() {
include_once( WMP_PATH . 'system/setup.php' );
WMP_setup::install();
}
public static function javascript() {
global $wp_query;
wp_reset_query();
wp_print_scripts('jquery');
$token = wp_create_nonce( 'wmp_token' );
if ( ! is_front_page() && ( is_page() || is_single() ) ) {
echo '<!-- WordPress Most Popular --><script type="text/javascript">/* <![CDATA[ */ jQuery.post("' . admin_url('admin-ajax.php') . '", { action: "wmp_update", id: ' . $wp_query->post->ID . ', token: "' . $token . '" }); /* ]]> */</script><!-- /WordPress Most Popular -->';
}
}
public static function uninstall() {
include_once( WMP_PATH . 'system/setup.php' );
WMP_setup::uninstall();
}
public static function widget() {
register_widget( 'WMP_Widget' );
}
}
// Use ajax for tracking popular posts
add_action( 'wp_head', 'WMP_system::javascript' );
add_action( 'wp_ajax_wmp_update', 'WMP_system::actions' );
// Comment out to stop logging stats for admin and logged in users
add_action( 'wp_ajax_nopriv_wmp_update', 'WMP_system::actions' );
// Widget
include_once( WMP_PATH . 'system/widget.php' );
add_action( 'widgets_init', 'WMP_system::widget' );
}