Skip to content

Add: Global Styles Rest endpoints#1816

Closed
jorgefilipecosta wants to merge 1 commit intoWordPress:trunkfrom
jorgefilipecosta:add/global-styles-rest-endpoints
Closed

Add: Global Styles Rest endpoints#1816
jorgefilipecosta wants to merge 1 commit intoWordPress:trunkfrom
jorgefilipecosta:add/global-styles-rest-endpoints

Conversation

@jorgefilipecosta
Copy link
Copy Markdown
Member

@jorgefilipecosta jorgefilipecosta commented Nov 5, 2021

Testing

With the tt1 block's theme active.
I opened the post editor, and then opened the browser console and execute the following commands:

User endpoint

(await wp.apiFetch({path: 'wp/v2/themes/theme-experiments/tt1-blocks' } ))._links['wp:user-global-styles'][0].href
>> http://yah.local/wp-json/wp/v2/global-styles/33301

await wp.apiFetch({path: 'wp/v2/global-styles/33301', method: 'POST', data: { settings: { color: { palette: [ { color:'red', slug: 'red', name: 'red' } ] } } } } );

 JSON.stringify( await wp.apiFetch({path: 'wp/v2/global-styles/33301'} ) );

>> '{"id":33301,"settings":{"color":{"palette":[{"color":"red","slug":"red","name":"red"}]}},"styles":{},"title":{"raw":"Custom Styles","rendered":"Custom Styles"},"_links":{"self":[{"href":"http://yah.local/wp-json/wp/v2/global-styles/"}],"collection":[{"href":"http://yah.local/wp-json/wp/v2/global-styles"}],"wp:action-publish":[{"href":"http://yah.local/wp-json/wp/v2/global-styles/"}],"curies":[{"name":"wp","href":"https://api.w.org/{rel}","templated":true}]}}'

await wp.apiFetch({path: 'wp/v2/global-styles/33301', method: 'POST', data: { styles: { color: { background: 'green' }  } } } );

JSON.stringify( await wp.apiFetch({path: 'wp/v2/global-styles/33301'} ) );

{"id":33301,"settings":{"color":{"palette":[{"color":"red","slug":"red","name":"red"}]}},"styles":{"color":{"background":"green"}},"title":{"raw":"Custom Styles","rendered":"Custom Styles"},"_links":{"self":[{"href":"http://yah.local/wp-json/wp/v2/global-styles/"}],"collection":[{"href":"http://yah.local/wp-json/wp/v2/global-styles"}],"wp:action-publish":[{"href":"http://yah.local/wp-json/wp/v2/global-styles/"}],"curies":[{"name":"wp","href":"https://api.w.org/{rel}","templated":true}]}}

await wp.apiFetch({path: 'wp/v2/global-styles/33301', method: 'POST', data: { styles: { color: { gradient: 'linear-gradient(135deg,rgb(255,0,0) 0%,rgb(0,0,255) 100%)' }  } } } );

Theme endpoint

(await wp.apiFetch({path: 'wp/v2/global-styles/themes/theme-experiments/tt1-blocks' } ) );
>> { settings ..., styles ... }

@jorgefilipecosta jorgefilipecosta force-pushed the add/global-styles-rest-endpoints branch 9 times, most recently from 0140996 to 479afc0 Compare November 6, 2021 00:13
Copy link
Copy Markdown
Member

@oandregal oandregal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This worked as advertised.

For testing the theme I've used the TwentyTwentyOne theme with the theme.json described in this other PR #1808 I couldn't get tt1-blocks to work without the Gutenberg plugin active.

(await wp.apiFetch({path: 'wp/v2/global-styles/themes/twentytwentyone' } ) );

As for the code, I've noticed we're missing @since 5.9 tags. It also needs rebasing from #1808

@jorgefilipecosta jorgefilipecosta force-pushed the add/global-styles-rest-endpoints branch from 479afc0 to 6e541f9 Compare November 8, 2021 19:37
@jorgefilipecosta jorgefilipecosta changed the base branch from master to trunk November 8, 2021 19:37
@jorgefilipecosta jorgefilipecosta force-pushed the add/global-styles-rest-endpoints branch from 6e541f9 to 0baea5b Compare November 8, 2021 20:38
@jorgefilipecosta
Copy link
Copy Markdown
Member Author

Thank you for the review @oandregal it was committed in 5ca3347.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants