PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.20.0
Independent Analytics – WordPress Analytics Plugin v1.20.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 3 years ago Migrations 3 years ago Models 3 years ago Queries 3 years ago Tables 3 years ago Utils 3 years ago Campaign_Builder.php 3 years ago Capability_Manager.php 3 years ago Chart.php 3 years ago Chart_Geo.php 3 years ago Chart_SVG.php 3 years ago Current_Resource.php 3 years ago Dashboard_Options.php 3 years ago Dashboard_Widget.php 3 years ago Email_Reports.php 3 years ago Filters.php 3 years ago Geo_Database.php 3 years ago Geo_Database_Download_Job.php 3 years ago Health_Check.php 3 years ago Independent_Analytics.php 3 years ago Known_Referrers.php 3 years ago PDF.php 3 years ago Query.php 3 years ago Quick_Stats.php 3 years ago REST_API.php 3 years ago Real_Time.php 3 years ago Settings.php 3 years ago Track_Resource_Changes.php 3 years ago View_Counter.php 3 years ago WP_Option_Cache_Bust.php 3 years ago WooCommerce_Order.php 3 years ago
Independent_Analytics.php
581 lines
1 <?php
2
3 namespace IAWP_SCOPED\IAWP;
4
5 use IAWP_SCOPED\IAWP\AJAX\Cleared_Cache_AJAX;
6 use IAWP_SCOPED\IAWP\AJAX\Create_Campaign_AJAX;
7 use IAWP_SCOPED\IAWP\AJAX\Delete_Data_AJAX;
8 use IAWP_SCOPED\IAWP\AJAX\Export_Campaigns_AJAX;
9 use IAWP_SCOPED\IAWP\AJAX\Export_Geo_AJAX;
10 use IAWP_SCOPED\IAWP\AJAX\Export_Referrers_AJAX;
11 use IAWP_SCOPED\IAWP\AJAX\Export_Views_AJAX;
12 use IAWP_SCOPED\IAWP\AJAX\Filters_AJAX;
13 use IAWP_SCOPED\IAWP\AJAX\Migration_Status_AJAX;
14 use IAWP_SCOPED\IAWP\AJAX\Real_Time_AJAX;
15 use IAWP_SCOPED\IAWP\AJAX\Test_Email_AJAX;
16 use IAWP_SCOPED\IAWP\AJAX\Update_Capabilities_AJAX;
17 use IAWP_SCOPED\IAWP\Queries\Country_Statistics;
18 use IAWP_SCOPED\IAWP\Queries\Views;
19 use IAWP_SCOPED\IAWP\Tables\Table_Campaigns;
20 use IAWP_SCOPED\IAWP\Tables\Table_Geo;
21 use IAWP_SCOPED\IAWP\Tables\Table_Referrers;
22 use IAWP_SCOPED\IAWP\Tables\Table_Views;
23 use IAWP_SCOPED\IAWP\Utils\Security;
24 use IAWP_SCOPED\IAWP\Utils\Singleton;
25 class Independent_Analytics
26 {
27 use Singleton;
28 public $settings;
29 public $email_reports;
30 // This is where we attach functions to WP hooks
31 private function __construct()
32 {
33 $this->settings = new Settings();
34 new REST_API();
35 new Dashboard_Widget();
36 new View_Counter();
37 new Delete_Data_AJAX();
38 new Filters_AJAX();
39 new Export_Geo_AJAX();
40 new Export_Referrers_AJAX();
41 new Export_Views_AJAX();
42 new Migration_Status_AJAX();
43 new Update_Capabilities_AJAX();
44 new Cleared_Cache_AJAX();
45 new Track_Resource_Changes();
46 WooCommerce_Order::initialize_order_tracker();
47 if (\IAWP_SCOPED\iawp_is_pro()) {
48 $this->email_reports = new Email_Reports();
49 new Export_Campaigns_AJAX();
50 new Create_Campaign_AJAX();
51 new Campaign_Builder();
52 new Real_Time_AJAX();
53 new Test_Email_AJAX();
54 }
55 \add_filter('admin_body_class', function ($classes) {
56 if (\get_option('iawp_dark_mode')) {
57 $classes .= ' iawp-dark-mode ';
58 }
59 return $classes;
60 });
61 \add_action('admin_menu', [$this, 'add_settings_page']);
62 \add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts']);
63 \add_filter('plugin_action_links_independent-analytics/iawp.php', [$this, 'plugin_action_links']);
64 \add_filter('admin_footer_text', [$this, 'ip_db_attribution'], 1, 1);
65 \add_filter('admin_head', [$this, 'style_premium_menu_item']);
66 \add_action('init', [$this, 'load_textdomain']);
67 \add_action('init', [$this, 'polylang_translations']);
68 IAWP_FS()->add_filter('connect_message_on_update', [$this, 'filter_connect_message_on_update'], 10, 6);
69 IAWP_FS()->add_filter('connect_message', [$this, 'filter_connect_message_on_update'], 10, 6);
70 IAWP_FS()->add_filter('is_submenu_visible', [$this, 'hide_freemius_sub_menus'], 10, 2);
71 IAWP_FS()->add_filter('pricing_url', [$this, 'change_freemius_pricing_url'], 10);
72 }
73 // Text domain is used for i18n
74 public function load_textdomain()
75 {
76 \load_plugin_textdomain('iawp', \false, \IAWP_LANGUAGES_DIRECTORY);
77 }
78 public function polylang_translations()
79 {
80 if (\function_exists('IAWP_SCOPED\\pll_register_string')) {
81 pll_register_string('view_counter', 'Views:', 'Independent Analytics');
82 }
83 }
84 // Settings page where the analytics will appear
85 public function add_settings_page()
86 {
87 \add_menu_page('Independent Analytics', \esc_html__('Analytics', 'iawp'), Capability_Manager::can_view_string(), 'independent-analytics', [$this, 'settings_page_markup'], 'dashicons-analytics', 3);
88 if (!Capability_Manager::white_labeled()) {
89 \add_submenu_page('independent-analytics', \esc_html__('Feedback', 'iawp'), \esc_html__('Feedback', 'iawp'), Capability_Manager::can_view_string(), \esc_url('https://feedback.independentwp.com/boards/feature-requests'));
90 }
91 if (\IAWP_SCOPED\iawp_is_free() && !Capability_Manager::white_labeled()) {
92 \add_submenu_page('independent-analytics', \esc_html__('Upgrade to Pro &rarr;', 'iawp'), \esc_html__('Upgrade to Pro &rarr;', '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'));
93 }
94 }
95 public function hide_freemius_sub_menus($is_visible, $menu_id)
96 {
97 if ('pricing' == $menu_id) {
98 return \false;
99 } elseif ('support' == $menu_id && Capability_Manager::white_labeled()) {
100 return \false;
101 } else {
102 return \true;
103 }
104 }
105 public function change_freemius_pricing_url()
106 {
107 return 'https://independentwp.com/pricing/?utm_source=User+Dashboard&utm_medium=WP+Admin&utm_campaign=Upgrade+to+Pro&utm_content=Account';
108 }
109 // The submenu item needs to be styled on all admin pages, and we only load stylesheets on our page
110 public function style_premium_menu_item()
111 {
112 if (\IAWP_SCOPED\iawp_is_free()) {
113 echo '<style>#toplevel_page_independent-analytics .wp-submenu li:nth-child(4) a { color: #F69D0A; }</style>';
114 }
115 }
116 private function get_current_tab()
117 {
118 if (\IAWP_SCOPED\iawp_is_pro()) {
119 $valid_tabs = ['views', 'referrers', 'geo', 'campaigns', 'campaign-builder', 'real-time', 'settings', 'learn'];
120 } else {
121 $valid_tabs = ['views', 'referrers', 'geo', 'settings', 'learn'];
122 }
123 $default_tab = $valid_tabs[0];
124 $tab = \array_key_exists('tab', $_GET) ? \sanitize_text_field($_GET['tab']) : \false;
125 $is_valid = \array_search($tab, $valid_tabs) != \false;
126 if (!$tab || !$is_valid) {
127 $tab = $default_tab;
128 }
129 return $tab;
130 }
131 public function settings_page_markup()
132 {
133 if (!Capability_Manager::can_view()) {
134 return;
135 }
136 // ray(Migrations\Migration::has_newer_database_version());
137 if (Migrations\Migration::has_newer_database_version()) {
138 ?>
139 <div id="iawp-parent" class="iawp-parent">
140 <?php
141 echo \IAWP_SCOPED\iawp()->templates()->render('layout/header', ['show_review' => \false]);
142 ?>
143 <?php
144 echo \IAWP_SCOPED\iawp()->templates()->render('newer_database');
145 ?>
146 </div>
147 <?php
148 return;
149 } elseif (Migrations\Migration::is_migrating()) {
150 ?>
151 <div id="iawp-parent" class="iawp-parent">
152 <?php
153 echo \IAWP_SCOPED\iawp()->templates()->render('layout/header', ['show_review' => \false]);
154 ?>
155 <?php
156 echo \IAWP_SCOPED\iawp()->templates()->render('migration_running');
157 ?>
158 </div>
159 <?php
160 return;
161 }
162 $tab = $this->get_current_tab();
163 ?>
164 <div id="iawp-parent" class="iawp-parent">
165 <?php
166 if (!Capability_Manager::white_labeled()) {
167 echo \IAWP_SCOPED\iawp()->templates()->render('layout/header');
168 }
169 ?>
170 <nav class="nav">
171 <ul class="menu">
172 <li class="menu-item">
173 <a href="?page=independent-analytics"
174 data-controller="track-date-range"
175 data-test-menu="views"
176 class="menu-link link-dark <?php
177 if ($tab === 'views') {
178 ?>active<?php
179 }
180 ?>">
181 <?php
182 \esc_html_e('Pages', 'iawp');
183 ?>
184 </a>
185 </li>
186 <li class="menu-item">
187 <a href="?page=independent-analytics&tab=referrers"
188 data-controller="track-date-range"
189 data-test-menu="referrers"
190 class="menu-link link-dark <?php
191 if ($tab === 'referrers') {
192 ?>active<?php
193 }
194 ?>">
195 <?php
196 \esc_html_e('Referrers', 'iawp');
197 ?>
198 </a>
199 </li>
200 <li class="menu-item">
201 <a href="?page=independent-analytics&tab=geo"
202 data-controller="track-date-range"
203 data-test-menu="geo"
204 class="menu-link link-dark <?php
205 if ($tab === 'geo') {
206 ?>active<?php
207 }
208 ?>">
209 <?php
210 \esc_html_e('Geographic', 'iawp');
211 ?>
212 </a>
213 </li>
214 <?php
215 if (\IAWP_SCOPED\iawp_is_pro()) {
216 ?>
217 <li class="menu-item">
218 <a href="?page=independent-analytics&tab=campaigns"
219 data-controller="track-date-range"
220 data-test-menu="campaigns"
221 class="menu-link link-dark <?php
222 if ($tab === 'campaigns' || $tab === 'campaign-builder') {
223 ?>active<?php
224 }
225 ?>">
226 <?php
227 \esc_html_e('Campaigns', 'iawp');
228 ?>
229 </a>
230 <div class="sub-menu">
231 <ul>
232 <li class="menu-item">
233 <a href="?page=independent-analytics&tab=campaign-builder"
234 class="menu-link link-dark">
235 <?php
236 \esc_html_e('Campaign Builder', 'iawp');
237 ?>
238 </a>
239 </li>
240 </ul>
241 </div>
242 </li>
243 <li class="menu-item">
244 <a href="?page=independent-analytics&tab=real-time"
245 data-test-menu="real-time"
246 class="menu-link link-dark <?php
247 if ($tab === 'real-time') {
248 ?>active<?php
249 }
250 ?>">
251 <?php
252 \esc_html_e('Real-time', 'iawp');
253 ?>
254 </a>
255 </li>
256 <?php
257 }
258 ?>
259 <?php
260 if (Capability_Manager::can_edit()) {
261 ?>
262 <li class="menu-item">
263 <a href="?page=independent-analytics&tab=settings"
264 data-test-menu="settings"
265 class="menu-link link-dark <?php
266 if ($tab === 'settings') {
267 ?>active<?php
268 }
269 ?>">
270 <?php
271 \esc_html_e('Settings', 'iawp');
272 ?>
273 </a>
274 </li>
275 <?php
276 }
277 ?>
278 <?php
279 if (!Capability_Manager::white_labeled()) {
280 ?>
281 <li class="menu-item">
282 <a href="?page=independent-analytics&tab=learn"
283 data-test-menu="learn"
284 class="menu-link link-dark <?php
285 if ($tab === 'learn') {
286 ?>active<?php
287 }
288 ?>">
289 <?php
290 \esc_html_e('Learn', 'iawp');
291 ?>
292 </a>
293 </li>
294 <?php
295 }
296 ?>
297 <?php
298 if (!Capability_Manager::white_labeled() && \IAWP_SCOPED\iawp_is_free()) {
299 ?>
300 <li class="menu-item upgrade first" data-controller="modal">
301 <a href="#"
302 data-test-menu="campaigns"
303 data-action="modal#toggleModal"
304 data-modal-target="modalButton"
305 class="menu-link link-dark">
306 <?php
307 \esc_html_e('Campaigns', 'iawp');
308 ?>
309 </a>
310 <div class="upgrade-popup"
311 data-modal-target="modal"
312 >
313 <div class="title">
314 <span class="name"><?php
315 \esc_html_e('Campaigns', 'iawp');
316 ?></span>
317 <span class="label"><?php
318 \esc_html_e('PRO', 'iawp');
319 ?></span>
320 </div>
321 <div class="description">
322 <p><?php
323 \esc_html_e("Campaigns let you track visits from individual links you share online, whether that's a Tweet, ad, or guest post.", 'iawp');
324 ?></p>
325 <a class="iawp-button purple" target="_blank"
326 href="https://independentwp.com/features/campaigns/?utm_source=User+Dashboard&utm_medium=WP+Admin&utm_campaign=Campaigns+menu+item&utm_content=Menu+item"><?php
327 \esc_html_e('Upgrade', 'iawp');
328 ?></a>
329 </div>
330 </div>
331 </li>
332 <li class="menu-item upgrade" data-controller="modal">
333 <a href="#"
334 data-test-menu="real-time"
335 data-action="modal#toggleModal"
336 data-modal-target="modalButton"
337 class="menu-link link-dark">
338 <?php
339 \esc_html_e('Real-time', 'iawp');
340 ?>
341 </a>
342 <div class="upgrade-popup"
343 data-modal-target="modal"
344 >
345 <div class="title">
346 <span class="name"><?php
347 \esc_html_e('Real-time analytics', 'iawp');
348 ?></span>
349 <span class="label"><?php
350 \esc_html_e('PRO', 'iawp');
351 ?></span>
352 </div>
353 <div class="description">
354 <p><?php
355 \esc_html_e("Real-time analytics let you see how many people are on your site right now, what pages they're viewing, and where they came from.", 'iawp');
356 ?></p>
357 <a class="iawp-button purple" target="_blank"
358 href="https://independentwp.com/features/real-time/?utm_source=User+Dashboard&utm_medium=WP+Admin&utm_campaign=Real-time+menu+item&utm_content=Menu+item"><?php
359 \esc_html_e('Upgrade', 'iawp');
360 ?></a>
361 </div>
362 </div>
363 </li>
364 <?php
365 }
366 ?>
367 </ul>
368 </nav>
369 <div class="tab-content"><?php
370 $opts = new Dashboard_Options();
371 $date_label = $opts->date_label();
372 $range = $opts->date_range();
373 $columns = $opts->columns();
374 if ($tab == 'views') {
375 $table = new Table_Views($columns);
376 $views = new Views(Views::RESOURCES, null, $range->start, $range->end);
377 $stats = new Quick_Stats($views, null);
378 $chart = new Chart($views, $date_label);
379 $this->interface($table, $stats, $chart);
380 } elseif ($tab == 'referrers') {
381 $table = new Table_Referrers($columns);
382 $views = new Views(Views::RESOURCES, null, $range->start, $range->end);
383 $stats = new Quick_Stats($views, null);
384 $chart = new Chart($views, $date_label);
385 $this->interface($table, $stats, $chart);
386 } elseif ($tab == 'geo') {
387 $table = new Table_Geo($columns);
388 $views = new Views(Views::GEO, null, $range->start, $range->end);
389 $stats = new Quick_Stats($views, null);
390 $country_statistics = new Country_Statistics(['start' => $range->start, 'end' => $range->end]);
391 $chart = new Chart_Geo($country_statistics->fetch(), $date_label);
392 $this->interface($table, $stats, $chart);
393 } elseif ($tab === 'campaigns') {
394 $table = new Table_Campaigns($columns);
395 $views = new Views(Views::CAMPAIGNS, null, $range->start, $range->end);
396 $stats = new Quick_Stats($views, null);
397 $chart = new Chart($views, $date_label);
398 $this->interface($table, $stats, $chart);
399 } elseif ($tab == 'campaign-builder') {
400 (new Campaign_Builder())->render_campaign_builder();
401 } elseif ($tab === 'real-time') {
402 (new Real_Time())->render_real_time_analytics();
403 } elseif ($tab == 'settings') {
404 echo '<div id="iawp-dashboard" class="iawp-dashboard">';
405 if (Capability_Manager::can_edit()) {
406 $this->settings->render_settings();
407 } else {
408 echo '<p class="permission-blocked">' . \esc_html__('You do not have permission to edit the settings.', 'iawp') . '</p>';
409 }
410 echo '</div>';
411 } elseif ($tab == 'learn') {
412 echo '<div id="iawp-dashboard" class="iawp-dashboard">';
413 echo \IAWP_SCOPED\iawp()->templates()->render('learn/index');
414 echo '</div>';
415 }
416 ?>
417 </div>
418 <div id="loading-icon" class="loading-icon"><img
419 src="<?php
420 echo \esc_url(\IAWP_SCOPED\iawp_url_to('img/loading.svg'));
421 ?>"/>
422 </div>
423 <button id="scroll-to-top" class="scroll-to-top"><span
424 class="dashicons dashicons-arrow-up-alt"></span>
425 </button>
426 </div>
427 <?php
428 }
429 public function interface($table, $stats, $chart)
430 {
431 $opts = new Dashboard_Options();
432 ?>
433 <div id="iawp-dashboard"
434 class="iawp-dashboard"
435 data-controller="report"
436 data-report-relative-range-id-value="<?php
437 echo Security::attr($opts->relative_range());
438 ?>"
439 data-report-exact-start-value="<?php
440 echo Security::attr($opts->start());
441 ?>"
442 data-report-exact-end-value="<?php
443 echo Security::attr($opts->end());
444 ?>"
445 data-report-columns-value="<?php
446 \esc_attr_e(Security::json_encode($table->visible_column_ids()));
447 ?>"
448 >
449 <?php
450 echo Security::html($table->output_toolbar());
451 ?>
452 <?php
453 echo $stats->get_html();
454 ?>
455 <?php
456 echo $chart->get_html();
457 ?>
458 <?php
459 echo Security::html($table->get_table_markup());
460 ?>
461 </div>
462 <div class="iawp-notices"><?php
463 $health_check = new Health_Check();
464 if (!$health_check->healthy()) {
465 echo \IAWP_SCOPED\iawp()->templates()->render('settings/notice', ['notice_text' => $health_check->error(), 'button_text' => \false, 'notice' => 'iawp-error', 'url' => 'https://independentwp.com/knowledgebase/common-questions/views-not-recording/']);
466 }
467 if (\get_option('iawp_need_clear_cache')) {
468 echo \IAWP_SCOPED\iawp()->templates()->render('settings/notice', ['notice_text' => \__('Please clear your cache to ensure tracking works properly.', 'iawp'), 'button_text' => \__('I\'ve cleared the cache', 'iawp'), 'notice' => 'iawp-warning', 'url' => 'https://independentwp.com/knowledgebase/common-questions/views-not-recording/']);
469 }
470 ?>
471 </div><?php
472 }
473 public function enqueue_scripts($hook)
474 {
475 if ($hook == 'toplevel_page_independent-analytics') {
476 $tab = $this->get_current_tab();
477 \wp_register_style('iawp-style', \IAWP_SCOPED\iawp_url_to('dist/styles/style.css'), [], \IAWP_VERSION);
478 \wp_enqueue_style('iawp-style');
479 \wp_register_script('iawp-js', \IAWP_SCOPED\iawp_url_to('dist/js/index.js'), [], \IAWP_VERSION);
480 \wp_enqueue_script('iawp-js');
481 \wp_add_inline_script('iawp-js', 'const IAWP_DELETE_DATA_NONCE = ' . \json_encode(\wp_create_nonce('iawp_delete_data')), 'before');
482 if ($tab === 'views' || $tab === 'referrers' || $tab === 'geo' || $tab === 'campaigns' || $tab === 'campaign-builder') {
483 \wp_register_script('iawp-data-table', \IAWP_SCOPED\iawp_url_to('dist/js/data-table.js'), [], \IAWP_VERSION);
484 \wp_enqueue_script('iawp-data-table');
485 \wp_add_inline_script('iawp-data-table', 'const IAWP_AJAX = ' . \json_encode(['filter_nonce' => \wp_create_nonce('iawp_filter'), 'create_campaign_nonce' => \wp_create_nonce('iawp_create_campaign'), 'copied_text' => \esc_html__('Copied!', 'iawp'), 'iawp_need_clear_cache_nonce' => \wp_create_nonce('iawp_need_clear_cache')]), 'before');
486 } elseif ($tab == 'settings') {
487 \wp_register_script('iawp-settings', \IAWP_SCOPED\iawp_url_to('dist/js/settings.js'), [], \IAWP_VERSION);
488 \wp_enqueue_script('iawp-settings');
489 \wp_add_inline_script('iawp-settings', 'const IAWP_AJAX = ' . \json_encode(['export_views_nonce' => \wp_create_nonce('iawp_export_views'), 'export_referrers_nonce' => \wp_create_nonce('iawp_export_referrers'), 'export_geo_nonce' => \wp_create_nonce('iawp_export_geo'), 'export_campaigns_nonce' => \wp_create_nonce('iawp_export_campaigns'), 'iawp_capabilities_nonce' => \wp_create_nonce('iawp_capabilities'), 'iawp_test_email_nonce' => \wp_create_nonce('iawp_test_email'), 'exporting_views_text' => \esc_html__('Exporting views...', 'iawp'), 'export_views_text' => \esc_html__('Export views', 'iawp'), 'exporting_referrers_text' => \esc_html__('Exporting referrers...', 'iawp'), 'export_referrers_text' => \esc_html__('Export referrers', 'iawp'), 'exporting_geo_text' => \esc_html__('Exporting geo...', 'iawp'), 'export_geo_text' => \esc_html__('Export geo', 'iawp'), 'exporting_campaigns_text' => \esc_html__('Exporting campaigns...', 'iawp'), 'export_campaigns_text' => \esc_html__('Export campaigns', 'iawp')]), 'before');
490 } elseif ($tab == 'learn') {
491 \wp_register_script('iawp-learn', \IAWP_SCOPED\iawp_url_to('dist/js/learn.js'), [], \IAWP_VERSION);
492 \wp_enqueue_script('iawp-learn');
493 }
494 } elseif ($hook == 'index.php') {
495 \wp_register_script('iawp-dashboard-widget', \IAWP_SCOPED\iawp_url_to('dist/js/dashboard_widget.js'), [], \IAWP_VERSION);
496 \wp_enqueue_script('iawp-dashboard-widget');
497 \wp_register_style('iawp-dashboard-widget-css', \IAWP_SCOPED\iawp_url_to('dist/styles/dashboard_widget.css'), [], \IAWP_VERSION);
498 \wp_enqueue_style('iawp-dashboard-widget-css');
499 }
500 }
501 /* WP uses $default when get_option() is empty, but it also saves empty fields
502 ** as empty strings, meaning the return value can be "" instead of the default. This is
503 ** a defensive function that guarantees we get the proper default when the setting is empty. */
504 public function get_option($name, $default)
505 {
506 $option = \get_option($name, $default);
507 return $option === '' ? $default : $option;
508 }
509 public function templates()
510 {
511 return new \IAWP_SCOPED\League\Plates\Engine(\IAWP_SCOPED\iawp_path_to('templates'));
512 }
513 public function get_users_can_write()
514 {
515 $roles = [];
516 foreach (\wp_roles()->roles as $role_name => $role_obj) {
517 if (!empty($role_obj['capabilities']['edit_posts'])) {
518 $roles[] = $role_name;
519 }
520 }
521 $users = \get_users(['role__in' => $roles]);
522 return $users;
523 }
524 public function get_custom_types(bool $tax = \false)
525 {
526 $args = ['public' => \true, '_builtin' => \false];
527 if ($tax) {
528 return \get_taxonomies($args);
529 } else {
530 return \get_post_types($args);
531 }
532 }
533 public function filter_connect_message_on_update($message, $user_first_name, $product_title, $user_login, $site_link, $freemius_link)
534 {
535 // Add the heading HTML.
536 $plugin_name = 'Independent Analytics';
537 $title = '<h3>' . \sprintf(\esc_html__('We hope you love %1$s', 'iawp'), $plugin_name) . '</h3>';
538 $html = '';
539 // Add the introduction HTML.
540 $html .= '<p>';
541 $html .= \sprintf(\esc_html__('Hi, %1$s! This is an invitation to help the %2$s community. ', 'iawp'), $user_first_name, $plugin_name);
542 $html .= '<strong>';
543 $html .= \sprintf(\esc_html__('If you opt-in, some data about your usage of %2$s will be shared with us', 'iawp'), $user_first_name, $plugin_name);
544 $html .= '</strong>';
545 $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.', 'iawp'), $user_first_name, $plugin_name);
546 $html .= '</p>';
547 $html .= '<p>';
548 $html .= \sprintf(\esc_html__('And if you skip this, that\'s okay! %1$s will still work just fine.', 'iawp'), $plugin_name);
549 $html .= '</p>';
550 return $title . $html;
551 }
552 public function plugin_action_links($links)
553 {
554 // Build the URL
555 $url = \add_query_arg('page', 'independent-analytics', \admin_url('admin.php'));
556 // Create the link
557 $settings_link = '<a class="calendar-link" href="' . \esc_url($url) . '">' . \esc_html__('Analytics Dashboard', 'iawp') . '</a>';
558 // Add the link to the start of the array
559 \array_unshift($links, $settings_link);
560 return $links;
561 }
562 public function set_time_limit($limit = 0)
563 {
564 if (!\function_exists('set_time_limit') && \false !== \strpos(\ini_get('disable_functions'), 'set_time_limit') && \ini_get('safe_mode')) {
565 return \false;
566 }
567 return @\set_time_limit($limit);
568 }
569 public function ip_db_attribution($text)
570 {
571 if ($this->get_current_tab() === 'geo') {
572 $text = $text . ' ' . \esc_html_x('Geolocation data powered by', 'Following text is a noun: DB-IP', 'iawp') . ' ' . '<a href="https://db-ip.com" class="geo-message" target="_blank">DB-IP</a>.';
573 }
574 return $text;
575 }
576 public function pagination_page_size()
577 {
578 return 50;
579 }
580 }
581