Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/Admin/Upgrades.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public function run() {
$this->upgrade_to_251();
}

if ( version_compare( $plausible_analytics_version, '2.5.3', '<' ) ) {
$this->upgrade_to_253();
}

// Add required upgrade routines for future versions here.
}

Expand Down Expand Up @@ -346,4 +350,40 @@ public function upgrade_to_251() {

update_option( 'plausible_analytics_version', '2.5.1' );
}

/**
* Show an admin-wide notice to CE users that haven't entered an API token yet.
*
* @return void
*/
public function upgrade_to_253() {
$self_hosted_domain = Helpers::get_settings()['self_hosted_domain'];
$api_token = Helpers::get_settings()['api_token'];

// Not a CE user or a CE user already using the Plugins API.
if ( empty( $self_hosted_domain ) || ! empty( $api_token ) ) {
update_option( 'plausible_analytics_version', '2.5.3' );

return;
}

add_action( 'admin_notices', [ $this, 'show_api_token_notice' ] );
}

/**
* Display a notice to CE users that haven't entered an API token yet.
*
* @return void
*/
public function show_api_token_notice() {
$url = admin_url( 'options-general.php?page=plausible_analytics' );

?>
<div class="notice notice-warning">
<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.',
'plausible-analytics' )
, $url ); ?></p>
</div>
<?php
}
}
Loading