WordPress.org

Make WordPress Core

Opened 5 months ago

Last modified 2 months ago

#41014 new enhancement

Add `permalink_structure` to REST API settings endpoint

Reported by: aduth Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9
Component: REST API Keywords: has-patch
Focuses: rest-api Cc:

Description

Related: #38490

It is not currently possible to view or edit the permalink_structure option from the REST API. 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.

See: https://github.com/WordPress/WordPress/blob/9fb2e79/wp-admin/includes/post.php#L1323-L1324

This is relevant for the Gutenberg post editor reimplementation, where effort is blocked by unavailability of this setting from the REST API:

https://github.com/WordPress/gutenberg/pull/1042

A workaround may be to include the option in a server-rendered initialized (localized) JavaScript object, but (a) this is not available to clients which may intend to recreate this experience totally separated from the WordPress PHP environment and (b) is inconsistent with the expectation that settings should be manageable from the REST API (given the presence of the settings endpoint).

Caveats:

  • There is validation that is meant to occur in sanitize_option that tests whether the incoming permalink_structure includes a "structure tag". This feels like something that should be baked into the settings endpoint behavior (calling sanitize_option), and isn't entirely relevant to the changes proposed here.
  • Other permalink settings (category_base, tag_base) may be useful to include, but aren't part of the changes proposed here. I'm not sure the criteria with which settings are decided to be included on this endpoint. To me, it seems anything manageable through the Settings section of the admin dashboard should also be surfaced through these endpoints.

https://github.com/WordPress/WordPress/blob/9fb2e79/wp-includes/formatting.php#L4030-L4294

Attachments (1)

41014.diff (1.0 KB) - added by aduth 5 months ago.

Download all attachments as: .zip

Change History (8)

@aduth
5 months ago

#1 @aduth
5 months ago

  • Keywords has-patch added

#2 @jnylen0
5 months ago

Unfortunately the settings endpoint is currently restricted to administrators (current_user_can( 'manage_options' )) which makes it unsuitable for this use case. See also #38731, #39854.

#3 follow-up: @aduth
5 months ago

Why would it be unsuitable if that's the same capability checked on the equivalent admin screen?

https://github.com/WordPress/WordPress/blob/f28f4fc/wp-admin/options-permalink.php#L12-L13

Even if it were unsuitable, what is the proposed workaround?

#4 in reply to: ↑ 3 @jnylen0
5 months ago

Replying to aduth:

Why would it be unsuitable if that's the same capability checked on the equivalent admin screen?

Because users without manage_options would not be able to read the value of this setting, which they need to do in order to see a correct permalink.

what is the proposed workaround?

A couple of options discussed at #38731 (add better permissions capabilities to the settings endpoint, or add read-only "site info" to /wp-json instead, like we did for gmt_offset).

This ticket was mentioned in Slack in #core by aduth. View the logs.


5 months ago

#6 @timmydcrawford
5 months ago

Another item to consider here, in the context of permalinks + editor - is my old favorite the auto slug. Not certain if the suggested slug is built in to the REST API or not yet. Sorry for the issue creep, but the issue brought back fond slug memories :)

This ticket was mentioned in Slack in #core-restapi by aduth. View the logs.


2 months ago

Note: See TracTickets for help on using tickets.