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