Skip to content

Commit 8c5e31c

Browse files
authored
Merge pull request #285 from plausible/ce_users_admin_notice
Improved: display a notice to CE users that haven't entered an API token yet.
2 parents 49b6c6a + f1badbc commit 8c5e31c

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/Admin/Upgrades.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ public function run() {
9494
$this->upgrade_to_251();
9595
}
9696

97+
if ( version_compare( $plausible_analytics_version, '2.5.3', '<' ) ) {
98+
$this->upgrade_to_253();
99+
}
100+
97101
// Add required upgrade routines for future versions here.
98102
}
99103

@@ -346,4 +350,40 @@ public function upgrade_to_251() {
346350

347351
update_option( 'plausible_analytics_version', '2.5.1' );
348352
}
353+
354+
/**
355+
* Show an admin-wide notice to CE users that haven't entered an API token yet.
356+
*
357+
* @return void
358+
*/
359+
public function upgrade_to_253() {
360+
$self_hosted_domain = Helpers::get_settings()['self_hosted_domain'];
361+
$api_token = Helpers::get_settings()['api_token'];
362+
363+
// Not a CE user or a CE user already using the Plugins API.
364+
if ( empty( $self_hosted_domain ) || ! empty( $api_token ) ) {
365+
update_option( 'plausible_analytics_version', '2.5.3' );
366+
367+
return;
368+
}
369+
370+
add_action( 'admin_notices', [ $this, 'show_api_token_notice' ] );
371+
}
372+
373+
/**
374+
* Display a notice to CE users that haven't entered an API token yet.
375+
*
376+
* @return void
377+
*/
378+
public function show_api_token_notice() {
379+
$url = admin_url( 'options-general.php?page=plausible_analytics' );
380+
381+
?>
382+
<div class="notice notice-warning">
383+
<p><?php echo sprintf( __( 'An API token for Plausible Analytics is required. Please create one from the <a href="%s">Settings screen</a> and upgrade Plausible CE if necessary.',
384+
'plausible-analytics' )
385+
, $url ); ?></p>
386+
</div>
387+
<?php
388+
}
349389
}

0 commit comments

Comments
 (0)