# woo-mailerlite/3.1.25/includes/common/WooMailerLiteOptions.php

MailerLite – WooCommerce integration, version 3.1.25. 156 lines.

- Page: https://pluginprobe.com/plugins/woo-mailerlite/3.1.25/code/includes/common/WooMailerLiteOptions.php
- Raw: https://pluginprobe.com/plugins/woo-mailerlite/3.1.25/raw/includes/common/WooMailerLiteOptions.php
- Modified: 2026-05-04T08:12:40+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/woo-mailerlite/3.1.25/code/includes/common/WooMailerLiteOptions.php#L10-L20`.

```php
<?php

class WooMailerLiteOptions
{
    private static $key = 'woo_mailerlite_options';
    private static $apiKey = 'apiKey';
    protected static $toJson = false;

    public const COMPLETE_ORDER_STATUSES = [
        'wc-completed',
        'wc-processing',
        'completed',
        'processing',
        'wc-iscrizione-ok',
        'iscrizione-ok',
    ];

    public const PENDING_ORDER_STATUSES = [
        'wc-pending',
    ];

    public static function all()
    {
        return get_option(self::$key, []);
    }

    public static function get($key, $default = false)
    {
        try {
            $options = get_option(self::$key, []);
            if (!isset($options['settings'])) {
                $options = self::update('settings', [
                    'subscribeOnCheckout' => false
                ]);
            }
            if (strpos($key, '.') !== false) {
                $needle = explode('.', $key);

                if (is_string($options[$needle[0]])) {
                    $cleanJson = stripslashes($options[$needle[0]]);
                    $options[$needle[0]] = json_decode($cleanJson, true);
                }
                if (isset($options[$needle[0]][$needle[1]])) {
                    return $options[$needle[0]][$needle[1]];
                } else {
                    return $default;
                }
            }

            if (isset($options[$key])) {
                if (is_string($options[$key])) {
                    $cleanJson = stripslashes($options[$key]);
                    if (is_array(json_decode($cleanJson, true))) {
                        $options[$key] = json_decode($cleanJson, true);
                    }
                }
                if (self::$toJson) {
                    return json_encode($options[$key]);
                }

                if ($key === self::$apiKey && !empty($options[$key])) {
                    return self::handleApiKeyRetrieval($options[$key]);
                }
                return $options[$key];
            }
            return $default;
        } catch(Exception $e) {
            return null;
        }
    }

    public static function update($key, $value)
    {
        if ($key === self::$apiKey && !empty($value) && !self::isEncryptedData($value)) {
            $encrypted = WooMailerLiteEncryption::instance()->encrypt($value);
            if ($encrypted !== false) {
                $value = $encrypted;
            } else {
                WooMailerLiteLog()->error('WooMailerLite: Encryption failed, storing as plain text temporarily.');
            }
        }

        $options =  get_option(self::$key, []);
        $options[$key] = $value;
        return update_option(self::$key, $options);
    }

    public static function updateMultiple($data)
    {
        if (isset($data[self::$apiKey]) && !empty($data[self::$apiKey])) {
            $data[self::$apiKey] = WooMailerLiteEncryption::instance()->encrypt($data[self::$apiKey]);
        }
        $options =  get_option(self::$key, []);
        $options = array_merge($options, $data);
        return update_option(self::$key, $options);
    }

    public static function delete($key)
    {
        $options =  get_option(self::$key, []);
        if (isset($options[$key])) {
            unset($options[$key]);
        }
        return update_option(self::$key, $options);
    }

    public static function deleteAll()
    {
        return delete_option(self::$key);
    }

    public static function toJson()
    {
        self::$toJson = true;
        return new self;
    }

    public static function allSupportedOrderStatuses()
    {
        return array_merge(self::COMPLETE_ORDER_STATUSES, self::PENDING_ORDER_STATUSES);
    }

    public static function isCompleteOrderStatus($status)
    {
        return in_array($status, self::COMPLETE_ORDER_STATUSES);
    }

    public static function isPendingOrderStatus($status)
    {
        return in_array($status, self::PENDING_ORDER_STATUSES);
    }

    private static function isEncryptedData($value) {
        return is_string($value)
            && strlen($value) > 50
            && preg_match('/^[A-Za-z0-9+\/]+=*$/', $value)
            && base64_decode($value, true) !== false;
    }

    private static function handleApiKeyRetrieval($value)
    {
        if (self::isEncryptedData($value)) {
            $decrypted = WooMailerLiteEncryption::instance()->decrypt($value);
            if ($decrypted !== false) {
                return $decrypted;
            } else {
                WooMailerLiteLog()->error('WooMailerLite: API key decryption failed. Re-enter API key.');
                return null;
            }
        } else {
            self::update(self::$apiKey, $value);
            return $value;
        }
    }
}

```
