Question

I want to pass some json data to JS from wordpress(PHP) and was thinking to use ob_start() and ob_end_clean() in wordpress but i am not sure weather any other plugins are using the same functions. I was thinking to manually add ob_start() at the beginning of the theme header and clear the document when necessary. I thought of using grep find if there are any ob_start() in wordpress, but i can't grep find everytime my website gets updated. Are there any workarounds? I will be calling ob_end_clean() from a shortcode.

Was it helpful?

Solution

WordPress has a whole set of useful functions to handle. It's called wp_send_json(). You have success and error functions too.

ob_start(), ob_get_clean() would be useful in case you want to include some views (~ MVC) in your shortcode, e.g in your shortcode handler. I don't see here why you would use them to pass data from PHP to js.

Otherwise I would use them in the shortcode handler, no use to put them in theme.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top