Exclude password protected posts from search #1789
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
The problem we faced was the display of password-protected posts in the search results. Upon further investigation we were not able to hide password-protected posts via any existing hooks. Looking at past issues, we found this one: #1083 which had a PR: #1094 that was reverted at a later time. Upon testing the PR we managed to successfully hide posts from search results using it hence I am re-opening the PR with an additional hook to be able to show posts regardless of admin status if one might want that.
Alternate Designs
We attempted to hide password-protected posts from the search results (which is default WP behavior) via existing hooks with no success.
Benefits
Hide password-protected posts from search results. This behavior can be disabled via the included hook.
Possible Drawbacks
None of which I can tell so far.
Verification Process
Upon implementing this code on our test and production sites, we re-run the indexing process and then tested the default WP search results in the front-end of the site using different keywords that we knew previously returned password-protected posts.
Checklist:
Applicable Issues
None so far.
Changelog Entry
Add support for hiding password-protected posts from search-results. Props @allan23 (#1094)
Add filter hook so you can still display password-protected posts from search-results. @cristianuibar