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 );
|
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 ) {
|
} elseif ( false !== $this->supports ) {
|
||||||
// Add default features.
|
// 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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! post_type_supports( $this->name, 'autosave' ) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if ( 'attachment' === $this->name ) {
|
if ( 'attachment' === $this->name ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -570,14 +570,14 @@ function create_initial_post_types() {
|
||||||
register_post_type(
|
register_post_type(
|
||||||
'wp_font_family',
|
'wp_font_family',
|
||||||
array(
|
array(
|
||||||
'labels' => array(
|
'labels' => array(
|
||||||
'name' => __( 'Font Families' ),
|
'name' => __( 'Font Families' ),
|
||||||
'singular_name' => __( 'Font Family' ),
|
'singular_name' => __( 'Font Family' ),
|
||||||
),
|
),
|
||||||
'public' => false,
|
'public' => false,
|
||||||
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
|
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
|
||||||
'hierarchical' => false,
|
'hierarchical' => false,
|
||||||
'capabilities' => array(
|
'capabilities' => array(
|
||||||
'read' => 'edit_theme_options',
|
'read' => 'edit_theme_options',
|
||||||
'read_private_posts' => 'edit_theme_options',
|
'read_private_posts' => 'edit_theme_options',
|
||||||
'create_posts' => 'edit_theme_options',
|
'create_posts' => 'edit_theme_options',
|
||||||
|
@ -589,28 +589,27 @@ function create_initial_post_types() {
|
||||||
'delete_others_posts' => 'edit_theme_options',
|
'delete_others_posts' => 'edit_theme_options',
|
||||||
'delete_published_posts' => 'edit_theme_options',
|
'delete_published_posts' => 'edit_theme_options',
|
||||||
),
|
),
|
||||||
'map_meta_cap' => true,
|
'map_meta_cap' => true,
|
||||||
'query_var' => false,
|
'query_var' => false,
|
||||||
'rewrite' => false,
|
'rewrite' => false,
|
||||||
'show_in_rest' => true,
|
'show_in_rest' => true,
|
||||||
'rest_base' => 'font-families',
|
'rest_base' => 'font-families',
|
||||||
'rest_controller_class' => 'WP_REST_Font_Families_Controller',
|
'rest_controller_class' => 'WP_REST_Font_Families_Controller',
|
||||||
// Disable autosave endpoints for font families.
|
'supports' => array( 'title' ),
|
||||||
'autosave_rest_controller_class' => 'stdClass',
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
register_post_type(
|
register_post_type(
|
||||||
'wp_font_face',
|
'wp_font_face',
|
||||||
array(
|
array(
|
||||||
'labels' => array(
|
'labels' => array(
|
||||||
'name' => __( 'Font Faces' ),
|
'name' => __( 'Font Faces' ),
|
||||||
'singular_name' => __( 'Font Face' ),
|
'singular_name' => __( 'Font Face' ),
|
||||||
),
|
),
|
||||||
'public' => false,
|
'public' => false,
|
||||||
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
|
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
|
||||||
'hierarchical' => false,
|
'hierarchical' => false,
|
||||||
'capabilities' => array(
|
'capabilities' => array(
|
||||||
'read' => 'edit_theme_options',
|
'read' => 'edit_theme_options',
|
||||||
'read_private_posts' => 'edit_theme_options',
|
'read_private_posts' => 'edit_theme_options',
|
||||||
'create_posts' => 'edit_theme_options',
|
'create_posts' => 'edit_theme_options',
|
||||||
|
@ -622,14 +621,13 @@ function create_initial_post_types() {
|
||||||
'delete_others_posts' => 'edit_theme_options',
|
'delete_others_posts' => 'edit_theme_options',
|
||||||
'delete_published_posts' => 'edit_theme_options',
|
'delete_published_posts' => 'edit_theme_options',
|
||||||
),
|
),
|
||||||
'map_meta_cap' => true,
|
'map_meta_cap' => true,
|
||||||
'query_var' => false,
|
'query_var' => false,
|
||||||
'rewrite' => false,
|
'rewrite' => false,
|
||||||
'show_in_rest' => true,
|
'show_in_rest' => true,
|
||||||
'rest_base' => 'font-families/(?P<font_family_id>[\d]+)/font-faces',
|
'rest_base' => 'font-families/(?P<font_family_id>[\d]+)/font-faces',
|
||||||
'rest_controller_class' => 'WP_REST_Font_Faces_Controller',
|
'rest_controller_class' => 'WP_REST_Font_Faces_Controller',
|
||||||
// Disable autosave endpoints for font faces.
|
'supports' => array( 'title' ),
|
||||||
'autosave_rest_controller_class' => 'stdClass',
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1719,8 +1717,10 @@ function get_post_types( $args = array(), $output = 'names', $operator = 'and' )
|
||||||
* 'editor', 'comments', 'revisions', 'trackbacks', 'author', 'excerpt',
|
* 'editor', 'comments', 'revisions', 'trackbacks', 'author', 'excerpt',
|
||||||
* 'page-attributes', 'thumbnail', 'custom-fields', and 'post-formats'.
|
* 'page-attributes', 'thumbnail', 'custom-fields', and 'post-formats'.
|
||||||
* Additionally, the 'revisions' feature dictates whether the post type
|
* 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
|
||||||
* comments count will show on the edit screen. A feature can also be
|
* 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
|
* specified as an array of arguments to provide additional information
|
||||||
* about supporting that feature.
|
* about supporting that feature.
|
||||||
* Example: `array( 'my_feature', array( 'field' => 'value' ) )`.
|
* Example: `array( 'my_feature', array( 'field' => 'value' ) )`.
|
||||||
|
@ -2198,7 +2198,8 @@ function _add_post_type_submenus() {
|
||||||
* 'thumbnail', 'custom-fields', and 'post-formats'.
|
* 'thumbnail', 'custom-fields', and 'post-formats'.
|
||||||
*
|
*
|
||||||
* Additionally, the 'revisions' feature dictates whether the post type will
|
* 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.
|
* count will show on the edit screen.
|
||||||
*
|
*
|
||||||
* A third, optional parameter can also be passed along with a feature to provide
|
* A third, optional parameter can also be passed along with a feature to provide
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue