diff --git a/classes/WpMatomo/Admin/SystemReport.php b/classes/WpMatomo/Admin/SystemReport.php index f0fbfddc3..8cc68089c 100644 --- a/classes/WpMatomo/Admin/SystemReport.php +++ b/classes/WpMatomo/Admin/SystemReport.php @@ -122,7 +122,7 @@ class SystemReport { */ public $db_settings; /** - * @var string the php binary used by Matomo + * @var string the php binary used by Matomo (use get_php_binary() to access) */ private $binary; @@ -133,11 +133,6 @@ public function __construct( Settings $settings ) { $this->logger = new Logger(); $this->db_settings = new \WpMatomo\Db\Settings(); $this->shell_exec_available = function_exists( 'shell_exec' ); - if ( ! WpMatomo::is_safe_mode() ) { - Bootstrap::do_bootstrap(); - $cli_php = new CliPhp(); - $this->binary = $cli_php->findPhpBinary(); - } } public function get_not_compatible_plugins() { @@ -289,20 +284,31 @@ private function get_error_tables() { } public function errors_present() { - $matomo_tables = $this->get_error_tables(); + $cache_key = 'matomo_system_report_has_errors'; + $cache_value = get_transient( $cache_key ); - $matomo_tables = apply_filters( 'matomo_systemreport_tables', $matomo_tables ); - $matomo_tables = $this->add_errors_first( $matomo_tables ); + if ( false === $cache_value ) { + // pre-record that there were no errors found. in case the system report fails to execute, this will + // allow the rest of Matomo for WordPress to continue to still be usable. + set_transient( $cache_key, 0, WEEK_IN_SECONDS ); - foreach ( $matomo_tables as $report_table ) { - foreach ( $report_table['rows'] as $row ) { - if ( ! empty( $row['is_error'] ) || ! empty( $row['is_warning'] ) ) { - return true; + $matomo_tables = $this->get_error_tables(); + + $matomo_tables = apply_filters( 'matomo_systemreport_tables', $matomo_tables ); + $matomo_tables = $this->add_errors_first( $matomo_tables ); + + foreach ( $matomo_tables as $report_table ) { + foreach ( $report_table['rows'] as $row ) { + if ( ! empty( $row['is_error'] ) || ! empty( $row['is_warning'] ) ) { + $cache_value = true; + } } } + + set_transient( $cache_key, (int) $cache_value, WEEK_IN_SECONDS ); } - return false; + return 1 === (int) $cache_value; } public function show() { @@ -442,9 +448,9 @@ private function get_phpcli_info() { private function get_phpcli_output( $phpcli_params ) { $output = ''; - if ( $this->shell_exec_available && $this->binary ) { + if ( $this->shell_exec_available && $this->get_php_cli_binary() ) { // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_shell_exec - $output = trim( '' . @shell_exec( $this->binary . ' ' . $phpcli_params ) ); + $output = trim( '' . @shell_exec( $this->get_php_cli_binary() . ' ' . $phpcli_params ) ); } return $output; @@ -1295,10 +1301,10 @@ private function get_server_info() { 'value' => $this->initial_error_reporting . ' After bootstrap: ' . @error_reporting(), ]; - if ( ! empty( $this->binary ) ) { + if ( ! empty( $this->get_php_cli_binary() ) ) { $rows[] = [ 'name' => 'PHP Found Binary', - 'value' => $this->binary, + 'value' => $this->get_php_cli_binary(), ]; } $rows[] = [ @@ -1927,4 +1933,14 @@ private function replace_hexadecimal_colors( $content ) { return $content; } + + private function get_php_cli_binary() { + if ( ! $this->binary && ! WpMatomo::is_safe_mode() ) { + Bootstrap::do_bootstrap(); + $cli_php = new CliPhp(); + $this->binary = $cli_php->findPhpBinary(); + } + + return $this->binary; + } } diff --git a/classes/WpMatomo/ErrorNotice.php b/classes/WpMatomo/ErrorNotice.php index d0bc4ec53..3716fa13c 100644 --- a/classes/WpMatomo/ErrorNotice.php +++ b/classes/WpMatomo/ErrorNotice.php @@ -31,10 +31,13 @@ public function check_errors() { if ( isset( $_GET['page'] ) && substr( sanitize_text_field( wp_unslash( $_GET['page'] ) ), 0, 7 ) === 'matomo-' ) { $system_report = new \WpMatomo\Admin\SystemReport( $this->settings ); if ( ! get_user_meta( get_current_user_id(), self::OPTION_NAME_SYSTEM_REPORT_ERRORS_DISMISSED ) && $system_report->errors_present() ) { - echo '
' . esc_html__( 'There are some errors in the', 'matomo' ) . - ' ' . esc_html__( 'Matomo Diagnostics System report', 'matomo' ) . ' ' . - esc_html__( 'that may prevent the plugin for working normally.', 'matomo' ) . '
' + . sprintf( + esc_html__( 'There are some errors in the %1$sMatomo Diagnostics System report%2$s that may prevent the plugin for working normally.', 'matomo' ), + '', + '' + ) + . '