method_sanitize_modal_id()

 
 
 
 

method_sanitize_modal_id( $id )

Makes a value safe to use as a modal’s element id, link hash and CSS id selector.


Description

Lowercases the value, collapses every run of characters other than a-z, 0-9, _ and - into a single -, trims leading and trailing - and _, and — because a CSS identifier cannot start with a digit — prefixes modal- when what is left does not begin with a letter. The same rules run in the editor as sanitizeModalId() in lib/blocks/utils/modalId.js, so the id shown in the Link and ID panel is the id the page prints.


Parameters

$id (string) :
The value to sanitise; anything is cast to string.


Return

(string) The sanitised id, or '' if nothing usable is left.

InputOutput
'Request a Quote!''request-a-quote'
'2024-offer''modal-2024-offer'
'--'''

Source

File: lib/class-method-modals.php


Notes

  • Applied by Method_Modals::register() to every id, and by the Modal block to both customId and modalId before choosing between them (method_modal_get_block_id()).
  • An id is only as unique as its source: two blocks sanitising to the same id register once, and the editor’s Modals panel warns about it.

Changelog

VersionDescription
2.0.0-beta26Introduced (e12c9c0).