Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling autosave post type support #6035

Closed
17 changes: 16 additions & 1 deletion src/wp-includes/class-wp-post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,20 @@ public function add_supports() {
}
}
unset( $this->supports );

/*
* 'editor' support implies 'autosave' support for backward compatibility.
* 'autosave' support needs to be explicitly removed if not desired.
*/
if (
post_type_supports( $this->name, 'editor' ) &&
! post_type_supports( $this->name, 'autosave' )
) {
add_post_type_support( $this->name, 'autosave' );
}
swissspidy marked this conversation as resolved.
Show resolved Hide resolved
} elseif ( false !== $this->supports ) {
// Add default features.
add_post_type_support( $this->name, array( 'title', 'editor' ) );
add_post_type_support( $this->name, array( 'title', 'editor', 'autosave' ) );
}
}

Expand Down Expand Up @@ -922,6 +933,10 @@ public function get_autosave_rest_controller() {
return null;
}

if ( ! post_type_supports( $this->name, 'autosave' ) ) {
return null;
}

if ( 'attachment' === $this->name ) {
return null;
}
Expand Down
6 changes: 4 additions & 2 deletions src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -1705,7 +1705,8 @@ function get_post_types( $args = array(), $output = 'names', $operator = 'and' )
* 'editor', 'comments', 'revisions', 'trackbacks', 'author', 'excerpt',
* 'page-attributes', 'thumbnail', 'custom-fields', and 'post-formats'.
* Additionally, the 'revisions' feature dictates whether the post type
* will store revisions, and the 'comments' feature dictates whether the
* will store revisions, the 'autosave' feature dictates whether the post type
* will be autosaved, and the 'comments' feature dictates whether the
swissspidy marked this conversation as resolved.
Show resolved Hide resolved
* comments count will show on the edit screen. A feature can also be
* specified as an array of arguments to provide additional information
* about supporting that feature.
Expand Down Expand Up @@ -2184,7 +2185,8 @@ function _add_post_type_submenus() {
* 'thumbnail', 'custom-fields', and 'post-formats'.
*
* Additionally, the 'revisions' feature dictates whether the post type will
* store revisions, and the 'comments' feature dictates whether the comments
* store revisions, the 'autosave' feature dictates whether the post type
* will be autosaved, and the 'comments' feature dictates whether the comments
* count will show on the edit screen.
*
* A third, optional parameter can also be passed along with a feature to provide
Expand Down
Loading