Make WordPress Core

Opened 7 years ago

Last modified 3 days ago

#41172 new enhancement

Allow autosaving to be disabled on a per post type basis

Reported by: frank-klein's profile Frank Klein Owned by:
Milestone: 6.6 Priority: normal
Severity: normal Version:
Component: Autosave Keywords: has-patch has-unit-tests
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 (21)

This ticket was mentioned in PR #6035 on WordPress/wordpress-develop by @swissspidy.


4 weeks ago
#1

  • Keywords has-patch added

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

@youknowriad commented on PR #6035:


4 weeks 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:


4 weeks 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:

https://github.com/WordPress/gutenberg/blob/8d94c3bd7af977d998466b56bd773f9b19de8d03/packages/editor/src/store/selectors.js#L600-L611

No need for a hardcoded wp_template check anymore

#4 @hellofromTonya
4 weeks 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:


3 weeks 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:


3 weeks 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:


3 weeks 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:


3 weeks 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:


3 weeks 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:


3 weeks 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:


3 weeks ago
#11

That is certainly true, yeah. I don't think there's anything cleaner than using supports.

lutzmex commented on PR #6035:


3 weeks 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>

lutzmex commented on PR #6035:


3 weeks 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:


3 weeks 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.


3 weeks ago

@hellofromTonya commented on PR #6035:


3 weeks 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:


3 weeks 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.

#18 @swissspidy
3 weeks ago

  • Milestone changed from 6.5 to 6.6

@swissspidy commented on PR #6035:


3 weeks ago
#19

Alright, punting for now 👍

lutzmex commented on PR #6035:


3 days 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>

lutzmex commented on PR #6035:


3 days 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>

Note: See TracTickets for help on using tickets.