Skip to content

Commit

Permalink
Add new feature: Matomo Safe Mode (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteur authored Nov 11, 2019
1 parent 56adbbd commit 14bc6a9
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
0.2.4
- Add new feature: Safe mode

0.2.3
- Better handling of stripslashes

Expand Down
13 changes: 13 additions & 0 deletions classes/WpMatomo.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ public function __construct() {

$this->settings = new Settings();

if ( self::is_safe_mode() ) {
if ( is_admin() ) {
new \WpMatomo\Admin\SafeModeMenu($this->settings);
}

return;
}

add_action( 'init', array( $this, 'init_plugin' ) );

$capabilities = new Capabilities( $this->settings );
Expand Down Expand Up @@ -141,6 +149,11 @@ public static function is_admin_user() {
return is_super_admin();
}

public static function is_safe_mode()
{
return defined('MATOMO_SAFE_MODE') && MATOMO_SAFE_MODE;
}

public function add_settings_link( $links ) {
$get_started = new \WpMatomo\Admin\GetStarted( $this->settings );

Expand Down
57 changes: 57 additions & 0 deletions classes/WpMatomo/Admin/SafeModeMenu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

namespace WpMatomo\Admin;

use Piwik\Plugins\UsersManager\UserPreferences;
use WpMatomo\Bootstrap;
use WpMatomo\Capabilities;
use WpMatomo\Marketplace\Api as MarketplaceApi;
use WpMatomo\Report\Dates;
use WpMatomo\Settings;
use WpMatomo\Site;

if ( ! defined( 'ABSPATH' ) ) {
exit; // if accessed directly
}

class SafeModeMenu {
/**
* @var Settings
*/
private $settings;

private $parentSlug = 'matomo';

/**
* @param Settings $settings
*/
public function __construct( $settings ) {
$this->settings = $settings;
add_action( 'admin_menu', array( $this, 'add_menu' ) );
add_action( 'network_admin_menu', array( $this, 'add_menu' ) );
}

public function add_menu() {
if (!\WpMatomo::is_admin_user()) {
return;
}

$system_report = new SystemReport( $this->settings );

add_menu_page( 'Matomo Analytics', 'Matomo Analytics', Menu::CAP_NOT_EXISTS, 'matomo', null, 'dashicons-analytics' );

add_submenu_page( $this->parentSlug, __( 'System Report', 'matomo' ), __( 'System Report', 'matomo' ), 'administrator', Menu::SLUG_SYSTEM_REPORT, array(
$system_report,
'show'
) );

}

}
18 changes: 10 additions & 8 deletions classes/WpMatomo/Admin/SystemReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,18 @@ private function get_matomo_info() {

}

$rows[] = array(
'section' => __( 'Mandatory checks', 'matomo' ),
);
if ( ! \WpMatomo::is_safe_mode() ) {
$rows[] = array(
'section' => __( 'Mandatory checks', 'matomo' ),
);

$rows = $this->add_diagnostic_results( $rows, $report->getMandatoryDiagnosticResults() );
$rows = $this->add_diagnostic_results( $rows, $report->getMandatoryDiagnosticResults() );

$rows[] = array(
'section' => __( 'Optional checks', 'matomo' ),
);
$rows = $this->add_diagnostic_results( $rows, $report->getOptionalDiagnosticResults() );
$rows[] = array(
'section' => __( 'Optional checks', 'matomo' ),
);
$rows = $this->add_diagnostic_results( $rows, $report->getOptionalDiagnosticResults() );
}

$cliMulti = new CliMulti();

Expand Down
2 changes: 1 addition & 1 deletion matomo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Description: Most powerful web analytics for WordPress giving you 100% data ownership and privacy protection
* Author: Matomo
* Author URI: https://matomo.org
* Version: 0.2.3
* Version: 0.2.4
* Domain Path: /languages
* WC requires at least: 2.4.0
* WC tested up to: 3.2.6
Expand Down

0 comments on commit 14bc6a9

Please sign in to comment.