PluginProbe
Boxzilla – WordPress Popup Builder / 3.4.0
Boxzilla – WordPress Popup Builder v3.4.0
3.4.11 3.4.10 3.4.9 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 trunk 3.0 3.0.1 3.0.2 3.0.3 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 All 72 releases
boxzilla / src / licensing / class-license.php

class-license.php in Boxzilla – WordPress Popup Builder 3.4.0, at src/licensing/class-license.php

119 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Boxzilla\Licensing;
4
5 /**
6 * Class License
7 *
8 *
9 * @property string $key
10 * @property string $site
11 * @property string $activation_key
12 * @property boolean $activated
13 * @property string $expires_at
14 *
15 * @package Boxzilla\Licensing
16 */
17 class License {
18
19
20 /**
21 * @var string The name of the option that holds the License data
22 */
23 protected $option_key = '';
24
25 /**
26 * @var bool Loaded?
27 */
28 protected $loaded = false;
29
30 /**
31 * @var bool Any changes?
32 */
33 protected $dirty = false;
34
35 /**
36 * @var array
37 */
38 protected $data;
39
40 /**
41 * @param string $option_key
42 */
43 public function __construct( $option_key ) {
44 $this->option_key = $option_key;
45 }
46
47 /**
48 * @param string $name
49 * @param mixed $value
50 */
51 public function __set( $name, $value ) {
52 $this->load();
53 $this->data[ $name ] = $value;
54 $this->dirty = true;
55 }
56
57 /**
58 * @param string $name
59 *
60 * @return mixed
61 */
62 public function __get( $name ) {
63 $this->load();
64 return $this->data[ $name ];
65 }
66
67 /**
68 * @param $name
69 *
70 * @return bool
71 */
72 public function __isset( $name ) {
73 $this->load();
74 return isset( $this->data[ $name ] );
75 }
76
77 /**
78 * Load the license data from the database
79 */
80 protected function load() {
81 if ( $this->loaded ) {
82 return;
83 }
84
85 $defaults = array(
86 'key' => '',
87 'activation_key' => '',
88 'activated' => false,
89 'expires_at' => '',
90 );
91
92 $data = (array) get_option( $this->option_key, array() );
93 $this->data = array_replace( $defaults, $data );
94 $this->loaded = true;
95 }
96
97 /**
98 * Reload the license data from DB
99 */
100 public function reload() {
101 $this->loaded = false;
102 $this->load();
103 }
104
105 /**
106 * Save the license in the database
107 *
108 * @return License
109 */
110 public function save() {
111 if ( ! $this->dirty ) {
112 return;
113 }
114
115 update_option( $this->option_key, $this->data );
116 $this->dirty = false;
117 }
118 }
119