Skip to content

Commit a2c264f

Browse files
authored
Switch from using name as the slug to client ID (#250)
* Switch from using name as the slug to client ID
1 parent 8caf7b1 commit a2c264f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

includes/class-indieauth-client-taxonomy.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ public static function update_client_icon_from_discovery( $url ) {
107107
}
108108

109109

110+
/**
111+
* Generate a slug based on the URL of a client.
112+
*
113+
* @param string URL
114+
* @return string|string[]|null
115+
*/
116+
public static function generate_slug( $url ) {
117+
$host = wp_parse_url( $url, PHP_URL_HOST );
118+
// strip leading www, if any.
119+
$host = preg_replace( '/^www\./', '', $host );
120+
$path = wp_parse_url( $url, PHP_URL_PATH );
121+
$path = str_replace( '/', '_', $title );
122+
return sanitize_title( $host . $path );
123+
}
110124

111125
/**
112126
* Add a client as a term and return.
@@ -135,7 +149,7 @@ public static function add_client( $url, $name = null, $icon = null ) {
135149
$name,
136150
'indieauth_client',
137151
array(
138-
'slug' => sanitize_title( $name ),
152+
'slug' => self::generate_slug( $url ),
139153
'description' => esc_url_raw( $url ),
140154
)
141155
);

0 commit comments

Comments
 (0)