Skip to content

Commit

Permalink
Improved: Analytics dashboard is now hidden for self-hosters, if they…
Browse files Browse the repository at this point in the history
… didn't enter a shared link.
  • Loading branch information
Dan0sz committed Feb 7, 2024
1 parent 8798584 commit d41ccb1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
5 changes: 4 additions & 1 deletion src/Admin/Settings/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,13 @@ public function register_menu() {
}
}

$settings = Helpers::get_settings();

/**
* Don't show the Analytics dashboard, if View Stats is disabled.
*/
if ( ! empty( Helpers::get_settings()[ 'enable_analytics_dashboard' ] ) ) {
if ( ! empty( $settings[ 'enable_analytics_dashboard' ] ) ||
( ! empty( $settings[ 'self_hosted_domain' ] ) && ! empty( $settings[ 'self_hosted_shared_link' ] ) ) ) {
// Setup `Analytics` page under Dashboard.
add_dashboard_page(
esc_html__( 'Analytics', 'plausible-analytics' ),
Expand Down
47 changes: 25 additions & 22 deletions src/Includes/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,36 +85,38 @@ public function admin_bar_node( $admin_bar ) {
}

// Add main admin bar node.
$args = [
$args[] = [
'id' => 'plausible-admin-bar',
'title' => 'Plausible Analytics',
];
$admin_bar->add_node( $args );

// Add link to view all stats.
$args = [];
$args[] = [
'id' => 'view-analytics',
'title' => esc_html__( 'View Analytics', 'plausible-analytics' ),
'href' => admin_url( 'index.php?page=plausible_analytics_statistics' ),
'parent' => 'plausible-admin-bar',
];

// Add link to individual page stats.
if ( is_singular() ) {
global $post;
$uri = wp_make_link_relative( get_permalink( $post->ID ) );
$settings = Helpers::get_settings();

if ( ! empty( $settings[ 'enable_analytics_dashboard' ] ) ||
( ! empty( $settings[ 'self_hosted_domain' ] ) && ! empty( $settings[ 'self_hosted_shared_link' ] ) ) ) {
$args[] = [
'id' => 'view-page-analytics',
'title' => esc_html__( 'View Page Analytics', 'plausible-analytics' ),
'href' => add_query_arg(
'page-url',
is_home() ? '' : $uri,
admin_url( 'index.php?page=plausible_analytics_statistics' )
),
'id' => 'view-analytics',
'title' => esc_html__( 'View Analytics', 'plausible-analytics' ),
'href' => admin_url( 'index.php?page=plausible_analytics_statistics' ),
'parent' => 'plausible-admin-bar',
];

// Add link to individual page stats.
if ( is_singular() ) {
global $post;
$uri = wp_make_link_relative( get_permalink( $post->ID ) );

$args[] = [
'id' => 'view-page-analytics',
'title' => esc_html__( 'View Page Analytics', 'plausible-analytics' ),
'href' => add_query_arg(
'page-url',
is_home() ? '' : $uri,
admin_url( 'index.php?page=plausible_analytics_statistics' )
),
'parent' => 'plausible-admin-bar',
];
}
}

// Add link to Plausible Settings page.
Expand All @@ -124,6 +126,7 @@ public function admin_bar_node( $admin_bar ) {
'href' => admin_url( 'options-general.php?page=plausible_analytics' ),
'parent' => 'plausible-admin-bar',
];

foreach ( $args as $arg ) {
$admin_bar->add_node( $arg );
}
Expand Down

0 comments on commit d41ccb1

Please sign in to comment.