Opened 2 years ago
Last modified 23 months ago
#60796 new defect (bug)
An error for page and post without revisions support
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | 6.4 |
| Component: | Posts, Post Types | Keywords: | |
| Focuses: | Cc: |
Description
Since 6.4.0 the $revisions_enabled argument was added to the arguments array of register_meta() function (https://developer.wordpress.org/reference/functions/register_meta/#changelog).
For post and page with disabled revisions support there is an error:
Error: Function register_meta was called incorrectly. Meta keys cannot enable revisions support unless the object subtype supports revisions. Please see Debugging in WordPress for more information. (This message was added in version 6.4.0.).
In register_block_core_footnotes() function revisions_enabled argument is permanently set to true and it's makes this error.
Change History (2)
#2
@
23 months ago
Thx @mrahsankhan for your answer, but you misunderstood me.
I know how to fixed it in custom post type. I suggest you to fixed it in core for built-in post types.
E.g. in register_block_core_footnotes() function $revisions_enabled argument is permanently set to true without checking is revision is enabled. It's very easy to add a simple condition in this place in core.
Consider to add this simple modification, please.
To address the error you're encountering with the
register_meta()function and the$revisions_enabledargument, you need to ensure that you're passing the correct value for the argument based on whether revisions are supported for the object subtype or not.If revisions are not supported for the object subtype (such as a post or page with disabled revisions support), you should not enable revisions support for the meta key. Here's how you can modify your code to handle this:
// Check if revisions are enabled for the post type if ( post_type_supports( 'post', 'revisions' ) ) { register_meta( 'post', 'your_meta_key', $args ); } else { // Revisions are not supported, so set $revisions_enabled to false $args['show_in_rest']['schema']['revisions_enabled'] = false; register_meta( 'post', 'your_meta_key', $args ); }Similarly, you can apply this logic for other object subtypes like pages or custom post types. Make sure to check whether revisions are supported for the specific object subtype before setting the
$revisions_enabledargument to true or false accordingly.In the context of
register_block_core_footnotes()function, you may need to modify it to dynamically determine whether revisions are supported for the post type being used and set the$revisions_enabledargument accordingly. This way, you can avoid the error you mentioned.Moreover, @audrasjb and @coffee2code can provide more accurate guidance and assistance to help you fix it.