#42465 closed enhancement (duplicate)
Add `permalink_structure` to REST API general site data
Reported by: | schlessera | Owned by: | pento |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | REST API | Keywords: | |
Focuses: | rest-api | Cc: |
Description
As already stated in the above ticket, it is not currently possible to view or edit the permalink_structure
option from the REST API, and this makes it difficult to reimplement a post editor leveraging the REST API because the "slug" field is only applicable for sites configured to include %postname%
in this option's value.
One current use case of this is the Permalink setting in the Gutenberg editing screen: https://github.com/WordPress/gutenberg/issues/1285
Previous discussions in the above related tickets concluded that the best way forward is to add required general site information to the wp-json
root.
Although the idea was to discuss a list of values that would be sensible to add because they might be needed, I think it would be more pragmatic to add values as specific use cases pop up. Otherwise, we might end up discussing a potential list for months, and still end up with useless as well as missing values.
The current code allows for two different ways to add the permalink_structure
:
- Add it directly to the
$available
array inWP_Rest_Server::get_index()
. - Add it through the
'rest_index'
filter, which could just as well be done in the Gutenberg code instead.
In this specific case, I'd argue that permalink_structure
is useful for any client-side code that deals with permalinks, so it might be best to have it generally be available, even outside of the Gutenberg project.
Attachments (1)
Change History (11)
#1
@
7 years ago
- Keywords has-patch has-unit-tests added
- Milestone changed from Awaiting Review to 5.0
- Owner set to pento
- Status changed from new to assigned
#2
@
7 years ago
I'm inclined to agree that the most pragmatic way forward is to add permalink_structure
to the index.
I'm fine with the treating this as "we may end up breaking back compat between 5.0 alpha versions", if we add several such options and decide it would be better to group them into a single endpoint in a few months.
#4
@
7 years ago
- Keywords needs-patch added; has-patch has-unit-tests removed
- Resolution fixed deleted
- Status changed from closed to reopened
This change is causing a dirty wp-api-generated.js
file when running tests. Similar issue previously: #41123.
#5
@
7 years ago
As a definitive solutions, is it possible for the PHPUnit test to save the changes to an untracked file and/or untrack tests/qunit/fixtures/wp-api-generated.js and generate it anyway from tests?
The QUnit tests depend on wp-api-generated.js, so, this way we need to run PHP tests first.
#6
@
7 years ago
I'd argue that
permalink_structure
is useful for any client-side code that deals with permalinks
I'd (partially) disagree :)
The permalink_structure
alone cannot be used to generate a permalink, see wp_unique_post_slug()
. It can only be used to check if the default structure has been changed, which perhaps could be useful in some rare cases.
Addition of
permalink_structure
towp-json
, with changes to test files as required