PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.3.0
ShopBuilder – WooCommerce Builder For Elementor v2.3.0
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Models / DataModel.php

DataModel.php in ShopBuilder – WooCommerce Builder For Elementor 2.3.0, at app/Models/DataModel.php

64 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace RadiusTheme\SB\Models;
4
5 // Do not allow directly accessing this file.
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit( 'This script cannot be accessed directly.' );
8 }
9
10 class DataModel {
11 private $db_key;
12 private static $instances = [];
13
14 private function __construct( $source ) {
15 $this->set_db_key( $source );
16 }
17
18 public static function source( $source = 'settings' ) {
19 if ( ! isset( self::$instances[ $source ] ) ) {
20 self::$instances[ $source ] = new self( $source );
21 }
22
23 return self::$instances[ $source ];
24 }
25
26 private function set_db_key( $source ) {
27 $this->db_key = 'rtsb_' . $source;
28 }
29
30 public function get_option( $key, $default = null, $cache = true ) {
31 if ( $cache && isset( $GLOBALS[ $this->db_key ] ) ) {
32 $db = $GLOBALS[ $this->db_key ];
33 } else {
34 $db = get_option( $this->db_key, [] );
35 $GLOBALS[ $this->db_key ] = $db;
36 }
37 return $db[ $key ] ?? $default;
38 }
39
40 public function set_option( $key, $value ) {
41 $db = get_option( $this->db_key, [] );
42
43 if ( is_object( $db ) ) {
44 $db = (array) $db;
45 }
46
47 if ( ! is_array( $db ) ) {
48 $db = [];
49 }
50
51 $db[ $key ] = $value;
52
53 return update_option( $this->db_key, $db );
54 }
55
56 public function delete_option( $key ) {
57 $db = get_option( $this->db_key, [] );
58 if ( isset( $db[ $key ] ) ) {
59 unset( $db[ $key ] );
60 }
61 return update_option( $this->db_key, $db );
62 }
63 }
64