self::instance_id(), 'site_url' => home_url('/'), 'admin_email' => (string) get_option('admin_email', ''), 'wp_version' => get_bloginfo('version'), 'plugin_version' => ARACNE_VERSION, ]); wp_remote_post(self::api_base() . '/api/v1/install', [ 'timeout' => 5, 'blocking' => false, 'headers' => [ 'Content-Type' => 'application/json', 'X-ARACNE-Install-Sign' => hash_hmac('sha256', $json, self::INSTALL_SECRET), ], 'body' => $json, ]); } public static function instance_id(): string { $id = (string) get_option(self::OPT_INSTANCE, ''); if ($id === '') { $id = preg_replace('/[^A-Za-z0-9\-]/', '', wp_generate_uuid4()); update_option(self::OPT_INSTANCE, $id, false); } return $id; } /** * URL base del servicio, sin barra final. Una URL no https configurada en la option se * descarta: el token de licencia y la clave viajan por este canal. */ public static function api_base(): string { $api = trim((string) get_option(self::OPT_API, '')); if ($api === '' || !self::is_acceptable_url($api)) { $api = self::API_DEFAULT; } return rtrim($api, '/'); } /** http solo se admite en desarrollo: WP_DEBUG y ARACNE_DEV_ALLOW_HTTP a la vez. */ public static function is_acceptable_url(string $url): bool { $scheme = strtolower((string) wp_parse_url($url, PHP_URL_SCHEME)); $host = (string) wp_parse_url($url, PHP_URL_HOST); if ($host === '') return false; if ($scheme === 'https') return true; return $scheme === 'http' && defined('WP_DEBUG') && WP_DEBUG && defined('ARACNE_DEV_ALLOW_HTTP') && ARACNE_DEV_ALLOW_HTTP; } }