Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a safe function for apply_filter #6629

Open
MathieuLamiot opened this issue May 13, 2024 · 0 comments
Open

Introduce a safe function for apply_filter #6629

MathieuLamiot opened this issue May 13, 2024 · 0 comments

Comments

@MathieuLamiot
Copy link
Contributor

MathieuLamiot commented May 13, 2024

Context

  • In the continuation of this WP Core issue: https://core.trac.wordpress.org/ticket/51525
  • @CrochetFeve0251 mentioned having something a bit related in WP Launchpad -> To check and possibly go from there?
  • This is useful for WP Rocket, but also WP Media in general and maybe WP Core. So we need to identify the proper way to implement a first version that could easily be re-used for all those projects. Start only in WP Rocket? Or a library/file easily movable to Launchpad and/or other plugins? That could easily be transmitted to WP Core? The proper way to implement this must be identify.

Expected behavior

  • Add a apply_filters_typed function, as per https://core.trac.wordpress.org/ticket/51525, that does apply_filter and throws a _doing_it_wrong in case of type mismatch.
  • Add a apply_filters_safetyped function, as per https://core.trac.wordpress.org/ticket/51525, that does apply_filte, throws a _doing_it_wrong in case of type mismatch and skips the $next_value to keep a valid one.
  • Add custom types to the is_type method, based on what we usually need
    • positive_integer: type integer and >= 0
    • strictly_positive_integer: type integer and > 0

Targeted implementation

The goal is to have a method we can start using in at least WP Rocket (and if possible in other places) that we can also share as a PoC to WP Core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants