#41172 closed enhancement (fixed)
Allow autosaving to be disabled on a per post type basis
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.6 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Autosave | Keywords: | has-patch has-unit-tests commit needs-dev-note |
Focuses: | administration | Cc: |
Description
Autosaving should be a post type feature, so that individual post types can opt out. Disabling this feature should remove both the server-side and the client-side saving.
Change History (31)
This ticket was mentioned in PR #6035 on WordPress/wordpress-develop by @swissspidy.
6 months ago
#1
- Keywords has-patch added
@youknowriad commented on PR #6035:
6 months ago
#2
This gets automatically added to the post type REST API right? Can we confirm that with a test or something? I'm thinking that it's a useful information for the editor to know. I know we've been hardcoding some checks recently about whether to enable or disable autosaves.
@swissspidy commented on PR #6035:
6 months ago
#3
This gets automatically added to the post type REST API right? Can we confirm that with a test or something? I'm thinking that it's a useful information for the editor to know. I know we've been hardcoding some checks recently about whether to enable or disable autosaves.
There is a supports
field in the /wp/v2/types
endpoint(s) that can be used to check if autosaves are supported.
This could be used in the isEditedPostAutosaveable
selector here:
No need for a hardcoded wp_template
check anymore
#4
@
6 months ago
- Keywords has-unit-tests added
- Milestone changed from Awaiting Review to 6.5
The Font Library #59166 is brand new in 6.5. It's currently using a hacky way to workaround this requested need. With this need and movement with a new patch, moving this into 6.5.
@peterwilsoncc commented on PR #6035:
6 months ago
#5
I understand why this needs to be opt-out for back-compat purposes.
What do folks think of allowing developers to opt out by setting supports to false?
register_post_type(
'no-autosave',
[
'public' => true,
'show_in_rest' => true,
'supports' => [
'title',
'editor',
'autosaves' => false,
],
]
);
At present supports['thing'] = false
would actually enable support of the thing, so this would be a technical BC break. However, I think the intent of the code is clear so it may be something that can be introduced relatively safely.
@peterwilsoncc commented on PR #6035:
6 months ago
#6
I'm wondering if we are overthinking this by adding a new supports
item.
How about allowing: register_post_type( 'cpt', [ 'autosave_rest_controller_class' => null ] );
?
The patch could then become:
public function get_autosave_rest_controller() {
if ( ! $this->show_in_rest ) {
return null;
}
if ( null === $this->autosave_rest_controller_class ) {
return null;
}
// ...
Regrettably, setting autosave_rest_controller_class => false
actually means: enable the controller and use the default. But null
is a new value that can indicate the controller should not be enabled.
It would still need a dev note for plugins outside the repository.
I think the current approach would need some additional changes for add|remove_post_types_support
to ensure that adding autosaves only works for posts with the editor and removing support for the editor would also need to remove support for autosaves. Similar to this PR for footnotes.
@swissspidy commented on PR #6035:
6 months ago
#7
null is better than stdClass, so that would be a step in the right direction. However it doesn‘t solve the discoverability issue for the editor, see https://github.com/WordPress/wordpress-develop/pull/6035#issuecomment-1929260835
Any thoughts on how to do that? Maybe with a _links entry in the API.
But then it would be weird to use the existance of a class to check for feature support, when post type supports is designed for this.
@peterwilsoncc commented on PR #6035:
6 months ago
#8
Any thoughts on how to do that? Maybe with a _links entry in the API.
A non-embedable links entry makes sense. Otherwise could it check the schema, either at http://xu-a8c-woo.local/wp-json/wp/v2 or higher up the tree if it's already loaded?
@swissspidy commented on PR #6035:
6 months ago
#9
I don't think Gutenberg looks at the schemas.
@youknowriad Would checking the post type's _links
property in isEditedPostAutosaveable
in work? i.e. if there's no autosave endpoint mentioned, then it means it's not supported.
@youknowriad commented on PR #6035:
6 months ago
#10
In Gutenberg, we don't look either at links or schemas so far in core-data selectors and I personally don't like adding "special cases" for some entities to the code base to retrieve information about a given entity. I see "links" as "schemas" as technical informations about the REST API implementation but not something a component user API should provide.
From a data information architecture, I think this is being part of the "supports" key of the endpoint makes more sense. If I'm fetching a post type through an endpoint, I want to know what it supports and what it doesn't. It seems weird to have to check "links" or "schema" to know what a post type support when we actually have a supports property for said entity.
That said, obviously we can adapt.
@swissspidy commented on PR #6035:
6 months ago
#11
That is certainly true, yeah. I don't think there's anything cleaner than using supports
.
6 months ago
#12
In the ongoing discussion about adding autosave support to the post type REST API in WordPress, there seems to be a debate regarding the most appropriate method for indicating autosave support. While some suggest utilizing the supports field in the endpoint, others propose alternative approaches like inspecting the _links property or relying on schema checks. What are the advantages and disadvantages of each approach, and how might the chosen method impact the usability and maintainability of the WordPress codebase?
<a href="https://dinetuatuwhoo.tk"> </a><a href="https://dickblenag.tk"> </a><a href="https://ceoplasthonnilanwho.tk"> </a><a href="https://apimslufli.tk"> </a><a href="https://enycuvceled.tk"> </a><a href="https://mowuwyjonofo.tk"> </a>
6 months ago
#13
In the ongoing discussion about adding autosave support to the post type REST API in WordPress, there seems to be a debate regarding the most appropriate method for indicating autosave support. While some suggest utilizing the supports field in the endpoint, others propose alternative approaches like inspecting the _links property or relying on schema checks. What are the advantages and disadvantages of each approach, and how might the chosen method impact the usability and maintainability of the WordPress codebase?
<a href="https://dinetuatuwhoo.tk"> </a><a href="https://dickblenag.tk"> </a><a href="https://ceoplasthonnilanwho.tk"> </a><a href="https://apimslufli.tk"> </a><a href="https://enycuvceled.tk"> </a><a href="https://mowuwyjonofo.tk"> </a>
@swissspidy commented on PR #6035:
6 months ago
#14
Just pinging people again to see whether this is something we'd like to commit in 6.5. Otherwise this would be punted.
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
6 months ago
@hellofromTonya commented on PR #6035:
6 months ago
#16
Thanks for the ping @swissspidy.
I don't think there's anything cleaner than using supports.
I too am not seeing a more clean solution than what's being proposed.
I'm not a fan of having only this one support be an opt-out, but I do understand why it has to be. That said, I like @peterwilsoncc's thinking:
At present supportsthing? = false would actually enable support of the thing, so this would be a technical BC break. However, I think the intent of the code is clear so it may be something that can be introduced relatively safely.
but it seems out-of-scope for this specific ticket. Why? It enhances the supports to allow configuring which ones should not be supported, whereas this ticket is about only autosave
. IMO this kind of enhancement needs it own ticket and could happen in the next major.
Back to this specific PR.
The Font Library has an immediate need for this change to avoid shipping the hack. That said, the hack is internal and could be replaced in the next cycle once a full solution / enhancement is ready.
Are there any other immediate needs within the editor?
If no, I'm lean towards punting. Then in the next cycle, add the autosave
support plus enhance supports to accept false
(as Peter suggested).
@peterwilsoncc commented on PR #6035:
6 months ago
#17
I'm inclined to punt this for now.
While using stdClass is not ideal, it works for now and I think it would be rushing things to try and get this solved in the time we (ie, those of us tracking this ticket) have between now and the beta release.
If using stdClass
going to lock WP Core in to supporting something in to the future then let's try to figure it out.
@swissspidy commented on PR #6035:
6 months ago
#19
Alright, punting for now 👍
5 months ago
#20
Should WordPress consider implementing a more robust solution for enabling or disabling autosaving on a per post type basis, possibly by enhancing the 'supports' parameter to accept 'false' values, as suggested by some contributors? How might such a feature enhancement align with the platform's backward compatibility and development roadmap?
#!html<a href='https://rubyofsiamthai.com'></a><a href='https://singha88.com'></a><a href='https://dgbet.org'></a><a href='https://avkuy.com'></a><a href='https://zimprofiles.com'></a><a href='https://cakecartsdisposable.com'></a><a href='https://igame.news'></a><a href='https://casinowire.io'></a><a href='https://igamingfeed.org'></a><a href='https://www.forca.nu'></a><a href='https://marcusoskarsson.se'></a><a href='https://Svensktderby.se'></a><a href='https://spelnytt.nu'></a><a href='https://cardleague.org'></a>
5 months ago
#21
Should WordPress consider implementing a more robust solution for enabling or disabling autosaving on a per post type basis, possibly by enhancing the 'supports' parameter to accept 'false' values, as suggested by some contributors? How might such a feature enhancement align with the platform's backward compatibility and development roadmap?
#!html<a href='https://rubyofsiamthai.com'></a><a href='https://singha88.com'></a><a href='https://dgbet.org'></a><a href='https://avkuy.com'></a><a href='https://zimprofiles.com'></a><a href='https://cakecartsdisposable.com'></a><a href='https://igame.news'></a><a href='https://casinowire.io'></a><a href='https://igamingfeed.org'></a><a href='https://www.forca.nu'></a><a href='https://marcusoskarsson.se'></a><a href='https://Svensktderby.se'></a><a href='https://spelnytt.nu'></a><a href='https://cardleague.org'></a>
@swissspidy commented on PR #6035:
3 months ago
#22
@peterwilsoncc WDYT about picking this up again for 6.6? I believe it's ready.
The back compat code is small and required, and the new autosave
support allows for a better discoverability in Gutenberg, which is a nice win.
#25
@
2 months ago
- Keywords needs-testing removed
I have tested the patch with the below code.
<?php /** * Register a custom post type called "book". * * @see get_post_type_labels() for label keys. */ function wpdocs_codex_book_init() { $labels = array( 'name' => _x( 'Books', 'Post type general name', 'textdomain' ), 'singular_name' => _x( 'Book', 'Post type singular name', 'textdomain' ), 'menu_name' => _x( 'Books', 'Admin Menu text', 'textdomain' ), 'name_admin_bar' => _x( 'Book', 'Add New on Toolbar', 'textdomain' ), 'add_new' => __( 'Add New', 'textdomain' ), 'add_new_item' => __( 'Add New Book', 'textdomain' ), 'new_item' => __( 'New Book', 'textdomain' ), 'edit_item' => __( 'Edit Book', 'textdomain' ), 'view_item' => __( 'View Book', 'textdomain' ), 'all_items' => __( 'All Books', 'textdomain' ), 'search_items' => __( 'Search Books', 'textdomain' ), 'parent_item_colon' => __( 'Parent Books:', 'textdomain' ), 'not_found' => __( 'No books found.', 'textdomain' ), 'not_found_in_trash' => __( 'No books found in Trash.', 'textdomain' ), ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'book' ), 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => false, 'menu_position' => null, 'show_in_rest' => true, 'supports' => array( 'title' ), ); register_post_type( 'book', $args ); } add_action( 'init', 'wpdocs_codex_book_init' );
✅ With Editor Support, AutoSave is turned on by default.
✅ With NO Editor Support, AutoSave is turned NOT turned on by default.
#26
@
2 months ago
- Owner set to swissspidy
- Resolution set to fixed
- Status changed from new to closed
In 58201:
@swissspidy commented on PR #6035:
2 months ago
#27
Committed in https://core.trac.wordpress.org/changeset/58201
Adds autosave support by default if the post type has editor support, to maintain backward compatibility.
Support can be removed by explicitly calling
remove_post_type_support()
.Avoid unnecessarily registering autosave REST controllers.
Trac ticket: https://core.trac.wordpress.org/ticket/41172