As my recent post on Make WordPress Plugins explains, there’s a serious problem in many themes and plugins using the content filter, and although this problem well known, it has largely been ignored by the WordPress community. :-/
I’d like your feedback on the new Block Filter Output (BFO) feature that will be enabled in WPSSO version 3.47.0 (currently in pre-release) — the Block Filter Output (BFO) feature attempts to make the content filter usable by monitoring the content filter for webpage output, and fixing incorrectly coded filter hooks (that send text to the webpage instead of returning it, as all filter hooks must). WPSSO version 3.47.0 will also enable the “Apply WordPress Content Filter” option by default, and use the BFO feature to report any content filter issues.
If you are a Pro version user, you can try the latest pre-release / release candidate version by selecting the “Release Candidate and Up” version filter for WPSSO under the SSO > Update Manager settings page. Let me know if WPSSO reports any issues with your content filters — hopefully it won’t, but if it does, you’ll have the necessary information to contact the theme or plugin author and have them fix their code. ;-)
If you’re not clear about the difference between WordPress actions and filters, you may end up breaking the page layout of WordPress – maybe days, months, or even years after you’ve written and implemented a new filter hook. The difference can be difficult for new developers to grasp – after all, hooking an action or filter runs your code, either way, right? Well, yes, it does, but filters can be executed several times, in different locations as the webpage is being built (header, body, footer, etc.), and even in the admin back-end. But more importantly, filters do not send anything to the webpage! Filter hooks receive their data / text as an argument, and then “return” the modified (or original) data / text at the end. They do not use “echo”, “print”, “printf”, etc. – they should not send anything to the webpage. If you need to output something directly to the webpage, use an action – that’s what they’re for. ;-)
I’ve just released version 1.1.0 of JSM’s Block Filter Output – a new plugin to monitor the content filter and fix incorrectly coded filter hooks (that send text to the webpage instead of returning it, as all filter hooks must).
A notice is also sent to the PHP error log when webpage output is detected:
[01-Oct-2017 01:48:28 UTC] Block Filter Output: The “ClassName::echoText” filter hook with priority 10 in the “the_content” filter has mistakenly provided some webpage output. All WordPress filter hooks must return their text – not send it to the webpage output. Please contact the author of that filter hook and report this issue as a coding error / bug. Incorrect webpage output:
<strong>Some output that should have been returned instead of echo’ed.</strong>
The plugin is fully tested and compatible with PHP v7.x (PHP v5.3 or better required).