Opened 3 years ago

Last modified 3 years ago

#12368 new enhancement

Allow setting limit in do_shortcode()

Reported by: abelcheung 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)

shortcode-limit.patch (978 bytes) - added by abelcheung 3 years ago.

Download all attachments as: .zip

Change History (4)

  • Keywords reporter-feedback added; has-patch removed
  • Milestone changed from Unassigned to Future Release

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.

comment:2 follow-up: ↓ 3   abelcheung3 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-Bernardy3 years ago

Replying to abelcheung:

Do you mean using a static counter to record number of shortcode instances already parsed?

pretty much exactly, yes.

Note: See TracTickets for help on using tickets.