diff --git a/assets/src/js/admin/main.js b/assets/src/js/admin/main.js index 2b634ecb..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; }, @@ -492,7 +501,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..75f2a274 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; ?>
-
+
- + - +
-
+
-

+