Opened 3 years ago
Last modified 3 years ago
#12368 new enhancement
Allow setting limit in do_shortcode()
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Shortcodes | Version: | |
| Severity: | normal | Keywords: | reporter-feedback |
| Cc: |
Description
Sometimes it is useful to limit the number of shortcode conversion occuring in do_shortcode(), such as preventing overuse of shortcode in untrusted content, or whatever reason. This patch adds a new int parameter to do_shortcode(), which is used as the $limit parameter in preg_replace_callback().
Attachments (1)
Change History (4)
abelcheung — 3 years ago
- Keywords reporter-feedback added; has-patch removed
- Milestone changed from Unassigned to Future Release
comment:2
follow-up:
↓ 3
abelcheung — 3 years ago
In my plugin's case, it converts shortcode enclosed content into images, but the process is resource hungry and time consuming, so I want to limit number of instances of shortcode parsed, and print others as vanilla text. That's the primary reason of this patch.
Do you mean using a static counter to record number of shortcode instances already parsed?
comment:3
in reply to:
↑ 2
Denis-de-Bernardy — 3 years ago
Replying to abelcheung:
Do you mean using a static counter to record number of shortcode instances already parsed?
pretty much exactly, yes.

I fail to see how the argument ever gets passed short of manually calling it in a function that overrides the shortcode function in the first place. in such a case, you might as well override this directly in your plugin.