PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.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
← All changes | src/model/setting/class-security-tweaks.php +81 -9 5.3.1 → 6.3.0 View file →
@@ -78,9 +78,9 @@
78 78 */
79 79 public function is_tweak_ignore( string $slug ): bool {
80 80 // Empty ignored tweak is string on old versions, so change it to array.
81 81 if ( is_string( $this->ignore ) ) {
82 - $this->ignore = empty( $this->ignore ) ? array() : array( $this->ignore );
82 + $this->ignore = '' === $this->ignore ? array() : array( $this->ignore );
83 83 $this->save();
84 84 }
85 85
86 86 return in_array( $slug, $this->ignore, true );
@@ -103,23 +103,95 @@
103 103 * @param string $status Status.
104 104 * @param string $slug Tweak slug.
105 105 */
106 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 );
107 + foreach ( array(
108 + \WP_Defender\Controller\Security_Tweaks::STATUS_ISSUES,
109 + \WP_Defender\Controller\Security_Tweaks::STATUS_RESOLVE,
110 + \WP_Defender\Controller\Security_Tweaks::STATUS_IGNORE,
111 + ) as $collection_name ) {
112 + $collection = $this->get_collection( $collection_name );
113 +
114 + if ( ! is_array( $collection ) ) {
115 + continue;
116 + }
117 +
118 + $index = array_search( $slug, $collection, true );
110 119 if ( false !== $index ) {
111 - unset( $arr[ $index ] );
120 + unset( $collection[ $index ] );
112 121 }
113 - $this->$collection = $arr;
122 + $this->set_collection( $collection_name, $collection );
114 123 }
124 +
115 125 if ( \WP_Defender\Controller\Security_Tweaks::STATUS_RESTORE === $status ) {
116 126 $status = \WP_Defender\Controller\Security_Tweaks::STATUS_ISSUES;
117 127 }
118 - $collection = $this->{$status};
119 - $collection[] = $slug;
120 - $this->{$status} = $collection;
128 +
129 + if ( ! property_exists( $this, $status ) ) {
130 + return;
131 + }
132 +
133 + try {
134 + $collection = $this->get_collection( $status );
135 + } catch ( \InvalidArgumentException $e ) {
136 + return;
137 + }
138 +
139 + $collection[] = $slug;
140 + $this->set_collection( $status, $collection );
121 141 $this->save();
142 + }
143 +
144 + /**
145 + * Get a tweak collection by name.
146 + *
147 + * @param string $name Collection name.
148 + *
149 + * @return array
150 + *
151 + * @throws \InvalidArgumentException Invalid collection name.
152 + */
153 + public function get_collection( string $name ): array {
154 + switch ( $name ) {
155 + case \WP_Defender\Controller\Security_Tweaks::STATUS_ISSUES:
156 + return $this->issues;
157 +
158 + case \WP_Defender\Controller\Security_Tweaks::STATUS_RESOLVE:
159 + return $this->fixed;
160 +
161 + case \WP_Defender\Controller\Security_Tweaks::STATUS_IGNORE:
162 + return $this->ignore;
163 +
164 + default:
165 + throw new \InvalidArgumentException( 'Invalid collection name.' );
166 + }
167 + }
168 +
169 + /**
170 + * Set a tweak collection by name.
171 + *
172 + * @param string $name Collection name.
173 + * @param array $value Collection value.
174 + *
175 + * @throws \InvalidArgumentException Invalid collection name.
176 + */
177 + private function set_collection( string $name, array $value ): void {
178 + switch ( $name ) {
179 + case \WP_Defender\Controller\Security_Tweaks::STATUS_ISSUES:
180 + $this->issues = $value;
181 + break;
182 +
183 + case \WP_Defender\Controller\Security_Tweaks::STATUS_RESOLVE:
184 + $this->fixed = $value;
185 + break;
186 +
187 + case \WP_Defender\Controller\Security_Tweaks::STATUS_IGNORE:
188 + $this->ignore = $value;
189 + break;
190 +
191 + default:
192 + throw new \InvalidArgumentException( 'Invalid collection name.' );
193 + }
122 194 }
123 195
124 196 /**
125 197 * Define settings labels.