ndiego / block-visibility

Conditional visibility controls for all WordPress blocks.
https://www.blockvisibilitywp.com
GNU General Public License v2.0
130 stars 10 forks source link

Option to add fallback content for hidden blocks #89

Closed coreyworrell closed 1 year ago

coreyworrell commented 1 year ago

What problem does this address?

Scenario: you set visibility for a block (let's say only show for specific user roles) and then want to show "fallback" content to everyone else (ie: "Sorry, you'll need to upgrade your account to view this").

Currently you would need to add a new block, then set the opposite visibility of the first one. This means maintaining two visibility lists, and then having to remember to update both inversely if you need to change a role (or other visibility setting).

What is your proposed solution?

One idea would be to have a toggle/checkbox in the sidebar like "Use fallback content" (not sure of the best wording), and enabling that would insert a sort of "group" block "within" the block (wrap the whole thing in a special wrapping block perhaps? not sure how it would best work internally), with UI reflecting it's purpose. This allows you to 1) Only maintain one set of visibility controls for a "restricted" block, and 2) use any blocks in the fallback (rather than just adding simple textarea field or similar in the sidebar).

ndiego commented 1 year ago

Thanks for opening an issue @coreyworrell. This would be a very cool idea, but the implementation would require Block Visibility to insert additional blocks and/or wrap the selected block in an additional block. I want to try and stay away from adding blocks with Block Visibility as it introduces another level of complexity to the plugin, and the UI/UX of this feature could prove very challenging.

While having to add another block with the reverse settings is not ideal, it is the most straightforward implementation. That said, anyone is welcome to explore this idea of inserting fallback content in a separate PR.

coreyworrell commented 1 year ago

@ndiego Thanks for reviewing. The additional/wrapper block would only be used in the editor and never output on frontend. But yes, the UI/UX could get complicated. I will look into possibility of creating a PR.