Plugin Directory

Changeset 3492219


Ignore:
Timestamp:
03/26/2026 11:00:09 PM (7 days ago)
Author:
madnesscode1
Message:

fix responsive device size persistence

Location:
madnesschat-button/tags/1.0.2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • madnesschat-button/tags/1.0.2/includes/class-mcnb-settings.php

    r3488520 r3492219  
    99        $saved = get_option( 'mcnb_basic_options', array() );
    1010        $result = wp_parse_args( $saved, $defaults );
    11        
    12        
     11
     12        if ( isset( $defaults['responsive_config'] ) && is_array( $defaults['responsive_config'] ) ) {
     13            $result['responsive_config'] = self::merge_responsive_config(
     14                is_array( $saved['responsive_config'] ?? null ) ? $saved['responsive_config'] : array(),
     15                $defaults['responsive_config']
     16            );
     17        }
     18
    1319        return $result;
    1420    }
     
    116122        // Checkbox responsive_enabled: ya procesado arriba
    117123       
    118         // Procesar configuración responsive
    119         $responsive_config = $pick( 'responsive_config' );
    120         if ( is_array( $responsive_config ) ) {
    121             $clean_responsive = array();
    122             $valid_devices = array( 'mobile', 'tablet', 'laptop', 'desktop' );
    123             foreach ( $valid_devices as $device ) {
    124                 if ( isset( $responsive_config[ $device ] ) && is_array( $responsive_config[ $device ] ) ) {
    125                     $device_config = $responsive_config[ $device ];
    126                     $clean_responsive[ $device ] = array(
    127                         'size' => in_array( (string) $device_config['size'], array( '48', '56', '64', '72', '80' ), true ) ? (string) $device_config['size'] : '56',
    128                         'position' => in_array( (string) $device_config['position'], array( 'bottom-right', 'bottom-left' ), true ) ? (string) $device_config['position'] : 'bottom-right',
    129                         'offset_x' => max( 0, min( 500, intval( $device_config['offset_x'] ) ) ),
    130                         'offset_y' => max( 0, min( 500, intval( $device_config['offset_y'] ) ) ),
    131                         'show_label' => ! empty( $device_config['show_label'] )
    132                     );
    133                 }
    134             }
    135             $sanitized['responsive_config'] = $clean_responsive;
    136         } else {
    137             $sanitized['responsive_config'] = $pick( 'responsive_config' );
    138         }
     124        // Procesar configuración responsive preservando valores faltantes por dispositivo.
     125        $default_responsive = is_array( $defaults['responsive_config'] ?? null ) ? $defaults['responsive_config'] : array();
     126        $saved_responsive   = is_array( $saved['responsive_config'] ?? null ) ? $saved['responsive_config'] : array();
     127        $input_responsive   = is_array( $input['responsive_config'] ?? null ) ? $input['responsive_config'] : array();
     128        $base_responsive    = self::merge_responsive_config( $saved_responsive, $default_responsive );
     129        $sanitized['responsive_config'] = self::sanitize_responsive_config( $input_responsive, $base_responsive );
    139130       
    140131       
     
    508499                $sizes = array( '48' => '48px', '56' => '56px', '64' => '64px', '72' => '72px', '80' => '80px' );
    509500                foreach ( $sizes as $value => $label ) {
    510                     $selected = ( $device_config['size'] ?? '56' ) === $value;
     501                    $selected = (string) ( $device_config['size'] ?? '56' ) === (string) $value;
    511502                    printf( '<option value="%s" %s>%s</option>', esc_attr( $value ), selected( $selected, true, false ), esc_html( $label ) );
    512503                }
     
    11041095    }
    11051096
     1097    private static function merge_responsive_config( $config, $defaults ) {
     1098        $merged        = array();
     1099        $valid_devices = array( 'mobile', 'tablet', 'laptop', 'desktop' );
     1100
     1101        foreach ( $valid_devices as $device ) {
     1102            $merged[ $device ] = wp_parse_args(
     1103                is_array( $config[ $device ] ?? null ) ? $config[ $device ] : array(),
     1104                is_array( $defaults[ $device ] ?? null ) ? $defaults[ $device ] : array()
     1105            );
     1106        }
     1107
     1108        return $merged;
     1109    }
     1110
     1111    private static function sanitize_responsive_config( $input_config, $base_config ) {
     1112        $clean         = array();
     1113        $valid_devices = array( 'mobile', 'tablet', 'laptop', 'desktop' );
     1114
     1115        foreach ( $valid_devices as $device ) {
     1116            $device_base   = is_array( $base_config[ $device ] ?? null ) ? $base_config[ $device ] : array();
     1117            $device_input  = is_array( $input_config[ $device ] ?? null ) ? $input_config[ $device ] : array();
     1118            $device_config = wp_parse_args( $device_input, $device_base );
     1119
     1120            $clean[ $device ] = array(
     1121                'size' => in_array( (string) ( $device_config['size'] ?? '' ), array( '48', '56', '64', '72', '80' ), true ) ? (string) $device_config['size'] : (string) ( $device_base['size'] ?? '56' ),
     1122                'position' => in_array( (string) ( $device_config['position'] ?? '' ), array( 'bottom-right', 'bottom-left' ), true ) ? (string) $device_config['position'] : (string) ( $device_base['position'] ?? 'bottom-right' ),
     1123                'offset_x' => max( 0, min( 500, intval( $device_config['offset_x'] ?? ( $device_base['offset_x'] ?? 20 ) ) ) ),
     1124                'offset_y' => max( 0, min( 500, intval( $device_config['offset_y'] ?? ( $device_base['offset_y'] ?? 20 ) ) ) ),
     1125                'show_label' => array_key_exists( 'show_label', $device_input ) ? ! empty( $device_input['show_label'] ) : ! empty( $device_base['show_label'] ),
     1126            );
     1127        }
     1128
     1129        return $clean;
     1130    }
     1131
    11061132}
    11071133
  • madnesschat-button/tags/1.0.2/madnesschat-button.php

    r3490823 r3492219  
    33 * Plugin Name: Floating Contact Button
    44 * Description: Easy-to-configure floating WhatsApp button with GDPR compliance, basic analytics, and smart triggers.
    5  * Version: 1.1.2
     5 * Version: 1.1.3
    66 * Author: Vórtice Labs
    77 * Requires at least: 5.6
     
    3939}
    4040
    41 define( 'MCNB_VERSION', '1.1.2' );
     41define( 'MCNB_VERSION', '1.1.3' );
    4242define( 'MCNB_SLUG', 'madnesschat-button' );
    4343define( 'MCNB_FILE', __FILE__ );
  • madnesschat-button/tags/1.0.2/readme.txt

    r3490823 r3492219  
    55Tested up to: 6.9
    66Requires PHP: 7.3
    7 Stable tag: 1.1.2
     7Stable tag: 1.1.3
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    123123
    124124== Changelog ==
     125
     126= 1.1.3 =
     127* FIXED: Responsive per-device settings now preserve values correctly when saving.
     128* FIXED: Device-specific size values are shown correctly after reloading the settings page.
    125129
    126130= 1.1.2 =
     
    202206== Upgrade Notice ==
    203207
     208= 1.1.3 =
     209Fixes saving and reloading of responsive per-device size settings. Recommended update if you use device-specific design options.
     210
    204211= 1.1.2 =
    205212Metadata compliance update for WordPress.org: fixed contributors, reduced tags, and refreshed release version.
Note: See TracChangeset for help on using the changeset viewer.