10up / ElasticPress

A fast and flexible search and query engine for WordPress.
https://elasticpress.io
GNU General Public License v2.0
1.25k stars 311 forks source link

Indexing is broken when plugins output directly during post content #3328

Open tomjn opened 1 year ago

tomjn commented 1 year ago

Describe the bug

If a plugin has a shortcode that outputs directly rather than returning content, or tries to hook in to display extra output at a later date ( e.g. Gravity Forms ). This breaks the output of syncing and can stop the sync if it was triggered in the Admin UI

Steps to Reproduce

  1. install a plugin that echo's rather than returns its content in a shortcode or block
  2. use that in a post
  3. Trigger an index from WP Admin
  4. Watch as it fails to parse the output due to the stray HTML, and syncing stops

Screenshots, screen recording, code snippet

No response

Environment information

No response

WordPress and ElasticPress information

No response

Code of Conduct

felipeelia commented 1 year ago

We will need a specific (free) plugin with specific steps for this one, @tomjn, as the documentation specifically states that:

Note that the function called by the shortcode should never produce an output of any kind. Shortcode functions should return the text that is to be used to replace the shortcode.

tomjn commented 1 year ago

Indeed I'm a strong proponent of that, unfortunately lots of new WP devs are unfamiliar with this, I've even had some outright rebel in disbelief when I tell them :( . An output buffer should suffice to mitigate this in the meantime.