REST API: Add activate themes endpoint#70847
REST API: Add activate themes endpoint#70847xavier-lc wants to merge 8 commits intoWordPress:trunkfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @xavier.lozano.carreras@a8c.com, @xavier-lc. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @xavier-lc! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
|
There is already a PR for this - #41836 |
@spacedmonkey thanks for pointing it out, I wasn't aware of it. The activate action is done there with the Is there any chance of that PR getting merged, given that it's from 3 years ago? Thanks! |
| public function activate_theme( WP_REST_Request $request ) { | ||
| $theme = wp_get_theme( $request['stylesheet'] ); | ||
|
|
||
| switch_theme( $theme->get_stylesheet() ); |
There was a problem hiding this comment.
If the theme requirements are not met switch_theme can call wp_die.
Maybe its good to handle this scenario. WDYT?
There was a problem hiding this comment.
I've checked and wp_die takes care of that. It gets into the wp_is_json_request() clause
And then the API returns this: {code: "wp_die", message: $message, data: {status: 500}, additional_errors: []} where $message is the wp_die param.
https://core.trac.wordpress.org/ticket/63739
What?
This PR adds the
/themes/activateendpoint.Why?
In order to be able to activate themes via REST API.
How?
The API validation follows the same logic currently used on wp-admin:
https://github.com/WordPress/wordpress-develop/blob/8a3c793e08e4374b3176424a3fece9d0906f4c6c/src/wp-admin/themes.php#L20-L35
Testing Instructions
npm run dev{ "message": "Theme activated successfully.", "theme": "twentyfifteen" }twentyfifteenTesting Instructions for Keyboard
Screenshots or screencast