WordPress.org

Make WordPress Core

Opened 6 weeks ago

Last modified 3 days ago

#42465 reopened enhancement

Add `permalink_structure` to REST API general site data

Reported by: schlessera Owned by: pento
Milestone: 5.0 Priority: normal
Severity: normal Version:
Component: REST API Keywords: needs-patch
Focuses: rest-api Cc:

Description

Related: #41014 , #38731

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:

  1. Add it directly to the $available array in WP_Rest_Server::get_index().
  2. 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)

42465.diff (2.6 KB) - added by schlessera 6 weeks ago.
Addition of permalink_structure to wp-json, with changes to test files as required

Download all attachments as: .zip

Change History (6)

@schlessera
6 weeks ago

Addition of permalink_structure to wp-json, with changes to test files as required

#1 @pento
5 weeks 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 @pento
5 weeks 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.

#3 @pento
5 weeks ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 42142:

REST API: Add permalink_structure to the index endpoint.

This allows Gutenberg to implement permalink editing.

Props schlessera.
Fixes #42465.

#4 @johnbillion
3 days 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 @enrico.sorcinelli
3 days 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.

Note: See TracTickets for help on using tickets.