# ivyforms/0.8/backend/src/Services/Settings/SettingsService.php

The Innovative Form Builder – IvyForms, version 0.8. 169 lines.

- Page: https://pluginprobe.com/plugins/ivyforms/0.8/code/backend/src/Services/Settings/SettingsService.php
- Raw: https://pluginprobe.com/plugins/ivyforms/0.8/raw/backend/src/Services/Settings/SettingsService.php
- Modified: 2026-01-13T11:11:38+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/ivyforms/0.8/code/backend/src/Services/Settings/SettingsService.php#L10-L20`.

```php
<?php

/**
 * Settings hook for settings
 */

namespace IvyForms\Services\Settings;

// phpcs:disable PSR1.Files.SideEffects
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

/**
 * Class SettingsService
 *
 * @package IvyForms\Services\Settings
 */
class SettingsService
{
    /** @var array|mixed */
    private $settingsCache;

    /**
     * @var array<string, string>  // Define that both keys and values are strings
     * */
    private static array $wpSettings = [
        'dateFormat'     => 'date_format',
        'timeFormat'     => 'time_format',
        'startOfWeek'    => 'start_of_week',
        'timeZoneString' => 'timezone_string',
        'gmtOffset'      => 'gmt_offset'
    ];

    /**
     * SettingsService constructor.
     */
    public function __construct()
    {
        $this->settingsCache = json_decode(get_option('ivyforms_settings'), true);

        foreach (self::$wpSettings as $setting => $wpSetting) {
            $this->settingsCache['wordpress'][$setting] = get_option($wpSetting);
        }
    }

    /**
     * @param string $settingCategoryKey
     * @param string $settingKey
     *
     * @return mixed
     */
    public function getSetting(string $settingCategoryKey, string $settingKey)
    {
        return $this->settingsCache[$settingCategoryKey][$settingKey] ?? null;
    }

    /**
     * @param string $settingCategoryKey
     *
     * @return mixed
     */
    public function getCategorySettings(string $settingCategoryKey)
    {
        return $this->settingsCache[$settingCategoryKey] ?? null;
    }

    /**
     * @return mixed[]
     */
    public function getAllSettings(): array
    {
        return $this->settingsCache;
    }

    /**
     * Return settings for frontend
     *
     * @return mixed[]
     */
    public function getFrontendSettings(): array
    {
//        $capabilities = [];
//
//        if (is_admin()) {
//            $currentScreenId = get_current_screen()->id;
//
//            $currentScreen = substr($currentScreenId, strrpos($currentScreenId, '-') + 1);
//
//            $capabilities = [
//                'canRead'        => current_user_can('ivyforms_read_' . $currentScreen),
//                'canReadOthers'  => current_user_can('ivyforms_read_others_' . $currentScreen),
//                'canWrite'       => current_user_can('ivyforms_write_' . $currentScreen),
//                'canWriteOthers' => current_user_can('ivyforms_write_others_' . $currentScreen),
//                'canDelete'      => current_user_can('ivyforms_delete_' . $currentScreen),
//                'canWriteStatus' => current_user_can('ivyforms_write_status_' . $currentScreen),
//            ];
//        }

        return [
            //'capabilities' => $capabilities,
            'general'      => [
                'fullscreen' => $this->getSetting('general', 'fullscreen'),
            ],
            'wordpress'    => [
                'dateFormat'  => $this->getSetting('wordpress', 'dateFormat'),
                'timeFormat'  => $this->getSetting('wordpress', 'timeFormat'),
                'startOfWeek' => (int)$this->getSetting('wordpress', 'startOfWeek'),
                'timezone'    => $this->getSetting('wordpress', 'timeZoneString'),
            ],
        ];
    }

    /**
     * @param string $settingCategoryKey
     * @param string $settingKey
     * @param mixed  $settingValue
     *
     * @return void
     */
    public function setSetting(string $settingCategoryKey, string $settingKey, $settingValue)
    {
        $this->settingsCache[$settingCategoryKey][$settingKey] = $settingValue;

        $settingsCopy = $this->settingsCache;

        unset($settingsCopy['wordpress']);

        update_option('ivyforms_settings', json_encode($settingsCopy));
    }

    /**
     * @param string $settingCategoryKey
     * @param mixed  $settingValue
     *
     * @return void
     */
    public function setCategorySettings(string $settingCategoryKey, $settingValue)
    {
        $this->settingsCache[$settingCategoryKey] = $settingValue;

        $settingsCopy = $this->settingsCache;

        unset($settingsCopy['wordpress']);

        update_option('ivyforms_settings', json_encode($settingsCopy));
    }

    /**
     * Get all settings
     *
     * Specify that $settings is an associative array with string keys and mixed values
     * @param array<string, mixed> $settings
     *
     */
    public function setAllSettings(array $settings): void
    {
        foreach ($settings as $settingCategoryKey => $settingValues) {
            $this->settingsCache[$settingCategoryKey] = $settingValues;
        }

        $settingsCopy = $this->settingsCache;

        unset($settingsCopy['wordpress']);

        update_option('ivyforms_settings', json_encode($settingsCopy));
    }
}

```
