When "Use HTML Purifier" is enabled for a CKEditor field any data-* attributes are stripped out. This happens regardless of the CKEditor ACF settings, and is pretty annoying considering how frequently data attributes are used/needed these days.
I'd like to keep HTML Purifier activated but I want to change the configuration to allow specific data attributes.
I know how to do this via addAttribute() - as mentioned here - and I can get this working if I directly edit MarkupHTMLPurifier::init() and clear the HTML Purifier cached files from /site/assets/cache/.
public function init() {
$this->settings->set('Cache.SerializerPath', $this->getCachePath());
$this->settings->set('Attr.AllowedRel', array('nofollow'));
$this->settings->set('HTML.DefinitionID', 'html5-definitions');
$this->settings->set('HTML.DefinitionRev', 1);
if($def = $this->settings->maybeGetRawHTMLDefinition()) {
$def->addElement('figure', 'Block', 'Optional: (figcaption, Flow) | (Flow, figcaption) | Flow', 'Common');
$def->addElement('figcaption', 'Inline', 'Flow', 'Common');
// Added line below to allow data-ext attribute on 'a' elements
$def->addAttribute('a', 'data-ext', 'Text');
}
}
But how can I change the configuration like this without modifying a core file? I want to set the configuration from a custom module. I don't see any hookable methods in MarkupHTMLPurifier but surely it must be configurable somehow. Does anyone know a way to do this?