-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcloudscale-site-analytics.php
More file actions
116 lines (105 loc) · 4.87 KB
/
Copy pathcloudscale-site-analytics.php
File metadata and controls
116 lines (105 loc) · 4.87 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
* Plugin Name: CloudScale Site Analytics
* Description: Accurate page view tracking via a JavaScript beacon that bypasses Cloudflare cache. Includes auto display on posts, Top Posts and Recent Posts sidebar widgets, and a live statistics dashboard under Tools.
* Version: 2.9.457
* Author: CloudScale
* Author URI: https://cloudscale.consulting
* Contributors: cloudscale
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: cloudscale-site-analytics
* Requires PHP: 7.4
* Requires at least: 6.0
*
* @package CloudScale_Site_Analytics
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'CSPV_VERSION', '2.9.457' );
define( 'CSPV_META_KEY', '_cspv_view_count' );
define( 'CSPV_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'CSPV_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
require_once CSPV_PLUGIN_DIR . 'includes/class-cloudscale-telegram.php';
require_once CSPV_PLUGIN_DIR . 'stats-library.php';
require_once CSPV_PLUGIN_DIR . 'database.php';
require_once CSPV_PLUGIN_DIR . 'ip-throttle.php';
require_once CSPV_PLUGIN_DIR . 'rest-api.php';
require_once CSPV_PLUGIN_DIR . 'beacon.php';
require_once CSPV_PLUGIN_DIR . 'template-functions.php';
require_once CSPV_PLUGIN_DIR . 'top-posts-widget.php';
require_once CSPV_PLUGIN_DIR . 'recent-posts-widget.php';
require_once CSPV_PLUGIN_DIR . 'search.php';
require_once CSPV_PLUGIN_DIR . 'not-found.php';
require_once CSPV_PLUGIN_DIR . 'auto-display.php';
require_once CSPV_PLUGIN_DIR . 'admin-columns.php';
require_once CSPV_PLUGIN_DIR . 'dashboard-widget.php';
require_once CSPV_PLUGIN_DIR . 'stats-page.php';
require_once CSPV_PLUGIN_DIR . 'site-health.php';
require_once CSPV_PLUGIN_DIR . 'debug-panel.php';
// Our UI uses plain native emoji characters everywhere (Smart Summary icons, flags).
// WP's built-in twemoji polyfill replaces them with <img> tags from s.w.org when it
// (sometimes wrongly) decides a browser lacks native emoji support; if that CDN is
// ever unreachable the images break. Since native rendering is all we need, skip the
// polyfill outright rather than depending on an external CDN we don't control.
add_action( 'init', function () {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'embed_head', 'print_emoji_detection_script' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
add_filter( 'tiny_mce_plugins', function ( $plugins ) {
return is_array( $plugins ) ? array_diff( $plugins, array( 'wpemoji' ) ) : $plugins;
} );
add_filter( 'wp_resource_hints', function ( $urls ) {
return array_values( array_diff( $urls, array( 'https://s.w.org' ) ) );
} );
}, 1 );
// wp-admin/includes/admin-filters.php re-registers the admin_print_scripts/
// admin_print_styles emoji hooks, and that file loads after `init` has already
// fired — so the removal above never catches them on admin pages. Remove again
// on admin_init, which runs after admin-filters.php has loaded.
add_action( 'admin_init', function () {
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
}, 1 );
register_activation_hook( __FILE__, 'cspv_activate' );
register_deactivation_hook( __FILE__, function () {
wp_clear_scheduled_hook( 'cspv_dbip_auto_update' );
wp_clear_scheduled_hook( 'cspv_flush_view_queue' );
} );
// Register a 1-minute WP-Cron interval for the view-queue flush.
add_filter( 'cron_schedules', function ( $schedules ) {
if ( ! isset( $schedules['cspv_every_minute'] ) ) {
$schedules['cspv_every_minute'] = array(
'interval' => 60,
'display' => __( 'Every Minute (CloudScale Analytics queue flush)', 'cloudscale-site-analytics' ),
);
}
return $schedules;
} );
// Ensure crons are always scheduled while the plugin is active.
add_action( 'init', function () {
if ( ! wp_next_scheduled( 'cspv_dbip_auto_update' ) ) {
wp_schedule_event( time(), 'daily', 'cspv_dbip_auto_update' );
}
if ( ! wp_next_scheduled( 'cspv_flush_view_queue' ) ) {
wp_schedule_event( time(), 'cspv_every_minute', 'cspv_flush_view_queue' );
}
} );
add_action( 'admin_init', function () {
$stored = get_option( 'cspv_version', '0' );
if ( $stored !== CSPV_VERSION ) {
if ( function_exists( 'opcache_reset' ) ) { opcache_reset(); }
cspv_create_table_v2();
cspv_create_table_referrers_v2();
cspv_create_table_geo_v2();
cspv_create_table_visitors_v2();
cspv_create_table_404_v2();
cspv_create_table_sessions_v2();
cspv_create_table_audio_v2();
update_option( 'cspv_version', CSPV_VERSION );
}
} );