Backoffice
1 month ago
build_widget_data_attributes.php
1 month ago
get_widget_settings.php
1 month ago
load_script_file.php
1 month ago
load_script_template_file.php
1 month ago
load_translations.php
1 year ago
register_shortcode.php
1 month ago
sanitize_restaurant_id.php
1 month ago
sanitize_widget_settings.php
1 month ago
get_widget_settings.php
38 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Zenchef\Widget\Widget; |
| 4 | |
| 5 | use function array_merge; |
| 6 | use function get_option; |
| 7 | use function is_array; |
| 8 | use const Zenchef\Widget\SETTINGS_OPTION_NAME; |
| 9 | |
| 10 | const WIDGET_SETTINGS_DEFAULTS = [ |
| 11 | 'restaurant_id' => '', |
| 12 | 'language' => '', |
| 13 | 'use_default_color' => '1', |
| 14 | 'primary_color' => '', |
| 15 | 'position' => 'right', |
| 16 | 'auto_open' => '1', |
| 17 | 'open_delay' => 3000, |
| 18 | 'hide_button' => '0', |
| 19 | 'disable_gtm' => '0', |
| 20 | 'disable_ga4' => '0', |
| 21 | ]; |
| 22 | |
| 23 | /** |
| 24 | * Returns the plugin's settings array merged with defaults, so callers never |
| 25 | * have to worry about missing keys on installs that pre-date a new field. |
| 26 | * |
| 27 | * @return array |
| 28 | */ |
| 29 | function get_widget_settings() |
| 30 | { |
| 31 | $stored = get_option(SETTINGS_OPTION_NAME, []); |
| 32 | if (!is_array($stored)) { |
| 33 | $stored = []; |
| 34 | } |
| 35 | |
| 36 | return array_merge(WIDGET_SETTINGS_DEFAULTS, $stored); |
| 37 | } |
| 38 |