sanitize.php
Cleans submitted HTML, preserves allowed native structures, removes editor-only output, and applies feature-specific validation before storage.
Responsibility#
Cleans submitted HTML, preserves allowed native structures, removes editor-only output, and applies feature-specific validation before storage.
This is an implementation reference for the released 0.9.13 module. Internal PHP helpers are not a compatibility promise for third-party callers. Prefer the documented REST, Abilities, theme, and filter contracts.
Related modules#
build-contract, element-css, element-js, element-php, native-allowed-html, render, responsive.
WordPress hooks#
| Operation | Hook |
|---|---|
add_filter |
safe_style_css |
add_filter |
safecss_filter_attr_allow_css |
add_action and add_filter subscribe to a hook; do_action and apply_filters expose a hook. A subscription is not itself a new extension API. Dynamic hook names are not included in this literal inventory.
Function and method reference#
cantata_edit_strip_invisible#
function cantata_edit_strip_invisible( string $html ): string
Characters nobody means to publish: zero-width spaces, word joiner, BOM, soft hyphen, and the direction marks and embeddings that come along from Word, PDFs and chat apps. They go from the words only: tags and attribute values are left exactly as they are, and so is anything inside
or (where someone may be
showing them on purpose). A no-break space (U+00A0), zero-width non-joiner (U+200C), and zero-width joiner (U+200D)
are meaningful characters and stay. The editor strips the same set on paste; this is the backstop for anything
that arrives another way.
Source location: includes/sanitize.php:39.
cantata_edit_sanitize#
function cantata_edit_sanitize( string $html, bool $css_checked = false ): string
$css_checked: the caller already compared any element CSS with the stored copy (cantata_edit_sanitize_saved_content).
Without that, an account that may not write CSS keeps none (there is nothing to tell new CSS from what was there).
Implementation connections: cantata_edit_allowed_html, cantata_edit_can_author_css, cantata_edit_clean_html, cantata_edit_element_css_strip.
Source location: includes/sanitize.php:66.
cantata_edit_clean_html#
function cantata_edit_clean_html( string $html, array $allowed ): string
Internal sanitizer with an explicit allowlist; callers must establish its provenance.
Implementation connections: cantata_edit_clean_element_css, cantata_edit_clean_live_slots, cantata_edit_clean_picture_restore, cantata_edit_clean_responsive, cantata_edit_drop_bad_urls, cantata_edit_element_css_prepare, cantata_edit_element_js_finish, cantata_edit_element_js_mask, cantata_edit_element_js_unmask, cantata_edit_normalize_inline_colours, cantata_edit_strip_artifacts, cantata_edit_strip_invisible.
Source location: includes/sanitize.php:74.
cantata_edit_sanitize_saved_content#
function cantata_edit_sanitize_saved_content( string $html, string $source, array $js = [] )
Preserve unchanged, already-stored embeds when an ordinary editor changes surrounding words.
Only matching occurrences from the authoritative source may survive. New/changed embeds are
refused, and even preserved markup passes the privileged allowlist (URLs/handlers are cleaned).
Random per-call placeholders are generated after matching, never accepted from the client.
Implementation connections: cantata_edit_build_contract_enabled, cantata_edit_build_contract_normalize, cantata_edit_element_js_check_submission, cantata_edit_element_js_finish, cantata_edit_element_php_check_submission, cantata_edit_sanitize_saved_content_html.
Source location: includes/sanitize.php:102.
cantata_edit_sanitize_saved_content_html#
function cantata_edit_sanitize_saved_content_html( string $html, string $source )
The HTML side of cantata_edit_sanitize_saved_content(), before element Custom JavaScript is signed.
Implementation connections: cantata_edit_allowed_html, cantata_edit_clean_html, cantata_edit_element_css_check_submission, cantata_edit_sanitize.
Source location: includes/sanitize.php:133.
cantata_edit_normalize_colours#
function cantata_edit_normalize_colours( string $css ): string
CSSOM serializes picker colors as rgb()/rgba(). Core's CSS filter rejects
those functions on supported WordPress versions. Convert only numeric color
tokens in color-bearing declarations; the result still passes native KSES.
No CSS function, property, selector or URL is added to the allowed list.
Source location: includes/sanitize.php:191.
cantata_edit_normalize_inline_colours#
function cantata_edit_normalize_inline_colours( string $html ): string
Internal implementation helper in this module. Its name and signature identify the operation and accepted PHP values; it is not a standalone authenticated endpoint.
Implementation connections: cantata_edit_normalize_colours.
Source location: includes/sanitize.php:212.
cantata_edit_drop_bad_urls#
function cantata_edit_drop_bad_urls( string $html ): string
A link or source whose address uses a scheme WordPress doesn't allow (javascript:, data:, vbscript:, however it
is disguised with entities, case or spaces) loses the attribute altogether, rather than keeping a broken remainder.
Source location: includes/sanitize.php:233.
cantata_edit_strip_artifacts#
function cantata_edit_strip_artifacts( string $html ): string
The editor's own marks, removed from inside tags only (never from the words). Mirrors clean() in editor.js.
Source location: includes/sanitize.php:252.
cantata_edit_allowed_html#
function cantata_edit_allowed_html( bool $admin = false ): array
Internal implementation helper in this module. Its name and signature identify the operation and accepted PHP values; it is not a standalone authenticated endpoint.
Implementation connections: cantata_edit_native_allowed_html.
Source location: includes/sanitize.php:279.
cantata_edit_clean_picture_restore#
function cantata_edit_clean_picture_restore( string $html ): string
Picture-size reset metadata is saved provenance, not a second arbitrary style channel.
Only declarations Simple itself temporarily replaces may be restored, and every value
passes the same WordPress CSS filter as inline styles before the editor can apply it.
Source location: includes/sanitize.php:289.