Skip to content

Improve kebabCase usage in plugin request utils #52411

@swissspidy

Description

@swissspidy

What problem does this address?

See the relevant code here:

// Ideally, we should be using sanitize_title() in PHP rather than kebabCase(),
// but we don't have the exact port of it in JS.
this.pluginsMap[ kebabCase( plugin.name ) ] = plugin.plugin;

kebabCase turns a plugin name like "SQLite Object Cache" into sq-lite-object-cache, whereas the correct plugin slug would be sqlite-object-cache. Same for "DynaMo", which is turned into dyna-mo instead of dynamo

What is your proposed solution?

Use toLowerCase() before running kebabCase(). That's what sanitize_title does internally as well.

I think that would solve most problems.

In addition to that, we could improve the error message when trying to activate a plugin with the wrong slug.

Example:

The plugin "foo-bar-baz" isn't installed. Did you mean "foobar-baz"?

This could be achieved by going through the pluginsMap and comparing the input with existing slugs, checking for similarity. For example by first removing all hyphens from both strings and then seeing if there is a match.

Bonus: we could actually do this comparison and choose the right plugin automatically, without annoying the developer. But not sure if that's desired.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions