<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[58201] trunk: Posts, Post Types: Autosave: Allow disabling autosave support per post type.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/58201">58201</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/58201","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>swissspidy</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2024-05-27 09:04:10 +0000 (Mon, 27 May 2024)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/ticket/41172">#41172</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasswpposttypephp">trunk/src/wp-includes/class-wp-post-type.php</a></li>
<li><a href="#trunksrcwpincludespostphp">trunk/src/wp-includes/post.php</a></li>
<li><a href="#trunktestsphpunittestsposttypesphp">trunk/tests/phpunit/tests/post/types.php</a></li>
<li><a href="#trunktestsphpunittestspostwpPostTypephp">trunk/tests/phpunit/tests/post/wpPostType.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsfontsfontlibrarypostTypesphp">trunk/tests/phpunit/tests/fonts/font-library/postTypes.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesclasswpposttypephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-post-type.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-post-type.php      2024-05-26 20:49:30 UTC (rev 58200)
+++ trunk/src/wp-includes/class-wp-post-type.php        2024-05-27 09:04:10 UTC (rev 58201)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -670,9 +670,20 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px">                        unset( $this->supports );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                       /*
+                        * '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' );
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                 } elseif ( false !== $this->supports ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        // Add default features.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        add_post_type_support( $this->name, array( 'title', 'editor' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 add_post_type_support( $this->name, array( 'title', 'editor', 'autosave' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -922,6 +933,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        return null;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                if ( ! post_type_supports( $this->name, 'autosave' ) ) {
+                       return null;
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( 'attachment' === $this->name ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return null;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span></span></pre></div>
<a id="trunksrcwpincludespostphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/post.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/post.php    2024-05-26 20:49:30 UTC (rev 58200)
+++ trunk/src/wp-includes/post.php      2024-05-27 09:04:10 UTC (rev 58201)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -570,14 +570,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">        register_post_type(
</span><span class="cx" style="display: block; padding: 0 10px">                'wp_font_family',
</span><span class="cx" style="display: block; padding: 0 10px">                array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'labels'                         => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'labels'                => array(
</ins><span class="cx" style="display: block; padding: 0 10px">                                 'name'          => __( 'Font Families' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'singular_name' => __( 'Font Family' ),
</span><span class="cx" style="display: block; padding: 0 10px">                        ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'public'                         => false,
-                       '_builtin'                       => true, /* internal use only. don't use this when registering your own post type. */
-                       'hierarchical'                   => false,
-                       'capabilities'                   => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'public'                => false,
+                       '_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
+                       'hierarchical'          => false,
+                       'capabilities'          => array(
</ins><span class="cx" style="display: block; padding: 0 10px">                                 'read'                   => 'edit_theme_options',
</span><span class="cx" style="display: block; padding: 0 10px">                                'read_private_posts'     => 'edit_theme_options',
</span><span class="cx" style="display: block; padding: 0 10px">                                'create_posts'           => 'edit_theme_options',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -589,14 +589,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'delete_others_posts'    => 'edit_theme_options',
</span><span class="cx" style="display: block; padding: 0 10px">                                'delete_published_posts' => 'edit_theme_options',
</span><span class="cx" style="display: block; padding: 0 10px">                        ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'map_meta_cap'                   => true,
-                       'query_var'                      => false,
-                       'rewrite'                        => false,
-                       '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',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'map_meta_cap'          => true,
+                       'query_var'             => false,
+                       'rewrite'               => false,
+                       'show_in_rest'          => true,
+                       'rest_base'             => 'font-families',
+                       'rest_controller_class' => 'WP_REST_Font_Families_Controller',
+                       'supports'              => array( 'title' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                 )
</span><span class="cx" style="display: block; padding: 0 10px">        );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -603,14 +602,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">        register_post_type(
</span><span class="cx" style="display: block; padding: 0 10px">                'wp_font_face',
</span><span class="cx" style="display: block; padding: 0 10px">                array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'labels'                         => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'labels'                => array(
</ins><span class="cx" style="display: block; padding: 0 10px">                                 'name'          => __( 'Font Faces' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'singular_name' => __( 'Font Face' ),
</span><span class="cx" style="display: block; padding: 0 10px">                        ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'public'                         => false,
-                       '_builtin'                       => true, /* internal use only. don't use this when registering your own post type. */
-                       'hierarchical'                   => false,
-                       'capabilities'                   => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'public'                => false,
+                       '_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
+                       'hierarchical'          => false,
+                       'capabilities'          => array(
</ins><span class="cx" style="display: block; padding: 0 10px">                                 'read'                   => 'edit_theme_options',
</span><span class="cx" style="display: block; padding: 0 10px">                                'read_private_posts'     => 'edit_theme_options',
</span><span class="cx" style="display: block; padding: 0 10px">                                'create_posts'           => 'edit_theme_options',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -622,14 +621,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'delete_others_posts'    => 'edit_theme_options',
</span><span class="cx" style="display: block; padding: 0 10px">                                'delete_published_posts' => 'edit_theme_options',
</span><span class="cx" style="display: block; padding: 0 10px">                        ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'map_meta_cap'                   => true,
-                       'query_var'                      => false,
-                       'rewrite'                        => false,
-                       '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',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'map_meta_cap'          => true,
+                       'query_var'             => false,
+                       'rewrite'               => false,
+                       'show_in_rest'          => true,
+                       'rest_base'             => 'font-families/(?P<font_family_id>[\d]+)/font-faces',
+                       'rest_controller_class' => 'WP_REST_Font_Faces_Controller',
+                       'supports'              => array( 'title' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                 )
</span><span class="cx" style="display: block; padding: 0 10px">        );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1719,8 +1717,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">  *                                                         'editor', 'comments', 'revisions', 'trackbacks', 'author', 'excerpt',
</span><span class="cx" style="display: block; padding: 0 10px">  *                                                         'page-attributes', 'thumbnail', 'custom-fields', and 'post-formats'.
</span><span class="cx" style="display: block; padding: 0 10px">  *                                                         Additionally, the 'revisions' feature dictates whether the post type
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *                                                         will store revisions, and the 'comments' feature dictates whether the
- *                                                         comments count will show on the edit screen. A feature can also be
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *                                                         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
</ins><span class="cx" style="display: block; padding: 0 10px">  *                                                         specified as an array of arguments to provide additional information
</span><span class="cx" style="display: block; padding: 0 10px">  *                                                         about supporting that feature.
</span><span class="cx" style="display: block; padding: 0 10px">  *                                                         Example: `array( 'my_feature', array( 'field' => 'value' ) )`.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2198,7 +2198,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * 'thumbnail', 'custom-fields', and 'post-formats'.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * Additionally, the 'revisions' feature dictates whether the post type will
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * store revisions, and the 'comments' feature dictates whether the comments
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * store revisions, the 'autosave' feature dictates whether the post type
+ * will be autosaved, and the 'comments' feature dictates whether the comments
</ins><span class="cx" style="display: block; padding: 0 10px">  * count will show on the edit screen.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * A third, optional parameter can also be passed along with a feature to provide
</span></span></pre></div>
<a id="trunktestsphpunittestsfontsfontlibrarypostTypesphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/tests/fonts/font-library/postTypes.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/fonts/font-library/postTypes.php                                (rev 0)
+++ trunk/tests/phpunit/tests/fonts/font-library/postTypes.php  2024-05-27 09:04:10 UTC (rev 58201)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,45 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Test the wp_font_family and wp_font_face post types.
+ *
+ * @package WordPress
+ * @subpackage Font Library
+ *
+ * @group fonts
+ * @group font-library
+ */
+class Tests_Fonts_Post_Types extends WP_UnitTestCase {
+       /**
+        * @ticket 41172
+        */
+       public function test_wp_font_family_does_not_support_autosaves() {
+               $this->assertFalse( post_type_supports( 'wp_font_family', 'autosave' ) );
+       }
+
+       /**
+        * @ticket 41172
+        */
+       public function test_wp_font_face_does_not_support_autosaves() {
+               $this->assertFalse( post_type_supports( 'wp_font_face', 'autosave' ) );
+       }
+
+       /**
+        * @ticket 41172
+        */
+       public function test_wp_font_family_does_not_have_an_autosave_controller() {
+               $post_type_object = get_post_type_object( 'wp_font_family' );
+               $controller       = $post_type_object->get_autosave_rest_controller();
+
+               $this->assertNull( $controller );
+       }
+
+       /**
+        * @ticket 41172
+        */
+       public function test_wp_font_face_does_not_have_an_autosave_controller() {
+               $post_type_object = get_post_type_object( 'wp_font_face' );
+               $controller       = $post_type_object->get_autosave_rest_controller();
+
+               $this->assertNull( $controller );
+       }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/tests/fonts/font-library/postTypes.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunittestsposttypesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/post/types.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/post/types.php  2024-05-26 20:49:30 UTC (rev 58200)
+++ trunk/tests/phpunit/tests/post/types.php    2024-05-27 09:04:10 UTC (rev 58201)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -217,16 +217,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="cx" style="display: block; padding: 0 10px">         * @ticket 21586
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         * @ticket 41172
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_post_type_with_no_support() {
</span><span class="cx" style="display: block; padding: 0 10px">                register_post_type( 'foo', array( 'supports' => array() ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertTrue( post_type_supports( 'foo', 'editor' ) );
-               $this->assertTrue( post_type_supports( 'foo', 'title' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertTrue( post_type_supports( 'foo', 'editor' ), 'Editor support should be enabled by default.' );
+               $this->assertTrue( post_type_supports( 'foo', 'title' ), 'Title support should be enabled by default.' );
+               $this->assertTrue( post_type_supports( 'foo', 'autosave' ), 'Autosaves support should be enabled by default.' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 _unregister_post_type( 'foo' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                register_post_type( 'foo', array( 'supports' => false ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertFalse( post_type_supports( 'foo', 'editor' ) );
-               $this->assertFalse( post_type_supports( 'foo', 'title' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertFalse( post_type_supports( 'foo', 'editor' ), 'Editor support should be disabled.' );
+               $this->assertFalse( post_type_supports( 'foo', 'title' ), 'Title support should be disabled.' );
+               $this->assertFalse( post_type_supports( 'foo', 'autosave' ), 'Autosaves support should be disabled.' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 _unregister_post_type( 'foo' );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -432,9 +435,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSameSetsWithIndex(
</span><span class="cx" style="display: block; padding: 0 10px">                        array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'editor' => true,
-                               'author' => true,
-                               'title'  => true,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'editor'   => true,
+                               'author'   => true,
+                               'title'    => true,
+                               'autosave' => true,
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        $_wp_post_type_features['foo']
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -589,4 +593,55 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_get_post_types_by_support_non_existent_feature() {
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSameSets( array(), get_post_types_by_support( 'somefeature' ) );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * @ticket 41172
+        */
+       public function test_post_type_supports_autosave_based_on_editor_support() {
+               register_post_type( 'foo', array( 'supports' => array( 'editor' ) ) );
+               $this->assertTrue( post_type_supports( 'foo', 'autosave' ) );
+               _unregister_post_type( 'foo' );
+
+               register_post_type( 'foo', array( 'supports' => array( 'title' ) ) );
+               $this->assertFalse( post_type_supports( 'foo', 'autosave' ) );
+               _unregister_post_type( 'foo' );
+       }
+
+       /**
+        * @ticket 41172
+        */
+       public function test_removing_autosave_support_removes_rest_api_controller() {
+               register_post_type(
+                       'foo',
+                       array(
+                               'show_in_rest' => true,
+                               'supports'     => array( 'editor' ),
+                       )
+               );
+
+               $post_type_object = get_post_type_object( 'foo' );
+               $this->assertInstanceOf( 'WP_REST_Autosaves_Controller', $post_type_object->get_autosave_rest_controller(), 'Autosave controller should be set by default.' );
+
+               remove_post_type_support( 'foo', 'autosave' );
+               $post_type_object = get_post_type_object( 'foo' );
+               $this->assertSame( null, $post_type_object->get_autosave_rest_controller(), 'Autosave controller should be removed.' );
+               _unregister_post_type( 'foo' );
+       }
+
+       /**
+        * @ticket 41172
+        */
+       public function test_removing_editor_support_does_not_remove_autosave_support() {
+               register_post_type(
+                       'foo',
+                       array(
+                               'show_in_rest' => true,
+                               'supports'     => array( 'editor' ),
+                       )
+               );
+               remove_post_type_support( 'foo', 'editor' );
+
+               $this->assertFalse( post_type_supports( 'foo', 'editor' ), 'Post type should not support editor.' );
+               $this->assertTrue( post_type_supports( 'foo', 'autosave' ), 'Post type should still support autosaves.' );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestspostwpPostTypephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/post/wpPostType.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/post/wpPostType.php     2024-05-26 20:49:30 UTC (rev 58200)
+++ trunk/tests/phpunit/tests/post/wpPostType.php       2024-05-27 09:04:10 UTC (rev 58201)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -24,8 +24,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSameSets(
</span><span class="cx" style="display: block; padding: 0 10px">                        array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'title'  => true,
-                               'editor' => true,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'title'    => true,
+                               'editor'   => true,
+                               'autosave' => true,
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        $post_type_supports
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -56,6 +57,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'editor'    => true,
</span><span class="cx" style="display: block; padding: 0 10px">                                'comments'  => true,
</span><span class="cx" style="display: block; padding: 0 10px">                                'revisions' => true,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'autosave'  => true,
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        $post_type_supports
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span></span></pre>
</div>
</div>

</body>
</html>