From 81cffac57914ab860893961597a4c38d78e6809c Mon Sep 17 00:00:00 2001 From: Dan0sz <18595395+Dan0sz@users.noreply.github.com> Date: Tue, 7 May 2024 12:14:45 +0200 Subject: [PATCH 1/2] Improved API token to Plugin token --- src/Admin/Settings/API.php | 8 ++++---- src/Admin/Settings/Hooks.php | 10 +++++----- src/Admin/Settings/Page.php | 6 +++--- src/Ajax.php | 6 +++--- src/Client.php | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Admin/Settings/API.php b/src/Admin/Settings/API.php index dffd528d..6215e654 100644 --- a/src/Admin/Settings/API.php +++ b/src/Admin/Settings/API.php @@ -62,7 +62,7 @@ public function settings_page() { $this->slides = [ 'welcome' => __( 'Welcome to Plausible Analytics', 'plausible-analytics' ), 'domain_name' => __( 'Confirm domain', 'plausible-analytics' ), - 'api_token' => __( 'Create API token', 'plausible-analytics' ), + 'api_token' => __( 'Create Plugin Token', 'plausible-analytics' ), 'enable_analytics_dashboard' => __( 'View the stats in your WP dashboard', 'plausible-analytics' ), 'enhanced_measurements' => __( 'Enhanced measurements', 'plausible-analytics' ), 'proxy_enabled' => __( 'Enable proxy', 'plausible-analytics' ), @@ -82,7 +82,7 @@ public function settings_page() { 'plausible-analytics' ), 'api_token' => __( - 'Create an API token (link opens in a new window) that we\'ll use to automate your setup process. Paste the API token in the field below and click "Next".', + 'Create a Plugin Token (link opens in a new window) that we\'ll use to automate your setup process. Paste the Plugin Token in the field below and click "Next".', 'plausible-analytics' ), 'enable_analytics_dashboard' => __( @@ -135,11 +135,11 @@ public function settings_page() { 'plausible-analytics' ), __( - 'For instance, after inserting the API token, enable the new Authors and categories tracking and it will be displayed in your stats immediately without you needing to add those properties manually in your site settings.', + 'For instance, after inserting the Plugin Token, enable the new Authors and categories tracking and it will be displayed in your stats immediately without you needing to add those properties manually in your site settings.', 'plausible-analytics' ), __( - 'This welcome screen will guide you through the process of creating the API token and introduce you to other new features we\'ve added, e.g. Revenue tracking. Click on the “Next” button below to start.', + 'This welcome screen will guide you through the process of creating the Plugin Token and introduce you to other new features we\'ve added, e.g. Revenue tracking. Click on the “Next” button below to start.', 'plausible-analytics' ), __( 'We hope you’ll find this useful. Thanks again for using Plausible!', 'plausible-analytics' ) diff --git a/src/Admin/Settings/Hooks.php b/src/Admin/Settings/Hooks.php index 2dba31c4..0234f8f1 100644 --- a/src/Admin/Settings/Hooks.php +++ b/src/Admin/Settings/Hooks.php @@ -108,7 +108,7 @@ public function proxy_warning() { } /** - * Show notice when API token notice is disabled. + * Show notice when Plugin Token notice is disabled. * * @output HTML */ @@ -162,7 +162,7 @@ public function option_disabled_by_proxy() { } /** - * Display missing API token warning. + * Display missing Plugin Token warning. * * @output HTML */ @@ -170,7 +170,7 @@ public function missing_api_token_warning() { echo sprintf( wp_kses( __( - 'Please create an API token and insert it into the API token field above.', + 'Please create a Plugin Token and insert it into the Plugin Token field above.', 'plausible-analytics' ), 'post' @@ -179,14 +179,14 @@ public function missing_api_token_warning() { } /** - * Display option disabled by missing API token warning. + * Display option disabled by missing Plugin Token warning. * * @output HTML */ public function option_disabled_by_missing_api_token() { echo wp_kses( __( - 'Please create an API token and insert it into the API token field above to enable this option.', + 'Please create a Plugin Token and insert it into the Plugin Token field above to enable this option.', 'plausible-analytics' ), 'post' diff --git a/src/Admin/Settings/Page.php b/src/Admin/Settings/Page.php index 6162af7e..a9449760 100644 --- a/src/Admin/Settings/Page.php +++ b/src/Admin/Settings/Page.php @@ -80,7 +80,7 @@ public function __construct() { 'desc' => sprintf( wp_kses( __( - 'Ensure your domain name matches the one in your Plausible account, then create an API token (link opens in a new window) and paste it into the \'API token\' field.', + 'Ensure your domain name matches the one in your Plausible account, then create a Plugin Token (link opens in a new window) and paste it into the \'Plugin Token\' field.', 'plausible-analytics' ), 'post' @@ -95,7 +95,7 @@ public function __construct() { 'value' => Helpers::get_domain(), ], [ - 'label' => esc_html__( 'API token', 'plausible-analytics' ), + 'label' => esc_html__( 'Plugin Token', 'plausible-analytics' ), 'slug' => 'api_token', 'type' => 'text', 'value' => $settings[ 'api_token' ], @@ -413,7 +413,7 @@ public function __construct() { } /** - * No API token is entered. + * No Plugin Token is entered. */ if ( empty( $settings[ 'api_token' ] ) ) { $this->fields[ 'general' ][ 0 ][ 'fields' ][] = self::API_TOKEN_MISSING_HOOK; diff --git a/src/Ajax.php b/src/Ajax.php index 5d9fbc4b..f6c0c3d2 100644 --- a/src/Ajax.php +++ b/src/Ajax.php @@ -284,7 +284,7 @@ public function save_options() { // Clean spaces $settings[ $option->name ] = trim( $option->value ); - // Validate API token, if this is the API token field. + // Validate Plugin Token, if this is the Plugin Token field. if ( $option->name === 'api_token' ) { $this->validate_api_token( $option->value ); } @@ -298,7 +298,7 @@ public function save_options() { } /** - * Validate the entered API token, before storing it to the DB. wp_send_json_error() ensures that code execution stops. + * Validate the entered Plugin Token, before storing it to the DB. wp_send_json_error() ensures that code execution stops. * * @param string $token * @@ -311,7 +311,7 @@ private function validate_api_token( $token = '' ) { if ( ! $client->validate_api_token() ) { Messages::set_error( __( - 'Oops! The API token you used is invalid. Please click here to generate a new token.', + 'Oops! The Plugin Token you used is invalid. Please click here to generate a new token.', 'plausible-analytics' ) ); diff --git a/src/Client.php b/src/Client.php index 8596e9a6..0712ab21 100644 --- a/src/Client.php +++ b/src/Client.php @@ -40,7 +40,7 @@ public function __construct( $token = '' ) { } /** - * Validates the API token (password) set in the current instance and caches the state to a transient valid for 1 day. + * Validates the Plugin Token (password) set in the current instance and caches the state to a transient valid for 1 day. * * @return bool * @throws ApiException @@ -83,7 +83,7 @@ private function get_features() { } /** - * Retrieve all capabilities assigned to configured API token. + * Retrieve all capabilities assigned to configured Plugin Token. * * @return bool|Client\Model\Capabilities * From f98c471346788fe86614a773ea99750ca72d0d11 Mon Sep 17 00:00:00 2001 From: Dan0sz <18595395+Dan0sz@users.noreply.github.com> Date: Tue, 7 May 2024 12:25:27 +0200 Subject: [PATCH 2/2] Added: Create Token link right besides Plugin Token field label. Added: Read more information link to Invalid Token error message. --- src/Admin/Settings/API.php | 2 +- src/Admin/Settings/Page.php | 6 +++++- src/Ajax.php | 9 ++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Admin/Settings/API.php b/src/Admin/Settings/API.php index 6215e654..2e519f3e 100644 --- a/src/Admin/Settings/API.php +++ b/src/Admin/Settings/API.php @@ -618,7 +618,7 @@ public function render_text_field( array $field ) { ?>
+ for="">
Helpers::get_domain(), ], [ - 'label' => esc_html__( 'Plugin Token', 'plausible-analytics' ), + 'label' => esc_html__( 'Plugin Token', 'plausible-analytics' ) . + ' - ' . + '' . + __( 'Create Token', 'plausible-analytics' ) . + '', 'slug' => 'api_token', 'type' => 'text', 'value' => $settings[ 'api_token' ], diff --git a/src/Ajax.php b/src/Ajax.php index f6c0c3d2..55facca2 100644 --- a/src/Ajax.php +++ b/src/Ajax.php @@ -310,9 +310,12 @@ private function validate_api_token( $token = '' ) { if ( ! $client->validate_api_token() ) { Messages::set_error( - __( - 'Oops! The Plugin Token you used is invalid. Please click here to generate a new token.', - 'plausible-analytics' + sprintf( + __( + 'Oops! The Plugin Token you used is invalid. Please click here to generate a new token. Read more', + 'plausible-analytics' + ), + 'https://plausible.io/wordpress-analytics-plugin#oops-the-token-you-used-is-invalid' ) );