Skip to content

Commit

Permalink
Switch from using name as the slug to client ID (#250)
Browse files Browse the repository at this point in the history
* Switch from using name as the slug to client ID
  • Loading branch information
dshanske authored Sep 2, 2023
1 parent 8caf7b1 commit a2c264f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion includes/class-indieauth-client-taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ public static function update_client_icon_from_discovery( $url ) {
}


/**
* Generate a slug based on the URL of a client.
*
* @param string URL
* @return string|string[]|null
*/
public static function generate_slug( $url ) {
$host = wp_parse_url( $url, PHP_URL_HOST );
// strip leading www, if any.
$host = preg_replace( '/^www\./', '', $host );
$path = wp_parse_url( $url, PHP_URL_PATH );
$path = str_replace( '/', '_', $title );
return sanitize_title( $host . $path );
}

/**
* Add a client as a term and return.
Expand Down Expand Up @@ -135,7 +149,7 @@ public static function add_client( $url, $name = null, $icon = null ) {
$name,
'indieauth_client',
array(
'slug' => sanitize_title( $name ),
'slug' => self::generate_slug( $url ),
'description' => esc_url_raw( $url ),
)
);
Expand Down

0 comments on commit a2c264f

Please sign in to comment.