| @@ -605,5 +605,33 @@ | ||
| 605 | 605 | $this->model->save(); |
| 606 | 606 | $this->log( 'Central IP automatically disabled due to expired membership.', 'central_ip.log' ); |
| 607 | 607 | } |
| 608 | 608 | } |
| 609 | + | |
| 610 | + /** | |
| 611 | + * Toggle the Custom IP List feature on hosting. | |
| 612 | + * | |
| 613 | + * @param bool $enable True to enable, false to disable. | |
| 614 | + * | |
| 615 | + * @return bool|WP_Error True on success, false if not on WPMU hosting, WP_Error on failure. | |
| 616 | + */ | |
| 617 | + public function toggle_on_hosting( bool $enable ) { | |
| 618 | + if ( ! $this->wpmudev->is_wpmu_hosting() ) { | |
| 619 | + return false; | |
| 620 | + } | |
| 621 | + | |
| 622 | + $this->attach_behavior( WPMUDEV::class, WPMUDEV::class ); | |
| 623 | + | |
| 624 | + $data = $this->make_wpmu_request( | |
| 625 | + WPMUDEV::API_GLOBAL_IP_LIST_HOSTING, | |
| 626 | + array( 'is_active' => $enable ), | |
| 627 | + array( 'method' => 'PUT' ) | |
| 628 | + ); | |
| 629 | + | |
| 630 | + if ( is_wp_error( $data ) ) { | |
| 631 | + $this->log( 'Global IP API Error: ' . $data->get_error_message(), Firewall::FIREWALL_LOG ); | |
| 632 | + return $data; | |
| 633 | + } | |
| 634 | + | |
| 635 | + return true; | |
| 636 | + } | |
| 609 | 637 | } |