Plugin Directory

Changeset 3448554


Ignore:
Timestamp:
01/28/2026 10:02:31 AM (6 weeks ago)
Author:
codersaiful
Message:

data saving issue fixed

Location:
woo-min-max-quantity-step-control-single
Files:
201 added
4 edited

Legend:

Unmodified
Added
Removed
  • woo-min-max-quantity-step-control-single/trunk/admin/functions.php

    r3447561 r3448554  
    275275    <?php
    276276}
     277
     278
     279function wcmmq_form_submit(){
     280    $nonce = isset($_POST['nonce']) ? sanitize_text_field( wp_unslash($_POST['nonce']) ) : '';
     281
     282    if ( empty($nonce) || ! wp_verify_nonce( $nonce, WC_MMQ_PLUGIN_BASE_FOLDER ) ) {
     283        return;
     284    }
     285
     286    /**
     287     * RESET
     288     */
     289    if ( isset($_POST['reset_button']) ) {
     290
     291        update_option( WC_MMQ_KEY, WC_MMQ::getDefaults() );
     292        echo '<div class="updated notice"><p>Settings reset successfully.</p></div>';
     293        return;
     294    }
     295
     296    /**
     297     * SAVE
     298     */
     299    if ( ! isset($_POST['configure_submit'], $_POST['data']) ) {
     300        return;
     301    }
     302
     303    $data = wp_unslash( $_POST['data'] );
     304
     305    /**
     306     * Keys
     307     */
     308    $min_key     = WC_MMQ_PREFIX . 'min_quantity';
     309    $max_key     = WC_MMQ_PREFIX . 'max_quantity';
     310    $step_key    = WC_MMQ_PREFIX . 'product_step';
     311    $default_key = WC_MMQ_PREFIX . 'default_quantity';
     312    $pm_key      = WC_MMQ_PREFIX . 'qty_plus_minus_btn';
     313
     314    /**
     315     * Sanitize (decimal supported)
     316     */
     317    $min     = isset($data[$min_key]) ? floatval($data[$min_key]) : 0;
     318    $step    = isset($data[$step_key]) ? floatval($data[$step_key]) : 1;
     319    $max_raw = isset($data[$max_key]) ? trim($data[$max_key]) : '';
     320    $default = isset($data[$default_key]) ? floatval($data[$default_key]) : 0;
     321
     322    /**
     323     * STEP validation (must not be zero)
     324     */
     325    if ( $step <= 0 ) {
     326        $step = 1;
     327        echo '<div class="error notice"><p>Step quantity can not be zero. Reset to 1.</p></div>';
     328    }
     329
     330    /**
     331     * MAX validation
     332     * empty = unlimited
     333     * zero NOT allowed
     334     */
     335    $max = '';
     336
     337    if ( $max_raw !== '' ) {
     338
     339        $max = floatval($max_raw);
     340
     341        if ( $max == 0 ) {
     342            $max = '';
     343            echo '<div class="error notice"><p>Maximum quantity can not be zero. Treated as unlimited.</p></div>';
     344        }
     345    }
     346
     347    /**
     348     * Min / Max relation
     349     */
     350    if ( $max !== '' && $max <= $min ) {
     351        $max = $min + $step;
     352        echo '<div class="error notice"><p>Maximum quantity must be greater than minimum. It has been adjusted automatically.</p></div>';
     353    }
     354
     355    /**
     356     * Default quantity validation
     357     */
     358    if ( $default < $min ) {
     359        $default = $min;
     360        echo '<div class="error notice"><p>Default quantity was lower than minimum. Reset to minimum.</p></div>';
     361    }
     362
     363    if ( $max !== '' && $default > $max ) {
     364        $default = $min;
     365        echo '<div class="error notice"><p>Default quantity exceeded maximum. Reset to minimum.</p></div>';
     366    }
     367
     368    /**
     369     * Checkbox normalize
     370     */
     371    $pm_btn = isset( $data[$pm_key] ) ? 1 : 0;
     372
     373    /**
     374     * Final data
     375     */
     376
     377    $data[$min_key]     = $min;
     378    $data[$step_key]    = $step;
     379    $data[$max_key]     = $max;
     380    $data[$default_key] = $default;
     381    $data[$pm_key]      = $pm_btn;
     382
     383    if( ! defined( 'WC_MMQ_PRO_VERSION' ) ){
     384        //min max step will be int, no decimal
     385        $data[$min_key]     = ! empty(  $min ) ? intval( $min ) : $min;
     386        $data[$step_key]    = ! empty(  $step ) ? intval( $step ) : $step;
     387         $data[$max_key]     = ! empty(  $max ) ? intval( $max ) : $max;
     388        $data[$default_key] = ! empty(  $default ) ? intval( $default ) : $default;
     389
     390    }
     391
     392
     393    $final_data = apply_filters( 'wcmmq_before_save_settings', $data );
     394
     395    update_option( WC_MMQ_KEY, $data );
     396    return $final_data;
     397    echo '<div class="updated notice"><p>Settings saved successfully.</p></div>';
     398
     399}   
  • woo-min-max-quantity-step-control-single/trunk/admin/page/main-page.php

    r3409281 r3448554  
    44
    55$saved_data = WC_MMQ::getOptions();
    6 $nonce = sanitize_text_field( wp_unslash( $_POST['nonce'] ?? '' ) );
    7 if ( ! empty($nonce) && wp_verify_nonce( $nonce, WC_MMQ_PLUGIN_BASE_FOLDER ) ) {
    8    
    9     if( isset( $_POST['reset_button'] ) ){
    10         $data = WC_MMQ::getDefaults();
    11         update_option( WC_MMQ_KEY, $data );
    12         ?><div class="updated"><p>Reset Successfully</p></div><?php
    13     }elseif( isset( $_POST['configure_submit'] ) && filter_input_array(INPUT_POST) ){
    14         $full_data = filter_input_array( INPUT_POST );
    15         $data = $full_data['data'] ?? array();
    166
    17         $_min_quantity_name = WC_MMQ_PREFIX . 'min_quantity';
    18         $_max_quantity_name = WC_MMQ_PREFIX . 'max_quantity';
    19         $_product_step_name = WC_MMQ_PREFIX . 'product_step';
    20         $_default_quantity_name = WC_MMQ_PREFIX . 'default_quantity';
    21         $_qty_plus_minus_btn_name = WC_MMQ_PREFIX . 'qty_plus_minus_btn';
     7if( ! empty( $_POST ) && ( isset( $_POST['configure_submit'] ) || isset( $_POST['reset_button'] ) ) ){
     8    $submit_form = wcmmq_form_submit();
     9    if( is_array( $submit_form ) && ! empty( $submit_form ) ){
     10        $saved_data = $submit_form;
     11    }
     12
     13}
    2214
    2315
    24         $min_quantity_set = !empty($data[$_min_quantity_name]);
    25         $min_quantity_not_zero = $data[$_min_quantity_name] != 0;
    26         $min_quantity_not_one = $data[$_min_quantity_name] != 1;
    27         $max_quantity_less_or_equal_min = $data[WC_MMQ_PREFIX . 'max_quantity'] <= $data[$_min_quantity_name];
    28         if ($min_quantity_set && $min_quantity_not_zero && $min_quantity_not_one && $max_quantity_less_or_equal_min) {
    29             $data[$_max_quantity_name] = $data[$_min_quantity_name] + 5;
    30             echo '<div class="error notice"><p>Maximum Quantity can not be smaller, So we have added 5</p></div>';
    31         }
    32         if( !$data[$_product_step_name] || $data[$_product_step_name] == '0' || $data[$_product_step_name] == 0 ){
    33         $data[$_product_step_name] = 1;
    34         }
    35        
    36         if( !$data[$_min_quantity_name] || $data[$_min_quantity_name] == '0' || $data[$_min_quantity_name] == 0 ){
    37         $data[$_min_quantity_name] = '0';
    38         }
    39         $data[$_default_quantity_name] = isset( $data[$_default_quantity_name] ) && $data[$_default_quantity_name] >= $data[$_min_quantity_name] && ( empty( $data[$_max_quantity_name] ) || $data[$_default_quantity_name] <= $data[$_max_quantity_name] ) ? $data[$_default_quantity_name] : false;
    40        
    41         //plus minus checkbox data fixer
    42         $data[ $_qty_plus_minus_btn_name ] = !isset( $data[ $_qty_plus_minus_btn_name ] ) ? 0 : 1;
    43        
    44         $data = apply_filters( 'wcmmq_before_save_settings', $data );
    45         $saved_data = $data;
    46         update_option( WC_MMQ_KEY, $data);
    47         ?><div class="updated"><p>Successfully Updated</p></div><?php
    48     }
    49 }
    5016
    5117
  • woo-min-max-quantity-step-control-single/trunk/readme.txt

    r3447561 r3448554  
    66Tested up to: 6.9
    77Requires PHP: 5.4
    8 Stable tag: 8.0.0
     8Stable tag: 8.0.1
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    257257== Changelog ==
    258258
     259= 8.0.1 =
     260* Fixed: Min max step setting saving issue has been fixed.
     261* Fixed: Textdomain loading issue has been fixed.
     262* Bug Fixed.
     263
    259264= 8.0.0 =
    260265* Vendor library removed.
  • woo-min-max-quantity-step-control-single/trunk/wcmmq.php

    r3447561 r3448554  
    99 * Tags: WooCommerce, minimum quantity, maximum quantity, woocommrce quantity, input step control for WC, customize wc quantity, wc qt, max qt, min qt, maximum qt, minimum qt
    1010 *
    11  * Version: 8.0.0
     11 * Version: 8.0.1
    1212 * Requires at least:    4.0.0
    1313 * Tested up to:         6.9
     
    3131
    3232define('WC_MMQ__FILE__', __FILE__);
    33 define('WC_MMQ_VERSION', '8.0.0.0');
     33define('WC_MMQ_VERSION', '8.0.1.0');
    3434define('WC_MMQ_PATH', plugin_dir_path(WC_MMQ__FILE__));
    3535define('WC_MMQ_URL', plugins_url(DIRECTORY_SEPARATOR, WC_MMQ__FILE__));
     
    291291            //check current value
    292292            $current_value = get_option(WC_MMQ_KEY);
    293             $default_value = self::$default_values;
    294             $changed_value = [];
    295             //Set default value in Options
    296             if ($current_value) {
    297                 foreach ($default_value as $key => $value) {
    298                     if (isset($current_value[$key]) && $key != 'plugin_version') { //We will add Plugin version in future
    299                         $changed_value[$key] = $current_value[$key];
    300                     } else {
    301                         $changed_value[$key] = $value;
    302                     }
    303                 }
    304                 update_option(WC_MMQ_KEY, $changed_value);
    305             } else {
    306                 update_option(WC_MMQ_KEY, $default_value);
     293            if ( empty( $current_value ) ) {
     294                update_option(WC_MMQ_KEY, self::$default_values);
    307295            }
    308296        }
Note: See TracChangeset for help on using the changeset viewer.