-
Notifications
You must be signed in to change notification settings - Fork 18
/
wp-stats.php
95 lines (82 loc) · 2.15 KB
/
wp-stats.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
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
class UserOnline_WpStats {
/**
* Variables
*
* @method static
*
* @var UserOnline_WpStats
*/
private static $instance;
/**
* Constructor method
*
* @access public
*/
public function __construct() {
add_action( 'plugins_loaded', array( $this, 'add_hooks' ) );
}
/**
* Initializes the plugin object and returns its instance
*
* @return UserOnline_WpStats
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Adds all the plugin's hooks
*
* @access public
*
* @return void
*/
public function add_hooks() {
add_filter( 'wp_stats_page_admin_plugins', array( $this, 'page_admin_general_stats' ) );
add_filter( 'wp_stats_page_plugins', array( $this, 'page_general_stats' ) );
}
/**
* Add WP-UserOnline General Stats To WP-Stats Page Options
*
* @param string $content
*
* @access public
*
* @return string
*/
public function page_admin_general_stats( $content ) {
$stats_display = get_option( 'stats_display' );
$content .= '<input type="checkbox" name="stats_display[]" id="wpstats_useronline" value="useronline"' . checked( $stats_display['useronline'], 1, false ) . '/> <label for="wpstats_useronline">'.__( 'WP-UserOnline', 'wp-useronline' ).'</label><br />'."\n";
return $content;
}
/**
* Add WP-UserOnline General Stats To WP-Stats Page
*
* @param string $content
*
* @access public
*
* @return string
*/
public function page_general_stats( $content ) {
$stats_display = get_option( 'stats_display' );
$str = _n(
'<strong>%s</strong> user online now.',
'<strong>%s</strong> users online now.',
get_users_online_count(), 'wp-useronline'
);
if ( $stats_display['useronline'] === 1 )
$content .=
html( 'p', html( 'strong', __( 'WP-UserOnline', 'wp-useronline' ) ) )
.html( 'ul',
html( 'li', sprintf( $str, number_format_i18n( get_users_online_count() ) ) )
.html( 'li', UserOnline_Template::format_most_users() )
);
return $content;
}
}
UserOnline_WpStats::get_instance();