Make WordPress Core

Opened 5 years ago

Last modified 4 weeks ago

#53417 new defect (bug)

The revisions endpoints provide an incorrect JSON schema

Reported by: johnbillion's profile johnbillion Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7
Component: Revisions Keywords: has-patch has-unit-tests
Focuses: rest-api Cc:

Description (last modified by johnbillion)

The schema provided by the REST API endpoints for revisions at wp/v2/posts/{id}/revisions and wp/v2/pages/{id}/revisions is incorrect. The schema states that content.protected and excerpt.protected properties exist for each revision, but these properties do not exist.

Two options:

  1. Remove the content.protected and excerpt.protected properties from the schema
  2. Add the content.protected and excerpt.protected properties to the response

Here is the content property from the schema. Note the protected.context property states that the property exists for all three contexts.

"content": {
    "description": "The content for the post.",
    "type": "object",
    "context": [
        "view",
        "edit"
    ],
    "properties": {
        "raw": {
            "description": "Content for the post, as it exists in the database.",
            "type": "string",
            "context": [
                "edit"
            ]
        },
        "rendered": {
            "description": "HTML content for the post, transformed for display.",
            "type": "string",
            "context": [
                "view",
                "edit"
            ],
            "readonly": true
        },
        "block_version": {
            "description": "Version of the content block format used by the post.",
            "type": "integer",
            "context": [
                "edit"
            ],
            "readonly": true
        },
        "protected": {
            "description": "Whether the content is protected with a password.",
            "type": "boolean",
            "context": [
                "view",
                "edit",
                "embed"
            ],
            "readonly": true
        }
    }
},

Change History (4)

#1 @johnbillion
5 years ago

  • Description modified (diff)

#2 @johnbillion
5 years ago

  • Description modified (diff)

#3 @johnbillion
5 years ago

  • Description modified (diff)

Update: the same applies to excerpt.protected too.

This ticket was mentioned in PR #11569 on WordPress/wordpress-develop by @lakshyajeet.


4 weeks ago
#4

  • Keywords has-patch has-unit-tests added; needs-patch removed

Trac ticket: https://core.trac.wordpress.org/ticket/53417

The schema provided by the REST API endpoints for revisions at wp/v2/posts/{id}/revisions and wp/v2/pages/{id}/revisions incorrectly states that content.protected and excerpt.protected properties exist. Revisions do not inherently support password protection in their response payloads, as they belong to the parent post.

This PR fixes the issue by removing the protected property from the revision schema for both the content and excerpt fields within WP_REST_Revisions_Controller::get_item_schema().

### Use of AI Tools

AI assistance: Yes
Tool(s): Github Copilot (Claude 4.6 Sonnet, Gemini 3.1 Pro)
Used for: Discussing the implementation approach and refining the PHPUnit tests for schema validation. Final code and tests were reviewed and verified locally by me.

Note: See TracTickets for help on using tickets.