From 192abb78e4afe8ea3b63a5394efa922fb06ad2aa Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Wed, 4 Nov 2026 14:38:13 +0530 Subject: [PATCH 1/4] Improve design guide defaults and schema descriptions --- inc/abilities.php | 384 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 296 insertions(+), 88 deletions(-) diff --git a/inc/abilities.php b/inc/abilities.php index 8f5875e..9b82ce5 100644 --- a/inc/abilities.php +++ b/inc/abilities.php @@ -27,18 +27,19 @@ function ipsum_register_abilities() { 'ipsum/get-design-guide', array( 'label' => __( 'Get Design Guide', 'ipsum' ), - 'description' => __( 'Returns the design guide of the Ipsum theme, read from the site as it is now: the color palette and what each color is for, whether it is light or dark, fonts, font sizes, spacing, layout widths, style variations, block styles, patterns, and the templates and template parts with the pattern that fills each. Read it before building pages, templates or styles. Pass fields to get only some sections.', 'ipsum' ), + 'description' => __( 'Returns the design guide of the Ipsum theme, read from the site as it is now. By default returns the basic design sections: the active theme, whether the palette is light or dark, the color palette and what each color is for, gradients, duotone, typography, spacing, layout widths, and guidelines. Pass fields to request specific sections, including larger lists such as style variations, block styles, patterns, templates, template parts, and template part areas. Read it before building pages, templates or styles.', 'ipsum' ), 'category' => 'site', 'input_schema' => array( 'type' => 'object', 'properties' => array( 'fields' => array( 'type' => 'array', + 'title' => __( 'Fields', 'ipsum' ), + 'description' => __( 'Optional. Sections to return. When omitted or empty, returns the basic design sections (theme, colorScheme, colors, gradients, duotone, typography, spacing, layout, guidelines). When set, returns only the listed sections. Every section name in the enum is valid, including larger lists such as patterns, templates, template parts, template part areas, block styles, and style variations.', 'ipsum' ), 'items' => array( 'type' => 'string', 'enum' => array_keys( $output_schema['properties'] ), ), - 'description' => __( 'Optional. Limits the guide to these sections. All sections are returned when it is omitted.', 'ipsum' ), ), ), 'additionalProperties' => false, @@ -84,164 +85,367 @@ function ipsum_get_color_roles() { } endif; +if ( ! function_exists( 'ipsum_get_design_guide_default_fields' ) ) : + /** + * Returns the design guide sections included when fields is omitted or empty. + * + * Larger lists (style variations, block styles, patterns, templates, + * template parts, and template part areas) are left out of the default + * response and must be requested through fields. + * + * @since Ipsum 1.0 + * + * @return string[] Section names. + */ + function ipsum_get_design_guide_default_fields() { + return array( + 'theme', + 'colorScheme', + 'colors', + 'gradients', + 'duotone', + 'typography', + 'spacing', + 'layout', + 'guidelines', + ); + } +endif; + if ( ! function_exists( 'ipsum_get_design_guide_schema' ) ) : /** * Returns the JSON Schema of the design guide, with one property per section. * + * Top-level sections stay optional so callers can request a subset. Nested + * objects with a fixed set of fields mark guaranteed properties as required + * and set additionalProperties to false. + * * @since Ipsum 1.0 * * @return array The output schema of the design guide ability. */ function ipsum_get_design_guide_schema() { - $string = array( 'type' => 'string' ); - $nullable = array( 'type' => array( 'string', 'null' ) ); - $strings = array( + $string = array( 'type' => 'string' ); + $nullable = array( + 'type' => array( 'string', 'null' ), + 'description' => __( 'A font family preset slug, a literal font-family value, or null when unset.', 'ipsum' ), + ); + $strings = array( 'type' => 'array', 'items' => $string, ); - $scheme = array( - 'type' => 'string', - 'enum' => array( 'light', 'dark' ), + $scheme = array( + 'type' => 'string', + 'title' => __( 'Color Scheme', 'ipsum' ), + 'description' => __( 'Whether the palette is light or dark.', 'ipsum' ), + 'enum' => array( 'light', 'dark' ), ); - $object_list = static function ( $description, $properties ) { + + $object_list = static function ( $title, $description, $properties, $required = array() ) { + $items = array( + 'type' => 'object', + 'properties' => $properties, + 'additionalProperties' => false, + ); + if ( ! empty( $required ) ) { + $items['required'] = $required; + } return array( 'type' => 'array', + 'title' => $title, 'description' => $description, - 'items' => array( - 'type' => 'object', - 'properties' => $properties, - ), + 'items' => $items, ); }; - $preset_list = static function ( $description, $value_key, $value_schema ) use ( $object_list, $string ) { - return $object_list( - $description, + + $titled = static function ( $title, $description = '' ) use ( $string ) { + $schema = array_merge( $string, array( 'title' => $title ) ); + if ( '' !== $description ) { + $schema['description'] = $description; + } + return $schema; + }; + + $preset_list = static function ( $title, $description, $value_key, $value_schema, $extra_properties = array() ) use ( $object_list, $titled ) { + $properties = array_merge( array( - 'slug' => $string, - 'name' => $string, + 'slug' => $titled( __( 'Slug', 'ipsum' ), __( 'The preset slug.', 'ipsum' ) ), + 'name' => $titled( __( 'Name', 'ipsum' ), __( 'The human-readable preset name.', 'ipsum' ) ), $value_key => $value_schema, - ) + ), + $extra_properties ); + return $object_list( $title, $description, $properties, array( 'slug', 'name', $value_key ) ); }; - $colors = $preset_list( __( 'The color palette, with what each color is for. Every style variation redefines the same slugs. Colors added on the site have no role.', 'ipsum' ), 'color', $string ); + $colors = $preset_list( + __( 'Colors', 'ipsum' ), + __( 'The color palette from the theme and any colors added on the site, with what each theme color is for. Every style variation redefines the same slugs. The role field is omitted for colors that have no known role.', 'ipsum' ), + 'color', + $titled( __( 'Color', 'ipsum' ), __( 'The CSS color value.', 'ipsum' ) ), + array( + 'role' => array( + 'type' => 'string', + 'title' => __( 'Role', 'ipsum' ), + 'description' => __( 'What the color is for. Present only for theme palette colors with a known role.', 'ipsum' ), + ), + ) + ); - $colors['items']['properties']['role'] = $string; + $font_value = array( + 'type' => array( 'string', 'null' ), + 'description' => __( 'A font family preset slug, a literal font-family value, or null when unset. headingFont falls back to bodyFont when headings do not set their own family.', 'ipsum' ), + ); return array( 'type' => 'object', 'additionalProperties' => false, 'properties' => array( 'theme' => array( - 'type' => 'object', - 'description' => __( 'The active theme. Its stylesheet is the one to use in REST routes such as /wp/v2/global-styles/themes/{stylesheet}.', 'ipsum' ), - 'properties' => array( - 'name' => $string, - 'stylesheet' => $string, + 'type' => 'object', + 'title' => __( 'Theme', 'ipsum' ), + 'description' => __( 'The active theme. Its stylesheet is the one to use in REST routes such as /wp/v2/global-styles/themes/{stylesheet}.', 'ipsum' ), + 'properties' => array( + 'name' => $titled( __( 'Name', 'ipsum' ), __( 'The active theme name.', 'ipsum' ) ), + 'stylesheet' => $titled( __( 'Stylesheet', 'ipsum' ), __( 'The theme stylesheet slug.', 'ipsum' ) ), ), + 'required' => array( 'name', 'stylesheet' ), + 'additionalProperties' => false, ), 'colorScheme' => array_merge( $scheme, array( 'description' => __( 'Whether the active palette is light or dark.', 'ipsum' ) ) ), 'colors' => $colors, - 'gradients' => $preset_list( __( 'The gradient presets.', 'ipsum' ), 'gradient', $string ), - 'duotone' => $preset_list( __( 'The duotone filter presets.', 'ipsum' ), 'colors', $strings ), + 'gradients' => $preset_list( + __( 'Gradients', 'ipsum' ), + __( 'The gradient presets from the theme and any added on the site.', 'ipsum' ), + 'gradient', + $titled( __( 'Gradient', 'ipsum' ), __( 'The CSS gradient value.', 'ipsum' ) ) + ), + 'duotone' => $preset_list( + __( 'Duotone', 'ipsum' ), + __( 'The duotone filter presets from the theme and any added on the site.', 'ipsum' ), + 'colors', + array_merge( + $strings, + array( + 'title' => __( 'Colors', 'ipsum' ), + 'description' => __( 'The two colors in the duotone filter.', 'ipsum' ), + ) + ) + ), 'typography' => array( - 'type' => 'object', - 'description' => __( 'The font families of body text and headings, by slug, and the font family and font size presets.', 'ipsum' ), - 'properties' => array( - 'bodyFont' => $nullable, - 'headingFont' => $nullable, + 'type' => 'object', + 'title' => __( 'Typography', 'ipsum' ), + 'description' => __( 'The font families of body text and headings, the blocks that use another family, and the font family and font size presets. Font values are preset slugs, literal font-family values, or null. headingFont falls back to bodyFont when headings do not set their own family. Font size presets list theme sizes first, then any custom sizes; they are not sorted by size.', 'ipsum' ), + 'properties' => array( + 'bodyFont' => array_merge( + $font_value, + array( 'title' => __( 'Body Font', 'ipsum' ) ) + ), + 'headingFont' => array_merge( + $font_value, + array( 'title' => __( 'Heading Font', 'ipsum' ) ) + ), 'blockFonts' => array( 'type' => 'object', - 'description' => __( 'The blocks set in another font than body text, such as buttons, navigation and post meta, grouped by font family slug.', 'ipsum' ), + 'title' => __( 'Block Fonts', 'ipsum' ), + 'description' => __( 'The blocks set in another font than body text, such as buttons, navigation and post meta, grouped by font family slug or literal value.', 'ipsum' ), 'additionalProperties' => $strings, ), - 'fontFamilies' => $preset_list( __( 'The font family presets.', 'ipsum' ), 'fontFamily', $string ), - 'fontSizes' => $preset_list( __( 'The font size presets, smallest first.', 'ipsum' ), 'size', $string ), + 'fontFamilies' => $preset_list( + __( 'Font Families', 'ipsum' ), + __( 'The font family presets from the theme and any added on the site.', 'ipsum' ), + 'fontFamily', + $titled( __( 'Font Family', 'ipsum' ), __( 'The CSS font-family value.', 'ipsum' ) ) + ), + 'fontSizes' => $preset_list( + __( 'Font Sizes', 'ipsum' ), + __( 'The font size presets from the theme, then any custom sizes. Not sorted by size.', 'ipsum' ), + 'size', + $titled( __( 'Size', 'ipsum' ), __( 'The CSS font-size value.', 'ipsum' ) ) + ), ), + 'required' => array( 'bodyFont', 'headingFont', 'blockFonts', 'fontFamilies', 'fontSizes' ), + 'additionalProperties' => false, + ), + 'spacing' => $preset_list( + __( 'Spacing', 'ipsum' ), + __( 'The spacing scale from the theme, then any custom sizes. Not sorted by size.', 'ipsum' ), + 'size', + $titled( __( 'Size', 'ipsum' ), __( 'The CSS spacing size value.', 'ipsum' ) ) ), - 'spacing' => $preset_list( __( 'The spacing scale, smallest first.', 'ipsum' ), 'size', $string ), 'layout' => array( - 'type' => 'object', - 'description' => __( 'The width of the content, and of wide-aligned blocks.', 'ipsum' ), - 'properties' => array( - 'contentSize' => $nullable, - 'wideSize' => $nullable, + 'type' => 'object', + 'title' => __( 'Layout', 'ipsum' ), + 'description' => __( 'The width of the content, and of wide-aligned blocks.', 'ipsum' ), + 'properties' => array( + 'contentSize' => array( + 'type' => array( 'string', 'null' ), + 'title' => __( 'Content Size', 'ipsum' ), + 'description' => __( 'The default content width, or null when unset.', 'ipsum' ), + ), + 'wideSize' => array( + 'type' => array( 'string', 'null' ), + 'title' => __( 'Wide Size', 'ipsum' ), + 'description' => __( 'The wide-aligned content width, or null when unset.', 'ipsum' ), + ), ), + 'required' => array( 'contentSize', 'wideSize' ), + 'additionalProperties' => false, ), 'styleVariations' => $object_list( - __( 'The style variations. Each one lists only what it changes: colorScheme and colors for the palette, bodyFont and headingFont for the fonts, and blocks for the style properties it sets on each block. Their full data is at /wp/v2/global-styles/themes/{stylesheet}/variations.', 'ipsum' ), + __( 'Style Variations', 'ipsum' ), + __( 'The style variations available for this theme. Each item lists only what that variation changes: colorScheme and colors for the palette, bodyFont and headingFont for the fonts, and blocks for the style properties it sets on each block. Optional fields are omitted when the variation does not change them. Their full data is at /wp/v2/global-styles/themes/{stylesheet}/variations.', 'ipsum' ), array( - 'title' => $string, + 'title' => $titled( __( 'Title', 'ipsum' ), __( 'The style variation title.', 'ipsum' ) ), 'colorScheme' => $scheme, 'colors' => array( 'type' => 'object', + 'title' => __( 'Colors', 'ipsum' ), + 'description' => __( 'Palette colors the variation sets, keyed by slug.', 'ipsum' ), 'additionalProperties' => $string, ), - 'bodyFont' => $nullable, - 'headingFont' => $nullable, + 'bodyFont' => array_merge( + $nullable, + array( 'title' => __( 'Body Font', 'ipsum' ) ) + ), + 'headingFont' => array_merge( + $nullable, + array( 'title' => __( 'Heading Font', 'ipsum' ) ) + ), 'blocks' => array( 'type' => 'object', + 'title' => __( 'Blocks', 'ipsum' ), + 'description' => __( 'Style property names the variation sets on each block, keyed by block name.', 'ipsum' ), 'additionalProperties' => $strings, ), - ) + ), + array( 'title' ) ), 'blockStyles' => $object_list( + __( 'Block Styles', 'ipsum' ), __( 'The block styles registered on this site, beyond the ones blocks define themselves. Add className to a block of one of the blockTypes to apply it.', 'ipsum' ), array( - 'name' => $string, - 'label' => $string, - 'className' => $string, - 'blockTypes' => $strings, - ) + 'name' => $titled( __( 'Name', 'ipsum' ), __( 'The block style slug.', 'ipsum' ) ), + 'label' => $titled( __( 'Label', 'ipsum' ), __( 'The human-readable block style label.', 'ipsum' ) ), + 'className' => $titled( __( 'Class Name', 'ipsum' ), __( 'The CSS class to add to the block, such as is-style-outline.', 'ipsum' ) ), + 'blockTypes' => array_merge( + $strings, + array( + 'title' => __( 'Block Types', 'ipsum' ), + 'description' => __( 'The block names this style can be applied to.', 'ipsum' ), + ) + ), + ), + array( 'name', 'label', 'className', 'blockTypes' ) ), 'patterns' => $object_list( - __( 'The patterns of the theme, without their markup, which is at /wp/v2/block-patterns/patterns. Hidden patterns fill templates and template parts and are left out of the inserter.', 'ipsum' ), + __( 'Patterns', 'ipsum' ), + __( 'The patterns registered by the active theme, without their markup, which is at /wp/v2/block-patterns/patterns. Includes both insertable patterns and hidden ones that fill templates and template parts. Optional fields (blockTypes, templateTypes, postTypes) are omitted when empty.', 'ipsum' ), array( - 'slug' => $string, - 'title' => $string, - 'description' => $string, - 'categories' => $strings, - 'blockTypes' => $strings, - 'templateTypes' => $strings, - 'postTypes' => $strings, - 'hidden' => array( 'type' => 'boolean' ), - ) + 'slug' => $titled( __( 'Slug', 'ipsum' ), __( 'The pattern slug.', 'ipsum' ) ), + 'title' => $titled( __( 'Title', 'ipsum' ), __( 'The pattern title.', 'ipsum' ) ), + 'description' => $titled( __( 'Description', 'ipsum' ), __( 'The pattern description.', 'ipsum' ) ), + 'categories' => array_merge( + $strings, + array( + 'title' => __( 'Categories', 'ipsum' ), + 'description' => __( 'Pattern categories for the inserter.', 'ipsum' ), + ) + ), + 'blockTypes' => array_merge( + $strings, + array( + 'title' => __( 'Block Types', 'ipsum' ), + 'description' => __( 'Block types this pattern is associated with, such as for the block transformer. Omitted when empty.', 'ipsum' ), + ) + ), + 'templateTypes' => array_merge( + $strings, + array( + 'title' => __( 'Template Types', 'ipsum' ), + 'description' => __( 'Template types this pattern is meant to fill. Omitted when empty.', 'ipsum' ), + ) + ), + 'postTypes' => array_merge( + $strings, + array( + 'title' => __( 'Post Types', 'ipsum' ), + 'description' => __( 'Limits which post types the pattern is available for. Omitted when empty.', 'ipsum' ), + ) + ), + 'hidden' => array( + 'type' => 'boolean', + 'title' => __( 'Hidden', 'ipsum' ), + 'description' => __( 'Whether the pattern is excluded from the inserter. Hidden does not mean private; these patterns typically fill templates and template parts.', 'ipsum' ), + ), + ), + array( 'slug', 'title', 'description', 'categories', 'hidden' ) ), 'templates' => $object_list( - __( 'The templates, with the pattern that fills each. The pattern is null when a template holds its own markup, as it does once it is customized.', 'ipsum' ), + __( 'Templates', 'ipsum' ), + __( 'The block templates available on the site, including theme templates and any customized copies, with the pattern each delegates to when its markup is a single Pattern block.', 'ipsum' ), array( - 'slug' => $string, - 'title' => $string, - 'description' => $string, - 'pattern' => $nullable, - 'customized' => array( 'type' => 'boolean' ), - 'postTypes' => $strings, - ) + 'slug' => $titled( __( 'Slug', 'ipsum' ), __( 'The template slug.', 'ipsum' ) ), + 'title' => $titled( __( 'Title', 'ipsum' ), __( 'The template title.', 'ipsum' ) ), + 'description' => $titled( __( 'Description', 'ipsum' ), __( 'The template description.', 'ipsum' ) ), + 'pattern' => array( + 'type' => array( 'string', 'null' ), + 'title' => __( 'Pattern', 'ipsum' ), + 'description' => __( 'The pattern slug when the template markup is a single Pattern block, otherwise null. A customized template can still reference a pattern.', 'ipsum' ), + ), + 'customized' => array( + 'type' => 'boolean', + 'title' => __( 'Customized', 'ipsum' ), + 'description' => __( 'Whether the template has a saved customization on this site.', 'ipsum' ), + ), + 'postTypes' => array_merge( + $strings, + array( + 'title' => __( 'Post Types', 'ipsum' ), + 'description' => __( 'Post types the template applies to. Omitted when empty.', 'ipsum' ), + ) + ), + ), + array( 'slug', 'title', 'description', 'pattern', 'customized' ) ), 'templateParts' => $object_list( - __( 'The template parts, with their area and the pattern that fills each.', 'ipsum' ), + __( 'Template Parts', 'ipsum' ), + __( 'The template parts available on the site, including theme parts and any customized copies, with their area and the pattern each delegates to when its markup is a single Pattern block.', 'ipsum' ), array( - 'slug' => $string, - 'title' => $string, - 'area' => $string, - 'pattern' => $nullable, - 'customized' => array( 'type' => 'boolean' ), - ) + 'slug' => $titled( __( 'Slug', 'ipsum' ), __( 'The template part slug.', 'ipsum' ) ), + 'title' => $titled( __( 'Title', 'ipsum' ), __( 'The template part title.', 'ipsum' ) ), + 'area' => $titled( __( 'Area', 'ipsum' ), __( 'The template part area, such as header, footer, or uncategorized.', 'ipsum' ) ), + 'pattern' => array( + 'type' => array( 'string', 'null' ), + 'title' => __( 'Pattern', 'ipsum' ), + 'description' => __( 'The pattern slug when the template part markup is a single Pattern block, otherwise null. A customized template part can still reference a pattern.', 'ipsum' ), + ), + 'customized' => array( + 'type' => 'boolean', + 'title' => __( 'Customized', 'ipsum' ), + 'description' => __( 'Whether the template part has a saved customization on this site.', 'ipsum' ), + ), + ), + array( 'slug', 'title', 'area', 'pattern', 'customized' ) ), 'templatePartAreas' => $object_list( - __( 'The areas a template part can belong to.', 'ipsum' ), + __( 'Template Part Areas', 'ipsum' ), + __( 'The areas a template part can belong to on this site.', 'ipsum' ), array( - 'area' => $string, - 'label' => $string, - 'description' => $string, - ) + 'area' => $titled( __( 'Area', 'ipsum' ), __( 'The template part area slug.', 'ipsum' ) ), + 'label' => $titled( __( 'Label', 'ipsum' ), __( 'The human-readable area label.', 'ipsum' ) ), + 'description' => $titled( __( 'Description', 'ipsum' ), __( 'What the area is for.', 'ipsum' ) ), + ), + array( 'area', 'label', 'description' ) ), - 'guidelines' => array_merge( - $strings, - array( 'description' => __( 'How the theme is meant to be built with.', 'ipsum' ) ) + 'guidelines' => array( + 'type' => 'array', + 'title' => __( 'Guidelines', 'ipsum' ), + 'description' => __( 'How the theme is meant to be built with.', 'ipsum' ), + 'items' => $string, ), ), ); @@ -332,14 +536,18 @@ static function ( $block ) { * @param array $input { * The ability input. * - * @type string[] $fields Optional. The sections to return. Default all of them. + * @type string[] $fields Optional. The sections to return. When omitted + * or empty, returns the basic design sections + * from ipsum_get_design_guide_default_fields(). * } * @return array The design guide. */ function ipsum_get_design_guide( $input = array() ) { - $sections = array_keys( ipsum_get_design_guide_schema()['properties'] ); + $all_sections = array_keys( ipsum_get_design_guide_schema()['properties'] ); if ( ! empty( $input['fields'] ) ) { - $sections = array_intersect( $sections, $input['fields'] ); + $sections = array_values( array_intersect( $all_sections, $input['fields'] ) ); + } else { + $sections = ipsum_get_design_guide_default_fields(); } $sections = array_flip( $sections ); From b6cf477a0f21a7103867813d1c4ee04694834d84 Mon Sep 17 00:00:00 2001 From: shail-mehta Date: Tue, 10 Nov 2026 02:47:35 +0000 Subject: [PATCH 2/4] Accept design guide output that theme.json actually produces. A preset without a name, a template part with no area, or an empty block font map was failing output validation on the default call. --- inc/abilities.php | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/inc/abilities.php b/inc/abilities.php index 898f018..11516bf 100644 --- a/inc/abilities.php +++ b/inc/abilities.php @@ -171,16 +171,20 @@ function ipsum_get_design_guide_schema() { return $schema; }; - $preset_list = static function ( $title, $description, $value_key, $value_schema, $extra_properties = array() ) use ( $object_list, $titled ) { - $properties = array_merge( + $preset_list = static function ( $title, $description, $value_key, $value_schema, $extra_properties = array(), $require_name = true ) use ( $object_list, $titled ) { + $name_description = $require_name + ? __( 'The human-readable preset name.', 'ipsum' ) + : __( 'The human-readable preset name. Omitted when the preset does not set one.', 'ipsum' ); + $properties = array_merge( array( 'slug' => $titled( __( 'Slug', 'ipsum' ), __( 'The preset slug.', 'ipsum' ) ), - 'name' => $titled( __( 'Name', 'ipsum' ), __( 'The human-readable preset name.', 'ipsum' ) ), + 'name' => $titled( __( 'Name', 'ipsum' ), $name_description ), $value_key => $value_schema, ), $extra_properties ); - return $object_list( $title, $description, $properties, array( 'slug', 'name', $value_key ) ); + $required = $require_name ? array( 'slug', 'name', $value_key ) : array( 'slug', $value_key ); + return $object_list( $title, $description, $properties, $required ); }; $colors = $preset_list( @@ -261,15 +265,19 @@ function ipsum_get_design_guide_schema() { ), 'fontFamilies' => $preset_list( __( 'Font Families', 'ipsum' ), - __( 'The font family presets from the theme and any added on the site.', 'ipsum' ), + __( 'The font family presets from the theme and any added on the site. The name is omitted when a preset does not set one.', 'ipsum' ), 'fontFamily', - $titled( __( 'Font Family', 'ipsum' ), __( 'The CSS font-family value.', 'ipsum' ) ) + $titled( __( 'Font Family', 'ipsum' ), __( 'The CSS font-family value.', 'ipsum' ) ), + array(), + false ), 'fontSizes' => $preset_list( __( 'Font Sizes', 'ipsum' ), - __( 'The font size presets from the theme, then any custom sizes. Not sorted by size.', 'ipsum' ), + __( 'The font size presets from the theme, then any custom sizes. Not sorted by size. The name is omitted when a preset does not set one.', 'ipsum' ), 'size', - $titled( __( 'Size', 'ipsum' ), __( 'The CSS font-size value.', 'ipsum' ) ) + $titled( __( 'Size', 'ipsum' ), __( 'The CSS font-size value.', 'ipsum' ) ), + array(), + false ), ), 'required' => array( 'bodyFont', 'headingFont', 'blockFonts', 'fontFamilies', 'fontSizes' ), @@ -277,9 +285,11 @@ function ipsum_get_design_guide_schema() { ), 'spacing' => $preset_list( __( 'Spacing', 'ipsum' ), - __( 'The spacing scale from the theme, then any custom sizes. Not sorted by size.', 'ipsum' ), + __( 'The spacing scale from the theme, then any custom sizes. Not sorted by size. The name is omitted when a preset does not set one.', 'ipsum' ), 'size', - $titled( __( 'Size', 'ipsum' ), __( 'The CSS spacing size value.', 'ipsum' ) ) + $titled( __( 'Size', 'ipsum' ), __( 'The CSS spacing size value.', 'ipsum' ) ), + array(), + false ), 'layout' => array( 'type' => 'object', @@ -422,7 +432,11 @@ function ipsum_get_design_guide_schema() { array( 'slug' => $titled( __( 'Slug', 'ipsum' ), __( 'The template part slug.', 'ipsum' ) ), 'title' => $titled( __( 'Title', 'ipsum' ), __( 'The template part title.', 'ipsum' ) ), - 'area' => $titled( __( 'Area', 'ipsum' ), __( 'The template part area, such as header, footer, or uncategorized.', 'ipsum' ) ), + 'area' => array( + 'type' => array( 'string', 'null' ), + 'title' => __( 'Area', 'ipsum' ), + 'description' => __( 'The template part area, such as header, footer, or uncategorized, or null when the part has no area term.', 'ipsum' ), + ), 'pattern' => array( 'type' => array( 'string', 'null' ), 'title' => __( 'Pattern', 'ipsum' ), @@ -614,7 +628,8 @@ function ipsum_get_design_guide( $input = array() ) { $guide['typography'] = array( 'bodyFont' => $body_font, 'headingFont' => ipsum_get_design_guide_font_slug( $styles['elements']['heading']['typography']['fontFamily'] ?? '' ) ?? $body_font, - 'blockFonts' => $block_fonts, + // An empty array JSON-encodes as [], which fails the object schema. + 'blockFonts' => (object) $block_fonts, 'fontFamilies' => ipsum_get_design_guide_presets( $settings['typography']['fontFamilies'] ?? array(), array( 'slug', 'name', 'fontFamily' ) ), 'fontSizes' => ipsum_get_design_guide_presets( $settings['typography']['fontSizes'] ?? array(), array( 'slug', 'name', 'size' ) ), ); From 50a163dd3d3d1c1ba95149ef46c90b9f86999da8 Mon Sep 17 00:00:00 2001 From: shail-mehta Date: Tue, 10 Nov 2026 02:52:47 +0000 Subject: [PATCH 3/4] Fix PHPCS --- inc/abilities.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/abilities.php b/inc/abilities.php index bb68195..9167223 100644 --- a/inc/abilities.php +++ b/inc/abilities.php @@ -183,7 +183,7 @@ function ipsum_get_design_guide_schema() { ), $extra_properties ); - $required = $require_name ? array( 'slug', 'name', $value_key ) : array( 'slug', $value_key ); + $required = $require_name ? array( 'slug', 'name', $value_key ) : array( 'slug', $value_key ); return $object_list( $title, $description, $properties, $required ); }; From 083e968315ab1951ce47429cfd29f4e87055e326 Mon Sep 17 00:00:00 2001 From: shail-mehta Date: Tue, 10 Nov 2026 04:56:40 +0000 Subject: [PATCH 4/4] Apply Feedback Changes --- inc/abilities.php | 174 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 130 insertions(+), 44 deletions(-) diff --git a/inc/abilities.php b/inc/abilities.php index 9167223..f955216 100644 --- a/inc/abilities.php +++ b/inc/abilities.php @@ -163,27 +163,26 @@ function ipsum_get_design_guide_schema() { ); }; - $titled = static function ( $title, $description = '' ) use ( $string ) { - $schema = array_merge( $string, array( 'title' => $title ) ); - if ( '' !== $description ) { - $schema['description'] = $description; - } - return $schema; - }; - - $preset_list = static function ( $title, $description, $value_key, $value_schema, $extra_properties = array(), $require_name = true ) use ( $object_list, $titled ) { - $name_description = $require_name + $preset_list = static function ( $title, $description, $value_key, $value_schema, $required, $extra_properties = array() ) use ( $object_list ) { + $name_description = in_array( 'name', $required, true ) ? __( 'The human-readable preset name.', 'ipsum' ) : __( 'The human-readable preset name. Omitted when the preset does not set one.', 'ipsum' ); $properties = array_merge( array( - 'slug' => $titled( __( 'Slug', 'ipsum' ), __( 'The preset slug.', 'ipsum' ) ), - 'name' => $titled( __( 'Name', 'ipsum' ), $name_description ), + 'slug' => array( + 'type' => 'string', + 'title' => __( 'Slug', 'ipsum' ), + 'description' => __( 'The preset slug.', 'ipsum' ), + ), + 'name' => array( + 'type' => 'string', + 'title' => __( 'Name', 'ipsum' ), + 'description' => $name_description, + ), $value_key => $value_schema, ), $extra_properties ); - $required = $require_name ? array( 'slug', 'name', $value_key ) : array( 'slug', $value_key ); return $object_list( $title, $description, $properties, $required ); }; @@ -191,7 +190,12 @@ function ipsum_get_design_guide_schema() { __( 'Colors', 'ipsum' ), __( 'The color palette from the theme and any colors added on the site, with what each theme color is for. Every style variation redefines the same slugs. The role field is omitted for colors that have no known role.', 'ipsum' ), 'color', - $titled( __( 'Color', 'ipsum' ), __( 'The CSS color value.', 'ipsum' ) ), + array( + 'type' => 'string', + 'title' => __( 'Color', 'ipsum' ), + 'description' => __( 'The CSS color value.', 'ipsum' ), + ), + array( 'slug', 'name', 'color' ), array( 'role' => array( 'type' => 'string', @@ -215,8 +219,16 @@ function ipsum_get_design_guide_schema() { 'title' => __( 'Theme', 'ipsum' ), 'description' => __( 'The active theme. Its stylesheet is the one to use in REST routes such as /wp/v2/global-styles/themes/{stylesheet}.', 'ipsum' ), 'properties' => array( - 'name' => $titled( __( 'Name', 'ipsum' ), __( 'The active theme name.', 'ipsum' ) ), - 'stylesheet' => $titled( __( 'Stylesheet', 'ipsum' ), __( 'The theme stylesheet slug.', 'ipsum' ) ), + 'name' => array( + 'type' => 'string', + 'title' => __( 'Name', 'ipsum' ), + 'description' => __( 'The active theme name.', 'ipsum' ), + ), + 'stylesheet' => array( + 'type' => 'string', + 'title' => __( 'Stylesheet', 'ipsum' ), + 'description' => __( 'The theme stylesheet slug.', 'ipsum' ), + ), ), 'required' => array( 'name', 'stylesheet' ), 'additionalProperties' => false, @@ -230,7 +242,12 @@ function ipsum_get_design_guide_schema() { __( 'Gradients', 'ipsum' ), __( 'The gradient presets from the theme and any added on the site.', 'ipsum' ), 'gradient', - $titled( __( 'Gradient', 'ipsum' ), __( 'The CSS gradient value.', 'ipsum' ) ) + array( + 'type' => 'string', + 'title' => __( 'Gradient', 'ipsum' ), + 'description' => __( 'The CSS gradient value.', 'ipsum' ), + ), + array( 'slug', 'name', 'gradient' ) ), 'duotone' => $preset_list( __( 'Duotone', 'ipsum' ), @@ -242,7 +259,8 @@ function ipsum_get_design_guide_schema() { 'title' => __( 'Colors', 'ipsum' ), 'description' => __( 'The two colors in the duotone filter.', 'ipsum' ), ) - ) + ), + array( 'slug', 'name', 'colors' ) ), 'typography' => array( 'type' => 'object', @@ -267,17 +285,23 @@ function ipsum_get_design_guide_schema() { __( 'Font Families', 'ipsum' ), __( 'The font family presets from the theme and any added on the site. The name is omitted when a preset does not set one.', 'ipsum' ), 'fontFamily', - $titled( __( 'Font Family', 'ipsum' ), __( 'The CSS font-family value.', 'ipsum' ) ), - array(), - false + array( + 'type' => 'string', + 'title' => __( 'Font Family', 'ipsum' ), + 'description' => __( 'The CSS font-family value.', 'ipsum' ), + ), + array( 'slug', 'fontFamily' ) ), 'fontSizes' => $preset_list( __( 'Font Sizes', 'ipsum' ), __( 'The font size presets from the theme, then any custom sizes. Not sorted by size. The name is omitted when a preset does not set one.', 'ipsum' ), 'size', - $titled( __( 'Size', 'ipsum' ), __( 'The CSS font-size value.', 'ipsum' ) ), - array(), - false + array( + 'type' => 'string', + 'title' => __( 'Size', 'ipsum' ), + 'description' => __( 'The CSS font-size value.', 'ipsum' ), + ), + array( 'slug', 'size' ) ), ), 'required' => array( 'bodyFont', 'headingFont', 'blockFonts', 'fontFamilies', 'fontSizes' ), @@ -287,9 +311,12 @@ function ipsum_get_design_guide_schema() { __( 'Spacing', 'ipsum' ), __( 'The spacing scale from the theme, then any custom sizes. Not sorted by size. The name is omitted when a preset does not set one.', 'ipsum' ), 'size', - $titled( __( 'Size', 'ipsum' ), __( 'The CSS spacing size value.', 'ipsum' ) ), - array(), - false + array( + 'type' => 'string', + 'title' => __( 'Size', 'ipsum' ), + 'description' => __( 'The CSS spacing size value.', 'ipsum' ), + ), + array( 'slug', 'size' ) ), 'layout' => array( 'type' => 'object', @@ -314,7 +341,11 @@ function ipsum_get_design_guide_schema() { __( 'Style Variations', 'ipsum' ), __( 'The style variations available for this theme. Each item lists only what that variation changes: colorScheme and colors for the palette, bodyFont and headingFont for the fonts, and blocks for the style properties it sets on each block. Optional fields are omitted when the variation does not change them. Their full data is at /wp/v2/global-styles/themes/{stylesheet}/variations.', 'ipsum' ), array( - 'title' => $titled( __( 'Title', 'ipsum' ), __( 'The style variation title.', 'ipsum' ) ), + 'title' => array( + 'type' => 'string', + 'title' => __( 'Title', 'ipsum' ), + 'description' => __( 'The style variation title.', 'ipsum' ), + ), 'colorScheme' => $scheme, 'colors' => array( 'type' => 'object', @@ -343,9 +374,21 @@ function ipsum_get_design_guide_schema() { __( 'Block Styles', 'ipsum' ), __( 'The block styles registered on this site, beyond the ones blocks define themselves. Add className to a block of one of the blockTypes to apply it.', 'ipsum' ), array( - 'name' => $titled( __( 'Name', 'ipsum' ), __( 'The block style slug.', 'ipsum' ) ), - 'label' => $titled( __( 'Label', 'ipsum' ), __( 'The human-readable block style label.', 'ipsum' ) ), - 'className' => $titled( __( 'Class Name', 'ipsum' ), __( 'The CSS class to add to the block, such as is-style-outline.', 'ipsum' ) ), + 'name' => array( + 'type' => 'string', + 'title' => __( 'Name', 'ipsum' ), + 'description' => __( 'The block style slug.', 'ipsum' ), + ), + 'label' => array( + 'type' => 'string', + 'title' => __( 'Label', 'ipsum' ), + 'description' => __( 'The human-readable block style label.', 'ipsum' ), + ), + 'className' => array( + 'type' => 'string', + 'title' => __( 'Class Name', 'ipsum' ), + 'description' => __( 'The CSS class to add to the block, such as is-style-outline.', 'ipsum' ), + ), 'blockTypes' => array_merge( $strings, array( @@ -360,9 +403,21 @@ function ipsum_get_design_guide_schema() { __( 'Patterns', 'ipsum' ), __( 'The patterns registered by the active theme, without their markup, which is at /wp/v2/block-patterns/patterns. Includes both insertable patterns and hidden ones that fill templates and template parts. Optional fields (blockTypes, templateTypes, postTypes) are omitted when empty.', 'ipsum' ), array( - 'slug' => $titled( __( 'Slug', 'ipsum' ), __( 'The pattern slug.', 'ipsum' ) ), - 'title' => $titled( __( 'Title', 'ipsum' ), __( 'The pattern title.', 'ipsum' ) ), - 'description' => $titled( __( 'Description', 'ipsum' ), __( 'The pattern description.', 'ipsum' ) ), + 'slug' => array( + 'type' => 'string', + 'title' => __( 'Slug', 'ipsum' ), + 'description' => __( 'The pattern slug.', 'ipsum' ), + ), + 'title' => array( + 'type' => 'string', + 'title' => __( 'Title', 'ipsum' ), + 'description' => __( 'The pattern title.', 'ipsum' ), + ), + 'description' => array( + 'type' => 'string', + 'title' => __( 'Description', 'ipsum' ), + 'description' => __( 'The pattern description.', 'ipsum' ), + ), 'categories' => array_merge( $strings, array( @@ -403,9 +458,21 @@ function ipsum_get_design_guide_schema() { __( 'Templates', 'ipsum' ), __( 'The block templates available on the site, including theme templates and any customized copies, with the pattern each delegates to when its markup is a single Pattern block.', 'ipsum' ), array( - 'slug' => $titled( __( 'Slug', 'ipsum' ), __( 'The template slug.', 'ipsum' ) ), - 'title' => $titled( __( 'Title', 'ipsum' ), __( 'The template title.', 'ipsum' ) ), - 'description' => $titled( __( 'Description', 'ipsum' ), __( 'The template description.', 'ipsum' ) ), + 'slug' => array( + 'type' => 'string', + 'title' => __( 'Slug', 'ipsum' ), + 'description' => __( 'The template slug.', 'ipsum' ), + ), + 'title' => array( + 'type' => 'string', + 'title' => __( 'Title', 'ipsum' ), + 'description' => __( 'The template title.', 'ipsum' ), + ), + 'description' => array( + 'type' => 'string', + 'title' => __( 'Description', 'ipsum' ), + 'description' => __( 'The template description.', 'ipsum' ), + ), 'pattern' => array( 'type' => array( 'string', 'null' ), 'title' => __( 'Pattern', 'ipsum' ), @@ -430,8 +497,16 @@ function ipsum_get_design_guide_schema() { __( 'Template Parts', 'ipsum' ), __( 'The template parts available on the site, including theme parts and any customized copies, with their area and the pattern each delegates to when its markup is a single Pattern block.', 'ipsum' ), array( - 'slug' => $titled( __( 'Slug', 'ipsum' ), __( 'The template part slug.', 'ipsum' ) ), - 'title' => $titled( __( 'Title', 'ipsum' ), __( 'The template part title.', 'ipsum' ) ), + 'slug' => array( + 'type' => 'string', + 'title' => __( 'Slug', 'ipsum' ), + 'description' => __( 'The template part slug.', 'ipsum' ), + ), + 'title' => array( + 'type' => 'string', + 'title' => __( 'Title', 'ipsum' ), + 'description' => __( 'The template part title.', 'ipsum' ), + ), 'area' => array( 'type' => array( 'string', 'null' ), 'title' => __( 'Area', 'ipsum' ), @@ -454,9 +529,21 @@ function ipsum_get_design_guide_schema() { __( 'Template Part Areas', 'ipsum' ), __( 'The areas a template part can belong to on this site.', 'ipsum' ), array( - 'area' => $titled( __( 'Area', 'ipsum' ), __( 'The template part area slug.', 'ipsum' ) ), - 'label' => $titled( __( 'Label', 'ipsum' ), __( 'The human-readable area label.', 'ipsum' ) ), - 'description' => $titled( __( 'Description', 'ipsum' ), __( 'What the area is for.', 'ipsum' ) ), + 'area' => array( + 'type' => 'string', + 'title' => __( 'Area', 'ipsum' ), + 'description' => __( 'The template part area slug.', 'ipsum' ), + ), + 'label' => array( + 'type' => 'string', + 'title' => __( 'Label', 'ipsum' ), + 'description' => __( 'The human-readable area label.', 'ipsum' ), + ), + 'description' => array( + 'type' => 'string', + 'title' => __( 'Description', 'ipsum' ), + 'description' => __( 'What the area is for.', 'ipsum' ), + ), ), array( 'area', 'label', 'description' ) ), @@ -628,8 +715,7 @@ function ipsum_get_design_guide( $input = array() ) { $guide['typography'] = array( 'bodyFont' => $body_font, 'headingFont' => ipsum_get_design_guide_font_slug( $styles['elements']['heading']['typography']['fontFamily'] ?? '' ) ?? $body_font, - // An empty array JSON-encodes as [], which fails the object schema. - 'blockFonts' => (object) $block_fonts, + 'blockFonts' => $block_fonts, 'fontFamilies' => ipsum_get_design_guide_presets( $settings['typography']['fontFamilies'] ?? array(), array( 'slug', 'name', 'fontFamily' ) ), 'fontSizes' => ipsum_get_design_guide_presets( $settings['typography']['fontSizes'] ?? array(), array( 'slug', 'name', 'size' ) ), );