mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-18 14:21:25 +01:00
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. Built from https://develop.svn.wordpress.org/trunk@58201 git-svn-id: http://core.svn.wordpress.org/trunk@57664 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
eba0df8c7b
commit
3504e15aa9
@ -670,9 +670,20 @@ final class WP_Post_Type {
|
||||
}
|
||||
}
|
||||
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' );
|
||||
}
|
||||
} 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' ) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -922,6 +933,10 @@ final class WP_Post_Type {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( ! post_type_supports( $this->name, 'autosave' ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( 'attachment' === $this->name ) {
|
||||
return null;
|
||||
}
|
||||
|
@ -595,8 +595,7 @@ function create_initial_post_types() {
|
||||
'show_in_rest' => true,
|
||||
'rest_base' => 'font-families',
|
||||
'rest_controller_class' => 'WP_REST_Font_Families_Controller',
|
||||
// Disable autosave endpoints for font families.
|
||||
'autosave_rest_controller_class' => 'stdClass',
|
||||
'supports' => array( 'title' ),
|
||||
)
|
||||
);
|
||||
|
||||
@ -628,8 +627,7 @@ function create_initial_post_types() {
|
||||
'show_in_rest' => true,
|
||||
'rest_base' => 'font-families/(?P<font_family_id>[\d]+)/font-faces',
|
||||
'rest_controller_class' => 'WP_REST_Font_Faces_Controller',
|
||||
// Disable autosave endpoints for font faces.
|
||||
'autosave_rest_controller_class' => 'stdClass',
|
||||
'supports' => array( 'title' ),
|
||||
)
|
||||
);
|
||||
|
||||
@ -1719,8 +1717,10 @@ 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
|
||||
* comments count will show on the edit screen. A feature can also be
|
||||
* will 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. For backward compatibility reasons,
|
||||
* adding 'editor' support implies 'autosave' support too. A feature can also be
|
||||
* specified as an array of arguments to provide additional information
|
||||
* about supporting that feature.
|
||||
* Example: `array( 'my_feature', array( 'field' => 'value' ) )`.
|
||||
@ -2198,7 +2198,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
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.6-alpha-58200';
|
||||
$wp_version = '6.6-alpha-58201';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user