johngodley / search-regex

Search Regex adds a powerful set of search and replace functions to WordPress that go beyond the standard searching capabilities, with full regex support.
https://searchregex.com
GNU General Public License v3.0
32 stars 9 forks source link

Is there a hook for dynamic global replace text value? #172

Open jure123 opened 9 months ago

jure123 commented 9 months ago

I noticed that hooks are supported for Modify matches action, but not for Global text replace action (I think). It would be useful to have a hook to be called before replacing text that would support dynamic replacement text value.

For example, I need to search all shortcodes like [vc_single_image image=”6800″], where I need to extract the image ID using regex params. Then I need to replace the shortcode with <img src="/wp-content/2020/01/image.jpg" />, where image ID must be replace with actual image URL. In this case it would be helpful that Search Regex plugin would call some hook like apply_filters('before_replace_value, $searchRegexResult, $replaceValue, $match, ...), where I could read the image ID (from the search regex param), then programatically get the corresponding image URL, and return the custom replace value <img src="image-url.jpg" /> that Search Regex plugin will replace to.