From 3a8a68c56752b875bdd498b986314a64571edf2d Mon Sep 17 00:00:00 2001 From: Dan0sz <18595395+Dan0sz@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:29:36 +0100 Subject: [PATCH 1/4] Fixed: don't remove NA in CE message when other options are toggled. --- assets/src/js/admin/main.js | 2 +- src/Admin/Settings/API.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/assets/src/js/admin/main.js b/assets/src/js/admin/main.js index 2b634ecb..287ff634 100644 --- a/assets/src/js/admin/main.js +++ b/assets/src/js/admin/main.js @@ -492,7 +492,7 @@ document.addEventListener('DOMContentLoaded', () => { } } - if (additionalMessage !== undefined) { + if (additionalMessage !== undefined && !additionalMessage.classList.contains('plausible-analytics-persist')) { container.removeChild(additionalMessage); } } diff --git a/src/Admin/Settings/API.php b/src/Admin/Settings/API.php index cd250794..5ef70449 100644 --- a/src/Admin/Settings/API.php +++ b/src/Admin/Settings/API.php @@ -730,9 +730,13 @@ public function render_hook_field( array $field ) { $text_class = 'text-green-700 dark:text-green-800'; } + if (!empty($field['slug'])) { + $persist_message = 'plausible-analytics-persist'; + } + ob_start(); ?> -
+
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
-

+

@@ -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(); ?> -
+

+ id="">
- +
- - + +
@@ -565,7 +578,7 @@ public function render_group_field( array $group, $hide_header = false ) { $is_list = array_filter( $fields, function ( $field ) { - return $field[ 'type' ] === 'checkbox'; + return $field['type'] === 'checkbox'; } ); @@ -582,24 +595,25 @@ function ( $field ) { /** * Render Text Field. * + * @return string * @since 1.3.0 * @access public - * @return string */ public function render_text_field( array $field ) { ob_start(); - $value = ! empty( $field[ 'value' ] ) ? $field[ 'value' ] : ''; - $placeholder = ! empty( $field[ 'placeholder' ] ) ? $field[ 'placeholder' ] : ''; - $disabled = ! empty( $field[ 'disabled' ] ) ? 'disabled' : ''; + $value = ! empty( $field['value'] ) ? $field['value'] : ''; + $placeholder = ! empty( $field['placeholder'] ) ? $field['placeholder'] : ''; + $disabled = ! empty( $field['disabled'] ) ? 'disabled' : ''; ?>
+ for="">
/>
@@ -616,19 +630,20 @@ class="block w-full !border-gray-300 !dark:border-gray-700 !rounded-md focus:rin */ public function render_button_field( array $field ) { ob_start(); - $disabled = isset( $field[ 'disabled' ] ) && $field[ 'disabled' ] === true; + $disabled = isset( $field['disabled'] ) && $field['disabled'] === true; ?>
- + - +
-
+
-

+

From 5ef52fa07684205df2b3df5b7b52b4787678411e Mon Sep 17 00:00:00 2001 From: Dan0sz <18595395+Dan0sz@users.noreply.github.com> Date: Tue, 7 Jan 2025 15:07:21 +0100 Subject: [PATCH 3/4] Fixed: warning. --- src/Admin/Settings/API.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Admin/Settings/API.php b/src/Admin/Settings/API.php index 6d568ef5..073cdec5 100644 --- a/src/Admin/Settings/API.php +++ b/src/Admin/Settings/API.php @@ -739,9 +739,10 @@ class="block w-full max-w-xl border-gray-300 dark:border-gray-700 resize-none sh * */ public function render_hook_field( array $field ) { - $hook_type = $field['hook_type'] ?? 'warning'; - $box_class = 'bg-yellow-50 dark:bg-yellow-100'; - $text_class = 'text-yellow-700 dark:text-yellow-800'; + $hook_type = $field['hook_type'] ?? 'warning'; + $box_class = 'bg-yellow-50 dark:bg-yellow-100'; + $text_class = 'text-yellow-700 dark:text-yellow-800'; + $persist_message = ''; if ( $hook_type === 'success' ) { $box_class = 'bg-green-50 dark:bg-green-100'; From 1eb47d73d08bb78f9014f05bc7a423977eeb7d8f Mon Sep 17 00:00:00 2001 From: Dan0sz <18595395+Dan0sz@users.noreply.github.com> Date: Tue, 7 Jan 2025 16:14:10 +0100 Subject: [PATCH 4/4] Fixed: prevent that existing messages are shown twice. --- assets/src/js/admin/main.js | 9 +++++++++ src/Admin/Settings/API.php | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/assets/src/js/admin/main.js b/assets/src/js/admin/main.js index 287ff634..d20efa99 100644 --- a/assets/src/js/admin/main.js +++ b/assets/src/js/admin/main.js @@ -469,6 +469,15 @@ document.addEventListener('DOMContentLoaded', () => { let targetElem = document.querySelector(`[name='${target}']`); let container = targetElem.closest('.plausible-analytics-group'); + if (container.children.length > 0) { + for (let i = 0; i < container.children.length; i++) { + if (container.children[i].id.includes(target)) { + // This message already exists. + return; + } + } + } + container.innerHTML += html; }, diff --git a/src/Admin/Settings/API.php b/src/Admin/Settings/API.php index 073cdec5..75f2a274 100644 --- a/src/Admin/Settings/API.php +++ b/src/Admin/Settings/API.php @@ -755,7 +755,8 @@ public function render_hook_field( array $field ) { ob_start(); ?> -
+