PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 3.1.0
Defender Security – Malware Scanner, Login Security & Firewall v3.1.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / framework / model / setting.php

setting.php in Defender Security – Malware Scanner, Login Security & Firewall 3.1.0, at framework/model/setting.php

76 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Calotes\Model;
4
5 use Calotes\Base\Model;
6 use WP_Defender\Component\Error_Code;
7
8 class Setting extends Model {
9 protected $exclude = array( 'table' );
10
11 public function __construct() {
12 // we parse the annotations here, and only one
13 $this->parse_annotations();
14 $this->before_load();
15 $this->load();
16 $this->after_load();
17 $this->sanitize();
18 }
19
20 public function save() {
21 $data = $this->prepare_data();
22 $data = json_encode( $data );
23 $ret = update_site_option( $this->table, $data );
24 if ( $ret === false ) {
25 $this->internal_logging[] = sprintf( 'Saving fail on %s with data %s', $this->table, json_encode( $data ) );
26 }
27 }
28
29 /**
30 * Load data
31 *
32 * @throws \ReflectionException
33 */
34 public function load() {
35 $time = microtime( true );
36 if ( empty( $this->table ) ) {
37 throw new \Exception( 'Table must be defined before using' );
38 }
39
40 $data = get_site_option( $this->table );
41 if ( $data === false ) {
42 return;
43 }
44
45 if ( ! is_array( $data ) ) {
46 $data = json_decode( $data, true );
47 }
48
49 if ( ! is_array( $data ) ) {
50 return;
51 }
52
53 $data = $this->prepare_data( $data );
54 $this->import( $data );
55 $this->log( sprintf( 'loaded %s - %s', $this->table, microtime( true ) - $time ) );
56 }
57
58 public function delete() {
59 delete_site_option( $this->table );
60 }
61
62 /**
63 * Empty function
64 */
65 protected function after_load() {
66 return 'For child class to implement';
67 }
68
69 /**
70 * @return string
71 */
72 protected function before_load() {
73 return 'For child class to implement';
74 }
75 }
76