PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.4.0
Defender Security – Malware Scanner, Login Security & Firewall v5.4.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 / src / model / setting / class-security-tweaks.php

class-security-tweaks.php in Defender Security – Malware Scanner, Login Security & Firewall 5.4.0, at src/model/setting/class-security-tweaks.php

152 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handle tweaks settings.
4 *
5 * @package WP_Defender\Model\Setting
6 */
7
8 namespace WP_Defender\Model\Setting;
9
10 use Calotes\Model\Setting;
11
12 /**
13 * Model for tweaks settings.
14 */
15 class Security_Tweaks extends Setting {
16
17 /**
18 * Option name.
19 *
20 * @var string
21 */
22 protected $table = 'hardener_settings';
23
24 /**
25 * Store a list of issues tweaks, as slug.
26 *
27 * @var array
28 */
29 public $issues = array();
30
31 /**
32 * Store a list of fixed tweaks, as slug.
33 *
34 * @var array
35 */
36 public $fixed = array();
37
38 /**
39 * Store a list of ignored tweaks, as slug.
40 *
41 * @var array
42 */
43 public $ignore = array();
44
45 /**
46 * Contains all the data generated by rules.
47 *
48 * @var array
49 */
50 public $data = array();
51
52 /**
53 * Last time visit into the hardener page.
54 *
55 * @var integer
56 */
57 public $last_seen;
58
59 /**
60 * Last notification sent out.
61 *
62 * @var integer
63 */
64 public $last_sent;
65 /**
66 * Automate tweaks
67 *
68 * @var bool
69 */
70 public $automate = false;
71
72 /**
73 * Check if a tweak is ignored.
74 *
75 * @param string $slug Tweak slug.
76 *
77 * @return bool
78 */
79 public function is_tweak_ignore( string $slug ): bool {
80 // Empty ignored tweak is string on old versions, so change it to array.
81 if ( is_string( $this->ignore ) ) {
82 $this->ignore = empty( $this->ignore ) ? array() : array( $this->ignore );
83 $this->save();
84 }
85
86 return in_array( $slug, $this->ignore, true );
87 }
88
89 /**
90 * Is the tweak in the Issue list?.
91 *
92 * @param string $slug Tweak slug.
93 *
94 * @return bool
95 */
96 public function is_tweak_issue( string $slug ): bool {
97 return in_array( $slug, $this->issues, true );
98 }
99
100 /**
101 * Mark a tweak as actioned.
102 *
103 * @param string $status Status.
104 * @param string $slug Tweak slug.
105 */
106 public function mark( $status, $slug ) {
107 foreach ( array( 'issues', 'fixed', 'ignore' ) as $collection ) {
108 $arr = $this->$collection;
109 $index = array_search( $slug, $arr, true );
110 if ( false !== $index ) {
111 unset( $arr[ $index ] );
112 }
113 $this->$collection = $arr;
114 }
115 if ( \WP_Defender\Controller\Security_Tweaks::STATUS_RESTORE === $status ) {
116 $status = \WP_Defender\Controller\Security_Tweaks::STATUS_ISSUES;
117 }
118 $collection = $this->{$status};
119 $collection[] = $slug;
120 $this->{$status} = $collection;
121 $this->save();
122 }
123
124 /**
125 * Define settings labels.
126 *
127 * @return array
128 */
129 public function labels(): array {
130 return array(
131 'data' => 'data',
132 'fixed' => esc_html__( 'Actioned', 'defender-security' ),
133 'issues' => esc_html__( 'Recommendations', 'defender-security' ),
134 'ignore' => esc_html__( 'Ignored', 'defender-security' ),
135 'automate' => 'automate',
136 );
137 }
138
139 /**
140 * Todo: Find a less expensive way.
141 *
142 * @return array
143 */
144 public function get_tweak_types(): array {
145 return array(
146 'count_fixed' => count( $this->fixed ),
147 'count_ignored' => count( $this->ignore ),
148 'count_issues' => count( $this->issues ),
149 );
150 }
151 }
152