AJAX
2 years ago
Date_Range
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_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
432 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP_SCOPED\IAWP; |
| 4 | |
| 5 | use IAWP_SCOPED\IAWP\AJAX\AJAX_Manager; |
| 6 | use IAWP_SCOPED\IAWP\Menu_Bar_Stats\Menu_Bar_Stats; |
| 7 | use IAWP_SCOPED\IAWP\Migrations\Migrations; |
| 8 | use IAWP_SCOPED\IAWP\Tables\Table; |
| 9 | use IAWP_SCOPED\IAWP\Tables\Table_Campaigns; |
| 10 | use IAWP_SCOPED\IAWP\Tables\Table_Devices; |
| 11 | use IAWP_SCOPED\IAWP\Tables\Table_Geo; |
| 12 | use IAWP_SCOPED\IAWP\Tables\Table_Pages; |
| 13 | use IAWP_SCOPED\IAWP\Tables\Table_Referrers; |
| 14 | use IAWP_SCOPED\IAWP\Utils\Security; |
| 15 | use IAWP_SCOPED\IAWP\Utils\Singleton; |
| 16 | /** @internal */ |
| 17 | class Independent_Analytics |
| 18 | { |
| 19 | use Singleton; |
| 20 | public $settings; |
| 21 | public $email_reports; |
| 22 | public $cron_manager; |
| 23 | // This is where we attach functions to WP hooks |
| 24 | private function __construct() |
| 25 | { |
| 26 | $this->settings = new Settings(); |
| 27 | new REST_API(); |
| 28 | new Dashboard_Widget(); |
| 29 | new View_Counter(); |
| 30 | AJAX_Manager::getInstance(); |
| 31 | if (!Migrations::is_migrating()) { |
| 32 | new Track_Resource_Changes(); |
| 33 | Menu_Bar_Stats::register(); |
| 34 | WooCommerce_Order::initialize_order_tracker(); |
| 35 | } |
| 36 | $this->cron_manager = new Cron_Manager(); |
| 37 | if (\IAWP_SCOPED\iawp_is_pro()) { |
| 38 | $this->email_reports = new Email_Reports(); |
| 39 | new Campaign_Builder(); |
| 40 | new WooCommerce_Referrer_Meta_Box(); |
| 41 | } |
| 42 | \add_filter('admin_body_class', function ($classes) { |
| 43 | if (\get_option('iawp_dark_mode')) { |
| 44 | $classes .= ' iawp-dark-mode '; |
| 45 | } |
| 46 | return $classes; |
| 47 | }); |
| 48 | \add_action('admin_menu', [$this, 'add_admin_menu_pages']); |
| 49 | \add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_scripts']); |
| 50 | \add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts']); |
| 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_filter('admin_head', [$this, 'style_premium_menu_item']); |
| 54 | \add_action('init', [$this, 'polylang_translations']); |
| 55 | \add_action('init', [$this, 'load_textdomain']); |
| 56 | IAWP_FS()->add_filter('connect_message_on_update', [$this, 'filter_connect_message_on_update'], 10, 6); |
| 57 | IAWP_FS()->add_filter('connect_message', [$this, 'filter_connect_message_on_update'], 10, 6); |
| 58 | IAWP_FS()->add_filter('is_submenu_visible', [$this, 'hide_freemius_sub_menus'], 10, 2); |
| 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 | } |
| 65 | /** |
| 66 | * At one point in time, there was a must-use plugin that was created. The plugin file and the |
| 67 | * option need to get cleaned up. |
| 68 | * @return void |
| 69 | */ |
| 70 | public function maybe_delete_mu_plugin() |
| 71 | { |
| 72 | $already_attempted = \get_option('iawp_attempted_to_delete_mu_plugin', '0'); |
| 73 | if ($already_attempted === '1') { |
| 74 | return; |
| 75 | } |
| 76 | if (\get_option('iawp_must_use_directory_not_writable', '0') === '1') { |
| 77 | \delete_option('iawp_must_use_directory_not_writable'); |
| 78 | } |
| 79 | $mu_plugin_file = \trailingslashit(\WPMU_PLUGIN_DIR) . 'iawp-performance-boost.php'; |
| 80 | if (\file_exists($mu_plugin_file)) { |
| 81 | \unlink($mu_plugin_file); |
| 82 | } |
| 83 | \update_option('iawp_attempted_to_delete_mu_plugin', '1'); |
| 84 | } |
| 85 | public function load_textdomain() |
| 86 | { |
| 87 | \load_plugin_textdomain('independent-analytics', \false, \IAWP_LANGUAGES_DIRECTORY); |
| 88 | } |
| 89 | public function polylang_translations() |
| 90 | { |
| 91 | if (\function_exists('IAWP_SCOPED\\pll_register_string')) { |
| 92 | pll_register_string('view_counter', 'Views:', 'Independent Analytics'); |
| 93 | } |
| 94 | } |
| 95 | // Settings page where the analytics will appear |
| 96 | public function add_admin_menu_pages() |
| 97 | { |
| 98 | $title = Capability_Manager::white_labeled() ? \esc_html__('Analytics', 'independent-analytics') : 'Independent Analytics'; |
| 99 | \add_menu_page($title, \esc_html__('Analytics', 'independent-analytics'), Capability_Manager::can_view_string(), 'independent-analytics', [$this, 'render_analytics_page'], 'dashicons-analytics', 3); |
| 100 | if (!Capability_Manager::white_labeled()) { |
| 101 | \add_submenu_page('independent-analytics', \esc_html__('Feedback', 'independent-analytics'), \esc_html__('Feedback', 'independent-analytics'), Capability_Manager::can_view_string(), \esc_url('https://feedback.independentwp.com/boards/feature-requests')); |
| 102 | } |
| 103 | if (\IAWP_SCOPED\iawp_is_free() && !Capability_Manager::white_labeled()) { |
| 104 | \add_submenu_page('independent-analytics', \esc_html__('Upgrade to Pro →', 'independent-analytics'), \esc_html__('Upgrade to Pro →', 'independent-analytics'), 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')); |
| 105 | } |
| 106 | } |
| 107 | public function hide_freemius_sub_menus($is_visible, $menu_id) |
| 108 | { |
| 109 | if ('pricing' == $menu_id) { |
| 110 | return \false; |
| 111 | } elseif ('support' == $menu_id && Capability_Manager::white_labeled()) { |
| 112 | return \false; |
| 113 | } else { |
| 114 | return \true; |
| 115 | } |
| 116 | } |
| 117 | public function change_freemius_pricing_url() |
| 118 | { |
| 119 | return 'https://independentwp.com/pricing/?utm_source=User+Dashboard&utm_medium=WP+Admin&utm_campaign=Upgrade+to+Pro&utm_content=Account'; |
| 120 | } |
| 121 | // The submenu item needs to be styled on all admin pages, and we only load stylesheets on our page |
| 122 | public function style_premium_menu_item() |
| 123 | { |
| 124 | if (\IAWP_SCOPED\iawp_is_free()) { |
| 125 | echo '<style>#toplevel_page_independent-analytics .wp-submenu li:nth-child(4) a { color: #F69D0A; }</style>'; |
| 126 | } |
| 127 | } |
| 128 | public function render_analytics_page() |
| 129 | { |
| 130 | if (!Capability_Manager::can_view()) { |
| 131 | return; |
| 132 | } |
| 133 | if (Migrations::is_migrating()) { |
| 134 | echo \IAWP_SCOPED\iawp_blade()->run('interrupt.migration-is-running'); |
| 135 | return; |
| 136 | } |
| 137 | $options = new Dashboard_Options(); |
| 138 | $tab = $this->get_current_tab(); |
| 139 | ?> |
| 140 | <div id="iawp-parent" class="iawp-parent <?php |
| 141 | \esc_attr_e($tab); |
| 142 | ?>"> |
| 143 | <div id="iawp-layout" class="iawp-layout <?php |
| 144 | echo $options->is_sidebar_collapsed() ? 'collapsed' : ''; |
| 145 | ?>"> |
| 146 | <?php |
| 147 | echo \IAWP_SCOPED\iawp_blade()->run('partials.sidebar', ['favorite_report' => Report_Finder::get_favorite(), 'report_finder' => new Report_Finder(), 'is_white_labeled' => Capability_Manager::white_labeled(), 'can_edit_settings' => Capability_Manager::can_edit(), 'is_dark_mode' => \get_option('iawp_dark_mode')]); |
| 148 | ?> |
| 149 | <div class="iawp-layout-main"> |
| 150 | <div class="iawp-tab-content"><?php |
| 151 | $date_rage = $options->get_date_range(); |
| 152 | $date_label = $date_rage->label(); |
| 153 | $columns = $options->columns(); |
| 154 | if ($tab == 'views') { |
| 155 | $table = new Table_Pages($columns); |
| 156 | $statistics_class = $table->group()->statistics_class(); |
| 157 | $statistics = new $statistics_class($date_rage, null, $options->chart_interval()); |
| 158 | $stats = new Quick_Stats(null, $statistics); |
| 159 | $chart = new Chart($statistics, $date_label); |
| 160 | $this->interface($table, $stats, $chart); |
| 161 | } elseif ($tab == 'referrers') { |
| 162 | $table = new Table_Referrers($columns); |
| 163 | $statistics_class = $table->group()->statistics_class(); |
| 164 | $statistics = new $statistics_class($date_rage, null, $options->chart_interval()); |
| 165 | $stats = new Quick_Stats(null, $statistics); |
| 166 | $chart = new Chart($statistics, $date_label); |
| 167 | $this->interface($table, $stats, $chart); |
| 168 | } elseif ($tab == 'geo') { |
| 169 | $table = new Table_Geo($columns, $options->group()); |
| 170 | $statistics_class = $table->group()->statistics_class(); |
| 171 | $statistics = new $statistics_class($date_rage, null, $options->chart_interval()); |
| 172 | $stats = new Quick_Stats(null, $statistics); |
| 173 | $table_data_class = $table->group()->rows_class(); |
| 174 | $geo_data = new $table_data_class($date_rage); |
| 175 | $chart = new Chart_Geo($geo_data->rows(), $date_label); |
| 176 | $this->interface($table, $stats, $chart); |
| 177 | } elseif ($tab === 'campaigns') { |
| 178 | $table = new Table_Campaigns($columns); |
| 179 | $statistics_class = $table->group()->statistics_class(); |
| 180 | $statistics = new $statistics_class($date_rage, null, $options->chart_interval()); |
| 181 | $stats = new Quick_Stats(null, $statistics); |
| 182 | $chart = new Chart($statistics, $date_label); |
| 183 | $this->interface($table, $stats, $chart); |
| 184 | } elseif ($tab == 'campaign-builder') { |
| 185 | (new Campaign_Builder())->render_campaign_builder(); |
| 186 | } elseif ($tab == 'devices') { |
| 187 | $table = new Table_Devices($columns, $options->group()); |
| 188 | $statistics_class = $table->group()->statistics_class(); |
| 189 | $statistics = new $statistics_class($date_rage, null, $options->chart_interval()); |
| 190 | $stats = new Quick_Stats(null, $statistics); |
| 191 | $chart = new Chart($statistics, $date_label); |
| 192 | $this->interface($table, $stats, $chart); |
| 193 | } elseif ($tab === 'real-time') { |
| 194 | (new Real_Time())->render_real_time_analytics(); |
| 195 | } elseif ($tab == 'settings') { |
| 196 | echo '<div id="iawp-dashboard" class="iawp-dashboard">'; |
| 197 | if (Capability_Manager::can_edit()) { |
| 198 | $this->settings->render_settings(); |
| 199 | } else { |
| 200 | echo '<p class="permission-blocked">' . \esc_html__('You do not have permission to edit the settings.', 'independent-analytics') . '</p>'; |
| 201 | } |
| 202 | echo '</div>'; |
| 203 | } elseif ($tab == 'learn') { |
| 204 | echo '<div id="iawp-dashboard" class="iawp-dashboard">'; |
| 205 | echo \IAWP_SCOPED\iawp_blade()->run('learn.learn'); |
| 206 | echo '</div>'; |
| 207 | } |
| 208 | ?> |
| 209 | </div> |
| 210 | <div id="loading-icon" class="loading-icon"><img |
| 211 | src="<?php |
| 212 | echo \esc_url(\IAWP_SCOPED\iawp_url_to('img/loading.svg')); |
| 213 | ?>"/> |
| 214 | </div> |
| 215 | <button id="scroll-to-top" class="scroll-to-top"><span |
| 216 | class="dashicons dashicons-arrow-up-alt"></span> |
| 217 | </button> |
| 218 | </div> |
| 219 | </div> |
| 220 | </div> |
| 221 | <?php |
| 222 | } |
| 223 | public function interface(Table $table, $stats, $chart) |
| 224 | { |
| 225 | $options = new Dashboard_Options(); |
| 226 | // Todo - Silly that I use table to get the params just to pass them back into table |
| 227 | $sort_configuration = $table->sanitize_sort_parameters($options->sort_column(), $options->sort_direction()); |
| 228 | ?> |
| 229 | <div id="iawp-dashboard" |
| 230 | class="iawp-dashboard" |
| 231 | data-controller="report" |
| 232 | data-report-relative-range-id-value="<?php |
| 233 | echo Security::attr($options->relative_range_id()); |
| 234 | ?>" |
| 235 | data-report-exact-start-value="<?php |
| 236 | echo Security::attr($options->start()); |
| 237 | ?>" |
| 238 | data-report-exact-end-value="<?php |
| 239 | echo Security::attr($options->end()); |
| 240 | ?>" |
| 241 | data-report-group-value="<?php |
| 242 | echo Security::attr($options->group()); |
| 243 | ?>" |
| 244 | data-report-filters-value="<?php |
| 245 | \esc_attr_e(Security::json_encode($options->filters())); |
| 246 | ?>" |
| 247 | data-report-chart-interval-value="<?php |
| 248 | echo Security::attr($options->chart_interval()->id()); |
| 249 | ?>" |
| 250 | data-report-sort-column-value="<?php |
| 251 | echo Security::attr($options->sort_column()); |
| 252 | ?>" |
| 253 | data-report-sort-direction-value="<?php |
| 254 | echo Security::attr($options->sort_direction()); |
| 255 | ?>" |
| 256 | data-report-columns-value="<?php |
| 257 | \esc_attr_e(Security::json_encode($table->visible_column_ids())); |
| 258 | ?>" |
| 259 | data-report-visible-datasets-value="<?php |
| 260 | \esc_attr_e(Security::json_encode($options->visible_datasets())); |
| 261 | ?>" |
| 262 | > |
| 263 | <div class="report-header-container"> |
| 264 | <?php |
| 265 | echo \IAWP_SCOPED\iawp_blade()->run('partials.report-header', ['report' => (new Report_Finder())->current(), 'can_edit' => Capability_Manager::can_edit()]); |
| 266 | ?> |
| 267 | <?php |
| 268 | $table->output_toolbar(); |
| 269 | ?> |
| 270 | </div> |
| 271 | <?php |
| 272 | echo $stats->get_html(); |
| 273 | ?> |
| 274 | <?php |
| 275 | echo $chart->get_html($options->visible_datasets()); |
| 276 | ?> |
| 277 | <?php |
| 278 | echo $table->get_table_markup($sort_configuration->column(), $sort_configuration->direction()); |
| 279 | ?> |
| 280 | </div> |
| 281 | <div class="iawp-notices"><?php |
| 282 | $plugin_conflict_detector = new Plugin_Conflict_Detector(); |
| 283 | if (!$plugin_conflict_detector->has_conflict()) { |
| 284 | echo \IAWP_SCOPED\iawp_blade()->run('settings.notice', ['notice_text' => $plugin_conflict_detector->get_error(), 'button_text' => \false, 'notice' => 'iawp-error', 'url' => 'https://independentwp.com/knowledgebase/common-questions/views-not-recording/']); |
| 285 | } |
| 286 | if (\get_option('iawp_need_clear_cache')) { |
| 287 | echo \IAWP_SCOPED\iawp_blade()->run('settings.notice', ['notice_text' => \__('Please clear your cache to ensure tracking works properly.', 'independent-analytics'), 'button_text' => \__('I\'ve cleared the cache', 'independent-analytics'), 'notice' => 'iawp-warning', 'url' => 'https://independentwp.com/knowledgebase/common-questions/views-not-recording/']); |
| 288 | } |
| 289 | ?> |
| 290 | </div><?php |
| 291 | } |
| 292 | public function enqueue_admin_scripts($hook) |
| 293 | { |
| 294 | $this->enqueue_translations(); |
| 295 | $this->enqueue_nonces(); |
| 296 | if ($hook == 'toplevel_page_independent-analytics') { |
| 297 | $tab = $this->get_current_tab(); |
| 298 | $this->dequeue_other_plugin_styles(); |
| 299 | \wp_register_style('iawp-style', \IAWP_SCOPED\iawp_url_to('dist/styles/style.css'), [], \IAWP_VERSION); |
| 300 | \wp_enqueue_style('iawp-style'); |
| 301 | \wp_register_script('iawp-js', \IAWP_SCOPED\iawp_url_to('dist/js/index.js'), [], \IAWP_VERSION); |
| 302 | \wp_enqueue_script('iawp-js'); |
| 303 | if ($tab === 'views' || $tab === 'referrers' || $tab === 'geo' || $tab === 'campaigns' || $tab === 'campaign-builder' || $tab === 'devices' || $tab === 'real-time') { |
| 304 | \wp_register_script('iawp-data-table', \IAWP_SCOPED\iawp_url_to('dist/js/data-table.js'), [], \IAWP_VERSION); |
| 305 | \wp_enqueue_script('iawp-data-table'); |
| 306 | } elseif ($tab == 'settings') { |
| 307 | \wp_enqueue_style('wp-color-picker'); |
| 308 | \wp_register_script('iawp-settings', \IAWP_SCOPED\iawp_url_to('dist/js/settings.js'), ['wp-color-picker'], \IAWP_VERSION); |
| 309 | \wp_enqueue_script('iawp-settings'); |
| 310 | } elseif ($tab == 'learn') { |
| 311 | \wp_register_script('iawp-learn', \IAWP_SCOPED\iawp_url_to('dist/js/learn.js'), [], \IAWP_VERSION); |
| 312 | \wp_enqueue_script('iawp-learn'); |
| 313 | } |
| 314 | } elseif ($hook == 'index.php') { |
| 315 | \wp_register_script('iawp-dashboard-widget', \IAWP_SCOPED\iawp_url_to('dist/js/dashboard_widget.js'), [], \IAWP_VERSION); |
| 316 | \wp_enqueue_script('iawp-dashboard-widget'); |
| 317 | \wp_register_style('iawp-dashboard-widget-css', \IAWP_SCOPED\iawp_url_to('dist/styles/dashboard_widget.css'), [], \IAWP_VERSION); |
| 318 | \wp_enqueue_style('iawp-dashboard-widget-css'); |
| 319 | } |
| 320 | $this->maybe_enqueue_menu_bar_stats_styles(); |
| 321 | \wp_register_style('iawp-freemius-notice-styles', \IAWP_SCOPED\iawp_url_to('dist/styles/freemius_notice_styles.css'), [], \IAWP_VERSION); |
| 322 | \wp_enqueue_style('iawp-freemius-notice-styles'); |
| 323 | } |
| 324 | public function enqueue_scripts($hook) |
| 325 | { |
| 326 | $this->maybe_enqueue_menu_bar_stats_styles(); |
| 327 | } |
| 328 | public function enqueue_translations() |
| 329 | { |
| 330 | \wp_register_script('iawp-translations', ''); |
| 331 | \wp_enqueue_script('iawp-translations'); |
| 332 | \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' => \esc_html__('Copied', 'independent-analytics'), 'exportingPages' => \esc_html__('Exporting Pages...', 'independent-analytics'), 'exportPages' => \esc_html__('Export Pages', 'independent-analytics'), 'exportingReferrers' => \esc_html__('Exporting Referrers...', 'independent-analytics'), 'exportReferrers' => \esc_html__('Export Referrers', 'independent-analytics'), 'exportingGeolocations' => \esc_html__('Exporting Geolocations...', 'independent-analytics'), 'exportGeolocations' => \esc_html__('Export Geolocations', 'independent-analytics'), 'exportingDevices' => \esc_html__('Exporting Devices...', 'independent-analytics'), 'exportDevices' => \esc_html__('Export Devices', 'independent-analytics'), 'exportingCampaigns' => \esc_html__('Exporting Campaigns...', 'independent-analytics'), 'exportCampaigns' => \esc_html__('Export Campaigns', 'independent-analytics'), 'invalidReportArchive' => \esc_html__('This report archive is invalid. Please export your reports and try again.', 'independent-analytics'), 'openMobileMenu' => \esc_html__('Open menu', 'independent-analytics'), 'closeMobileMenu' => \esc_html__('Close menu', 'independent-analytics')]), 'before'); |
| 333 | } |
| 334 | public function enqueue_nonces() |
| 335 | { |
| 336 | \wp_register_script('iawp-nonces', ''); |
| 337 | \wp_enqueue_script('iawp-nonces'); |
| 338 | \wp_add_inline_script('iawp-nonces', 'const iawpActions = ' . \json_encode(AJAX_Manager::getInstance()->get_action_signatures()), 'before'); |
| 339 | } |
| 340 | public function maybe_enqueue_menu_bar_stats_styles() |
| 341 | { |
| 342 | if (Menu_Bar_Stats::is_option_enabled()) { |
| 343 | \wp_register_style('iawp-front-end-css', \IAWP_SCOPED\iawp_url_to('dist/styles/menu_bar_stats.css'), [], \IAWP_VERSION); |
| 344 | \wp_enqueue_style('iawp-front-end-css'); |
| 345 | } |
| 346 | } |
| 347 | // Remove errant CSS from other plugins affecting our styles |
| 348 | public function dequeue_other_plugin_styles() |
| 349 | { |
| 350 | // https://wordpress.org/plugins/comment-link-remove/ |
| 351 | \wp_dequeue_style('qc_clr_admin_style_css'); |
| 352 | } |
| 353 | public function get_option($name, $default) |
| 354 | { |
| 355 | $option = \get_option($name, $default); |
| 356 | return $option === '' ? $default : $option; |
| 357 | } |
| 358 | public function get_authors() |
| 359 | { |
| 360 | $roles = []; |
| 361 | foreach (\wp_roles()->roles as $role_name => $role_obj) { |
| 362 | if (!empty($role_obj['capabilities']['edit_posts'])) { |
| 363 | $roles[] = $role_name; |
| 364 | } |
| 365 | } |
| 366 | $users = \get_users(['role__in' => $roles]); |
| 367 | return $users; |
| 368 | } |
| 369 | public function get_custom_types(bool $tax = \false) |
| 370 | { |
| 371 | $args = ['public' => \true, '_builtin' => \false]; |
| 372 | if ($tax) { |
| 373 | return \get_taxonomies($args); |
| 374 | } else { |
| 375 | return \get_post_types($args); |
| 376 | } |
| 377 | } |
| 378 | public function filter_connect_message_on_update($message, $user_first_name, $product_title, $user_login, $site_link, $freemius_link) |
| 379 | { |
| 380 | // Add the heading HTML. |
| 381 | $plugin_name = 'Independent Analytics'; |
| 382 | $title = '<h3>' . \sprintf(\esc_html__('We hope you love %1$s', 'independent-analytics'), $plugin_name) . '</h3>'; |
| 383 | $html = ''; |
| 384 | // Add the introduction HTML. |
| 385 | $html .= '<p>'; |
| 386 | $html .= \sprintf(\esc_html__('Hi, %1$s! This is an invitation to help the %2$s community.', 'independent-analytics'), $user_first_name, $plugin_name); |
| 387 | $html .= '<strong>'; |
| 388 | $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); |
| 389 | $html .= '</strong>'; |
| 390 | $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); |
| 391 | $html .= '</p>'; |
| 392 | $html .= '<p>'; |
| 393 | $html .= \sprintf(\esc_html__('And if you skip this, that\'s okay! %1$s will still work just fine.', 'independent-analytics'), $plugin_name); |
| 394 | $html .= '</p>'; |
| 395 | return $title . $html; |
| 396 | } |
| 397 | public function plugin_action_links($links) |
| 398 | { |
| 399 | // Create the link |
| 400 | $settings_link = '<a class="calendar-link" href="' . \esc_url(\IAWP_SCOPED\iawp_dashboard_url()) . '">' . \esc_html__('Analytics Dashboard', 'independent-analytics') . '</a>'; |
| 401 | // Add the link to the start of the array |
| 402 | \array_unshift($links, $settings_link); |
| 403 | return $links; |
| 404 | } |
| 405 | public function ip_db_attribution($text) |
| 406 | { |
| 407 | if ($this->get_current_tab() === 'geo') { |
| 408 | $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>.'; |
| 409 | } |
| 410 | return $text; |
| 411 | } |
| 412 | public function pagination_page_size() |
| 413 | { |
| 414 | return 50; |
| 415 | } |
| 416 | public function get_current_tab() : string |
| 417 | { |
| 418 | if (\IAWP_SCOPED\iawp_is_pro()) { |
| 419 | $valid_tabs = ['views', 'referrers', 'geo', 'devices', 'campaigns', 'campaign-builder', 'real-time', 'settings', 'learn']; |
| 420 | } else { |
| 421 | $valid_tabs = ['views', 'referrers', 'geo', 'devices', 'settings', 'learn']; |
| 422 | } |
| 423 | $default_tab = $valid_tabs[0]; |
| 424 | $tab = \array_key_exists('tab', $_GET) ? \sanitize_text_field($_GET['tab']) : \false; |
| 425 | $is_valid = \array_search($tab, $valid_tabs) != \false; |
| 426 | if (!$tab || !$is_valid) { |
| 427 | $tab = $default_tab; |
| 428 | } |
| 429 | return $tab; |
| 430 | } |
| 431 | } |
| 432 |