WordPress.org

Make WordPress Core

Opened 10 days ago

Last modified 2 days ago

#48798 new enhancement

REST API: Expose editor-color-palette theme support in /themes endpoint

Reported by: koke Owned by:
Milestone: 5.4 Priority: normal
Severity: normal Version: 5.0
Component: REST API Keywords: has-patch
Focuses: rest-api Cc:
PR Number:

Description

In #45016, a new /themes endpoint was created to expose some of the supported theme features.

As part of the work in bringing in more features to gutenberg-mobile we'll need to access the color palette defined by themes. We are running across this in the Button block but I imagine it will start coming up in more places.

As a secondary issue, we currently don't have any supported method for authentication in the apps (waiting for basic auth in #42790 or the efforts in WP-API/authentication to materialize). I'm wondering if it would be OK to expose those settings to unauthenticated requests, since it doesn't seem like sensitive information, and it's likely publicly available somewhere in the theme's CSS.

Attachments (2)

48799-1.diff (4.8 KB) - added by koke 10 days ago.
Adds editor-color-palette to themes endpoint, with unit tests
48799-2.diff (10.3 KB) - added by koke 7 days ago.
Exposes editor-color-palette, editor-font-sizes, disable-custom-colors, disable-custom-font-sizes

Download all attachments as: .zip

Change History (11)

@koke
10 days ago

Adds editor-color-palette to themes endpoint, with unit tests

#1 @koke
10 days ago

  • Keywords has-patch added

#2 @spacedmonkey
10 days ago

  • Version set to 5.0

Thanks for your ticket @koke

Can I recommend also adding some extra fields as well.

editor-font-sizes
disable-custom-colors
disable-custom-font-sizes

All of which are used by the editor.

I would also look at editor-gradient-presets and disable-custom-gradients

#3 @koke
10 days ago

@spacedmonkey good call, we'll certainly need the gradients soon enough. I don't think we'll use any custom fonts on mobile for now, but it seems like a good idea to include those.

I'm wondering if it would be better to keep the patch small and add those later, or if it's best to add them all at once.

#4 @SergeyBiryukov
10 days ago

  • Milestone changed from Awaiting Review to 5.4

#5 @spacedmonkey
10 days ago

I think that editor-gradient-presets and disable-custom-gradients should wait until these are in core. They are still in the gutenberg plugin and being tested.

As for the other fields, I don't see why not to add them here. Save code review later.

#6 @koke
7 days ago

I've sent a PR with an override on Gutenberg for the editor-gradient-presets, I can't find any references to disable-custom-gradients. https://github.com/WordPress/gutenberg/pull/18822

#7 @spacedmonkey
7 days ago

disable-custom-gradients can be found here

@koke
7 days ago

Exposes editor-color-palette, editor-font-sizes, disable-custom-colors, disable-custom-font-sizes

#8 @koke
7 days ago

Added an updated patch, here's the API output for quick reference:

$ http -ba admin:password http://localhost:8889/wp-json/wp/v2/themes status==active
[
    {
        "theme_supports": {
            "disable-custom-colors": false,
            "disable-custom-font-sizes": false,
            "editor-color-palette": [
                {
                    "color": "#cd2653",
                    "name": "Accent Color",
                    "slug": "accent"
                },
                {
                    "color": "#000000",
                    "name": "Primary",
                    "slug": "primary"
                },
                {
                    "color": "#6d6d6d",
                    "name": "Secondary",
                    "slug": "secondary"
                },
                {
                    "color": "#dcd7ca",
                    "name": "Subtle Background",
                    "slug": "subtle-background"
                },
                {
                    "color": "#f5efe0",
                    "name": "Background Color",
                    "slug": "background"
                }
            ],
            "editor-font-sizes": [
                {
                    "name": "Small",
                    "shortName": "S",
                    "size": 18,
                    "slug": "small"
                },
                {
                    "name": "Regular",
                    "shortName": "M",
                    "size": 21,
                    "slug": "normal"
                },
                {
                    "name": "Large",
                    "shortName": "L",
                    "size": 26.25,
                    "slug": "large"
                },
                {
                    "name": "Larger",
                    "shortName": "XL",
                    "size": 32,
                    "slug": "larger"
                }
            ],
            "formats": [
                "standard"
            ],
            "post-thumbnails": true,
            "responsive-embeds": false
        }
    }
]

It looks like twenty nineteen adds a shortName field when registering the font sizes, which is not part of the schema. I'm not sure if I should filter the output to only those properties defined in the schema or it's fine to leave that in the response.

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


2 days ago

Note: See TracTickets for help on using tickets.