| @@ -7,9 +7,8 @@ | ||
| 7 | 7 | |
| 8 | 8 | namespace WP_Defender\Traits; |
| 9 | 9 | |
| 10 | 10 | use WP_Error; |
| 11 | -use WP_Defender\Component\Quarantine as Quarantine_Component; | |
| 12 | 11 | use WP_Defender\Model\Scan_Item; |
| 13 | 12 | use WP_Filesystem_Base; |
| 14 | 13 | |
| 15 | 14 | trait Plugin { |
| @@ -119,9 +118,9 @@ | ||
| 119 | 118 | public function ping_wp_org_by_plugin_slug( string $slug ) { |
| 120 | 119 | $url = 'https://api.wordpress.org/plugins/info/1.0/' . $slug . '.json'; |
| 121 | 120 | $http_args = array( |
| 122 | 121 | 'timeout' => 15, |
| 123 | - 'sslverify' => false, // Many hosts have no updated CA bundle. | |
| 122 | + 'sslverify' => true, | |
| 124 | 123 | 'user-agent' => defender_get_own_user_agent(), |
| 125 | 124 | ); |
| 126 | 125 | |
| 127 | 126 | return wp_remote_get( $url, $http_args ); |
| @@ -480,17 +479,10 @@ | ||
| 480 | 479 | * |
| 481 | 480 | * @return array|WP_Error |
| 482 | 481 | */ |
| 483 | 482 | public function quarantine( string $parent_action, Scan_Item $scan_item ) { |
| 484 | - if ( ! class_exists( 'WP_Defender\Controller\Quarantine' ) ) { | |
| 485 | - return new WP_Error( | |
| 486 | - 'DEFENDER_PRO_ONLY_FEATURE', | |
| 487 | - defender_quarantine_pro_only() | |
| 488 | - ); | |
| 489 | - } | |
| 483 | + $quarantine_component = wd_di()->get( \WP_Defender\Component\Quarantine::class ); | |
| 490 | 484 | |
| 491 | - $quarantine_component = wd_di()->get( Quarantine_Component::class ); | |
| 492 | - | |
| 493 | 485 | return $quarantine_component->quarantine_file( $scan_item, $parent_action ); |
| 494 | 486 | } |
| 495 | 487 | |
| 496 | 488 | /** |
| @@ -550,6 +542,82 @@ | ||
| 550 | 542 | } |
| 551 | 543 | } |
| 552 | 544 | |
| 553 | 545 | return $plugin_names; |
| 546 | + } | |
| 547 | + | |
| 548 | + /** | |
| 549 | + * Data for the “update Defender” notification bubble (React). | |
| 550 | + * | |
| 551 | + * Uses the update_plugins site transient (WordPress.org for Free; WPMU DEV Dashboard merges | |
| 552 | + * Pro updates into the same transient when that plugin is active). | |
| 553 | + * | |
| 554 | + * @return array{ | |
| 555 | + * available:bool, | |
| 556 | + * newVersion:string, | |
| 557 | + * learnMoreUrl:string, | |
| 558 | + * updateUrl:string, | |
| 559 | + * canUpdate:bool, | |
| 560 | + * currentVersion:string, | |
| 561 | + * releaseDate:string | |
| 562 | + * } | |
| 563 | + */ | |
| 564 | + public function get_plugin_update_notice_data(): array { | |
| 565 | + $basename = DEFENDER_PLUGIN_BASENAME; | |
| 566 | + | |
| 567 | + $default_learn_more = defender_is_wp_org_version() | |
| 568 | + ? 'https://wordpress.org/plugins/defender-security/' | |
| 569 | + : 'https://wpmudev.com/project/wp-defender/#changelog_all'; | |
| 570 | + | |
| 571 | + $learn_more_url = $default_learn_more; | |
| 572 | + $new_version = ''; | |
| 573 | + $has_update = false; | |
| 574 | + | |
| 575 | + $updates = get_site_transient( 'update_plugins' ); | |
| 576 | + if ( is_object( $updates ) && isset( $updates->response[ $basename ] ) ) { | |
| 577 | + $pkg = $updates->response[ $basename ]; | |
| 578 | + if ( is_object( $pkg ) ) { | |
| 579 | + $has_update = true; | |
| 580 | + $new_version = isset( $pkg->new_version ) ? (string) $pkg->new_version : ''; | |
| 581 | + if ( isset( $pkg->url ) && is_string( $pkg->url ) && '' !== $pkg->url ) { | |
| 582 | + $learn_more_url = $pkg->url; | |
| 583 | + } | |
| 584 | + } elseif ( is_array( $pkg ) ) { | |
| 585 | + $has_update = true; | |
| 586 | + $new_version = isset( $pkg['new_version'] ) ? (string) $pkg['new_version'] : ''; | |
| 587 | + if ( isset( $pkg['url'] ) && is_string( $pkg['url'] ) && '' !== $pkg['url'] ) { | |
| 588 | + $learn_more_url = $pkg['url']; | |
| 589 | + } | |
| 590 | + } | |
| 591 | + } | |
| 592 | + | |
| 593 | + $can_update = $has_update && current_user_can( 'update_plugins' ); | |
| 594 | + $update_url = ''; | |
| 595 | + if ( $can_update ) { | |
| 596 | + // Build a plain URL for wp_localize_script (wp_nonce_url() HTML-escapes and breaks JSON). | |
| 597 | + $update_url = add_query_arg( | |
| 598 | + array( | |
| 599 | + '_wpnonce' => wp_create_nonce( 'upgrade-plugin_' . $basename ), | |
| 600 | + 'action' => 'upgrade-plugin', | |
| 601 | + 'plugin' => $basename, | |
| 602 | + ), | |
| 603 | + self_admin_url( 'update.php' ) | |
| 604 | + ); | |
| 605 | + } | |
| 606 | + | |
| 607 | + $release_date_raw = defined( 'DEFENDER_RELEASE_DATE' ) ? DEFENDER_RELEASE_DATE : ''; | |
| 608 | + $timestamp = strtotime( $release_date_raw ); | |
| 609 | + $release_date = false !== $timestamp | |
| 610 | + ? date_i18n( get_option( 'date_format' ), $timestamp ) | |
| 611 | + : ''; | |
| 612 | + | |
| 613 | + return array( | |
| 614 | + 'available' => $has_update, | |
| 615 | + 'newVersion' => $new_version, | |
| 616 | + 'learnMoreUrl' => esc_url_raw( $learn_more_url ), | |
| 617 | + 'updateUrl' => esc_url_raw( $update_url ), | |
| 618 | + 'canUpdate' => $can_update && '' !== $update_url, | |
| 619 | + 'currentVersion' => DEFENDER_VERSION, | |
| 620 | + 'releaseDate' => $release_date, | |
| 621 | + ); | |
| 554 | 622 | } |
| 555 | 623 | } |