Skip to content

Rewrite filtering logic using the DOM extension (instead of regular expressions) #58

Description

@jan-san

Trying to parse HTML with regular expressions is cumbersome, error-prone and ultimately futile.
A safer (and potentially more efficient) approach would be to use the DOM extension instead.

The DOM extension is not a hard requirement for running WordPress - based on a brief look into the code, all calls to DOM extension functionality in the WP core seem to be guarded with class_exists() checks to prevent errors. However, the extension is enabled in PHP by default (see here), and is listed as a required module for WordPress in the WP Extension Check command for WP-CLI.

The following would be necessary to move to the DOM extension:

  • (optional) Implement a performance check for the filter_*() functions (to get a before/after comparison)
  • Re-implement the filter_*() functions using the DOM extension
  • Add a check to the plugin that disables all functionality and shows a warning if the DOM extension is not active

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