From 470c57e87c2eb30de116274f1b9b9e94c625148b Mon Sep 17 00:00:00 2001
From: Dan0sz <18595395+Dan0sz@users.noreply.github.com>
Date: Tue, 7 Jan 2025 15:05:29 +0100
Subject: [PATCH 2/4] Fixed: don't remove "Create Plugin Token" message, when
disabling "View Stats" option.
---
src/Admin/Settings/API.php | 184 ++++++++++++++++++++-----------------
1 file changed, 102 insertions(+), 82 deletions(-)
diff --git a/src/Admin/Settings/API.php b/src/Admin/Settings/API.php
index 5ef70449..6d568ef5 100644
--- a/src/Admin/Settings/API.php
+++ b/src/Admin/Settings/API.php
@@ -45,15 +45,15 @@ class API {
/**
* Render Fields.
*
+ * @return void
* @since 1.3.0
* @access public
- * @return void
*/
public function settings_page() {
wp_nonce_field( 'plausible_analytics_toggle_option' );
$settings = Helpers::get_settings();
- $followed_wizard = get_option( 'plausible_analytics_wizard_done' ) || ! empty( $settings[ 'self_hosted_domain' ] );
+ $followed_wizard = get_option( 'plausible_analytics_wizard_done' ) || ! empty( $settings['self_hosted_domain'] );
/**
* On-boarding wizard.
@@ -108,8 +108,8 @@ public function settings_page() {
),
];
- if ( empty( $settings[ 'enable_analytics_dashboard' ] ) ) {
- $this->slides_description[ 'success' ] = sprintf(
+ if ( empty( $settings['enable_analytics_dashboard'] ) ) {
+ $this->slides_description['success'] = sprintf(
__(
'
Congrats! Your traffic is now being counted without compromising the user experience and privacy of your visitors.
Note that visits from logged in users aren\'t tracked. If you want to track visits for certain user roles, then please specify them in the plugin\'s settings .
Need help? Our documentation is the best place to find most answers right away.
Still haven\'t found the answer you\'re looking for? We\'re here to help. Please contact our support .
',
'plausible-analytics'
@@ -130,7 +130,7 @@ public function settings_page() {
/**
* Settings screen
*/
- $current_tab = ! empty( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'general';
+ $current_tab = ! empty( $_GET['tab'] ) ? $_GET['tab'] : 'general';
?>
@@ -157,7 +157,7 @@ public function settings_page() {
fields[ $current_tab ] as $tab => $field ): ?>
get_wizard_option_properties( $id );
if ( ! empty( $field ) ) {
- $hide_header = $field[ 'type' ] === 'group';
+ $hide_header = $field['type'] === 'group';
- echo call_user_func( [ $this, "render_{$field['type']}_field" ], $field, $hide_header );
+ echo call_user_func( [
+ $this,
+ "render_{$field['type']}_field"
+ ], $field, $hide_header );
}
?>
@@ -288,7 +291,8 @@ class="hover:cursor-pointer no-underline gap-x-2 rounded-md bg-indigo-600 px-3.5
-
+
class="plausible-analytics-wizard-active-step flex hidden items-start mb-6"
data-completed-steps="">
-
-
-
+
+
+
-
-
+
-
@@ -385,7 +395,8 @@ class="hidden max-w-sm w-full bg-white dark:bg-gray-800 shadow-lg rounded-lg poi
-
@@ -393,7 +404,8 @@ class="w-6 h-8 text-yellow-400">
@@ -411,13 +423,13 @@ class="w-6 h-8 text-yellow-400">
* @return array|mixed
*/
private function get_wizard_option_properties( $slug ) {
- foreach ( $this->fields[ 'general' ] as $group ) {
- if ( $group[ 'slug' ] === $slug ) {
+ foreach ( $this->fields['general'] as $group ) {
+ if ( $group['slug'] === $slug ) {
return $group;
}
- foreach ( $group[ 'fields' ] as $field ) {
- if ( $field[ 'slug' ] === $slug ) {
+ foreach ( $group['fields'] as $field ) {
+ if ( $field['slug'] === $slug ) {
return $field;
}
}
@@ -429,9 +441,9 @@ private function get_wizard_option_properties( $slug ) {
/**
* Render Header Navigation.
*
+ * @return void
* @since 1.3.0
* @access public
- * @return void
*/
public function render_navigation() {
$screen = get_current_screen();
@@ -441,7 +453,7 @@ public function render_navigation() {
return;
}
- $current_tab = ! empty( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : '';
+ $current_tab = ! empty( $_GET['tab'] ) ? $_GET['tab'] : '';
$tabs = apply_filters(
'plausible_analytics_settings_navigation_tabs',
[
@@ -462,9 +474,9 @@ public function render_navigation() {
foreach ( $tabs as $tab ) {
printf(
'
%3$s ',
- esc_url( $tab[ 'url' ] ),
- esc_attr( $tab[ 'class' ] ),
- esc_html( $tab[ 'name' ] )
+ esc_url( $tab['url'] ),
+ esc_attr( $tab['class'] ),
+ esc_html( $tab['name'] )
);
}
?>
@@ -474,8 +486,8 @@ public function render_navigation() {
/**
* Render Quick Actions
*
- * @since 1.3.0
* @return string
+ * @since 1.3.0
*/
private function render_quick_actions() {
ob_start();
@@ -483,13 +495,13 @@ private function render_quick_actions() {
?>
0 ) : ?>
-
+
-
-
+
+
@@ -500,8 +512,8 @@ private function render_quick_actions() {
/**
* Get Quick Actions.
*
- * @since 1.3.0
* @return array
+ * @since 1.3.0
*/
private function get_quick_actions() {
$settings = Helpers::get_settings();
@@ -513,7 +525,7 @@ private function get_quick_actions() {
'url' => admin_url( "admin-ajax.php?action=plausible_analytics_show_wizard&_nonce=$nonce&redirect=1" ),
'id' => 'show_wizard',
'target' => '_self',
- 'disabled' => ! empty( $settings[ 'self_hosted_domain' ] ),
+ 'disabled' => ! empty( $settings['self_hosted_domain'] ),
],
'view-docs' => [
'label' => esc_html__( 'Documentation', 'plausible-analytics' ),
@@ -533,26 +545,27 @@ private function get_quick_actions() {
/**
* Render Group Field.
*
+ * @return string
* @since 1.3.0
* @access public
- * @return string
*/
public function render_group_field( array $group, $hide_header = false ) {
- $toggle = $group[ 'toggle' ] ?? [];
- $fields = $group[ 'fields' ];
+ $toggle = $group['toggle'] ?? [];
+ $fields = $group['fields'];
ob_start();
?>
-