Admin
2 months ago
Commands
2 years ago
Db
1 year ago
Ecommerce
3 months ago
Report
2 months ago
Site
2 months ago
TrackingCode
4 months ago
Updater
4 years ago
User
2 months ago
Workarounds
2 years ago
WpStatistics
5 months ago
views
4 years ago
AIBotTracking.php
4 months ago
API.php
2 months ago
Access.php
4 years ago
AjaxTracker.php
4 months ago
Annotations.php
2 months ago
Bootstrap.php
10 months ago
Capabilities.php
2 months ago
Compatibility.php
2 months ago
Email.php
2 years ago
ErrorNotice.php
2 months ago
Feature.php
2 months ago
Installer.php
5 months ago
Logger.php
1 year ago
OptOut.php
2 months ago
Paths.php
5 months ago
PluginActionLinks.php
2 months ago
PluginAdminOverrides.php
2 months ago
PluginInit.php
2 months ago
PrivacyBadge.php
4 years ago
RedirectOnActivation.php
2 months ago
Referral.php
2 months ago
Roles.php
2 months ago
ScheduledTasks.php
2 months ago
Settings.php
4 months ago
Site.php
3 years ago
TrackingCode.php
2 months ago
Uninstaller.php
5 months ago
Updater.php
10 months ago
User.php
4 years ago
PluginAdminOverrides.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; |
| 11 | |
| 12 | /** |
| 13 | * Customizations for the WordPress plugins page. |
| 14 | */ |
| 15 | class PluginAdminOverrides extends Feature { |
| 16 | /** |
| 17 | * @var Settings |
| 18 | */ |
| 19 | private $settings; |
| 20 | |
| 21 | public function __construct( $settings ) { |
| 22 | $this->settings = $settings; |
| 23 | } |
| 24 | |
| 25 | public function is_active() { |
| 26 | return is_admin(); |
| 27 | } |
| 28 | |
| 29 | public function register_hooks() { |
| 30 | if ( $this->is_plugins_php_page() ) { |
| 31 | add_action( 'admin_footer', [ $this, 'add_data_deletion_notice_if_plugins_php' ] ); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | public function add_data_deletion_notice_if_plugins_php() { |
| 36 | $note = esc_html__( 'Note', 'matomo' ); |
| 37 | $change_settings_url = home_url( '/wp-admin/admin.php?page=matomo-settings&tab=advanced' ); |
| 38 | $change_data_deletion_settings = esc_html__( 'Change data deletion settings.', 'matomo' ); |
| 39 | |
| 40 | if ( $this->settings->should_delete_all_data_on_uninstall() ) { |
| 41 | $deletion_setting_notice = esc_html__( 'Data will be permanently deleted upon plugin deletion.', 'matomo' ); |
| 42 | } else { |
| 43 | $deletion_setting_notice = esc_html__( 'Data will %1$snot%2$s be deleted upon plugin deletion.', 'matomo' ); |
| 44 | $deletion_setting_notice = sprintf( $deletion_setting_notice, '<strong style="display:inline;">', '</strong>' ); |
| 45 | } |
| 46 | |
| 47 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 48 | echo <<<EOF |
| 49 | <script> |
| 50 | jQuery(document).ready( |
| 51 | function () { |
| 52 | var \$title = jQuery('body.plugins-php tr[data-slug="matomo"] td.plugin-title > strong:first-child'); |
| 53 | \$title.after('<p><span style="margin: 0 2px 2px 0; display: inline-block; vertical-align: middle;">ℹ️</span> $note: $deletion_setting_notice<br/><a href="$change_settings_url" id="mwp-data-deletion-settings">$change_data_deletion_settings</a></p>'); |
| 54 | } |
| 55 | ); |
| 56 | </script> |
| 57 | EOF; |
| 58 | } |
| 59 | |
| 60 | private function is_plugins_php_page() { |
| 61 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 62 | $request_uri = wp_unslash( isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '' ); |
| 63 | $plugins_php_path = wp_parse_url( home_url(), PHP_URL_PATH ) . '/wp-admin/plugins.php'; |
| 64 | $current_path = wp_parse_url( $request_uri, PHP_URL_PATH ); |
| 65 | |
| 66 | return $plugins_php_path === $current_path; |
| 67 | } |
| 68 | } |
| 69 |