Commit b717e4b
fix: grant read_post cap for preview post to enable Block Bindings (#225)
* fix: grant read_post cap for preview post to enable Block Bindings
Since WordPress 6.5, Block Bindings sources (core/post-meta,
core/post-data) check is_post_publicly_viewable() OR
current_user_can('read_post') before returning a value. For public
previews, the post is still a draft, so anonymous users fail both
checks and all Block Bindings render empty.
Hook into map_meta_cap to grant read_post for the specific preview
post ID during the preview request. This requires no object cache
manipulation and does not affect any other posts or requests.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor: replace static property + method with closure for map_meta_cap
The static $preview_post_id property and grant_read_post_for_preview()
method are unnecessary — a closure with use ($post_id) keeps the post ID
scoped directly, which is simpler and equally safe.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Use `exist` to grant preview user capabilites to read metadata
Co-authored-by: Dominik Schilling <dominikschilling+git@gmail.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Dominik Schilling <dominikschilling+git@gmail.com>1 parent 62726ce commit b717e4b
1 file changed
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
731 | 731 | | |
732 | 732 | | |
733 | 733 | | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
734 | 751 | | |
735 | 752 | | |
736 | 753 | | |
| |||
0 commit comments