bozdoz / wp-plugin-leaflet-map

Add leaflet maps to Wordpress with shortcodes
https://wordpress.org/plugins/leaflet-map/
GNU General Public License v2.0
140 stars 71 forks source link

Investigate calling do_shortcode in all shortcodes #185

Closed bozdoz closed 1 year ago

bozdoz commented 1 year ago

https://wordpress.org/support/topic/how-to-add-shortcode-inside-leaflet-marker/#post-16268816

I don’t think any of our shortcodes call do_shortcode (https://developer.wordpress.org/reference/functions/do_shortcode/) I could try to add it, I suppose, or if you wanted to alter your own files, you could probably add it yourself, somewhere in here, using $content:

https://github.com/bozdoz/wp-plugin-leaflet-map/blob/master/shortcodes/class.marker-shortcode.php#L31

or here, to affect all shortcodes:

https://github.com/bozdoz/wp-plugin-leaflet-map/blob/master/shortcodes/class.shortcode.php#L48

I might just try to add $content = do_shortcode($content);

I might have a hard time justifying adding this to the library, but I could try to test it out myself and see if it’s easy to add (it’s possible that it’s super easy without any drawbacks!)

hupe13 commented 1 year ago

Possible solution: https://github.com/bozdoz/wp-plugin-leaflet-map/blob/5e524873bb64602e4976fc89fe4c35b0f41f5777/class.leaflet-map.php#L375

Change:

if (! str_starts_with($message,'[')) { 
      $message = str_replace(array("\r\n", "\n", "\r"), '<br>', $message);
} else {
      $message = do_shortcode($message);
      $message = str_replace(array("\r\n", "\n", "\r"), '', $message);
}

str_starts_with is new at php8. https://github.com/bozdoz/wp-plugin-leaflet-map/blob/5e524873bb64602e4976fc89fe4c35b0f41f5777/class.leaflet-map.php#L383 You may change unescape also, it is deprecated.