PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.7.0
Independent Analytics – WordPress Analytics Plugin v2.7.0
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 Data_Pruning 2 years ago Date_Range 2 years ago Email_Reports 2 years ago Filter_Lists 2 years ago Form_Submissions 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 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 Patch.php 2 years ago Plugin_Conflict_Detector.php 2 years ago Plugin_Group.php 2 years ago Plugin_Group_Option.php 2 years ago Query.php 2 years ago Query_Taps.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
348 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\Data_Pruning\Pruner;
12 use IAWP\Email_Reports\Email_Reports;
13 use IAWP\Form_Submissions\Form;
14 use IAWP\Form_Submissions\Submission_Listener;
15 use IAWP\Menu_Bar_Stats\Menu_Bar_Stats;
16 use IAWP\Migrations\Migrations;
17 use IAWP\Utils\Singleton;
18 /** @internal */
19 class Independent_Analytics
20 {
21 use Singleton;
22 public $settings;
23 public $email_reports;
24 public $cron_manager;
25 private $is_woocommerce_support_enabled;
26 private $is_form_submission_support_enabled;
27 // This is where we attach functions to WP hooks
28 private function __construct()
29 {
30 $this->settings = new \IAWP\Settings();
31 new \IAWP\REST_API();
32 new \IAWP\Dashboard_Widget();
33 new \IAWP\View_Counter();
34 new Submission_Listener();
35 Pruner::register_hook();
36 AJAX_Manager::getInstance();
37 if (!Migrations::is_migrating()) {
38 new \IAWP\Track_Resource_Changes();
39 Menu_Bar_Stats::register();
40 \IAWP\WooCommerce_Order::initialize_order_tracker();
41 }
42 $this->cron_manager = new \IAWP\Cron_Manager();
43 if (\IAWPSCOPED\iawp_is_pro()) {
44 $this->email_reports = new Email_Reports();
45 new \IAWP\Campaign_Builder();
46 new \IAWP\WooCommerce_Referrer_Meta_Box();
47 }
48 \add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts_and_styles'], 110);
49 // Called at 110 to dequeue other scripts
50 \add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts_and_styles_front_end']);
51 \add_action('admin_menu', [$this, 'add_admin_menu_pages']);
52 \add_action('admin_init', [$this, 'remove_freemius_pricing_menu']);
53 \add_filter('plugin_action_links_independent-analytics/iawp.php', [$this, 'plugin_action_links']);
54 \add_filter('admin_footer_text', [$this, 'ip_db_attribution'], 1, 1);
55 \add_action('init', [$this, 'polylang_translations']);
56 \add_action('init', [$this, 'load_textdomain']);
57 \IAWP_FS()->add_filter('connect_message_on_update', [$this, 'filter_connect_message_on_update'], 10, 6);
58 \IAWP_FS()->add_filter('connect_message', [$this, 'filter_connect_message_on_update'], 10, 6);
59 \IAWP_FS()->add_filter('pricing_url', [$this, 'change_freemius_pricing_url'], 10);
60 \IAWP_FS()->add_filter('show_deactivation_feedback_form', function () {
61 return \false;
62 });
63 \add_action('admin_init', [$this, 'maybe_delete_mu_plugin']);
64 \add_action('admin_body_class', [$this, 'add_body_class']);
65 }
66 public function add_body_class($classes)
67 {
68 if (\get_option('iawp_dark_mode')) {
69 $classes .= ' iawp-dark-mode ';
70 }
71 $page = \IAWP\Env::get_page();
72 if (\is_string($page)) {
73 $classes .= " {$page} ";
74 }
75 return $classes;
76 }
77 /**
78 * At one point in time, there was a must-use plugin that was created. The plugin file and the
79 * option need to get cleaned up.
80 * @return void
81 */
82 public function maybe_delete_mu_plugin()
83 {
84 $already_attempted = \get_option('iawp_attempted_to_delete_mu_plugin', '0');
85 if ($already_attempted === '1') {
86 return;
87 }
88 if (\get_option('iawp_must_use_directory_not_writable', '0') === '1') {
89 \delete_option('iawp_must_use_directory_not_writable');
90 }
91 $mu_plugin_file = \trailingslashit(\WPMU_PLUGIN_DIR) . 'iawp-performance-boost.php';
92 if (\file_exists($mu_plugin_file)) {
93 \unlink($mu_plugin_file);
94 }
95 \update_option('iawp_attempted_to_delete_mu_plugin', '1', \true);
96 }
97 public function load_textdomain()
98 {
99 \load_plugin_textdomain('independent-analytics', \false, \IAWP_LANGUAGES_DIRECTORY);
100 }
101 public function polylang_translations()
102 {
103 if (\function_exists('IAWPSCOPED\\pll_register_string')) {
104 pll_register_string('view_counter', 'Views:', 'Independent Analytics');
105 }
106 }
107 // Changes the URL for the "Upgrade" tab in the Account menu
108 public function change_freemius_pricing_url()
109 {
110 return 'https://independentwp.com/pricing/?utm_source=User+Dashboard&utm_medium=WP+Admin&utm_campaign=Upgrade+to+Pro&utm_content=Account';
111 }
112 public function add_admin_menu_pages()
113 {
114 $title = \IAWP\Capability_Manager::white_labeled() ? \esc_html__('Analytics', 'independent-analytics') : 'Independent Analytics';
115 \add_menu_page($title, \esc_html__('Analytics', 'independent-analytics'), \IAWP\Capability_Manager::menu_page_capability_string(), 'independent-analytics', function () {
116 $analytics_page = new Analytics_Page();
117 $analytics_page->render();
118 }, 'dashicons-analytics', 3);
119 if (\IAWP\Capability_Manager::can_edit()) {
120 \add_submenu_page('independent-analytics', \esc_html__('Settings', 'independent-analytics'), \esc_html__('Settings', 'independent-analytics'), \IAWP\Capability_Manager::menu_page_capability_string(), 'independent-analytics-settings', function () {
121 $settings_page = new Settings_Page();
122 $settings_page->render(\false);
123 });
124 }
125 if (\IAWPSCOPED\iawp_is_pro()) {
126 \add_submenu_page('independent-analytics', \esc_html__('Campaign Builder', 'independent-analytics'), \esc_html__('Campaign Builder', 'independent-analytics'), \IAWP\Capability_Manager::menu_page_capability_string(), 'independent-analytics-campaign-builder', function () {
127 $campaign_builder_page = new Campaign_Builder_Page();
128 $campaign_builder_page->render(\false);
129 });
130 }
131 if (!\IAWP\Capability_Manager::white_labeled()) {
132 \add_submenu_page('independent-analytics', \esc_html__('Help & Support', 'independent-analytics'), \esc_html__('Help & Support', 'independent-analytics'), \IAWP\Capability_Manager::menu_page_capability_string(), 'independent-analytics-support-center', function () {
133 $support_page = new Support_Page();
134 $support_page->render(\false);
135 });
136 }
137 if (!\IAWP\Capability_Manager::white_labeled()) {
138 $menu_html = '<span class="menu-name">' . \esc_html__('Changelog', 'independent-analytics') . '</span>';
139 $menu_html = $this->changelog_viewed_since_update() ? $menu_html . ' <span class="menu-counter">' . \esc_html__('New', 'independent-analytics') . '</span>' : $menu_html;
140 \add_submenu_page('independent-analytics', \esc_html__('Changelog', 'independent-analytics'), $menu_html, \IAWP\Capability_Manager::menu_page_capability_string(), 'independent-analytics-updates', function () {
141 $updates_page = new Updates_Page();
142 $updates_page->render(\false);
143 });
144 }
145 if (\IAWPSCOPED\iawp_is_free() && !\IAWP\Capability_Manager::white_labeled()) {
146 \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::menu_page_capability_string(), \esc_url('https://independentwp.com/pricing/?utm_source=User+Dashboard&utm_medium=WP+Admin&utm_campaign=Upgrade+to+Pro&utm_content=Sidebar'));
147 }
148 }
149 // The menu link is removed in the SDK setup, but this makes it completely inaccessible
150 public function remove_freemius_pricing_menu()
151 {
152 \remove_submenu_page('independent-analytics', 'independent-analytics-pricing');
153 }
154 public function register_scripts_and_styles() : void
155 {
156 \wp_register_style('iawp-styles', \IAWPSCOPED\iawp_url_to('dist/styles/style.css'), [], \IAWP_VERSION);
157 \wp_register_style('iawp-dashboard-widget-styles', \IAWPSCOPED\iawp_url_to('dist/styles/dashboard_widget.css'), [], \IAWP_VERSION);
158 \wp_register_style('iawp-freemius-notice-styles', \IAWPSCOPED\iawp_url_to('dist/styles/freemius_notice_styles.css'), [], \IAWP_VERSION);
159 \wp_register_style('iawp-posts-menu-styles', \IAWPSCOPED\iawp_url_to('dist/styles/posts_menu.css'), [], \IAWP_VERSION);
160 \wp_register_script('iawp-javascript', \IAWPSCOPED\iawp_url_to('dist/js/index.js'), [], \IAWP_VERSION);
161 \wp_register_script('iawp-dashboard-widget-javascript', \IAWPSCOPED\iawp_url_to('dist/js/dashboard_widget.js'), [], \IAWP_VERSION);
162 \wp_register_script('iawp-layout-javascript', \IAWPSCOPED\iawp_url_to('dist/js/layout.js'), [], \IAWP_VERSION);
163 \wp_register_script('iawp-settings-javascript', \IAWPSCOPED\iawp_url_to('dist/js/settings.js'), ['wp-color-picker'], \IAWP_VERSION);
164 if (Menu_Bar_Stats::is_option_enabled()) {
165 \wp_register_style('iawp-front-end-styles', \IAWPSCOPED\iawp_url_to('dist/styles/menu_bar_stats.css'), [], \IAWP_VERSION);
166 }
167 if (\is_rtl()) {
168 \wp_register_style('iawp-styles-rtl', \IAWPSCOPED\iawp_url_to('dist/styles/rtl.css'), [], \IAWP_VERSION);
169 }
170 }
171 public function register_scripts_and_styles_front_end() : void
172 {
173 if (Menu_Bar_Stats::is_option_enabled()) {
174 \wp_register_style('iawp-front-end-styles', \IAWPSCOPED\iawp_url_to('dist/styles/menu_bar_stats.css'), [], \IAWP_VERSION);
175 }
176 }
177 public function enqueue_scripts_and_styles($hook)
178 {
179 $this->register_scripts_and_styles();
180 $page = \IAWP\Env::get_page();
181 $this->enqueue_translations();
182 $this->enqueue_nonces();
183 \wp_enqueue_style('iawp-freemius-notice-styles');
184 if (\is_string($page)) {
185 \wp_enqueue_style('iawp-styles');
186 \wp_enqueue_script('iawp-javascript');
187 \wp_enqueue_script('iawp-layout-javascript');
188 $this->dequeue_bad_actors();
189 $this->maybe_override_adminify_styles();
190 if (\is_rtl()) {
191 \wp_enqueue_style('iawp-styles-rtl');
192 }
193 }
194 if ($page === 'independent-analytics-settings') {
195 \wp_enqueue_style('wp-color-picker');
196 \wp_enqueue_script('iawp-settings-javascript');
197 } elseif ($hook === 'index.php') {
198 \wp_enqueue_script('iawp-dashboard-widget-javascript');
199 \wp_enqueue_style('iawp-dashboard-widget-styles');
200 } elseif ($hook === 'edit.php') {
201 \wp_enqueue_style('iawp-posts-menu-styles');
202 }
203 if (Menu_Bar_Stats::is_option_enabled()) {
204 \wp_enqueue_style('iawp-front-end-styles');
205 }
206 }
207 public function enqueue_scripts_and_styles_front_end()
208 {
209 if (Menu_Bar_Stats::is_option_enabled()) {
210 $this->register_scripts_and_styles_front_end();
211 \wp_enqueue_style('iawp-front-end-styles');
212 }
213 }
214 public function enqueue_translations()
215 {
216 \wp_register_script('iawp-translations', '');
217 \wp_enqueue_script('iawp-translations');
218 \wp_add_inline_script('iawp-translations', 'const iawpText = ' . \json_encode(['views' => \__('Views', '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');
219 }
220 public function enqueue_nonces()
221 {
222 \wp_register_script('iawp-nonces', '');
223 \wp_enqueue_script('iawp-nonces');
224 \wp_add_inline_script('iawp-nonces', 'const iawpActions = ' . \json_encode(AJAX_Manager::getInstance()->get_action_signatures()), 'before');
225 }
226 public function get_option($name, $default)
227 {
228 $option = \get_option($name, $default);
229 return $option === '' ? $default : $option;
230 }
231 public function filter_connect_message_on_update($message, $user_first_name, $product_title, $user_login, $site_link, $freemius_link)
232 {
233 // Add the heading HTML.
234 $plugin_name = 'Independent Analytics';
235 $title = '<h3>' . \sprintf(\esc_html__('We hope you love %1$s', 'independent-analytics'), $plugin_name) . '</h3>';
236 $html = '';
237 // Add the introduction HTML.
238 $html .= '<p>';
239 $html .= \sprintf(\esc_html__('Hi, %1$s! This is an invitation to help the %2$s community.', 'independent-analytics'), $user_first_name, $plugin_name);
240 $html .= '<strong>';
241 $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);
242 $html .= '</strong>';
243 $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);
244 $html .= '</p>';
245 $html .= '<p>';
246 $html .= \sprintf(\esc_html__('And if you skip this, that\'s okay! %1$s will still work just fine.', 'independent-analytics'), $plugin_name);
247 $html .= '</p>';
248 return $title . $html;
249 }
250 public function plugin_action_links($links)
251 {
252 // Create the link
253 $settings_link = '<a class="calendar-link" href="' . \esc_url(\IAWPSCOPED\iawp_dashboard_url()) . '">' . \esc_html__('Analytics Dashboard', 'independent-analytics') . '</a>';
254 // Add the link to the start of the array
255 \array_unshift($links, $settings_link);
256 return $links;
257 }
258 public function ip_db_attribution($text)
259 {
260 if (\IAWP\Env::get_tab() === 'geo') {
261 $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>.';
262 }
263 return $text;
264 }
265 public function pagination_page_size()
266 {
267 return 50;
268 }
269 public function dequeue_bad_actors()
270 {
271 // https://wordpress.org/plugins/comment-link-remove/
272 \wp_dequeue_style('qc_clr_admin_style_css');
273 // https://wordpress.org/plugins/webappick-pdf-invoice-for-woocommerce/
274 \wp_dequeue_style('woo-invoice');
275 // https://wordpress.org/plugins/wp-media-files-name-rename/
276 \wp_dequeue_style('wpcmp_bootstrap_css');
277 // https://wordpress.org/plugins/morepuzzles/
278 \wp_dequeue_style('bscss');
279 \wp_dequeue_style('mypluginstyle');
280 }
281 public function maybe_override_adminify_styles()
282 {
283 if (\in_array('adminify/adminify.php', \get_option('active_plugins'))) {
284 $settings = \get_option('_wpadminify');
285 if ($settings) {
286 if (\array_key_exists('admin_ui', $settings)) {
287 if ($settings['admin_ui']) {
288 \wp_register_style('iawp-adminify-styles', \IAWPSCOPED\iawp_url_to('dist/styles/adminify.css'), [], \IAWP_VERSION);
289 \wp_enqueue_style('iawp-adminify-styles');
290 }
291 }
292 }
293 }
294 }
295 public function changelog_viewed_since_update() : bool
296 {
297 if (\number_format(\floatval(\IAWP_VERSION), 1) > \floatval($this->get_option('iawp_last_update_viewed', '0'))) {
298 return \true;
299 }
300 return \false;
301 }
302 public function is_form_submission_support_enabled() : bool
303 {
304 if (!\is_bool($this->is_form_submission_support_enabled)) {
305 $this->is_form_submission_support_enabled = \IAWPSCOPED\iawp_is_pro() && Form::has_active_form_plugin() && !\IAWP\Capability_Manager::can_only_view_authored_analytics();
306 }
307 return $this->is_form_submission_support_enabled;
308 }
309 public function is_woocommerce_support_enabled() : bool
310 {
311 if (!\is_bool($this->is_woocommerce_support_enabled)) {
312 $this->is_woocommerce_support_enabled = $this->actually_check_if_woocommerce_support_enabled();
313 }
314 return $this->is_woocommerce_support_enabled;
315 }
316 private function actually_check_if_woocommerce_support_enabled() : bool
317 {
318 global $wpdb;
319 if (\IAWPSCOPED\iawp_is_free()) {
320 return \false;
321 }
322 if (\IAWP\Capability_Manager::can_only_view_authored_analytics()) {
323 return \false;
324 }
325 if (\is_multisite()) {
326 $active_plugins = \get_option('active_plugins');
327 $sitewide_plugins = \get_site_option('active_sitewide_plugins');
328 if (!\in_array('woocommerce/woocommerce.php', $active_plugins) && !\array_key_exists('woocommerce/woocommerce.php', $sitewide_plugins)) {
329 return \false;
330 }
331 } else {
332 $active_plugins = \get_option('active_plugins');
333 if (!\in_array('woocommerce/woocommerce.php', $active_plugins)) {
334 return \false;
335 }
336 }
337 $table_name = $wpdb->prefix . 'wc_order_stats';
338 $order_stats_table = $wpdb->get_row($wpdb->prepare('
339 SELECT * FROM INFORMATION_SCHEMA.TABLES
340 WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s
341 ', $wpdb->dbname, $table_name));
342 if (\is_null($order_stats_table)) {
343 return \false;
344 }
345 return \true;
346 }
347 }
348