WordPress.org

Make WordPress Core

Opened 20 months ago

Closed 20 months ago

Last modified 20 months ago

#38610 closed defect (bug) (fixed)

Set `format` enum based on the post formats registered to the theme

Reported by: danielbachhuber Owned by: rmccue
Milestone: 4.7 Priority: normal
Severity: normal Version:
Component: REST API Keywords: needs-unit-tests has-patch
Focuses: Cc:

Description

In the Post schema, we're registering the enum based on get_post_format_slugs(), which returns all slugs, not those specific to the theme.

Instead, we should make sure the enum is specific to the post formats supported by the theme.

Attachments (1)

38610.diff (701 bytes) - added by rmccue 20 months ago.

Download all attachments as: .zip

Change History (6)

#1 @rmccue
20 months ago

  • Owner set to rmccue
  • Status changed from new to assigned

We can use get_theme_support( 'post-formats' ) here, which does an array_intersect with get_post_format_slugs internally.

@rmccue
20 months ago

#2 @rmccue
20 months ago

  • Keywords has-patch added; needs-patch removed

Attached patch that uses get_theme_support - we know it's going to be truthy, as has_theme_support is checked in the loop above.

Unsure how best to unit test this.

#3 @rmccue
20 months ago

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

In 39084:

REST API: Only expose formats supported by the current theme.

While it's valid to save any format to the database, and WordPress is totally fine with that, we should only include the formats specified by the theme in the schema.

Props danielbachhuber.
Fixes #38610.

#4 @nerrad
20 months ago

I have some questions about this commit because it seems to mean that themes are informing the data that gets returned via the api. However, I might be misunderstanding what got changed here.

If I'm understanding correctly, with this change, it means that the schema will only return the enum values for post formats that are registered by the active theme on a site (regardless of what post format slugs may be in the database).

Does this mean that any validation of rest request queries against post_format only allow these slugs?

Are clients still able to discover all post_formats available on a WP site (regardless) of what the theme has registered?

If clients want to utilize post_formats for how the client is displaying the data, are they still able to POST and GET any custom formats that are _not_ registered by the active theme on the WordPress site?

#5 @joehoyle
20 months ago

@nerrad so, the theme is dictating what post formats you can create, this was done to reflect the WordPress admin, where you can't create a post of a format that your theme does not support.

This change basically means different wordpress sites will have different formats available (depending on what theme they have activated).

Note: See TracTickets for help on using tickets.