TrackingSettings
5 years ago
views
5 years ago
AccessSettings.php
6 years ago
Admin.php
6 years ago
AdminSettings.php
6 years ago
AdminSettingsInterface.php
6 years ago
AdvancedSettings.php
6 years ago
Dashboard.php
6 years ago
ExclusionSettings.php
6 years ago
GeolocationSettings.php
6 years ago
GetStarted.php
6 years ago
Info.php
6 years ago
Marketplace.php
6 years ago
Menu.php
5 years ago
PrivacySettings.php
5 years ago
SafeModeMenu.php
6 years ago
Summary.php
5 years ago
SystemReport.php
5 years ago
TrackingSettings.php
5 years ago
Info.php
69 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 WpMatomo\Capabilities; |
| 13 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit; // if accessed directly |
| 16 | } |
| 17 | |
| 18 | class Info { |
| 19 | const NONCE_NAME = 'matomo_newsletter'; |
| 20 | const FORM_NAME = 'matomo_newsletter_signup'; |
| 21 | |
| 22 | private function update_if_submitted() { |
| 23 | if ( isset( $_POST ) |
| 24 | && !empty( $_POST[ self::FORM_NAME ] ) |
| 25 | && is_admin() |
| 26 | && check_admin_referer( self::NONCE_NAME ) |
| 27 | && $this->show_newsletter_signup() |
| 28 | && current_user_can( Capabilities::KEY_VIEW ) ) { |
| 29 | |
| 30 | $user = wp_get_current_user(); |
| 31 | $locale = explode('_', get_user_locale($user->ID)); |
| 32 | wp_remote_get('https://api.matomo.org/1.0/subscribeNewsletter/?' . http_build_query(array( |
| 33 | 'email' => $user->user_email, |
| 34 | 'wordpress' => 1, |
| 35 | 'language' => $locale[0], |
| 36 | ))); |
| 37 | update_user_meta($user->ID, self::FORM_NAME, '1'); |
| 38 | |
| 39 | return true; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | private function show_newsletter_signup() { |
| 44 | if (!is_user_logged_in()) { |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | $user = wp_get_current_user(); |
| 49 | return !get_user_meta($user->ID, self::FORM_NAME, true); |
| 50 | } |
| 51 | |
| 52 | public function show() { |
| 53 | $this->render('info'); |
| 54 | } |
| 55 | |
| 56 | public function show_multisite() { |
| 57 | $this->render('info_multisite'); |
| 58 | } |
| 59 | |
| 60 | private function render($template) { |
| 61 | $signedup_newsletter = $this->update_if_submitted(); |
| 62 | $show_newsletter = $this->show_newsletter_signup(); |
| 63 | |
| 64 | include dirname( __FILE__ ) . '/views/' . $template . '.php'; |
| 65 | } |
| 66 | |
| 67 | |
| 68 | } |
| 69 |