Repository navigation
fix(academy): let content staff view synced patterns in the editor - #1086
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Content Editors and Reviewers can't see synced patterns. In lessons, every Learning checkpoint, Q&A and Break block shows "Block has been deleted or is unavailable", and the inserter lists no synced patterns. The patterns exist and the lessons reference the right IDs (for example, 5916 in lesson 7241).
Cause
Core maps reading a synced pattern (
wp_block) toedit_posts. The block editor loads each pattern withcontext=edit, which also needsedit_poston the pattern itself (WP_REST_Posts_Controller::get_item_permissions_check). Listing patterns in that context needsedit_posts. Content Editors and Reviewers haveedit_coursesbut notedit_posts, so they get 403s on single patterns and an empty or forbidden list.Fix
A new mu-plugin,
cbf-staff-synced-patterns.php, applies only to users who haveedit_coursesbut notedit_posts:map_meta_capfilter mapsread_poston a publishedwp_blocktoedit_courses.rest_request_before_callbacksfilter changescontext=editGET requests on/wp/v2/blocksand/wp/v2/blocks/<id>toview. For patterns, theviewcontext still returnstitle.rawandcontent.raw, which is all the editor needs.These users still can't edit patterns, so the editor doesn't offer "Edit original". Patterns keep changing in their source files and reach the site through
wp cbf patterns sync.Testing
Tested locally through the REST API:
GET /wp/v2/blocks/5916(view/edit)GET /wp/v2/blocks(view/edit)PUT /wp/v2/blocks/5916Not yet checked in the block editor in a browser. After deploy, open lesson 7241 as a Content Editor and confirm the three checkpoints render and the patterns appear in the inserter.
phpcs passes.