-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
REST API: Simplify 'default_rendering_mode' field registration for post types #67867
base: trunk
Are you sure you want to change the base?
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
lib/compat/wordpress-6.8/class-gutenberg-rest-post-types-controller-6-8.php
Outdated
Show resolved
Hide resolved
*/ | ||
$rendering_mode = apply_filters( "post_type_{$item->name}_default_rendering_mode", $rendering_mode, $item ); | ||
// Property will only exist if the post type supports the block editor. | ||
if ( ! $post_type_object || ! isset( $post_type_object->default_rendering_mode ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not a fan of a) artificially adding properties to the WP_Post_Type
and b) the name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean artificially
? This is the only way to expose new properties in response.
Agreed on the name, I'll create a new discussion for it + if we should migrate to supports
. This PR here is just refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean
artificially
? This is the only way to expose new properties in response.
When I worked on WP_Post_Type
it wasn't really the intention to allow passing non-default fields to post type registration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like your posed idea in the original PR to use post type supports - 'editor-rendering-mode' => 'post-only'
, and I guess we can make that change here.
It will be a conditional support value, like the autosave
you recently implemented.
@fabiankaegy, @TylerB24890, @youknowriad, what do you think?
Edit: I think the key difference compared to other support values is that you can't really remove it. Removal would mean fallback to default rendering mode - post-only
.
return { | ||
hasLoadedPostObject: _hasLoadedPostObject, | ||
editorSettings: getEditorSettings(), | ||
isReady: __unstableIsEditorReady(), | ||
mode: getRenderingMode(), | ||
defaultMode: | ||
postTypeObject?.default_rendering_mode ?? 'post-only', | ||
postTypeObject?.default_rendering_mode || 'post-only', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just extra hardening to provide correct fallback on falsy values like empty string
Size Change: -44 B (0%) Total Size: 1.84 MB
ℹ️ View Unchanged
|
3f047eb
to
547a7cc
Compare
What?
A follow-up to #62304.
Simplifies the registration of the
default_rendering_mode
post-type REST property by adding it viaregister_rest_field
instead of a controller override. It also adds a schema for the new property.I've removed the new filters introduced in the original PR. Why:
default_rendering_mode
for REST API responses. This could cause some unexpected results.register_post_type_args
orrest_prepare_post_type
filters.In the future, we could provide API like
add_post_type_support
, but first, let's see how these configurations mature.cc @TylerB24890
Testing Instructions
template-locked
mode.Testing Instructions for Keyboard
Same.