Plugin Directory

Changeset 2707856


Ignore:
Timestamp:
04/11/2022 08:02:04 AM (4 years ago)
Author:
Ahaenor
Message:
  • Fix for the Additional plugin options page bug.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • leyka/trunk/inc/leyka-class-options-controller.php

    r2682366 r2707856  
    6262        $main_currency_id = leyka_get_country_currency();
    6363
    64         add_filter("leyka_option_default-payments_single_amounts_options_".$main_currency_id, function($option_value){
     64        add_filter('leyka_option_default-payments_single_amounts_options_'.$main_currency_id, function($option_value){
    6565            return leyka_get_payments_amounts_options('single');
    6666        });
    6767
    68         add_filter("leyka_option_default-payments_recurring_amounts_options_".$main_currency_id, function($option_value){
     68        add_filter('leyka_option_default-payments_recurring_amounts_options_'.$main_currency_id, function($option_value){
    6969            return leyka_get_payments_amounts_options('recurring');
    70         });
     70        }, 10, 2);
    7171
    7272        // If Country option value changes, clear active PM lists:
     
    8383
    8484        $option_id = apply_filters('leyka_option_id-'.$option_id, str_replace('leyka_', '', $option_id));
    85         $option_id = apply_filters('leyka_option_id', $option_id);
    86 
    87         return $option_id;
     85
     86        return apply_filters('leyka_option_id', $option_id);
    8887
    8988    }
     
    9493
    9594    /**
    96      * A service method to retrieve a plugin option value when the plugin is just being initialized
     95     * A service method to retrieve a plugin option value when the plugin is just being initialized,
    9796     * and it can't properly load options metadata yet.
    9897     *
    9998     * @param $option_id string
     99     * @package $use_option_value_filters boolean
    100100     * @return mixed
    101101     */
    102     public static function get_option_value($option_id) {
     102    public static function get_option_value($option_id, $use_option_value_filters = true) {
    103103
    104104        // Don't use $this->_get_filtered_option_id() here:
    105         $option_id = stristr($option_id, 'leyka_') !== false ? $option_id : 'leyka_'.$option_id;
    106         $value = apply_filters('leyka_option_value-'.$option_id, get_option($option_id));
    107 
    108         return apply_filters('leyka_option_value', $value, $option_id);
    109 
    110     }
    111 
    112     /**
    113      * A service method to set a plugin option value when the plugin is just being initialized
     105        $option_id = stripos($option_id, 'leyka_') === false ? 'leyka_'.$option_id : $option_id;
     106        $value = get_option($option_id);
     107
     108        if($use_option_value_filters) {
     109            $value = apply_filters(
     110                'leyka_option_value-'.$option_id,
     111                apply_filters('leyka_option_value', $value, $option_id)
     112            );
     113        }
     114
     115        return $value;
     116
     117    }
     118
     119    /**
     120     * A service method to set a plugin option value when the plugin is just being initialized,
    114121     * and it can't properly load options metadata yet.
    115122     *
     
    119126    public static function set_option_value($option_id, $value) {
    120127
    121         $option_id = mb_stristr($option_id, 'leyka_') !== false ? $option_id : 'leyka_'.$option_id;
     128        $option_id = mb_stripos($option_id, 'leyka_') !== false ? $option_id : 'leyka_'.$option_id;
    122129
    123130        $value = apply_filters('leyka_new_option_value', $value, $option_id);
     
    142149        $new_options_group_meta = [];
    143150
    144         if(stristr($option_id, 'org_') !== false) {
     151        if(stripos($option_id, 'org_') !== false) {
    145152            $new_options_group_meta = Leyka_Options_Meta_Controller::get_instance()->get_options_meta('org');
    146         } else if(stristr($option_id, 'person_') !== false) {
     153        } else if(stripos($option_id, 'person_') !== false) {
    147154            $new_options_group_meta = Leyka_Options_Meta_Controller::get_instance()->get_options_meta('person');
    148         } else if(stristr($option_id, 'payments') !== false) {
     155        } else if(stripos($option_id, 'payments') !== false) {
    149156            $new_options_group_meta = Leyka_Options_Meta_Controller::get_instance()->get_options_meta('payments');
    150         } else if(stristr($option_id, 'currency') !== false) {
     157        } else if(stripos($option_id, 'currency') !== false) {
    151158            $new_options_group_meta = Leyka_Options_Meta_Controller::get_instance()->get_options_meta('currency');
    152         } else if(stristr($option_id, 'email') !== false || stristr($option_id, 'notify') !== false) {
     159        } else if(stripos($option_id, 'email') !== false || stripos($option_id, 'notify') !== false) {
    153160            $new_options_group_meta = Leyka_Options_Meta_Controller::get_instance()->get_options_meta('emails');
    154161        } else if(
    155             stristr($option_id, 'template') !== false
    156             || stristr($option_id, 'display') !== false
    157             || stristr($option_id, 'show') !== false
    158             || stristr($option_id, 'widget') !== false
    159             || stristr($option_id, 'revo') !== false
     162            stripos($option_id, 'template') !== false
     163            || stripos($option_id, 'display') !== false
     164            || stripos($option_id, 'show') !== false
     165            || stripos($option_id, 'widget') !== false
     166            || stripos($option_id, 'revo') !== false
    160167        ) {
    161168            $new_options_group_meta = Leyka_Options_Meta_Controller::get_instance()->get_options_meta('templates');
    162         } else if(stristr($option_id, '_ua') !== false || stristr($option_id, '_gtm') !== false) {
     169        } else if(stripos($option_id, '_ua') !== false || stripos($option_id, '_gtm') !== false) {
    163170            $new_options_group_meta = Leyka_Options_Meta_Controller::get_instance()->get_options_meta('analytics');
    164         } else if(stristr($option_id, 'terms') !== false) {
     171        } else if(stripos($option_id, 'terms') !== false) {
    165172            $new_options_group_meta = Leyka_Options_Meta_Controller::get_instance()->get_options_meta('terms');
    166         } else if(stristr($option_id, 'admin') !== false || stristr($option_id, 'plugin')) {
     173        } else if(
     174            stripos($option_id, 'admin') !== false
     175            || stripos($option_id, 'plugin') !== false
     176            || stripos($option_id, 'paltform') !== false
     177        ) {
    167178            $new_options_group_meta = Leyka_Options_Meta_Controller::get_instance()->get_options_meta('admin');
    168179        }
     
    222233            $this->_options[$option_id]['value'] = get_option("leyka_$option_id");
    223234
    224             // Option is not set, use default value from meta:
     235            // Option is not set, use default value from options meta:
    225236            if($this->_options[$option_id]['value'] === false && !empty(self::$_options_meta[$option_id])) {
    226237                $this->_options[$option_id]['value'] = empty(self::$_options_meta[$option_id]['default']) ?
     
    272283                trim($this->_options[$option_id]['value']);
    273284
    274         } else if(stristr($this->_options[$option_id]['type'], 'multi_') !== false && !$this->_options[$option_id]['value']) {
     285        } else if(stripos($this->_options[$option_id]['type'], 'multi_') !== false && !$this->_options[$option_id]['value']) {
    275286            $this->_options[$option_id]['value'] = [];
    276287        }
     
    278289        $this->_options[$option_id]['value'] = apply_filters(
    279290            'leyka_option_value-'.$option_id,
    280             $this->_options[$option_id]['value']
     291            apply_filters('leyka_option_value', $this->_options[$option_id]['value'], $option_id)
    281292        );
    282293
    283         return apply_filters('leyka_option_value', $this->_options[$option_id]['value'], $option_id);
     294        return $this->_options[$option_id]['value'];
    284295
    285296    }
     
    287298    public function add_option($option_id, $type, $params) {
    288299
    289         $option_id = stristr($option_id, 'leyka_') !== false ? $option_id : 'leyka_'.$option_id;
    290 
    291         if( !in_array($type, self::$_field_types) && stristr($type, 'custom_') === false ) {
     300        $option_id = stripos($option_id, 'leyka_') !== false ? $option_id : 'leyka_'.$option_id;
     301
     302        if( !in_array($type, self::$_field_types) && stripos($type, 'custom_') === false ) {
    292303            return false;
    293304        }
     
    332343    public function delete_option($option_id) {
    333344
    334         $option_id = stristr($option_id, 'leyka_') !== false ? $option_id : 'leyka_'.$option_id;
     345        $option_id = stripos($option_id, 'leyka_') !== false ? $option_id : 'leyka_'.$option_id;
    335346
    336347        $this->_intialize_option($option_id);
     
    511522        $this->_intialize_option($option_id, true);
    512523
    513         $filtered_options = [
     524        $filtered_option_metadata = [
    514525            'title' => apply_filters('leyka_option_title-'.$option_id, $this->_options[$option_id]['title']),
    515526            'type' => apply_filters('leyka_option_type-'.$option_id, $this->_options[$option_id]['type']),
     
    524535        ];
    525536
    526         $this->_options[$option_id] = array_merge($this->_options[$option_id], $filtered_options);
     537        $this->_options[$option_id] = array_merge($this->_options[$option_id], $filtered_option_metadata);
    527538
    528539        return apply_filters('leyka_option_info-'.$option_id, $this->_options[$option_id]);
Note: See TracChangeset for help on using the changeset viewer.