From c4fee971882900e2ad8e46357e475ae390ce378a Mon Sep 17 00:00:00 2001 From: David Shanske Date: Sat, 2 Sep 2023 05:39:33 +0000 Subject: [PATCH 1/2] Switch from using name as the slug to client ID --- includes/class-indieauth-client-taxonomy.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/includes/class-indieauth-client-taxonomy.php b/includes/class-indieauth-client-taxonomy.php index 0838e71..bfc8b68 100755 --- a/includes/class-indieauth-client-taxonomy.php +++ b/includes/class-indieauth-client-taxonomy.php @@ -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 + */ + 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. @@ -135,7 +149,7 @@ public static function add_client( $url, $name = null, $icon = null ) { $name, 'indieauth_client', array( - 'slug' => sanitize_title( $name ), + 'slug' => $this->generate_slug( $url ), 'description' => esc_url_raw( $url ), ) ); From bb475407c2dcd47f184bf0226d4dad7307c1e512 Mon Sep 17 00:00:00 2001 From: David Shanske Date: Sat, 2 Sep 2023 05:57:13 +0000 Subject: [PATCH 2/2] Fix issue --- includes/class-indieauth-client-taxonomy.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-indieauth-client-taxonomy.php b/includes/class-indieauth-client-taxonomy.php index bfc8b68..f441a3e 100755 --- a/includes/class-indieauth-client-taxonomy.php +++ b/includes/class-indieauth-client-taxonomy.php @@ -113,7 +113,7 @@ public static function update_client_icon_from_discovery( $url ) { * @param string URL * @return string|string[]|null */ - function generate_slug( $url ) { + public static function generate_slug( $url ) { $host = wp_parse_url( $url, PHP_URL_HOST ); // strip leading www, if any. $host = preg_replace( '/^www\./', '', $host ); @@ -149,7 +149,7 @@ public static function add_client( $url, $name = null, $icon = null ) { $name, 'indieauth_client', array( - 'slug' => $this->generate_slug( $url ), + 'slug' => self::generate_slug( $url ), 'description' => esc_url_raw( $url ), ) );