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/post.php

    r58200 r58201  
    571571        'wp_font_family',
    572572        array(
    573             'labels'                         => array(
     573            'labels'                => array(
    574574                'name'          => __( 'Font Families' ),
    575575                'singular_name' => __( 'Font Family' ),
    576576            ),
    577             'public'                         => false,
    578             '_builtin'                       => true, /* internal use only. don't use this when registering your own post type. */
    579             'hierarchical'                   => false,
    580             'capabilities'                   => array(
     577            'public'                => false,
     578            '_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
     579            'hierarchical'          => false,
     580            'capabilities'          => array(
    581581                'read'                   => 'edit_theme_options',
    582582                'read_private_posts'     => 'edit_theme_options',
     
    590590                'delete_published_posts' => 'edit_theme_options',
    591591            ),
    592             'map_meta_cap'                   => true,
    593             'query_var'                      => false,
    594             'rewrite'                        => false,
    595             'show_in_rest'                   => true,
    596             'rest_base'                      => 'font-families',
    597             'rest_controller_class'          => 'WP_REST_Font_Families_Controller',
    598             // Disable autosave endpoints for font families.
    599             'autosave_rest_controller_class' => 'stdClass',
     592            'map_meta_cap'          => true,
     593            'query_var'             => false,
     594            'rewrite'               => false,
     595            'show_in_rest'          => true,
     596            'rest_base'             => 'font-families',
     597            'rest_controller_class' => 'WP_REST_Font_Families_Controller',
     598            'supports'              => array( 'title' ),
    600599        )
    601600    );
     
    604603        'wp_font_face',
    605604        array(
    606             'labels'                         => array(
     605            'labels'                => array(
    607606                'name'          => __( 'Font Faces' ),
    608607                'singular_name' => __( 'Font Face' ),
    609608            ),
    610             'public'                         => false,
    611             '_builtin'                       => true, /* internal use only. don't use this when registering your own post type. */
    612             'hierarchical'                   => false,
    613             'capabilities'                   => array(
     609            'public'                => false,
     610            '_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
     611            'hierarchical'          => false,
     612            'capabilities'          => array(
    614613                'read'                   => 'edit_theme_options',
    615614                'read_private_posts'     => 'edit_theme_options',
     
    623622                'delete_published_posts' => 'edit_theme_options',
    624623            ),
    625             'map_meta_cap'                   => true,
    626             'query_var'                      => false,
    627             'rewrite'                        => false,
    628             'show_in_rest'                   => true,
    629             'rest_base'                      => 'font-families/(?P<font_family_id>[\d]+)/font-faces',
    630             'rest_controller_class'          => 'WP_REST_Font_Faces_Controller',
    631             // Disable autosave endpoints for font faces.
    632             'autosave_rest_controller_class' => 'stdClass',
     624            'map_meta_cap'          => true,
     625            'query_var'             => false,
     626            'rewrite'               => false,
     627            'show_in_rest'          => true,
     628            'rest_base'             => 'font-families/(?P<font_family_id>[\d]+)/font-faces',
     629            'rest_controller_class' => 'WP_REST_Font_Faces_Controller',
     630            'supports'              => array( 'title' ),
    633631        )
    634632    );
     
    17201718 *                                                         'page-attributes', 'thumbnail', 'custom-fields', and 'post-formats'.
    17211719 *                                                         Additionally, the 'revisions' feature dictates whether the post type
    1722  *                                                         will store revisions, and the 'comments' feature dictates whether the
    1723  *                                                         comments count will show on the edit screen. A feature can also be
     1720 *                                                         will store revisions, the 'autosave' feature dictates whether the post type
     1721 *                                                         will be autosaved, and the 'comments' feature dictates whether the
     1722 *                                                         comments count will show on the edit screen. For backward compatibility reasons,
     1723 *                                                         adding 'editor' support implies 'autosave' support too. A feature can also be
    17241724 *                                                         specified as an array of arguments to provide additional information
    17251725 *                                                         about supporting that feature.
     
    21992199 *
    22002200 * Additionally, the 'revisions' feature dictates whether the post type will
    2201  * store revisions, and the 'comments' feature dictates whether the comments
     2201 * store revisions, the 'autosave' feature dictates whether the post type
     2202 * will be autosaved, and the 'comments' feature dictates whether the comments
    22022203 * count will show on the edit screen.
    22032204 *
Note: See TracChangeset for help on using the changeset viewer.