PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.4.2
Independent Analytics – WordPress Analytics Plugin v2.4.2
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / IAWP / Independent_Analytics.php
independent-analytics / IAWP Last commit date
AJAX 2 years ago Admin_Page 2 years ago Custom_WordPress_Columns 2 years ago Date_Range 2 years ago Filter_Lists 2 years ago Interval 2 years ago Menu_Bar_Stats 2 years ago Migrations 2 years ago Models 2 years ago Public_API 2 years ago Rows 2 years ago Statistics 2 years ago Tables 2 years ago Utils 2 years ago Campaign_Builder.php 2 years ago Capability_Manager.php 2 years ago Chart.php 2 years ago Chart_Geo.php 2 years ago Cron_Manager.php 2 years ago Current_Traffic_Finder.php 2 years ago Dashboard_Options.php 2 years ago Dashboard_Widget.php 2 years ago Database.php 2 years ago Database_Manager.php 2 years ago Email_Chart.php 2 years ago Email_Reports.php 2 years ago Empty_Report_Option.php 2 years ago Env.php 2 years ago Filters.php 2 years ago Geo_Database_Background_Job.php 2 years ago Geo_Database_Manager.php 2 years ago Geoposition.php 2 years ago Icon_Directory.php 2 years ago Icon_Directory_Factory.php 2 years ago Illuminate_Builder.php 2 years ago Independent_Analytics.php 2 years ago Interrupt.php 2 years ago Known_Referrers.php 2 years ago Plugin_Conflict_Detector.php 2 years ago Query.php 2 years ago Quick_Stats.php 2 years ago REST_API.php 2 years ago Real_Time.php 2 years ago Report.php 2 years ago Report_Finder.php 2 years ago Report_Options_Parser.php 2 years ago Resource_Identifier.php 2 years ago Settings.php 2 years ago Sort_Configuration.php 2 years ago Track_Resource_Changes.php 2 years ago View.php 2 years ago View_Counter.php 2 years ago Visitors_Over_Time_Finder.php 2 years ago WP_Option_Cache_Bust.php 2 years ago WooCommerce_Order.php 2 years ago WooCommerce_Referrer_Meta_Box.php 2 years ago
Independent_Analytics.php
307 lines
1 <?php
2
3 namespace IAWP;
4
5 use IAWP\Admin_Page\Analytics_Page;
6 use IAWP\Admin_Page\Campaign_Builder_Page;
7 use IAWP\Admin_Page\Settings_Page;
8 use IAWP\Admin_Page\Support_Page;
9 use IAWP\Admin_Page\Updates_Page;
10 use IAWP\AJAX\AJAX_Manager;
11 use IAWP\Menu_Bar_Stats\Menu_Bar_Stats;
12 use IAWP\Migrations\Migrations;
13 use IAWP\Utils\Singleton;
14 use IAWP\Utils\String_Util;
15 /** @internal */
16 class Independent_Analytics
17 {
18 use Singleton;
19 public $settings;
20 public $email_reports;
21 public $cron_manager;
22 // This is where we attach functions to WP hooks
23 private function __construct()
24 {
25 $this->settings = new \IAWP\Settings();
26 new \IAWP\REST_API();
27 new \IAWP\Dashboard_Widget();
28 new \IAWP\View_Counter();
29 AJAX_Manager::getInstance();
30 if (!Migrations::is_migrating()) {
31 new \IAWP\Track_Resource_Changes();
32 Menu_Bar_Stats::register();
33 \IAWP\WooCommerce_Order::initialize_order_tracker();
34 }
35 $this->cron_manager = new \IAWP\Cron_Manager();
36 if (\IAWPSCOPED\iawp_is_pro()) {
37 $this->email_reports = new \IAWP\Email_Reports();
38 new \IAWP\Campaign_Builder();
39 new \IAWP\WooCommerce_Referrer_Meta_Box();
40 }
41 \add_filter('admin_body_class', function ($classes) {
42 if (\get_option('iawp_dark_mode')) {
43 $classes .= ' iawp-dark-mode ';
44 }
45 return $classes;
46 });
47 \add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts_and_styles'], 110);
48 // Called at 110 to dequeue other scripts
49 \add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts_and_styles_front_end']);
50 \add_action('admin_menu', [$this, 'add_admin_menu_pages']);
51 \add_filter('plugin_action_links_independent-analytics/iawp.php', [$this, 'plugin_action_links']);
52 \add_filter('admin_footer_text', [$this, 'ip_db_attribution'], 1, 1);
53 \add_action('init', [$this, 'polylang_translations']);
54 \add_action('init', [$this, 'load_textdomain']);
55 \IAWP_FS()->add_filter('connect_message_on_update', [$this, 'filter_connect_message_on_update'], 10, 6);
56 \IAWP_FS()->add_filter('connect_message', [$this, 'filter_connect_message_on_update'], 10, 6);
57 \IAWP_FS()->add_filter('pricing_url', [$this, 'change_freemius_pricing_url'], 10);
58 \IAWP_FS()->add_filter('show_deactivation_feedback_form', function () {
59 return \false;
60 });
61 \add_action('admin_init', [$this, 'maybe_delete_mu_plugin']);
62 }
63 /**
64 * At one point in time, there was a must-use plugin that was created. The plugin file and the
65 * option need to get cleaned up.
66 * @return void
67 */
68 public function maybe_delete_mu_plugin()
69 {
70 $already_attempted = \get_option('iawp_attempted_to_delete_mu_plugin', '0');
71 if ($already_attempted === '1') {
72 return;
73 }
74 if (\get_option('iawp_must_use_directory_not_writable', '0') === '1') {
75 \delete_option('iawp_must_use_directory_not_writable');
76 }
77 $mu_plugin_file = \trailingslashit(\WPMU_PLUGIN_DIR) . 'iawp-performance-boost.php';
78 if (\file_exists($mu_plugin_file)) {
79 \unlink($mu_plugin_file);
80 }
81 \update_option('iawp_attempted_to_delete_mu_plugin', '1');
82 }
83 public function load_textdomain()
84 {
85 \load_plugin_textdomain('independent-analytics', \false, \IAWP_LANGUAGES_DIRECTORY);
86 }
87 public function polylang_translations()
88 {
89 if (\function_exists('IAWPSCOPED\\pll_register_string')) {
90 pll_register_string('view_counter', 'Views:', 'Independent Analytics');
91 }
92 }
93 // Changes the URL for the "Upgrade" tab in the Account menu
94 public function change_freemius_pricing_url()
95 {
96 return 'https://independentwp.com/pricing/?utm_source=User+Dashboard&utm_medium=WP+Admin&utm_campaign=Upgrade+to+Pro&utm_content=Account';
97 }
98 public function add_admin_menu_pages()
99 {
100 $title = \IAWP\Capability_Manager::white_labeled() ? \esc_html__('Analytics', 'independent-analytics') : 'Independent Analytics';
101 \add_menu_page($title, \esc_html__('Analytics', 'independent-analytics'), \IAWP\Capability_Manager::can_view_string(), 'independent-analytics', function () {
102 $analytics_page = new Analytics_Page();
103 $analytics_page->render();
104 }, 'dashicons-analytics', 3);
105 if (\IAWP\Capability_Manager::can_edit()) {
106 \add_submenu_page('independent-analytics', \esc_html__('Settings', 'independent-analytics'), \esc_html__('Settings', 'independent-analytics'), \IAWP\Capability_Manager::can_view_string(), 'independent-analytics-settings', function () {
107 $settings_page = new Settings_Page();
108 $settings_page->render(\false);
109 });
110 }
111 if (\IAWPSCOPED\iawp_is_pro()) {
112 \add_submenu_page('independent-analytics', \esc_html__('Campaign Builder', 'independent-analytics'), \esc_html__('Campaign Builder', 'independent-analytics'), \IAWP\Capability_Manager::can_view_string(), 'independent-analytics-campaign-builder', function () {
113 $campaign_builder_page = new Campaign_Builder_Page();
114 $campaign_builder_page->render(\false);
115 });
116 }
117 if (!\IAWP\Capability_Manager::white_labeled()) {
118 \add_submenu_page('independent-analytics', \esc_html__('Help & Support', 'independent-analytics'), \esc_html__('Help & Support', 'independent-analytics'), \IAWP\Capability_Manager::can_view_string(), 'independent-analytics-support-center', function () {
119 $support_page = new Support_Page();
120 $support_page->render(\false);
121 });
122 }
123 if (!\IAWP\Capability_Manager::white_labeled()) {
124 $count = $this->get_update_notification_count();
125 $menu_html = '<span class="menu-name">' . \esc_html__('Changelog', 'independent-analytics') . '</span>';
126 $menu_html = $count > 0 ? $menu_html . ' <span class="menu-counter">' . \absint($count) . '</span>' : $menu_html;
127 \add_submenu_page('independent-analytics', \esc_html__('Changelog', 'independent-analytics'), $menu_html, \IAWP\Capability_Manager::can_view_string(), 'independent-analytics-updates', function () {
128 $updates_page = new Updates_Page();
129 $updates_page->render(\false);
130 });
131 }
132 if (\IAWPSCOPED\iawp_is_free() && !\IAWP\Capability_Manager::white_labeled()) {
133 \add_submenu_page('independent-analytics', \esc_html__('Upgrade to Pro &rarr;', 'independent-analytics'), '<span style="color: #F69D0A;">' . \esc_html__('Upgrade to Pro &rarr;', 'independent-analytics') . '</span>', \IAWP\Capability_Manager::can_view_string(), \esc_url('https://independentwp.com/pricing/?utm_source=User+Dashboard&utm_medium=WP+Admin&utm_campaign=Upgrade+to+Pro&utm_content=Sidebar'));
134 }
135 }
136 public function register_scripts_and_styles() : void
137 {
138 \wp_register_style('iawp-styles', \IAWPSCOPED\iawp_url_to('dist/styles/style.css'), [], \IAWP_VERSION);
139 \wp_register_style('iawp-dashboard-widget-styles', \IAWPSCOPED\iawp_url_to('dist/styles/dashboard_widget.css'), [], \IAWP_VERSION);
140 \wp_register_style('iawp-freemius-notice-styles', \IAWPSCOPED\iawp_url_to('dist/styles/freemius_notice_styles.css'), [], \IAWP_VERSION);
141 \wp_register_style('iawp-posts-menu-styles', \IAWPSCOPED\iawp_url_to('dist/styles/posts_menu.css'), [], \IAWP_VERSION);
142 \wp_register_script('iawp-javascript', \IAWPSCOPED\iawp_url_to('dist/js/index.js'), [], \IAWP_VERSION);
143 \wp_register_script('iawp-dashboard-widget-javascript', \IAWPSCOPED\iawp_url_to('dist/js/dashboard_widget.js'), [], \IAWP_VERSION);
144 \wp_register_script('iawp-layout-javascript', \IAWPSCOPED\iawp_url_to('dist/js/layout.js'), [], \IAWP_VERSION);
145 \wp_register_script('iawp-settings-javascript', \IAWPSCOPED\iawp_url_to('dist/js/settings.js'), ['wp-color-picker'], \IAWP_VERSION);
146 if (Menu_Bar_Stats::is_option_enabled()) {
147 \wp_register_style('iawp-front-end-styles', \IAWPSCOPED\iawp_url_to('dist/styles/menu_bar_stats.css'), [], \IAWP_VERSION);
148 }
149 if (\is_rtl()) {
150 \wp_register_style('iawp-styles-rtl', \IAWPSCOPED\iawp_url_to('dist/styles/rtl.css'), [], \IAWP_VERSION);
151 }
152 }
153 public function register_scripts_and_styles_front_end() : void
154 {
155 if (Menu_Bar_Stats::is_option_enabled()) {
156 \wp_register_style('iawp-front-end-styles', \IAWPSCOPED\iawp_url_to('dist/styles/menu_bar_stats.css'), [], \IAWP_VERSION);
157 }
158 }
159 public function enqueue_scripts_and_styles($hook)
160 {
161 $this->register_scripts_and_styles();
162 $page = \IAWP\Env::get_page();
163 $this->enqueue_translations();
164 $this->enqueue_nonces();
165 \wp_enqueue_style('iawp-freemius-notice-styles');
166 if (\is_string($page)) {
167 \wp_enqueue_style('iawp-styles');
168 \wp_enqueue_script('iawp-javascript');
169 \wp_enqueue_script('iawp-layout-javascript');
170 $this->dequeue_bad_actors();
171 $this->maybe_override_adminify_styles();
172 if (\is_rtl()) {
173 \wp_enqueue_style('iawp-styles-rtl');
174 }
175 }
176 if ($page === 'independent-analytics-settings') {
177 \wp_enqueue_style('wp-color-picker');
178 \wp_enqueue_script('iawp-settings-javascript');
179 } elseif ($hook === 'index.php') {
180 \wp_enqueue_script('iawp-dashboard-widget-javascript');
181 \wp_enqueue_style('iawp-dashboard-widget-styles');
182 } elseif ($hook === 'edit.php') {
183 \wp_enqueue_style('iawp-posts-menu-styles');
184 }
185 if (Menu_Bar_Stats::is_option_enabled()) {
186 \wp_enqueue_style('iawp-front-end-styles');
187 }
188 }
189 public function enqueue_scripts_and_styles_front_end()
190 {
191 if (Menu_Bar_Stats::is_option_enabled()) {
192 $this->register_scripts_and_styles_front_end();
193 \wp_enqueue_style('iawp-front-end-styles');
194 }
195 }
196 public function enqueue_translations()
197 {
198 \wp_register_script('iawp-translations', '');
199 \wp_enqueue_script('iawp-translations');
200 \wp_add_inline_script('iawp-translations', 'const iawpText = ' . \json_encode(['visitors' => \__('Visitors', 'independent-analytics'), 'views' => \__('Views', 'independent-analytics'), 'sessions' => \__('Sessions', 'independent-analytics'), 'orders' => \__('Orders', 'independent-analytics'), 'netSales' => \__('Net Sales', 'independent-analytics'), 'country' => \__('country', 'independent-analytics'), 'exactDates' => \__('Apply Exact Dates', 'independent-analytics'), 'relativeDates' => \__('Apply Relative Dates', 'independent-analytics'), 'copied' => \__('Copied', 'independent-analytics'), 'exportingPages' => \__('Exporting Pages...', 'independent-analytics'), 'exportPages' => \__('Export Pages', 'independent-analytics'), 'exportingReferrers' => \__('Exporting Referrers...', 'independent-analytics'), 'exportReferrers' => \__('Export Referrers', 'independent-analytics'), 'exportingGeolocations' => \__('Exporting Geolocations...', 'independent-analytics'), 'exportGeolocations' => \__('Export Geolocations', 'independent-analytics'), 'exportingDevices' => \__('Exporting Devices...', 'independent-analytics'), 'exportDevices' => \__('Export Devices', 'independent-analytics'), 'exportingCampaigns' => \__('Exporting Campaigns...', 'independent-analytics'), 'exportCampaigns' => \__('Export Campaigns', 'independent-analytics'), 'invalidReportArchive' => \__('This report archive is invalid. Please export your reports and try again.', 'independent-analytics'), 'openMobileMenu' => \__('Open menu', 'independent-analytics'), 'closeMobileMenu' => \__('Close menu', 'independent-analytics')]), 'before');
201 }
202 public function enqueue_nonces()
203 {
204 \wp_register_script('iawp-nonces', '');
205 \wp_enqueue_script('iawp-nonces');
206 \wp_add_inline_script('iawp-nonces', 'const iawpActions = ' . \json_encode(AJAX_Manager::getInstance()->get_action_signatures()), 'before');
207 }
208 public function get_option($name, $default)
209 {
210 $option = \get_option($name, $default);
211 return $option === '' ? $default : $option;
212 }
213 public function filter_connect_message_on_update($message, $user_first_name, $product_title, $user_login, $site_link, $freemius_link)
214 {
215 // Add the heading HTML.
216 $plugin_name = 'Independent Analytics';
217 $title = '<h3>' . \sprintf(\esc_html__('We hope you love %1$s', 'independent-analytics'), $plugin_name) . '</h3>';
218 $html = '';
219 // Add the introduction HTML.
220 $html .= '<p>';
221 $html .= \sprintf(\esc_html__('Hi, %1$s! This is an invitation to help the %2$s community.', 'independent-analytics'), $user_first_name, $plugin_name);
222 $html .= '<strong>';
223 $html .= \sprintf(\esc_html__('If you opt-in, some data about your usage of %2$s will be shared with us', 'independent-analytics'), $user_first_name, $plugin_name);
224 $html .= '</strong>';
225 $html .= \sprintf(\esc_html__(' so we can improve %2$s. We will also share some helpful info on using the plugin so you can get the most out of your sites analytics.', 'independent-analytics'), $user_first_name, $plugin_name);
226 $html .= '</p>';
227 $html .= '<p>';
228 $html .= \sprintf(\esc_html__('And if you skip this, that\'s okay! %1$s will still work just fine.', 'independent-analytics'), $plugin_name);
229 $html .= '</p>';
230 return $title . $html;
231 }
232 public function plugin_action_links($links)
233 {
234 // Create the link
235 $settings_link = '<a class="calendar-link" href="' . \esc_url(\IAWPSCOPED\iawp_dashboard_url()) . '">' . \esc_html__('Analytics Dashboard', 'independent-analytics') . '</a>';
236 // Add the link to the start of the array
237 \array_unshift($links, $settings_link);
238 return $links;
239 }
240 public function ip_db_attribution($text)
241 {
242 if (\IAWP\Env::get_tab() === 'geo') {
243 $text = $text . ' ' . \esc_html_x('Geolocation data powered by', 'Following text is a noun: DB-IP', 'independent-analytics') . ' ' . '<a href="https://db-ip.com" class="geo-message" target="_blank">DB-IP</a>.';
244 }
245 return $text;
246 }
247 public function pagination_page_size()
248 {
249 return 50;
250 }
251 public function dequeue_bad_actors()
252 {
253 // https://wordpress.org/plugins/comment-link-remove/
254 \wp_dequeue_style('qc_clr_admin_style_css');
255 // https://wordpress.org/plugins/webappick-pdf-invoice-for-woocommerce/
256 \wp_dequeue_style('woo-invoice');
257 // https://wordpress.org/plugins/wp-media-files-name-rename/
258 \wp_dequeue_style('wpcmp_bootstrap_css');
259 // https://wordpress.org/plugins/morepuzzles/
260 \wp_dequeue_style('bscss');
261 \wp_dequeue_style('mypluginstyle');
262 $this->dequeue_bootstrap_stylesheets();
263 }
264 // Dequeue any stylesheets loading Twitter Bootstrap. It shouldn't be loaded in our menu and makes all modals inaccessible among other issues.
265 public function dequeue_bootstrap_stylesheets()
266 {
267 global $wp_styles;
268 $bootstrap_strings = ['/bootstrap.css', '/bootstrap.min.css', '/bootstrap.bundle.css', '/bootstrap.bundle.min.css'];
269 foreach ($wp_styles->queue as $key => $handle) {
270 if (\array_key_exists($handle, $wp_styles->registered)) {
271 $url = $wp_styles->registered[$handle]->src;
272 // WP Core scripts can return boolean
273 if (\is_string($url)) {
274 foreach ($bootstrap_strings as $bootstrap) {
275 if (String_Util::str_contains($url, $bootstrap)) {
276 \wp_dequeue_style($handle);
277 continue;
278 }
279 }
280 }
281 }
282 }
283 }
284 public function maybe_override_adminify_styles()
285 {
286 if (\in_array('adminify/adminify.php', \get_option('active_plugins'))) {
287 $settings = \get_option('_wpadminify');
288 if (\array_key_exists('admin_ui', $settings)) {
289 if ($settings['admin_ui']) {
290 \wp_register_style('iawp-adminify-styles', \IAWPSCOPED\iawp_url_to('dist/styles/adminify.css'), [], \IAWP_VERSION);
291 \wp_enqueue_style('iawp-adminify-styles');
292 }
293 }
294 }
295 }
296 public function get_update_notification_count()
297 {
298 // https://api.wordpress.org/plugins/info/1.0/independent-analytics.json
299 $version_history = ['2.4.0', '2.3.0', '2.2.0', '2.1.0'];
300 $last_update_viewed = $this->get_option('iawp_last_update_viewed', '0');
301 $unseen_versions = \array_filter($version_history, function ($version) use($last_update_viewed) {
302 return \version_compare($last_update_viewed, $version, '<');
303 });
304 return \count($unseen_versions);
305 }
306 }
307