Skip to content

Font collection registration: handling invalid slugs #58695

@creativecoder

Description

@creativecoder

Font collections are registered with a slug that is used as a unique identifier for the collection.

For example:

wp_register_font_collection( 'my-collection, ... )

I now reference that collection by its slug in PHP or using the REST API:

  • WP_Font_Library::get_font_collection( 'my-collection')
  • wp/v2/font-collections/my-colleciton

Collection slugs are sanitized with sanitize_title to create slugs that are url safe values appropriate to use as identifiers.

The question came up in this wordpress-develop PR, what is the appropriate level of error handling when a slug is invalid (the sanitized slug value does not match it's given value)?

Some possibilities include

  • Triggering a _doing_it_wrong notice (this is what we're doing at the moment)
  • Throwing an exception, which would error the entire request
  • Storing a WP_Error instance somewhere and returning it at an appropriate time (perhaps when retrieving the slug?)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions