is_enabled()) { return $max_tries; } if ('checking-ssl-cert' === $domain->get_stage()) { $max_tries = 10; } return $max_tries; } /** * Picks up on tips that a given host provider is being used. * * We use this to suggest that the user should activate an integration module. * * @since 2.0.0 * @return boolean */ public function detect() { return defined('WPMUDEV_HOSTING_SITE_ID') && WPMUDEV_HOSTING_SITE_ID; } /** * This method gets called when a new domain is mapped. * * @since 2.0.0 * @param string $domain The domain name being mapped. * @param int $site_id ID of the site that is receiving that mapping. * @return void */ public function on_add_domain($domain, $site_id): void { $site_id = WPMUDEV_HOSTING_SITE_ID; $api_key = get_site_option('wpmudev_apikey'); $domains = [$domain]; if (! str_starts_with($domain, 'www.')) { $domains[] = "www.$domain"; } foreach ($domains as $_domain) { $response = wp_remote_post( "https://premium.wpmudev.org/api/hosting/v1/$site_id/domains", [ 'timeout' => 50, 'body' => [ 'domain' => $_domain, 'site_id' => $site_id, ], 'headers' => [ 'Authorization' => $api_key, ], ] ); if (is_wp_error($response)) { // translators: The %s placeholder will be replaced with the domain name. wu_log_add('integration-wpmudev', sprintf(__('An error occurred while trying to add the custom domain %s to WPMU Dev hosting.', 'wp-multisite-waas'), $_domain), LogLevel::ERROR); } $body = json_decode(wp_remote_retrieve_body($response)); if ($body->message) { // translators: The %1$s will be replaced with the domain name and %2$s is the error message. wu_log_add('integration-wpmudev', sprintf(__('An error occurred while trying to add the custom domain %1$s to WPMU Dev hosting: %2$s', 'wp-multisite-waas'), $_domain, $body->message->message), LogLevel::ERROR); } else { // translators: The %s placeholder will be replaced with the domain name. wu_log_add('integration-wpmudev', sprintf(__('Domain %s added to WPMU Dev hosting successfully.', 'wp-multisite-waas'), $_domain)); } } } /** * This method gets called when a mapped domain is removed. * * @since 2.0.0 * @param string $domain The domain name being removed. * @param int $site_id ID of the site that is receiving that mapping. * @return void */ public function on_remove_domain($domain, $site_id): void { /** * The WPMU DEV Hosting REST API does not offer an endpoint to remove domains yet. * As soon as that's the case, we'll implement it here. * * @todo Implement support to removing domains when a mapping is removed. */ } /** * This method gets called when a new subdomain is being added. * * This happens every time a new site is added to a network running on subdomain mode. * * @since 2.0.0 * @param string $subdomain The subdomain being added to the network. * @param int $site_id ID of the site that is receiving that mapping. * @return void */ public function on_add_subdomain($subdomain, $site_id) {} /** * This method gets called when a new subdomain is being removed. * * This happens every time a new site is removed to a network running on subdomain mode. * * @since 2.0.0 * @param string $subdomain The subdomain being removed to the network. * @param int $site_id ID of the site that is receiving that mapping. * @return void */ public function on_remove_subdomain($subdomain, $site_id) {} /** * Tests the connection with the WPMUDEV API. * * @since 2.0.0 * @return void */ public function test_connection(): void { $site_id = WPMUDEV_HOSTING_SITE_ID; $api_key = get_site_option('wpmudev_apikey'); $response = wp_remote_get( "https://premium.wpmudev.org/api/hosting/v1/{$site_id}/domains", [ 'timeout' => 50, 'headers' => [ 'Authorization' => $api_key, ], ] ); if (is_wp_error($response) || wp_remote_retrieve_response_code($response) !== 200) { wp_send_json_error($response); } else { wp_send_json_success(wp_remote_retrieve_body($response)); } } /** * Returns the description of this integration. * * @since 2.0.0 * @return string */ public function get_description() { return __('WPMU DEV is one of the largest companies in the WordPress space. Founded in 2004, it was one of the first companies to scale the Website as a Service model with products such as Edublogs and CampusPress.', 'wp-multisite-waas'); } /** * Returns the logo for the integration. * * @since 2.0.0 * @return string */ public function get_logo() { return wu_get_asset('wpmudev.webp', 'img/hosts'); } }