get(); if ( empty( $value['deepl']['api_key'] ) ) { return $this->format_single_value_for_site_health_info( __( 'DeepL is activated but no API key is set.', 'polylang-pro' ) ); } $service = new Service( array( 'api_key' => $value['deepl']['api_key'], 'formality' => $value['deepl']['formality'] ?? null, ), PLL()->model ); $result = $service->get_client()->is_api_key_valid(); if ( $result->has_errors() ) { return $this->format_single_value_for_site_health_info( $result->get_error_message() ); } return $this->format_single_value_for_site_health_info( __( 'The API key is valid', 'polylang-pro' ) ); } /** * Returns the default value. * * @since 3.7 * * @return array */ protected function get_default() { $services = array(); foreach ( Factory::get_classnames() as $service ) { $services[ $service::get_slug() ] = array(); } return $services; } /** * Returns the JSON schema part specific to this option. * * @since 3.7 * * @return array Partial schema. * * @phpstan-return array{ * type: 'object', * properties: array< * non-falsy-string, * array{ * type: 'object', * properties: array, * additionalProperties: false * } * >, * additionalProperties: false * } */ protected function get_data_structure(): array { $structure = array( 'type' => 'object', // Correspond to associative array in PHP, @see{https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/#primitive-types}. 'properties' => array(), 'additionalProperties' => false, ); foreach ( Factory::get_classnames() as $service ) { $structure['properties'][ $service::get_slug() ] = array( 'type' => 'object', 'properties' => $service::get_option_schema(), 'additionalProperties' => false, ); } return $structure; } /** * Returns the description used in the JSON schema. * * @since 3.7 * * @return string */ protected function get_description(): string { return __( 'Settings for machine translation services: DeepL\'s API key, formality, and glossary for now.', 'polylang-pro' ); } }