Admin
1 month ago
Commands
2 years ago
Db
1 year ago
Ecommerce
1 month ago
Report
3 months ago
Site
3 months ago
TrackingCode
4 months ago
Updater
4 years ago
User
3 months ago
Workarounds
2 years ago
WpStatistics
6 months ago
views
2 months ago
AIBotTracking.php
4 months ago
API.php
3 weeks ago
Access.php
4 years ago
AjaxTracker.php
4 months ago
Annotations.php
3 months ago
Bootstrap.php
10 months ago
Capabilities.php
1 month ago
Compatibility.php
3 months ago
Email.php
2 years ago
ErrorNotice.php
2 months ago
Feature.php
3 months ago
Installer.php
2 months ago
Logger.php
1 year ago
MinimumRequirementsNotice.php
1 month ago
OptOut.php
1 month ago
Paths.php
6 months ago
PluginActionLinks.php
3 months ago
PluginAdminOverrides.php
3 months ago
PluginInit.php
3 months ago
PrivacyBadge.php
4 years ago
RedirectOnActivation.php
3 months ago
Referral.php
3 months ago
Roles.php
3 months ago
ScheduledTasks.php
3 months ago
Settings.php
4 months ago
Site.php
3 years ago
TrackingCode.php
3 months ago
Uninstaller.php
6 months ago
Updater.php
10 months ago
User.php
4 years ago
MinimumRequirementsNotice.php
175 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 | use WpMatomo; |
| 13 | use WpMatomo\Admin\Admin; |
| 14 | |
| 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | exit; // if accessed directly |
| 17 | } |
| 18 | |
| 19 | class MinimumRequirementsNotice extends Feature { |
| 20 | const OPTION_NAME_MINIMUM_REQUIREMENTS_DISMISSED = 'matomo_minimum_requirements_notice_dismissed'; |
| 21 | const DISMISS_NONCE_NAME = 'matomo-minimum-requirements-notice-dismiss'; |
| 22 | |
| 23 | const REQUIRED_PHP_VERSION = '8.1'; |
| 24 | const REQUIRED_MYSQL_VERSION = '8.0'; |
| 25 | const REQUIRED_MARIADB_VERSION = '10.6'; |
| 26 | |
| 27 | public function is_active() { |
| 28 | return is_admin(); |
| 29 | } |
| 30 | |
| 31 | public function register_hooks() { |
| 32 | add_action( 'admin_notices', [ $this, 'check_requirements' ] ); |
| 33 | add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); |
| 34 | } |
| 35 | |
| 36 | public function enqueue_scripts() { |
| 37 | wp_localize_script( |
| 38 | 'matomo-admin-js', |
| 39 | 'mtmMinimumRequirementsNoticeAjax', |
| 40 | [ |
| 41 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 42 | 'nonce' => wp_create_nonce( self::DISMISS_NONCE_NAME ), |
| 43 | ] |
| 44 | ); |
| 45 | } |
| 46 | |
| 47 | public function register_ajax() { |
| 48 | add_action( |
| 49 | 'wp_ajax_matomo_minimum_requirements_notice_dismissed', |
| 50 | function () { |
| 51 | check_ajax_referer( self::DISMISS_NONCE_NAME ); |
| 52 | |
| 53 | if ( is_admin() ) { |
| 54 | update_user_meta( get_current_user_id(), self::OPTION_NAME_MINIMUM_REQUIREMENTS_DISMISSED, true ); |
| 55 | } |
| 56 | } |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | public function check_requirements() { |
| 61 | if ( ! \WpMatomo::is_admin_user() ) { |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | $is_plugins_admin_page = $this->is_plugins_admin_page(); |
| 66 | $is_matomo_page = Admin::is_matomo_admin(); |
| 67 | |
| 68 | // only display on matomo admin pages and the plugins admin page |
| 69 | if ( ! $is_plugins_admin_page && ! $is_matomo_page ) { |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | if ( |
| 74 | $is_plugins_admin_page |
| 75 | && get_user_meta( get_current_user_id(), self::OPTION_NAME_MINIMUM_REQUIREMENTS_DISMISSED, true ) |
| 76 | ) { |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | $unmet = $this->get_unmet_requirements(); |
| 81 | if ( empty( $unmet ) ) { |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | $dismissible = $is_plugins_admin_page ? 'is-dismissible' : ''; |
| 86 | |
| 87 | echo '<div class="matomo-notice notice notice-warning ' . esc_attr( $dismissible ) . '" id="matomo-minimumrequirements"><p>' |
| 88 | . sprintf( |
| 89 | esc_html__( '%1$sHeads up!%2$s Matomo Analytics version 6 and later will require a newer server environment. You will not be able to update the plugin to that version until your server meets the new minimum requirements:', 'matomo' ), |
| 90 | '<strong>', |
| 91 | '</strong>' |
| 92 | ) |
| 93 | . '</p><ul style="list-style: disc; margin-left: 20px;">'; |
| 94 | |
| 95 | foreach ( $unmet as $requirement ) { |
| 96 | echo '<li>' . esc_html( $requirement ) . '</li>'; |
| 97 | } |
| 98 | |
| 99 | echo '</ul><p>' |
| 100 | . sprintf( |
| 101 | esc_html__( 'Please ask your hosting provider to update your server by %1$sNovember, 2026%2$s so you can keep receiving the latest Matomo features, bug fixes and security updates.', 'matomo' ), |
| 102 | '<strong>', |
| 103 | '</strong>' |
| 104 | ) |
| 105 | . '</p></div>'; |
| 106 | } |
| 107 | |
| 108 | public function get_unmet_requirements( $php_version = PHP_VERSION ) { |
| 109 | $unmet = []; |
| 110 | |
| 111 | if ( version_compare( $php_version, self::REQUIRED_PHP_VERSION, '<' ) ) { |
| 112 | $unmet[] = sprintf( |
| 113 | __( 'PHP %1$s or higher is required (you are currently using PHP %2$s).', 'matomo' ), |
| 114 | self::REQUIRED_PHP_VERSION, |
| 115 | $php_version |
| 116 | ); |
| 117 | } |
| 118 | |
| 119 | $db = $this->get_db_server(); |
| 120 | if ( ! empty( $db['version'] ) ) { |
| 121 | if ( $db['is_mariadb'] ) { |
| 122 | if ( version_compare( $db['version'], self::REQUIRED_MARIADB_VERSION, '<' ) ) { |
| 123 | $unmet[] = sprintf( |
| 124 | __( 'MariaDB %1$s or higher is required (you are currently using MariaDB %2$s).', 'matomo' ), |
| 125 | self::REQUIRED_MARIADB_VERSION, |
| 126 | $db['version'] |
| 127 | ); |
| 128 | } |
| 129 | } elseif ( version_compare( $db['version'], self::REQUIRED_MYSQL_VERSION, '<' ) ) { |
| 130 | $unmet[] = sprintf( |
| 131 | __( 'MySQL %1$s or higher is required (you are currently using MySQL %2$s).', 'matomo' ), |
| 132 | self::REQUIRED_MYSQL_VERSION, |
| 133 | $db['version'] |
| 134 | ); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | return $unmet; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Public for tests. |
| 143 | */ |
| 144 | public function get_db_server() { |
| 145 | global $wpdb; |
| 146 | |
| 147 | if ( empty( $wpdb ) || empty( $wpdb->is_mysql ) ) { |
| 148 | return [ |
| 149 | 'is_mariadb' => false, |
| 150 | 'version' => '', |
| 151 | ]; |
| 152 | } |
| 153 | |
| 154 | $server_info = method_exists( $wpdb, 'db_server_info' ) ? $wpdb->db_server_info() : ''; |
| 155 | $is_mariadb = $server_info && false !== stripos( $server_info, 'mariadb' ); |
| 156 | |
| 157 | if ( $is_mariadb && preg_match( '/(?:5\.5\.5-)?(\d+\.\d+\.\d+).*?mariadb/i', $server_info, $matches ) ) { |
| 158 | $version = $matches[1]; |
| 159 | } else { |
| 160 | // db_version() strips any suffix and returns the numeric version only. |
| 161 | $version = (string) $wpdb->db_version(); |
| 162 | } |
| 163 | |
| 164 | return [ |
| 165 | 'is_mariadb' => $is_mariadb, |
| 166 | 'version' => $version, |
| 167 | ]; |
| 168 | } |
| 169 | |
| 170 | private function is_plugins_admin_page() { |
| 171 | $screen = get_current_screen(); |
| 172 | return ! empty( $screen ) && 'plugins' === $screen->id; |
| 173 | } |
| 174 | } |
| 175 |