Commit Graph

23 Commits

Author SHA1 Message Date
spacedmonkey
16dfb05173 REST API: Avoid unnecessarily preparing item links.
Do not call the `prepare_links` methods in core REST API controllers, unless the `_links` or `_embedded` fields are requested. There is no need to prepare links if they are never returned in the response. This saves resources, as many calls to `prepare_links` methods perform database queries. 

Props Spacedmonkey, timothyblynjacobs, rachelbaker, desrosj, dlh, hellofromTonya.
Fixes #52992.
Built from https://develop.svn.wordpress.org/trunk@53760


git-svn-id: http://core.svn.wordpress.org/trunk@53319 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-07-22 14:00:12 +00:00
Sergey Biryukov
d09d194f12 Docs: Capitalize "ID", when referring to a widget ID or sidebar ID, in a more consistent way.
Follow-up to [48104], [52357], [52361].

See #53399.
Built from https://develop.svn.wordpress.org/trunk@52362


git-svn-id: http://core.svn.wordpress.org/trunk@51954 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-12-13 10:21:07 +00:00
John Blackbourn
c9746ab584 Docs: Various corrections and improvements relating to types used in inline documentation.
See #53399

Built from https://develop.svn.wordpress.org/trunk@52204


git-svn-id: http://core.svn.wordpress.org/trunk@51796 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-18 13:50:05 +00:00
TimothyBlynJacobs
84dae82fd3 REST API: Add batch support for posts and terms controllers.
This also exposes the value of `allow_batch` in `OPTIONS` requests to a route.

A future commit will add batch support to more resources.

Props spacedmonkey, chrisvanpatten.
See #53063.

Built from https://develop.svn.wordpress.org/trunk@52068


git-svn-id: http://core.svn.wordpress.org/trunk@51660 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-09 01:59:02 +00:00
TimothyBlynJacobs
04a853195b REST API: Allow sidebars and their widgets to be public.
By default, only users with the `edit_theme_options` capability can access the sidebars and widgets REST API endpoints. In this commit, A new `show_in_rest` parameter is added to the `register_sidebar` function. When enabled, all users will be able to access that sidebar and any widgets belonging to that sidebar.

This commit reduces the `context` for a widget's `instance` information to only `edit`. This is to ensure that internal widget data is not inadvertently exposed to the public. A future ticket may expose additional APIs to allow widget authors to indicate that their instance data can be safely exposed. REST API consumers intending to access this `instance` information should take care to explicitly set the `context` parameter to `edit`.

Props spacedmonkey, zieladam.
Fixes #53915.

Built from https://develop.svn.wordpress.org/trunk@52016


git-svn-id: http://core.svn.wordpress.org/trunk@51608 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-05 02:15:59 +00:00
hellofromTonya
07139653b9 Widgets: Revert [51705].
While the new name is much better, it doesn't fully tell what will happen when invoked nor does it fully solve the root problems. 

Why? The function is doing too much. And naming is hard.

Props azaozz, desrosj, andraganescu, zieladam, hellofromTonya.
See #53811.
Built from https://develop.svn.wordpress.org/trunk@51791


git-svn-id: http://core.svn.wordpress.org/trunk@51398 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-09 21:40:57 +00:00
hellofromTonya
71977c215d Widgets: Rename and soft deprecate retrieve_widgets().
The original name `retrieve_widgets()` was unclear as it suggested it was a getter, i.e. getting the widgets. This function does more than get: finds orphaned widgets, assigns them to the inactive sidebar, and updates the database.

The new name is `sync_registered_widgets()` which better represents what happens when this function is invoked.

The original `retrieve_widgets()` function is soft deprecated to avoid unnecessary code churn downstream for developers that support more than the latest version of WordPress.

Follow-up to [18630].

Props zieladam, timothyblynjacobs, andraganescu, hellofromTonya.
See #53811.
Built from https://develop.svn.wordpress.org/trunk@51705


git-svn-id: http://core.svn.wordpress.org/trunk@51311 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-08-31 19:58:58 +00:00
hellofromTonya
c7d3e267b8 Coding Standards: Use static closures when not using $this.
When a closure does not use `$this`, it can be made `static` for improved performance.

Static closures are supported in PHP since PHP 5.4. ​

Props jrf, hellofromTonya, swissspidy, SergeyBiryukov.
See #53359.
Built from https://develop.svn.wordpress.org/trunk@51657


git-svn-id: http://core.svn.wordpress.org/trunk@51263 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-08-26 12:59:02 +00:00
desrosj
88309aa27e Widgets: Prevent widgets unintentionally being moved to the inactive sidebar.
This fixes a bug where widgets are unintentionally moved to the `wp_inactive_widgets` sidebar when batch updates occur through the REST API.

When batch requests are processed, only `$_wp_sidebars_widgets is updated by previous calls to `WP_REST_Widgets_Controller::create_item()`. `$sidebars_widgets` is not aware of the new widget’s intended location, and `retrieve_widgets()` mistakenly flags the widget as inactive.

Calling `wp_get_sidebars_widgets()` before `retrieve_widgets()` ensures both global variables match and is intended as a temporary fix until the root cause of the problem can be fixed.

Props zieladam, htmgarcia, timothyblynjacobs.
Fixes #53657.
Built from https://develop.svn.wordpress.org/trunk@51432


git-svn-id: http://core.svn.wordpress.org/trunk@51043 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-07-14 16:45:58 +00:00
desrosj
1dcad8f5bb REST API: Add the $request parameter to methods checking permissions.
This adds the `$request` parameter to the `permissions_check()` methods within `WP_REST_Widgets_Controller` and adds `$request` as an allowed parameter to the `permissions_check()` method within `WP_REST_Templates_Controller`.

Even when this parameter is not used by default, it should be implemented to support the class being extended and the method overidden.

Props johnbillion, timothyblynjacobs.
Fixes #53593.
Built from https://develop.svn.wordpress.org/trunk@51349


git-svn-id: http://core.svn.wordpress.org/trunk@50958 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-07-06 15:43:00 +00:00
Sergey Biryukov
1b749d971a Docs: Remove an empty line between @param and @return tags in some newly added REST API methods, per the documentation standards.
Follow-up to [48242], [49925], [51003], [51021].

See #52628, #53461.
Built from https://develop.svn.wordpress.org/trunk@51289


git-svn-id: http://core.svn.wordpress.org/trunk@50898 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-06-30 18:43:58 +00:00
Sergey Biryukov
a2f00a677c Docs: Document the globals used in WP_REST_Widget_Types_Controller and WP_REST_Widgets_Controller.
Follow-up to [50995].

See #52628, #53461.
Built from https://develop.svn.wordpress.org/trunk@51279


git-svn-id: http://core.svn.wordpress.org/trunk@50888 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-06-30 12:55:57 +00:00
Sergey Biryukov
ffafbefc36 REST API: Allow multiple widgets to be deleted in a single batch request.
This resets the `WP_Widget::$updated` flag when deleting a widget, to avoid blocking all future updates in a request.

Props noisysocks, andraganescu.
Fixes #53557.
Built from https://develop.svn.wordpress.org/trunk@51277


git-svn-id: http://core.svn.wordpress.org/trunk@50886 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-06-30 10:41:58 +00:00
noisysocks
7131a90b0a Widgets REST API: Fix non-multi widgets not appearing in wp_inactive_widgets
Registered widgets that do not extend WP_Widget should appear in the
wp_inactive_widgets sidebar by default. Having the widgets REST API call
retrieve_widgets() before serving any request ensures that this will happen.

This is a similar fix to [51235].

Fixes #53534.
Props zieladam, timothyblynjacobs.

Built from https://develop.svn.wordpress.org/trunk@51248


git-svn-id: http://core.svn.wordpress.org/trunk@50857 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-06-28 04:34:57 +00:00
desrosj
49a6a14915 REST API: Include the sidebar ID when saving a widget.
This ensures backwards compatibility for code expecting this field to be present.

Props strategio, noisysocks, spacedmonkey.
See #53452.
Built from https://develop.svn.wordpress.org/trunk@51239


git-svn-id: http://core.svn.wordpress.org/trunk@50848 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-06-25 15:25:59 +00:00
Sergey Biryukov
47231831f7 REST API: Restore the $creating parameter of rest_after_save_widget action.
This is consistent with other similar REST API actions.

Partially reverts [51071], except for DocBlock formatting fixes.

Props TimothyBlynJacobs.
See #53317.
Built from https://develop.svn.wordpress.org/trunk@51074


git-svn-id: http://core.svn.wordpress.org/trunk@50683 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-06-04 23:13:59 +00:00
Sergey Biryukov
36cf03ca52 REST API: Rename the $creating parameter of rest_after_save_widget action to $update.
This brings some consistency with similar actions for posts, e.g. `save_post` or `wp_insert_post`.

Follow-up to [51068], [51069].

See #53317.
Built from https://develop.svn.wordpress.org/trunk@51071


git-svn-id: http://core.svn.wordpress.org/trunk@50680 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-06-04 10:48:56 +00:00
noisysocks
222541d7c3 REST API: Delete fresh_site option when updating widgets via REST API
Adds new hooks (rest_save_sidebar, rest_delete_widget, rest_after_save_widget)
to the widgets REST API and uses them to delete the fresh_site option when
updating widgets via the REST API. This ensures that starter content isn't
loaded in the Customizer after a user makes changes.

Fixes #53317.
Props kevin940726, garrett-eclipse, andraganescu, hellofromtonya.

Built from https://develop.svn.wordpress.org/trunk@51068


git-svn-id: http://core.svn.wordpress.org/trunk@50677 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-06-04 00:45:56 +00:00
noisysocks
5162c8e6a8 REST API: Add 'delete_widget' action to delete widget endpoint
Triggers the 'delete_widget' action to the delete widget endpoint in the REST
API. This aligns with the behaviour in the widgets WP Admin screen.

Fixes #53289.
Props isabel_brison, TimothyBlynJacobs.

Built from https://develop.svn.wordpress.org/trunk@51060


git-svn-id: http://core.svn.wordpress.org/trunk@50669 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-06-02 01:40:57 +00:00
noisysocks
2fd3f23408 REST API: Fix delete widget endpoint
Makes the `DELETE /wp/v2/widgets/:id?force=1` endpoint actually delete the
widget from the `"widget-$id_base"` option and not just remove it from
`'sidebars_widgets'`.

Fixes #53313.
Props TimothyBlynJacobs.

Built from https://develop.svn.wordpress.org/trunk@51059


git-svn-id: http://core.svn.wordpress.org/trunk@50668 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-06-02 01:22:57 +00:00
noisysocks
1314542c50 REST API: Add widget endpoints
Adds the sidebars, widgets and widget-types REST API endpoints from the
Gutenberg plugin.

Fixes #41683.
Props TimothyBlynJacobs, spacedmonkey, zieladam, jorgefilipecosta, youknowriad, kevin940726.

Built from https://develop.svn.wordpress.org/trunk@50995


git-svn-id: http://core.svn.wordpress.org/trunk@50604 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-05-25 08:27:57 +00:00
noisysocks
ed195fbd89 REST API: Revert widget endpoints
Reverts [50993] as it has missing props.

Reverts [50993].
See #41683.

Built from https://develop.svn.wordpress.org/trunk@50994


git-svn-id: http://core.svn.wordpress.org/trunk@50603 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-05-25 08:22:56 +00:00
noisysocks
2a4e1e0c04 REST API: Add widget endpoints
Adds the sidebars, widgets and widget-types REST API endpoints from the
Gutenberg plugin.

Fixes #41683.
Props TimothyBlynJacobs.

Built from https://develop.svn.wordpress.org/trunk@50993


git-svn-id: http://core.svn.wordpress.org/trunk@50602 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-05-25 07:52:55 +00:00