| 1 |
<?php |
| 2 |
/** |
| 3 |
* REST API compatibility functions for real-time collaboration. |
| 4 |
* |
| 5 |
* @package gutenberg |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Overrides the default REST controller for autosaves to fix real-time |
| 10 |
* collaboration on draft posts. |
| 11 |
* |
| 12 |
* When RTC is enabled, regular draft autosaves are stored as revisions instead |
| 13 |
* of updating the parent post based on its lock and author. Auto-drafts are |
| 14 |
* still promoted to drafts. |
| 15 |
* |
| 16 |
* Only overrides when RTC is enabled and autosave_rest_controller_class is not |
| 17 |
* explicitly set, i.e. when WP_REST_Autosaves_Controller would be used by |
| 18 |
* default. Post types with their own specialized autosave controller (e.g. |
| 19 |
* templates) are left alone. |
| 20 |
* |
| 21 |
* @param array $args Array of arguments for registering a post type. |
| 22 |
* @return array Modified array of arguments. |
| 23 |
*/ |
| 24 |
function gutenberg_override_autosaves_rest_controller( $args ) { |
| 25 |
if ( empty( $args['autosave_rest_controller_class'] ) && wp_is_collaboration_enabled() ) { |
| 26 |
$args['autosave_rest_controller_class'] = 'Gutenberg_REST_Autosaves_Controller'; |
| 27 |
} |
| 28 |
return $args; |
| 29 |
} |
| 30 |
|
| 31 |
add_filter( 'register_post_type_args', 'gutenberg_override_autosaves_rest_controller', 10, 1 ); |
| 32 |
|