Make WordPress Core


Ignore:
Timestamp:
05/27/2024 09:04:10 AM (12 months ago)
Author:
swissspidy
Message:

Posts, Post Types: Autosave: Allow disabling autosave support per post type.

Not all post types support autosaving. By making autosave a post type feature, support can be more granularly handled without any workarounds or hardcoded allowlists. wp_font_family and wp_font_face are examples of built-in post types which do not support autosave.

For backward compatibility reasons, adding editor support implies autosave support, so one would need to explicitly use remove_post_type_support() to remove it again.

Props swissspidy, youknowriad, hellofromtonya, peterwilsoncc.
Fixes #41172.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-post-type.php

    r57628 r58201  
    671671            }
    672672            unset( $this->supports );
     673
     674            /*
     675             * 'editor' support implies 'autosave' support for backward compatibility.
     676             * 'autosave' support needs to be explicitly removed if not desired.
     677             */
     678            if (
     679                post_type_supports( $this->name, 'editor' ) &&
     680                ! post_type_supports( $this->name, 'autosave' )
     681            ) {
     682                add_post_type_support( $this->name, 'autosave' );
     683            }
    673684        } elseif ( false !== $this->supports ) {
    674685            // Add default features.
    675             add_post_type_support( $this->name, array( 'title', 'editor' ) );
     686            add_post_type_support( $this->name, array( 'title', 'editor', 'autosave' ) );
    676687        }
    677688    }
     
    920931    public function get_autosave_rest_controller() {
    921932        if ( ! $this->show_in_rest ) {
     933            return null;
     934        }
     935
     936        if ( ! post_type_supports( $this->name, 'autosave' ) ) {
    922937            return null;
    923938        }
Note: See TracChangeset for help on using the changeset viewer.