Skip to content

Commit

Permalink
Try removing all object subtype
Browse files Browse the repository at this point in the history
  • Loading branch information
cbravobernal committed Sep 10, 2024
1 parent 1f02079 commit a0bce8f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 39 deletions.
32 changes: 0 additions & 32 deletions lib/compat/wordpress-6.7/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,35 +114,3 @@ function gutenberg_override_default_rest_server() {
return 'Gutenberg_REST_Server';
}
add_filter( 'wp_rest_server_class', 'gutenberg_override_default_rest_server', 1 );

/**
* Add `object_subtype` to schema.
*
* @param array $args Array of arguments for registering meta.
* @return array Modified arguments array including `object_subtype`.
*/
function gutenberg_add_object_subtype_to_schema( $args ) {
// Don't update schema when object_subtype isn't provided.
if ( ! isset( $args['object_subtype'] ) ) {
return $args;
}

$schema = array( 'object_subtype' => $args['object_subtype'] );
if ( ! is_array( $args['show_in_rest'] ) ) {
$args['show_in_rest'] = array(
'schema' => $schema,
);
return $args;
}

if ( ! empty( $args['show_in_rest']['schema'] ) ) {
$args['show_in_rest']['schema'] = array_merge( $args['show_in_rest']['schema'], $schema );
} else {
$args['show_in_rest']['schema'] = $schema;
}

return $args;
}

// Priority must be lower than 10 to ensure the object_subtype is not removed.
add_filter( 'register_meta_args', 'gutenberg_add_object_subtype_to_schema', 5, 1 );
8 changes: 1 addition & 7 deletions packages/editor/src/bindings/post-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ function getMetadata( registry, context ) {
const { getRegisteredPostMeta } = unlock(
registry.select( coreDataStore )
);

// Inherit the postType from the slug if it is a template.
if ( ! context?.postType && type === 'wp_template' ) {
// Get the 'kind' from the start of the slug.
Expand All @@ -34,11 +33,11 @@ function getMetadata( registry, context ) {
if ( kind === 'page' ) {
postType = 'page';
} else if ( kind === 'single' ) {
// Get postTypes is returning [].
const postTypes =
getPostTypes( { per_page: -1 } )?.map(
( entity ) => entity.slug
) || [];

// Infer the post type from the slug.
// TODO: Review, as it may not have a post type. http://localhost:8888/wp-admin/site-editor.php?canvas=edit
const match = slug.match(
Expand All @@ -48,13 +47,8 @@ function getMetadata( registry, context ) {
}
}
const fields = getRegisteredPostMeta( postType );

// Populate the `metaFields` object with the default values.
Object.entries( fields || {} ).forEach( ( [ key, props ] ) => {
// If the template is global, skip the fields with a subtype.
if ( isGlobalTemplate && props.object_subtype ) {
return;
}
metaFields[ key ] = props.default;
} );
} else {
Expand Down

0 comments on commit a0bce8f

Please sign in to comment.