Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking: Core data revisions follow ups #56413

Closed
6 of 7 tasks
ramonjd opened this issue Nov 22, 2023 · 2 comments
Closed
6 of 7 tasks

Tracking: Core data revisions follow ups #56413

ramonjd opened this issue Nov 22, 2023 · 2 comments
Assignees
Labels
[Package] Core data /packages/core-data [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues.

Comments

@ramonjd
Copy link
Member

ramonjd commented Nov 22, 2023

A list of tasks/bugs to address related to the following PR:

Tasks/Bugs

Related

@ramonjd ramonjd added [Status] In Progress Tracking issues with work in progress [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues. labels Nov 22, 2023
@ramonjd ramonjd self-assigned this Nov 22, 2023
@ramonjd ramonjd added the [Package] Core data /packages/core-data label Nov 22, 2023
@ramonjd ramonjd changed the title Core data: revisions follow ups Tracking: Core data revisions follow ups Nov 22, 2023
@ramonjd
Copy link
Member Author

ramonjd commented Nov 29, 2023

Add "supports" information to the view context for /types or at least get it from the backend somehow

Dumping some research here.

Adding revisions support info to the /wp/v2/types?context=view response is trivial via a rest_prepare_post_type filter hook.

/**
 * Returns post type supports data in the request's view context.
 *
 * @since 6.5.0
 *
 * @param WP_REST_Response $response  The response object.
 * @param WP_Post_Type     $post_type The original post type object.
 * @param WP_REST_Request  $request   Request used to generate the response.
 */
function gutenberg_rest_prepare_post_type_add_support( $response, $post_type, $request ) {
	if ( 'view' === $request['context'] ) {
		$supports = get_all_post_type_supports( $post_type->name );
		if ( isset( $supports['revisions'] ) && true === $supports['revisions'] ) {
			$response->data['supports']['revisions'] = true;
		}
	}
	return $response;
}

add_filter( 'rest_prepare_post_type', 'gutenberg_rest_prepare_post_type_add_support', 10, 3 );

The question is: what's the best path to Core migration? 🤔

Do we want to return revision supports info for all /wp/v2/types?context=view get requests?

If yes...

...then we could modify get_item_schema() and allow supports.revisions in view context always.

The next question is, is this okay out of the edit context? I'm not sure but I can't see why not.

And do we have to worry about returning data that folks don't expect? We're not removing data, and the structure would mirror the supports structure in the edit context.

If no...

We could ask for supports information via a request parameter or something? E.g., /wp/v2/types?context=view&include_supports=revisions

We'd need to modify WP_REST_Post_Types_Controller to add this data to the response based on the request parameter.

It seems undesirable to add a non-standard parameter in this way. And not great for maintenance.

Edit: #56701 addresses this issue by letting the server decide :)

@ramonjd
Copy link
Member Author

ramonjd commented Dec 5, 2023

Closing this issue now, since all directly related issues are resolved.

#56355 was an existing core data issue and not related to revisions.

@ramonjd ramonjd closed this as completed Dec 5, 2023
@ramonjd ramonjd removed the [Status] In Progress Tracking issues with work in progress label Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Core data /packages/core-data [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues.
Projects
None yet
Development

No branches or pull requests

1 participant