| @@ -118,17 +118,18 @@ | ||
| 118 | 118 | update_option( self::FIRST_SEEN_OPTION, time() ); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
| 122 | - * Generate a stable install ID hash from the current domain. | |
| 122 | + * Generate a stable install ID hash from the current domain slug. | |
| 123 | 123 | * |
| 124 | 124 | * Same domain (e.g. example.com, app.example.com) always yields the same id, |
| 125 | 125 | * so uninstall + reactivate on the same site is not counted as a new install. |
| 126 | + * Uses the slug form so existing install_id hashes stay stable. | |
| 126 | 127 | * |
| 127 | 128 | * @return string |
| 128 | 129 | */ |
| 129 | 130 | private static function get_install_id_hash() { |
| 130 | - $domain = self::get_domain(); | |
| 131 | + $domain = self::get_domain_slug(); | |
| 131 | 132 | $salt = defined( 'AUTH_KEY' ) ? AUTH_KEY : 'ctc-telemetry-salt'; |
| 132 | 133 | $full = hash( 'sha256', $domain . $salt ); |
| 133 | 134 | return substr( $full, 0, self::INSTALL_ID_HASH_LENGTH ); |
| 134 | 135 | } |
| @@ -191,9 +192,10 @@ | ||
| 191 | 192 | $copy_as[] = sanitize_key( $rule['copy_as'] ); |
| 192 | 193 | } |
| 193 | 194 | } |
| 194 | 195 | |
| 195 | - $domain = self::get_domain(); | |
| 196 | + // Real hostname for dashboards (e.g. example.com). install_id still uses get_domain_slug(). | |
| 197 | + $domain = self::get_hostname(); | |
| 196 | 198 | $env = [ |
| 197 | 199 | 'wp_version' => get_bloginfo( 'version' ), |
| 198 | 200 | 'php_version' => PHP_VERSION, |
| 199 | 201 | 'theme_name' => wp_get_theme()->get( 'Name' ), |
| @@ -239,19 +241,44 @@ | ||
| 239 | 241 | return apply_filters( 'ctc/telemetry/payload', $payload ); |
| 240 | 242 | } |
| 241 | 243 | |
| 242 | 244 | /** |
| 243 | - * Get domain slug from home URL. | |
| 245 | + * Hostname from home URL (no www), for telemetry environment.domain. | |
| 244 | 246 | * |
| 245 | 247 | * @return string |
| 246 | 248 | */ |
| 247 | - private static function get_domain() { | |
| 249 | + private static function get_hostname() { | |
| 248 | 250 | $host = wp_parse_url( home_url(), PHP_URL_HOST ); |
| 249 | 251 | if ( empty( $host ) ) { |
| 250 | 252 | return ''; |
| 251 | 253 | } |
| 254 | + $host = preg_replace( '/^www\./', '', strtolower( $host ) ); | |
| 255 | + /** | |
| 256 | + * Filter the hostname sent in telemetry environment.domain. | |
| 257 | + * | |
| 258 | + * @param string $host Hostname without www. | |
| 259 | + */ | |
| 260 | + return apply_filters( 'ctc/telemetry/hostname', $host ); | |
| 261 | + } | |
| 262 | + | |
| 263 | + /** | |
| 264 | + * Domain slug used only for stable install_id hashing (must not change format). | |
| 265 | + * | |
| 266 | + * @return string | |
| 267 | + */ | |
| 268 | + private static function get_domain_slug() { | |
| 269 | + $host = wp_parse_url( home_url(), PHP_URL_HOST ); | |
| 270 | + if ( empty( $host ) ) { | |
| 271 | + return ''; | |
| 272 | + } | |
| 252 | 273 | $host = preg_replace( '/^www\./', '', $host ); |
| 253 | 274 | $slug = sanitize_key( str_replace( '.', '-', $host ) ); |
| 275 | + /** | |
| 276 | + * Filter the domain slug used for install_id hashing. | |
| 277 | + * Changing this remaps install identity — avoid unless intentional. | |
| 278 | + * | |
| 279 | + * @param string $slug Slug like example-com. | |
| 280 | + */ | |
| 254 | 281 | return apply_filters( 'ctc/telemetry/domain', $slug ); |
| 255 | 282 | } |
| 256 | 283 | |
| 257 | 284 | /** |