-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcloudscale-wordpress-free-analytics.php
More file actions
99 lines (90 loc) · 3.86 KB
/
cloudscale-wordpress-free-analytics.php
File metadata and controls
99 lines (90 loc) · 3.86 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
<?php
/**
* Plugin Name: CloudScale Free Analytics
* Plugin URI: https://andrewbaker.ninja
* 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.175
* Author: Andrew Baker
* Author URI: https://andrewbaker.ninja
* Contributors: andrewbaker
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: cloudscale-wordpress-free-analytics
* Requires PHP: 7.4
* Requires at least: 6.0
*
* @package CloudScale_Free_Analytics
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'CSPV_VERSION', '2.9.175' );
define( 'CSPV_META_KEY', '_cspv_view_count' );
define( 'CSPV_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'CSPV_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
// ── OPcache buster: invalidate all plugin files when version changes ──
$cspv_cached_ver = get_option( 'cspv_opcache_version', '' );
if ( $cspv_cached_ver !== CSPV_VERSION && function_exists( 'opcache_invalidate' ) ) {
foreach ( glob( CSPV_PLUGIN_DIR . '*.php' ) as $cspv_file ) {
opcache_invalidate( $cspv_file, true );
}
update_option( 'cspv_opcache_version', CSPV_VERSION, true );
}
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 . 'jetpack-migration.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';
register_activation_hook( __FILE__, 'cspv_activate' );
register_deactivation_hook( __FILE__, function () {
$dir = plugin_dir_path( __FILE__ );
foreach ( glob( $dir . '*.{js,css}', GLOB_BRACE ) as $f ) {
if ( is_file( $f ) ) { wp_delete_file( $f ); }
}
require_once ABSPATH . 'wp-admin/includes/file.php';
WP_Filesystem();
global $wp_filesystem;
foreach ( array( $dir . 'assets/', $dir . 'admin/', $dir . 'includes/' ) as $subdir ) {
if ( ! is_dir( $subdir ) ) { continue; }
foreach ( glob( $subdir . '*' ) as $f ) {
if ( is_file( $f ) ) { wp_delete_file( $f ); }
}
if ( $wp_filesystem ) { $wp_filesystem->rmdir( $subdir ); }
}
} );
add_action( 'admin_init', function () {
$stored = get_option( 'cspv_version', '0' );
if ( $stored !== CSPV_VERSION ) {
if ( function_exists( 'opcache_reset' ) ) { opcache_reset(); }
$dir = plugin_dir_path( __FILE__ );
require_once ABSPATH . 'wp-admin/includes/file.php';
WP_Filesystem();
global $wp_filesystem;
foreach ( array( $dir . 'assets/', $dir . 'admin/', $dir . 'includes/' ) as $subdir ) {
if ( ! is_dir( $subdir ) ) { continue; }
foreach ( glob( $subdir . '*' ) as $f ) {
if ( is_file( $f ) ) { wp_delete_file( $f ); }
}
if ( $wp_filesystem ) { $wp_filesystem->rmdir( $subdir ); }
}
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();
update_option( 'cspv_version', CSPV_VERSION );
}
} );