-
Notifications
You must be signed in to change notification settings - Fork 4.7k
REST API: Use posts endpoint for reusable blocks #10751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
e681848
e3b1279
c8ad73a
9c1da9e
0235f5d
ac75c14
921f669
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ import { | |
| getBlocks, | ||
| getBlocksByClientId, | ||
| } from '../selectors'; | ||
| import { getPostRawValue } from '../reducer'; | ||
|
|
||
| /** | ||
| * Module Constants | ||
|
|
@@ -61,26 +62,25 @@ export const fetchReusableBlocks = async ( action, store ) => { | |
|
|
||
| let result; | ||
| if ( id ) { | ||
| result = apiFetch( { path: `/wp/v2/${ postType.rest_base }/${ id }` } ); | ||
| result = apiFetch( { path: `/wp/v2/${ postType.rest_base }/${ id }?context=edit` } ); | ||
| } else { | ||
| result = apiFetch( { path: `/wp/v2/${ postType.rest_base }?per_page=-1` } ); | ||
| result = apiFetch( { path: `/wp/v2/${ postType.rest_base }?per_page=-1&context=edit` } ); | ||
| } | ||
|
|
||
| try { | ||
| const reusableBlockOrBlocks = await result; | ||
| dispatch( receiveReusableBlocksAction( map( | ||
| castArray( reusableBlockOrBlocks ), | ||
| ( reusableBlock ) => { | ||
| const parsedBlocks = parse( reusableBlock.content ); | ||
| if ( parsedBlocks.length === 1 ) { | ||
| return { | ||
| reusableBlock, | ||
| parsedBlock: parsedBlocks[ 0 ], | ||
| }; | ||
| } | ||
| ( post ) => { | ||
| const parsedBlocks = parse( post.content.raw ); | ||
| return { | ||
| reusableBlock, | ||
| parsedBlock: createBlock( 'core/template', {}, parsedBlocks ), | ||
| reusableBlock: { | ||
| id: post.id, | ||
| title: getPostRawValue( post.title ), | ||
| }, | ||
| parsedBlock: parsedBlocks.length === 1 ? | ||
| parsedBlocks[ 0 ] : | ||
| createBlock( 'core/template', {}, parsedBlocks ), | ||
| }; | ||
| } | ||
| ) ) ); | ||
|
|
@@ -119,7 +119,7 @@ export const saveReusableBlocks = async ( action, store ) => { | |
| const reusableBlock = getBlock( state, clientId ); | ||
| const content = serialize( reusableBlock.name === 'core/template' ? reusableBlock.innerBlocks : reusableBlock ); | ||
|
|
||
| const data = isTemporary ? { title, content } : { id, title, content }; | ||
| const data = isTemporary ? { title, content, status: 'publish' } : { id, title, content, status: 'publish' }; | ||
| const path = isTemporary ? `/wp/v2/${ postType.rest_base }` : `/wp/v2/${ postType.rest_base }/${ id }`; | ||
| const method = isTemporary ? 'POST' : 'PUT'; | ||
|
|
||
|
|
@@ -184,7 +184,10 @@ export const deleteReusableBlocks = async ( action, store ) => { | |
| ] ) ); | ||
|
|
||
| try { | ||
| await apiFetch( { path: `/wp/v2/${ postType.rest_base }/${ id }`, method: 'DELETE' } ); | ||
| await apiFetch( { | ||
| path: `/wp/v2/${ postType.rest_base }/${ id }?force=true`, | ||
|
||
| method: 'DELETE', | ||
| } ); | ||
| dispatch( { | ||
| type: 'DELETE_REUSABLE_BLOCK_SUCCESS', | ||
| id, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the CPT now supports
titleandeditor, we can go a step further and remove this line fromgutenberg.php:267:This PR would then close #9964.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in c8ad73a