Skip to content

Commit

Permalink
Merge pull request #205 from plausible/rename_api_token
Browse files Browse the repository at this point in the history
Rename API token to Plugin token
  • Loading branch information
Dan0sz authored May 17, 2024
2 parents e766417 + f98c471 commit 102da20
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
10 changes: 5 additions & 5 deletions src/Admin/Settings/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand All @@ -82,7 +82,7 @@ public function settings_page() {
'plausible-analytics'
),
'api_token' => __(
'<a class="hover:cursor-pointer underline plausible-create-api-token">Create an API token</a> (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".',
'<a class="hover:cursor-pointer underline plausible-create-api-token">Create a Plugin Token</a> (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' => __(
Expand Down Expand Up @@ -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' )
Expand Down Expand Up @@ -618,7 +618,7 @@ public function render_text_field( array $field ) {
?>
<div class="mt-4">
<label class="block text-sm font-medium leading-5 !text-gray-700 !dark:text-gray-300"
for="<?php echo $field[ 'slug' ]; ?>"><?php echo esc_attr( $field[ 'label' ] ); ?></label>
for="<?php echo $field[ 'slug' ]; ?>"><?php echo $field[ 'label' ]; ?></label>
<div class="mt-1">
<input
class="block w-full !border-gray-300 !dark:border-gray-700 !rounded-md focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm dark:bg-gray-900 dark:text-gray-300 py-2 px-3"
Expand Down
10 changes: 5 additions & 5 deletions src/Admin/Settings/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -162,15 +162,15 @@ public function option_disabled_by_proxy() {
}

/**
* Display missing API token warning.
* Display missing Plugin Token warning.
*
* @output HTML
*/
public function missing_api_token_warning() {
echo sprintf(
wp_kses(
__(
'Please <a class="plausible-create-api-token hover:cursor-pointer underline">create an API token</a> and insert it into the API token field above.',
'Please <a class="plausible-create-api-token hover:cursor-pointer underline">create a Plugin Token</a> and insert it into the Plugin Token field above.',
'plausible-analytics'
),
'post'
Expand All @@ -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 <a class="plausible-create-api-token hover:cursor-pointer underline">create an API token</a> and insert it into the API token field above to enable this option.',
'Please <a class="plausible-create-api-token hover:cursor-pointer underline">create a Plugin Token</a> and insert it into the Plugin Token field above to enable this option.',
'plausible-analytics'
),
'post'
Expand Down
10 changes: 7 additions & 3 deletions src/Admin/Settings/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function __construct() {
'desc' => sprintf(
wp_kses(
__(
'Ensure your domain name matches the one in <a href="%s" target="_blank">your Plausible account</a>, then <a class="hover:cursor-pointer underline plausible-create-api-token">create an API token</a> (link opens in a new window) and paste it into the \'API token\' field.',
'Ensure your domain name matches the one in <a href="%s" target="_blank">your Plausible account</a>, then <a class="hover:cursor-pointer underline plausible-create-api-token">create a Plugin Token</a> (link opens in a new window) and paste it into the \'Plugin Token\' field.',
'plausible-analytics'
),
'post'
Expand All @@ -95,7 +95,11 @@ public function __construct() {
'value' => Helpers::get_domain(),
],
[
'label' => esc_html__( 'API token', 'plausible-analytics' ),
'label' => esc_html__( 'Plugin Token', 'plausible-analytics' ) .
' - ' .
'<a class="hover:cursor-pointer underline plausible-create-api-token">' .
__( 'Create Token', 'plausible-analytics' ) .
'</a>',
'slug' => 'api_token',
'type' => 'text',
'value' => $settings[ 'api_token' ],
Expand Down Expand Up @@ -413,7 +417,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;
Expand Down
13 changes: 8 additions & 5 deletions src/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand All @@ -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
*
Expand All @@ -310,9 +310,12 @@ private function validate_api_token( $token = '' ) {

if ( ! $client->validate_api_token() ) {
Messages::set_error(
__(
'Oops! The API token you used is invalid. Please <a class="plausible-create-api-token hover:cursor-pointer underline">click here</a> to generate a new token.',
'plausible-analytics'
sprintf(
__(
'Oops! The Plugin Token you used is invalid. Please <a class="plausible-create-api-token hover:cursor-pointer underline">click here</a> to generate a new token. <a target="_blank" href="%s">Read more</a>',
'plausible-analytics'
),
'https://plausible.io/wordpress-analytics-plugin#oops-the-token-you-used-is-invalid'
)
);

Expand Down
4 changes: 2 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 102da20

Please sign in to comment.