Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from using name as the slug to client ID #250

Merged
merged 2 commits into from
Sep 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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