PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.13.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.13.0
5.13.0 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 / AdvancedSettings.php
matomo / classes / WpMatomo / Admin Last commit date
Marketplace 2 months ago PluginSuggestions 1 month ago TrackingSettings 1 month ago views 4 days ago AccessSettings.php 1 month ago AdBlockDetector.php 8 months ago Admin.php 2 months ago AdminSettings.php 1 month ago AdminSettingsInterface.php 6 years ago AdvancedSettings.php 1 month ago Chart.php 3 months ago CookieConsent.php 4 years ago Dashboard.php 1 month ago ExclusionSettings.php 1 month ago GeolocationSettings.php 1 month ago GetStarted.php 1 month ago ImportWpStatistics.php 1 month ago Info.php 1 month ago InvalidIpException.php 4 years ago Marketplace.php 1 month ago MarketplaceSetupWizard.php 1 month ago MarketplaceSetupWizardBody.php 1 month ago MatomoPage.php 4 months ago MatomoPageContent.php 4 months ago Menu.php 1 month ago PluginMeasurableSettings.php 1 month ago PrivacySettings.php 1 month ago SafeModeMenu.php 1 month ago Summary.php 1 month ago SystemReport.php 4 days ago TrackingSettings.php 1 month ago WhatsNewNotifications.php 4 months ago
AdvancedSettings.php
128 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\CliMulti\Process;
13 use Piwik\IP;
14 use WpMatomo\Bootstrap;
15 use WpMatomo\Capabilities;
16 use WpMatomo\Settings;
17 use WpMatomo\Site\Sync\SyncConfig as SiteConfigSync;
18
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit; // if accessed directly
21 }
22 /**
23 * phpcs:disable WordPress.Security.NonceVerification.Missing
24 */
25 class AdvancedSettings implements AdminSettingsInterface {
26 const FORM_NAME = 'matomo';
27 const NONCE_NAME = 'matomo_advanced';
28
29 public static $valid_host_headers = [
30 'HTTP_CLIENT_IP',
31 'HTTP_X_REAL_IP',
32 'HTTP_X_FORWARDED_FOR',
33 'HTTP_X_FORWARDED',
34 'HTTP_FORWARDED_FOR',
35 'HTTP_FORWARDED',
36 'HTTP_CF_CONNECTING_IP',
37 'HTTP_TRUE_CLIENT_IP',
38 'HTTP_X_CLUSTER_CLIENT_IP',
39 ];
40
41 /**
42 * @var Settings
43 */
44 private $settings;
45
46 /**
47 * @var SiteConfigSync
48 */
49 private $site_config_sync;
50
51 /**
52 * @param Settings $settings
53 */
54 public function __construct( $settings ) {
55 $this->settings = $settings;
56 $this->site_config_sync = new SiteConfigSync( $settings );
57 }
58
59 public function get_title() {
60 return esc_html__( 'Advanced', 'matomo' );
61 }
62
63 public function show_settings() {
64 $was_updated = $this->update_if_submitted();
65
66 $matomo_client_headers = $this->site_config_sync->get_config_value( 'General', 'proxy_client_headers' );
67 if ( empty( $matomo_client_headers ) ) {
68 $matomo_client_headers = [];
69 }
70
71 Bootstrap::do_bootstrap();
72 $matomo_detected_ip = IP::getIpFromHeader();
73 $matomo_delete_all_data = $this->settings->should_delete_all_data_on_uninstall();
74 $matomo_disable_async_archiving = $this->settings->is_async_archiving_disabled_by_option();
75 $matomo_async_archiving_supported = $this->settings->is_async_archiving_supported();
76 $matomo_server_side_tracking_delay = $this->settings->get_option( Settings::SERVER_SIDE_TRACKING_DELAY_SECS );
77
78 include __DIR__ . '/views/advanced_settings.php';
79 }
80
81 private function update_if_submitted() {
82 if ( isset( $_POST )
83 && ! empty( $_POST[ self::FORM_NAME ] )
84 && is_admin()
85 && check_admin_referer( self::NONCE_NAME )
86 && $this->can_user_manage() ) {
87 $this->apply_settings();
88
89 return true;
90 }
91
92 return false;
93 }
94
95 public function can_user_manage() {
96 return current_user_can( Capabilities::KEY_SUPERUSER );
97 }
98
99 private function apply_settings() {
100 $delay = isset( $_POST['matomo'][ Settings::SERVER_SIDE_TRACKING_DELAY_SECS ] )
101 ? intval( wp_unslash( $_POST['matomo'][ Settings::SERVER_SIDE_TRACKING_DELAY_SECS ] ) )
102 : null;
103
104 $changes = [
105 Settings::DISABLE_ASYNC_ARCHIVING_OPTION_NAME => ! empty( $_POST['matomo']['disable_async_archiving'] ),
106 Settings::SERVER_SIDE_TRACKING_DELAY_SECS => $delay,
107 ];
108
109 if ( ! defined( 'MATOMO_REMOVE_ALL_DATA' ) ) {
110 $changes[ Settings::DELETE_ALL_DATA_ON_UNINSTALL ] = ! empty( $_POST['matomo']['delete_all_data'] );
111 }
112
113 $this->settings->apply_changes( $changes );
114
115 $client_headers = [];
116 if ( ! empty( $_POST[ self::FORM_NAME ]['proxy_client_header'] ) ) {
117 $client_header = sanitize_text_field( wp_unslash( $_POST[ self::FORM_NAME ]['proxy_client_header'] ) );
118 if ( in_array( $client_header, self::$valid_host_headers, true ) ) {
119 $client_headers[] = $client_header;
120 }
121 }
122
123 $this->site_config_sync->set_config_value( 'General', 'proxy_client_headers', $client_headers );
124
125 return true;
126 }
127 }
128