PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.12.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.12.1
5.12.1 5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / classes / WpMatomo / Admin / AdminSettings.php
matomo / classes / WpMatomo / Admin Last commit date
Marketplace 2 months ago PluginSuggestions 2 weeks ago TrackingSettings 2 weeks ago views 2 weeks ago AccessSettings.php 2 weeks ago AdBlockDetector.php 8 months ago Admin.php 2 months ago AdminSettings.php 2 weeks ago AdminSettingsInterface.php 6 years ago AdvancedSettings.php 2 weeks ago Chart.php 3 months ago CookieConsent.php 4 years ago Dashboard.php 2 weeks ago ExclusionSettings.php 2 weeks ago GeolocationSettings.php 2 weeks ago GetStarted.php 2 weeks ago ImportWpStatistics.php 2 weeks ago Info.php 2 weeks ago InvalidIpException.php 4 years ago Marketplace.php 2 weeks ago MarketplaceSetupWizard.php 2 weeks ago MarketplaceSetupWizardBody.php 2 weeks ago MatomoPage.php 4 months ago MatomoPageContent.php 4 months ago Menu.php 2 weeks ago PluginMeasurableSettings.php 2 weeks ago PrivacySettings.php 2 weeks ago SafeModeMenu.php 2 weeks ago Summary.php 2 weeks ago SystemReport.php 2 weeks ago TrackingSettings.php 2 weeks ago WhatsNewNotifications.php 4 months ago
AdminSettings.php
170 lines
1 <?php
2 /**
3 * Matomo - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 * @package matomo
8 */
9
10 namespace WpMatomo\Admin;
11
12 use Piwik\Plugin\Manager;
13 use WpMatomo\Access;
14 use WpMatomo\Bootstrap;
15 use WpMatomo\Settings;
16
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit; // if accessed directly
19 }
20
21 class AdminSettings implements MatomoPageContent {
22 const TAB_TRACKING = 'tracking';
23 const TAB_ACCESS = 'access';
24 const TAB_EXCLUSIONS = 'exlusions';
25 const TAB_PRIVACY = 'privacy';
26 const TAB_GEOLOCATION = 'geolocation';
27 const TAB_ADVANCED = 'advanced';
28
29 /**
30 * @var Settings
31 */
32 private $settings;
33
34 public function __construct( Settings $settings ) {
35 $this->settings = $settings;
36 }
37
38 public static function make_url( $tab ) {
39 global $_parent_pages;
40 $menu_slug = Menu::SLUG_SETTINGS;
41
42 if ( is_multisite() && is_network_admin() ) {
43 if ( isset( $_parent_pages[ $menu_slug ] ) ) {
44 $parent_slug = $_parent_pages[ $menu_slug ];
45 if ( $parent_slug && ! isset( $_parent_pages[ $parent_slug ] ) ) {
46 $url = network_admin_url( add_query_arg( 'page', $menu_slug, $parent_slug ) );
47 } else {
48 $url = network_admin_url( 'admin.php?page=' . $menu_slug );
49 }
50 } else {
51 $url = '';
52 }
53 } else {
54 $url = menu_page_url( $menu_slug, false );
55 }
56
57 return add_query_arg( [ 'tab' => $tab ], $url );
58 }
59
60 public function show() {
61 $access = new Access( $this->settings );
62 $access_settings = new AccessSettings( $access, $this->settings );
63 $tracking = new TrackingSettings( $this->settings );
64 $exclusions = new ExclusionSettings( $this->settings );
65 $geolocation = new GeolocationSettings( $this->settings );
66 $privacy = new PrivacySettings( $this->settings );
67 $advanced = new AdvancedSettings( $this->settings );
68 $setting_tabs = [
69 self::TAB_TRACKING => $tracking,
70 self::TAB_ACCESS => $access_settings,
71 self::TAB_PRIVACY => $privacy,
72 self::TAB_EXCLUSIONS => $exclusions,
73 self::TAB_GEOLOCATION => $geolocation,
74 self::TAB_ADVANCED => $advanced,
75 ];
76
77 $active_tab = self::TAB_TRACKING;
78
79 if ( $this->settings->is_network_enabled() && ! is_network_admin() ) {
80 $active_tab = self::TAB_EXCLUSIONS;
81 $setting_tabs = [
82 self::TAB_EXCLUSIONS => $exclusions,
83 self::TAB_PRIVACY => $privacy,
84 ];
85 }
86
87 $plugin_settings_tabs = $this->get_plugin_settings_tabs();
88 $plugin_settings_tabs = array_map(
89 function ( $info ) {
90 return new PluginMeasurableSettings( $info['plugin_name'], $info['plugin_display_name'] );
91 },
92 $plugin_settings_tabs
93 );
94 $setting_tabs = array_merge( $setting_tabs, $plugin_settings_tabs );
95
96 $setting_tabs = apply_filters( 'matomo_setting_tabs', $setting_tabs, $this->settings );
97
98 if ( ! empty( $_GET['tab'] ) ) {
99 $tab = sanitize_text_field( wp_unslash( $_GET['tab'] ) );
100 if ( isset( $setting_tabs[ $tab ] ) ) {
101 $active_tab = $tab;
102 }
103 }
104
105 $content_tab = $setting_tabs[ $active_tab ];
106 $matomo_settings = $this->settings;
107
108 include __DIR__ . '/views/settings.php';
109 }
110
111 private function get_plugin_settings_tabs() {
112 $active_wordpress_plugins = (array) get_option( 'active_plugins', [] );
113
114 $cache_key = 'plugin-settings-tabs-' . md5( implode( ',', $active_wordpress_plugins ) );
115
116 if ( $this->settings->is_network_enabled() ) {
117 $network_plugins = (array) get_site_option( 'active_sitewide_plugins', [] );
118 $cache_key = $cache_key . '-' . md5( implode( ',', $network_plugins ) );
119 }
120
121 $tabs = get_transient( $cache_key );
122 if ( false === $tabs || ! is_array( $tabs ) || empty( $active_wordpress_plugins ) ) {
123 $all_wordpress_plugins = $this->get_wordpress_plugins();
124
125 Bootstrap::do_bootstrap();
126 $all_matomo_plugins = Manager::getInstance()->getActivatedPlugins();
127
128 $marketplace_plugins = array_intersect( array_keys( $all_wordpress_plugins ), $all_matomo_plugins );
129
130 $tabs = [];
131 foreach ( $marketplace_plugins as $plugin_name ) {
132 $settings_class = 'Piwik\\Plugins\\' . $plugin_name . '\\MeasurableSettings';
133 if ( ! class_exists( $settings_class ) ) {
134 continue;
135 }
136
137 $plugin_display_name = $all_wordpress_plugins[ $plugin_name ]['Name'];
138 $plugin_display_name = preg_replace( '/\s+\(Matomo Plugin\)\s*/', '', $plugin_display_name );
139
140 $tabs[ "plugin-{$plugin_name}" ] = [
141 'plugin_name' => $plugin_name,
142 'plugin_display_name' => $plugin_display_name,
143 ];
144 }
145
146 set_transient( $cache_key, $tabs, 60 * 60 * 24 * 7 );
147 }
148
149 return $tabs;
150 }
151
152 private function get_wordpress_plugins() {
153 $all_wordpress_plugins = array_merge( get_plugins(), get_mu_plugins() );
154 $all_wordpress_plugins = array_combine(
155 array_map(
156 function ( $path ) {
157 return basename( dirname( $path ) );
158 },
159 array_keys( $all_wordpress_plugins )
160 ),
161 $all_wordpress_plugins
162 );
163 return $all_wordpress_plugins;
164 }
165
166 public function get_title() {
167 return __( 'Settings', 'matomo' );
168 }
169 }
170