= $request->get_data( array( 'status' => array( 'type' => 'string', 'sanitize' => 'sanitize_text_field', ), ) ); $current_status = $data['status'] ?? null; if ( ! in_array( $current_status, array( 'good', 'new', 'blacklisted' ), true ) ) { return false; } if ( false === $this->get_apikey() ) { return new Response( false, array( 'message' => esc_html__( 'A WPMU DEV subscription is required for blocklist monitoring.', 'wpdef' ), ) ); } if ( 'new' === $current_status ) { $this->make_wpmu_request( WPMUDEV::API_BLACKLIST, array(), array( 'method' => 'POST' ) ); $status = $this->domain_status(); } else { $this->reset_blocklist_monitor(); $status = - 1; } set_site_transient( self::CACHE_BLACKLIST_STATUS, $status, self::CACHE_TIME ); return new Response( true, array( 'status' => $status ) ); } /** * Changes the domain's block list status if it differs from the current status. * * @param string $current_status The current status to compare against. * * @return void */ public function change_status( $current_status ): void { $status = get_site_transient( self::CACHE_BLACKLIST_STATUS ); if ( false === $status ) { $status = $this->domain_status(); } // Check changes. if ( $status !== $current_status ) { if ( '1' === $current_status ) { $this->make_wpmu_request( WPMUDEV::API_BLACKLIST, array(), array( 'method' => 'POST' ) ); $status = $this->domain_status(); } else { $this->reset_blocklist_monitor(); $status = - 1; } set_site_transient( self::CACHE_BLACKLIST_STATUS, $status, self::CACHE_TIME ); } } /** * Get domain status. Variants: * '1' -> 'good' */ public function get_status() { $status = get_site_transient( self::CACHE_BLACKLIST_STATUS ); if ( false === $status ) { $status = $this->domain_status(); } if ( is_wp_error( $status ) ) { return $status->get_error_message(); } return $status; } /** * Auto-enable blocklist monitoring after Hub connection if user triggered from Settings/Tools page. * * @return void */ public function maybe_hcm_connection_attempt(): void { $data = get_site_transient( Hub_Connector::TRANSIENT_KEY ); $module_slug = $data['module_slug'] ?? ''; if ( self::MODULE_SLUG !== $module_slug || ! self::get_hcm_status() ) { return; } delete_site_transient( Hub_Connector::TRANSIENT_KEY ); $this->make_wpmu_request( WPMUDEV::API_BLACKLIST, array(), array( 'method' => 'POST' ) ); $status = $this->domain_status(); set_site_transient( self::CACHE_BLACKLIST_STATUS, $status, self::CACHE_TIME ); } /** * Exports strings. * * @return array An array of strings. */ public function export_strings(): array { if ( false === $this->get_apikey() ) { return array( esc_html__( 'Blocklist Monitor inactive', 'wpdef' ) ); } if ( '1' === (string) $this->get_status() ) { $strings = array( esc_html__( 'Blocklist Monitor active', 'wpdef' ) ); } else { $strings = array( esc_html__( 'Blocklist Monitor inactive', 'wpdef' ) ); } return $strings; } /** * Configures strings based on the provided configuration * * @param array $config Configuration array. * * @return array An array of configuration strings. */ public function config_strings( array $config ): array { if ( false === $this->get_apikey() ) { return array( esc_html__( 'Blocklist Monitor inactive', 'wpdef' ) ); } return $config['enabled'] ? array( esc_html__( 'Blocklist Monitor active', 'wpdef' ) ) : array( esc_html__( 'Blocklist Monitor inactive', 'wpdef' ), ); } /** * Define settings labels. * * @return array */ public function labels(): array { return array( 'enabled' => esc_html__( 'Blocklist Monitor', 'wpdef' ), 'status' => esc_html__( 'Status', 'wpdef' ), ); } } = $request->get_data( array( 'status' => array( 'type' => 'string', 'sanitize' => 'sanitize_text_field', ), ) ); $current_status = $data['status'] ?? null; if ( ! in_array( $current_status, array( 'good', 'new', 'blacklisted' ), true ) ) { return false; } if ( false === $this->get_apikey() ) { return new Response( false, array( 'message' => esc_html__( 'A WPMU DEV subscription is required for blocklist monitoring.', 'wpdef' ), ) ); } if ( 'new' === $current_status ) { $this->make_wpmu_request( WPMUDEV::API_BLACKLIST, array(), array( 'method' => 'POST' ) ); $status = $this->domain_status(); } else { $this->reset_blocklist_monitor(); $status = - 1; } set_site_transient( self::CACHE_BLACKLIST_STATUS, $status, self::CACHE_TIME ); return new Response( true, array( 'status' => $status ) ); } /** * Changes the domain's block list status if it differs from the current status. * * @param string $current_status The current status to compare against. * * @return void */ public function change_status( $current_status ): void { $status = get_site_transient( self::CACHE_BLACKLIST_STATUS ); if ( false === $status ) { $status = $this->domain_status(); } // Check changes. if ( $status !== $current_status ) { if ( '1' === $current_status ) { $this->make_wpmu_request( WPMUDEV::API_BLACKLIST, array(), array( 'method' => 'POST' ) ); $status = $this->domain_status(); } else { $this->reset_blocklist_monitor(); $status = - 1; } set_site_transient( self::CACHE_BLACKLIST_STATUS, $status, self::CACHE_TIME ); } } /** * Get domain status. Variants: * '1' -> 'good' */ public function get_status() { $status = get_site_transient( self::CACHE_BLACKLIST_STATUS ); if ( false === $status ) { $status = $this->domain_status(); } if ( is_wp_error( $status ) ) { return $status->get_error_message(); } return $status; } /** * Auto-enable blocklist monitoring after Hub connection if user triggered from Settings/Tools page. * * @return void */ public function maybe_hcm_connection_attempt(): void { $data = get_site_transient( Hub_Connector::TRANSIENT_KEY ); $module_slug = $data['module_slug'] ?? ''; if ( self::MODULE_SLUG !== $module_slug || ! self::get_hcm_status() ) { return; } delete_site_transient( Hub_Connector::TRANSIENT_KEY ); $this->make_wpmu_request( WPMUDEV::API_BLACKLIST, array(), array( 'method' => 'POST' ) ); $status = $this->domain_status(); set_site_transient( self::CACHE_BLACKLIST_STATUS, $status, self::CACHE_TIME ); } /** * Exports strings. * * @return array An array of strings. */ public function export_strings(): array { if ( false === $this->get_apikey() ) { return array( esc_html__( 'Blocklist Monitor inactive', 'wpdef' ) ); } if ( '1' === (string) $this->get_status() ) { $strings = array( esc_html__( 'Blocklist Monitor active', 'wpdef' ) ); } else { $strings = array( esc_html__( 'Blocklist Monitor inactive', 'wpdef' ) ); } return $strings; } /** * Configures strings based on the provided configuration * * @param array $config Configuration array. * * @return array An array of configuration strings. */ public function config_strings( array $config ): array { if ( false === $this->get_apikey() ) { return array( esc_html__( 'Blocklist Monitor inactive', 'wpdef' ) ); } return $config['enabled'] ? array( esc_html__( 'Blocklist Monitor active', 'wpdef' ) ) : array( esc_html__( 'Blocklist Monitor inactive', 'wpdef' ), ); } /** * Define settings labels. * * @return array */ public function labels(): array { return array( 'enabled' => esc_html__( 'Blocklist Monitor', 'wpdef' ), 'status' => esc_html__( 'Status', 'wpdef' ), ); } } = $request->get_data( array( 'status' => array( 'type' => 'string', 'sanitize' => 'sanitize_text_field', ), ) ); $current_status = $data['status'] ?? null; if ( ! in_array( $current_status, array( 'good', 'new', 'blacklisted' ), true ) ) { return false; } if ( false === $this->get_apikey() ) { return new Response( false, array( 'message' => esc_html__( 'A WPMU DEV subscription is required for blocklist monitoring.', 'wpdef' ), ) ); } if ( 'new' === $current_status ) { $this->make_wpmu_request( WPMUDEV::API_BLACKLIST, array(), array( 'method' => 'POST' ) ); $status = $this->domain_status(); } else { $this->reset_blocklist_monitor(); $status = - 1; } set_site_transient( self::CACHE_BLACKLIST_STATUS, $status, self::CACHE_TIME ); return new Response( true, array( 'status' => $status ) ); } /** * Changes the domain's block list status if it differs from the current status. * * @param string $current_status The current status to compare against. * * @return void */ public function change_status( $current_status ): void { $status = get_site_transient( self::CACHE_BLACKLIST_STATUS ); if ( false === $status ) { $status = $this->domain_status(); } // Check changes. if ( $status !== $current_status ) { if ( '1' === $current_status ) { $this->make_wpmu_request( WPMUDEV::API_BLACKLIST, array(), array( 'method' => 'POST' ) ); $status = $this->domain_status(); } else { $this->reset_blocklist_monitor(); $status = - 1; } set_site_transient( self::CACHE_BLACKLIST_STATUS, $status, self::CACHE_TIME ); } } /** * Get domain status. Variants: * '1' -> 'good' */ public function get_status() { $status = get_site_transient( self::CACHE_BLACKLIST_STATUS ); if ( false === $status ) { $status = $this->domain_status(); } if ( is_wp_error( $status ) ) { return $status->get_error_message(); } return $status; } /** * Auto-enable blocklist monitoring after Hub connection if user triggered from Settings/Tools page. * * @return void */ public function maybe_hcm_connection_attempt(): void { $data = get_site_transient( Hub_Connector::TRANSIENT_KEY ); $module_slug = $data['module_slug'] ?? ''; if ( self::MODULE_SLUG !== $module_slug || ! self::get_hcm_status() ) { return; } delete_site_transient( Hub_Connector::TRANSIENT_KEY ); $this->make_wpmu_request( WPMUDEV::API_BLACKLIST, array(), array( 'method' => 'POST' ) ); $status = $this->domain_status(); set_site_transient( self::CACHE_BLACKLIST_STATUS, $status, self::CACHE_TIME ); } /** * Exports strings. * * @return array An array of strings. */ public function export_strings(): array { if ( false === $this->get_apikey() ) { return array( esc_html__( 'Blocklist Monitor inactive', 'wpdef' ) ); } if ( '1' === (string) $this->get_status() ) { $strings = array( esc_html__( 'Blocklist Monitor active', 'wpdef' ) ); } else { $strings = array( esc_html__( 'Blocklist Monitor inactive', 'wpdef' ) ); } return $strings; } /** * Configures strings based on the provided configuration * * @param array $config Configuration array. * * @return array An array of configuration strings. */ public function config_strings( array $config ): array { if ( false === $this->get_apikey() ) { return array( esc_html__( 'Blocklist Monitor inactive', 'wpdef' ) ); } return $config['enabled'] ? array( esc_html__( 'Blocklist Monitor active', 'wpdef' ) ) : array( esc_html__( 'Blocklist Monitor inactive', 'wpdef' ), ); } /** * Define settings labels. * * @return array */ public function labels(): array { return array( 'enabled' => esc_html__( 'Blocklist Monitor', 'wpdef' ), 'status' => esc_html__( 'Status', 'wpdef' ), ); } }