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/component/audit/class-core-audit.php +20 -17 5.4.0 → 6.3.0 View file →
@@ -15,8 +15,9 @@
15 15 * Handles the auditing of WordPress core, themes, and plugins such as plugin activation, deactivation, and
16 16 * installation, and theme activation, deactivation, and installation.
17 17 */
18 18 class Core_Audit extends Audit_Event {
19 + use \WP_Defender\Traits\Plugin;
19 20
20 21 public const ACTION_ACTIVATED = 'activated', ACTION_DEACTIVATED = 'deactivated', ACTION_INSTALLED = 'installed', ACTION_UPGRADED = 'upgraded';
21 22 public const FILE_ADDED = 'file_added', FILE_MODIFIED = 'file_modified';
22 23 public const CONTEXT_THEME = 'ct_theme', CONTEXT_PLUGIN = 'ct_plugin', CONTEXT_CORE = 'ct_core';
@@ -173,9 +174,9 @@
173 174 $updates = array_shift( $updates );
174 175 if ( is_object( $updates ) && property_exists( $updates, 'version' ) ) {
175 176 return $this->get_upgraded_core_data_for_record( $updates->version );
176 177 }
177 - } elseif ( empty( $update_core ) && $this->is_hub_request() ) {
178 + } elseif ( $this->is_hub_request() ) {
178 179 // Hub has already updated WP core to the latest version.
179 180 $wp_version = ( new WP_Version() )->get_latest_version();
180 181
181 182 return $wp_version ? $this->get_upgraded_core_data_for_record( $wp_version ) : false;
@@ -236,10 +237,10 @@
236 237 }
237 238 } elseif ( 'plugin' === $options['type'] ) {
238 239 $texts = array();
239 240 foreach ( $options['plugins'] as $slug ) {
240 - $plugin = get_plugin_data( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $slug );
241 - if ( is_array( $plugin ) && isset( $plugin['Name'] ) && ! empty( $plugin['Name'] ) ) {
241 + $plugin = get_plugin_data( $this->get_abs_plugin_path_by_slug( $slug ) );
242 + if ( is_array( $plugin ) && isset( $plugin['Name'] ) && '' !== $plugin['Name'] ) {
242 243 $texts[] = sprintf(
243 244 /* translators: 1: Plugin name, 2: Plugin version. */
244 245 $failed_result ? esc_html( '%1$s version %2$s' ) : esc_html( '%1$s to %2$s' ),
245 246 $plugin['Name'],
@@ -264,25 +265,25 @@
264 265 } else {
265 266 return false;
266 267 }
267 268 }
269 + return false;
268 270 }
269 271
270 272 /**
271 273 * Handles single item upgrade for themes or plugins and prepares the audit log entry.
272 274 *
273 - * @param WP_Upgrader $upgrader The upgrade instance.
274 - * @param array $options Options containing type and the item being upgraded.
275 + * @param array $options Options containing type and the item being upgraded.
275 276 *
276 277 * @return array|bool Returns the log entry data or false if unable to generate log data.
277 278 */
278 - public function single_upgrade( WP_Upgrader $upgrader, array $options ) {
279 + public function single_upgrade( array $options ) {
279 280 $blog_name = is_multisite() ? '[' . get_bloginfo( 'name' ) . ']' : '';
280 281
281 282 if ( 'theme' === $options['type'] ) {
282 283 $theme = wp_get_theme( $options['theme'] );
283 284 if ( is_object( $theme ) ) {
284 - $name = $theme->Name; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
285 + $name = $theme->get( 'Name' );
285 286 $version = $theme->get( 'Version' );
286 287
287 288 return array(
288 289 sprintf(
@@ -299,9 +300,9 @@
299 300 return false;
300 301 }
301 302 } elseif ( 'plugin' === $options['type'] ) {
302 303 $slug = $options['plugin'];
303 - $data = get_plugin_data( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $slug );
304 + $data = get_plugin_data( $this->get_abs_plugin_path_by_slug( $slug ) );
304 305 if ( is_array( $data ) ) {
305 306 $name = $data['Name'];
306 307 $version = $data['Version'];
307 308
@@ -319,8 +320,9 @@
319 320 } else {
320 321 return false;
321 322 }
322 323 }
324 + return false;
323 325 }
324 326
325 327 /**
326 328 * Install process.
@@ -340,18 +342,18 @@
340 342 return false;
341 343 }
342 344
343 345 $name = '';
344 - if ( ! empty( $upgrade->skin->api ) ) {
346 + if ( isset( $upgrade->skin->api->name ) && '' !== $upgrade->skin->api->name ) {
345 347 $name = $upgrade->skin->api->name;
346 - } elseif ( ! empty( $upgrade->skin->upgrader ) ) {
348 + } elseif ( isset( $upgrade->skin->upgrader ) && $upgrade->skin->upgrader instanceof \WP_Upgrader ) {
347 349 $type_data = ( 'theme' === $options['type'] && isset( $upgrade->skin->upgrader->new_theme_data ) )
348 350 ? $upgrade->skin->upgrader->new_theme_data
349 351 : $upgrade->skin->upgrader->new_plugin_data;
350 - if ( ! empty( $type_data['Name'] ) && ! empty( $type_data['Version'] ) ) {
352 + if ( isset( $type_data['Name'] ) && '' !== $type_data['Name'] && isset( $type_data['Version'] ) && '' !== $type_data['Version'] ) {
351 353 $name = $type_data['Name'] . ', version ' . $type_data['Version'];
352 354 }
353 - } elseif ( ! empty( $upgrade->skin->result ) ) {
355 + } elseif ( isset( $upgrade->skin->result ) ) {
354 356 if ( is_array( $upgrade->skin->result ) && isset( $upgrade->skin->result['destination_name'] ) ) {
355 357 $name = $upgrade->skin->result['destination_name'];
356 358 } elseif ( is_object( $upgrade->skin->result ) && property_exists(
357 359 $upgrade->skin->result,
@@ -360,9 +362,9 @@
360 362 $name = $upgrade->skin->result->destination_name;
361 363 }
362 364 }
363 365
364 - if ( empty( $name ) ) {
366 + if ( '' === $name ) {
365 367 return false;
366 368 }
367 369
368 370 $blog_name = is_multisite() ? '[' . get_bloginfo( 'name' ) . ']' : '';
@@ -404,9 +406,9 @@
404 406 * 'plugins' (array) Array of the basename paths of the plugins' main files.
405 407 * 'themes' (array) The theme slugs.
406 408 * 'translations' (array) Array of translations update data: 'language', 'type', 'slug', 'version'.
407 409 *
408 - * @return mixed
410 + * @return array|bool
409 411 */
410 412 public function process_installer() {
411 413 $args = func_get_args();
412 414 $upgrader = $args[1]['upgrader'];
@@ -421,10 +423,11 @@
421 423 // Case: actions from Hub.
422 424 return $this->single_install( $upgrader, $options );
423 425 } elseif ( 'update' === $options['action'] ) {
424 426 // Case: actions from Hub.
425 - return $this->single_upgrade( $upgrader, $options );
427 + return $this->single_upgrade( $options );
426 428 }
429 + return true;
427 430 }
428 431
429 432 /**
430 433 * Fires after the theme is switched.
@@ -463,9 +466,9 @@
463 466 public function process_delete_plugin(): array {
464 467 $args = func_get_args();
465 468
466 469 // If 'deleted'-arg is false then the plugin deletion wasn't successful.
467 - if ( empty( $args[1]['deleted'] ) ) {
470 + if ( ! isset( $args[1]['deleted'] ) || false === $args[1]['deleted'] ) {
468 471 // Todo: extend Audit table with a new column for the result of the process and divide it into success and failure.
469 472 $failed_result = true;
470 473 } else {
471 474 $failed_result = false;
@@ -515,9 +518,9 @@
515 518 * @return string The absolute path of the plugin.
516 519 */
517 520 public function get_plugin_abs_path( string $slug ): string {
518 521 if ( ! is_file( $slug ) ) {
519 - $slug = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $slug;
522 + $slug = $this->get_abs_plugin_path_by_slug( $slug );
520 523 }
521 524
522 525 return $slug;
523 526 }