GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(admin): repair customization tab language selector and default va… · axeptio/wordpress-plugin@a67331d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • includes/classes
    • admin/pages
      • class-admin-callbacks.php
    • models
      • class-axeptio-steps.php
  • templates/admin
    • common/fields
      • textarea.php
    • main/fields
      • widget-options.php
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎includes/classes/admin/pages/class-admin-callbacks.php‎

Copy file name to clipboardExpand all lines: includes/classes/admin/pages/class-admin-callbacks.php
+8-12Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,21 +169,16 @@ private static function get_field_attributes( string $base_name, string $languag
169169
}
170170

171171
/**
172-
* Get option value with language support and fallback
172+
* Get the saved value for a widget field in a given language.
173173
*
174174
* @param string $base_name Base option name
175175
* @param string $language Language code
176176
* @return string Option value
177177
*/
178178
private static function get_widget_value( string $base_name, string $language ): string {
179-
if ( $language ) {
180-
$value = Settings::get_option( $base_name . '_' . $language, null );
181-
if ( null !== $value ) {
182-
return $value;
183-
}
184-
}
179+
$option_name = $language ? $base_name . '_' . $language : $base_name;
185180

186-
return Settings::get_option( $base_name, '' );
181+
return (string) Settings::get_option( $option_name, '' );
187182
}
188183

189184
/**
@@ -205,10 +200,11 @@ private static function render_widget_field( array $args ): void {
205200
$template,
206201
array_merge(
207202
array(
208-
'label' => self::format_label_with_language( $label, $language ),
209-
'group' => 'axeptio_settings',
210-
'value' => $value,
211-
'language' => $language,
203+
'label' => self::format_label_with_language( $label, $language ),
204+
'group' => 'axeptio_settings',
205+
'value' => $value,
206+
'language' => $language,
207+
'placeholder' => Axeptio_Steps::get_default_value( $field_name ),
212208
),
213209
$field_attrs
214210
)
Collapse file

‎includes/classes/models/class-axeptio-steps.php‎

Copy file name to clipboardExpand all lines: includes/classes/models/class-axeptio-steps.php
+11-14Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Axeptio_Steps {
1515
* @param string $field Field name
1616
* @return string Default value
1717
*/
18-
private static function get_default_value( string $field ): string {
18+
public static function get_default_value( string $field ): string {
1919
switch ( $field ) {
2020
case 'widget_title':
2121
return esc_html__( 'WordPress Cookies', 'axeptio-wordpress-plugin' );
@@ -38,18 +38,13 @@ private static function get_default_value( string $field ): string {
3838
private static function get_widget_field( string $field_name, string $language = '' ): string {
3939
$default = self::get_default_value( $field_name );
4040

41-
if ( $language ) {
42-
$option_name = $field_name . '_' . $language;
43-
$value = Settings::get_option( $option_name, null );
44-
45-
// If the value exists, return it.
46-
if ( null !== $value ) {
47-
return $value;
48-
}
41+
if ( ! $language ) {
42+
return $default;
4943
}
5044

51-
// Fallback to the legacy method (non-language specific)
52-
return Settings::get_option( $field_name, $default ) ?? $default;
45+
$saved_value = Settings::get_option( $field_name . '_' . $language, '' );
46+
47+
return ! empty( $saved_value ) ? $saved_value : $default;
5348
}
5449

5550
/**
@@ -88,12 +83,14 @@ public static function get_description( string $language = '' ): string {
8883
* @return array[]
8984
*/
9085
public static function all() {
86+
$language = I18n::get_current_language();
87+
9188
return array(
9289
array(
93-
'title' => self::get_title(),
94-
'subTitle' => self::get_sub_title(),
90+
'title' => self::get_title( $language ),
91+
'subTitle' => self::get_sub_title( $language ),
9592
'topTitle' => false,
96-
'message' => self::get_description(),
93+
'message' => self::get_description( $language ),
9794
'image' => false,
9895
'imageWidth' => 0,
9996
'imageHeight' => 0,
Collapse file

‎templates/admin/common/fields/textarea.php‎

Copy file name to clipboardExpand all lines: templates/admin/common/fields/textarea.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
<?php endif ?>
99
</label>
1010
<div class="mt-2">
11-
<textarea id="<?php echo esc_attr( $data->id ); ?>" name="<?php echo isset( $data->group ) ? esc_attr( $data->group . '[' . $data->name . ']' ) : esc_attr( $data->name ); ?>" rows="3" class="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-amber-600 sm:text-sm sm:leading-6"><?php echo esc_html( $data->value ); ?></textarea>
11+
<textarea id="<?php echo esc_attr( $data->id ); ?>" name="<?php echo isset( $data->group ) ? esc_attr( $data->group . '[' . $data->name . ']' ) : esc_attr( $data->name ); ?>" rows="3" class="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-amber-600 sm:text-sm sm:leading-6"<?php echo isset( $data->placeholder ) ? ' placeholder="' . esc_attr( $data->placeholder ) . '"' : ''; ?>><?php echo esc_html( $data->value ); ?></textarea>
1212
</div>
1313
</div>
Collapse file

‎templates/admin/main/fields/widget-options.php‎

Copy file name to clipboardExpand all lines: templates/admin/main/fields/widget-options.php
+16-16Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,38 @@
1919
}
2020
?>
2121

22-
<div class="widgetOptions lg:w-4/6 2xl:w-3/4" <?php echo $axeptio_is_multilingual ? 'x-data="{ selectedLang: ' . wp_json_encode( $axeptio_default_lang ) . ' }"' : ''; ?>>
22+
<div class="widgetOptions lg:w-4/6 2xl:w-3/4"
23+
<?php if ( $axeptio_is_multilingual ) : ?>
24+
x-data="{ selectedLang: '<?php echo esc_attr( $axeptio_default_lang ); ?>' }"
25+
@language-changed.window="selectedLang = $event.detail.language || $event.detail.value"
26+
<?php endif; ?>
27+
>
2328
<?php if ( $axeptio_is_multilingual ) : ?>
2429
<div class="mb-6">
2530
<?php
31+
// UI-only filter: an empty 'group' keeps the selector out of the saved settings.
2632
\Axeptio\Plugin\get_template_part(
2733
'admin/common/fields/select-languages',
2834
array(
2935
'label' => __( 'Widget language', 'axeptio-wordpress-plugin' ),
30-
'group' => 'axeptio_settings',
31-
'name' => 'widget_title',
32-
'id' => 'xpwp_widget_title',
36+
'group' => '',
37+
'name' => 'widget_lang',
38+
'id' => 'xpwp_widget_lang',
3339
'languages' => $axeptio_languages,
3440
'value' => $axeptio_default_lang,
3541
)
3642
);
3743
?>
38-
39-
<?php // Event listener to update the selected language. ?>
40-
<div x-init="
41-
window.addEventListener('language-changed', (event) => {
42-
if (event.detail && event.detail.language) {
43-
selectedLang = event.detail.language;
44-
} else if (event.detail && event.detail.value) {
45-
selectedLang = event.detail.value;
46-
}
47-
});
48-
"></div>
4944
</div>
5045
<?php endif; ?>
5146

5247
<?php foreach ( $axeptio_languages as $axeptio_lang ) : ?>
53-
<div class="space-y-6" <?php echo $axeptio_is_multilingual ? 'x-show="selectedLang === ' . wp_json_encode( $axeptio_lang['language_code'] ) . '"' : ''; ?>>
48+
<div class="space-y-6"
49+
<?php if ( $axeptio_is_multilingual ) : ?>
50+
x-show="selectedLang === '<?php echo esc_attr( $axeptio_lang['language_code'] ); ?>'"
51+
x-cloak
52+
<?php endif; ?>
53+
>
5454
<?php Admin_Callbacks::render_widget_fields( $axeptio_lang['language_code'] ); ?>
5555
</div>
5656
<?php endforeach; ?>

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.