PluginProbe
YayMail – WooCommerce Email Customizer / 4.3.3
YayMail – WooCommerce Email Customizer v4.3.3
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
yaymail / src / Models / SettingModel.php

SettingModel.php in YayMail – WooCommerce Email Customizer 4.3.3, at src/Models/SettingModel.php

83 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMail\Models;
4
5 use YayMail\Utils\SingletonTrait;
6
7 /**
8 * Setting Model
9 *
10 * @method static SettingModel get_instance()
11 */
12 class SettingModel {
13 use SingletonTrait;
14
15 const OPTION_NAME = 'yaymail_settings';
16
17 public const META_KEYS = [
18 'direction' => 'direction',
19 'container_width' => 'container_width',
20 'payment_display_mode' => 'payment_display_mode',
21 'show_product_image' => 'show_product_image',
22 'product_image_position' => 'product_image_position',
23 'product_image_height' => 'product_image_height',
24 'product_image_width' => 'product_image_width',
25 'show_product_sku' => 'show_product_sku',
26 'show_product_description' => 'show_product_description',
27 'show_product_hyper_links' => 'show_product_hyper_links',
28 'show_product_regular_price' => 'show_product_regular_price',
29 'show_product_item_cost' => 'show_product_item_cost',
30 'enable_custom_css' => 'enable_custom_css',
31 'custom_css' => 'custom_css',
32 'global_header_footer_enabled' => 'global_header_footer_enabled',
33 ];
34
35 // TODO: change variable name to be more meaning in db ( when initialize )
36 const DEFAULT = [
37 self::META_KEYS['direction'] => 'ltr',
38 self::META_KEYS['container_width'] => 605,
39 self::META_KEYS['payment_display_mode'] => 'yes',
40 self::META_KEYS['show_product_image'] => false,
41 self::META_KEYS['product_image_position'] => 'top',
42 self::META_KEYS['product_image_height'] => 30,
43 self::META_KEYS['product_image_width'] => 30,
44 self::META_KEYS['show_product_sku'] => true,
45 self::META_KEYS['show_product_description'] => false,
46 self::META_KEYS['show_product_hyper_links'] => false,
47 self::META_KEYS['show_product_regular_price'] => false,
48 self::META_KEYS['show_product_item_cost'] => false,
49 self::META_KEYS['enable_custom_css'] => false,
50 self::META_KEYS['custom_css'] => '',
51 self::META_KEYS['global_header_footer_enabled'] => false,
52 ];
53
54 public static function find_by_name( $name ) {
55 $settings = self::find_all();
56 if ( isset( $settings[ $name ] ) && ! empty( $settings[ $name ] ) ) {
57 return $settings[ $name ];
58 }
59 return null;
60 }
61
62 public static function find_all() {
63 $default_settings = self::DEFAULT;
64 $settings = get_option( self::OPTION_NAME, [] );
65 if ( ! is_array( $settings ) ) {
66 return $default_settings;
67 }
68 return wp_parse_args( $settings, $default_settings );
69 }
70
71 public static function update( $settings ) {
72 $settings_option = get_option( self::OPTION_NAME );
73 if ( ! empty( $settings ) && is_array( $settings ) ) {
74 return update_option( self::OPTION_NAME, wp_parse_args( $settings, $settings_option ) );
75 }
76 return false;
77 }
78
79 public static function delete() {
80 delete_option( self::OPTION_NAME );
81 }
82 }
83