Make WordPress Core

Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#42465 closed enhancement (duplicate)

Add `permalink_structure` to REST API general site data

Reported by: schlessera's profile schlessera Owned by: pento's profile pento
Milestone: Priority: normal
Severity: normal Version:
Component: REST API Keywords:
Focuses: rest-api Cc:


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:

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 7 years ago.
Addition of permalink_structure to wp-json, with changes to test files as required

Download all attachments as: .zip

Change History (11)

7 years ago

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

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

#3 @pento
7 years 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
6 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 @enrico.sorcinelli
6 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 @azaozz
6 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.

#7 @danielbachhuber
6 years ago

Given Gutenberg ended up using a different implementation and that permalink_structure is a setting, I think r42142 should be reverted. It's not necessary at this time.

#8 @pento
6 years ago

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

In 42997:

REST API: Remove permalink_structure from the index.

This was originally added to allow Gutenberg to do permalink editing, but is no longer required. It's also superceded by #41014.

Reverts [42142].
Fixes #42465.

#9 @pento
6 years ago

  • Resolution changed from fixed to duplicate

Duplicate of #41014.

#10 @pento
6 years ago

  • Keywords needs-patch removed
  • Milestone 5.0 deleted
Note: See TracTickets for help on using tickets.