@@ -1317,41 +1317,32 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
13171317 'after '
13181318 );
13191319
1320- // Prepopulate with some test content in demo.
1320+ // Assign initial edits, if applicable. These are not initially assigned
1321+ // to the persisted post, but should be included in its save payload.
13211322 if ( $ is_new_post && $ is_demo ) {
1323+ // Prepopulate with some test content in demo.
13221324 ob_start ();
13231325 include gutenberg_dir_path () . 'post-content.php ' ;
13241326 $ demo_content = ob_get_clean ();
13251327
1326- wp_add_inline_script (
1327- 'wp-edit-post ' ,
1328- sprintf (
1329- 'window._wpGutenbergDefaultPost = { title: %s, content: %s }; ' ,
1330- wp_json_encode (
1331- array (
1332- 'raw ' => __ ( 'Welcome to the Gutenberg Editor ' , 'gutenberg ' ),
1333- )
1334- ),
1335- wp_json_encode (
1336- array (
1337- 'raw ' => $ demo_content ,
1338- )
1339- )
1340- )
1328+ $ initial_edits = array (
1329+ 'title ' => array (
1330+ 'raw ' => __ ( 'Welcome to the Gutenberg Editor ' , 'gutenberg ' ),
1331+ ),
1332+ 'content ' => array (
1333+ 'raw ' => $ demo_content ,
1334+ ),
13411335 );
13421336 } elseif ( $ is_new_post ) {
1343- wp_add_inline_script (
1344- 'wp-edit-post ' ,
1345- sprintf (
1346- 'window._wpGutenbergDefaultPost = { title: %s }; ' ,
1347- wp_json_encode (
1348- array (
1349- 'raw ' => '' ,
1350- 'rendered ' => apply_filters ( 'the_title ' , '' , $ post ->ID ),
1351- )
1352- )
1353- )
1337+ // Override "(Auto Draft)" new post default title with empty string,
1338+ // or filtered value.
1339+ $ initial_edits = array (
1340+ 'title ' => array (
1341+ 'raw ' => apply_filters ( 'the_title ' , '' , $ post ->ID ),
1342+ ),
13541343 );
1344+ } else {
1345+ $ initial_edits = null ;
13551346 }
13561347
13571348 // Prepare Jed locale data.
@@ -1489,10 +1480,9 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
14891480
14901481 $ init_script = <<<JS
14911482 ( function() {
1492- var editorSettings = %s;
14931483 window._wpLoadGutenbergEditor = new Promise( function( resolve ) {
14941484 wp.domReady( function() {
1495- resolve( wp.editPost.initializeEditor( 'editor', "%s", %d, editorSettings, window._wpGutenbergDefaultPost ) );
1485+ resolve( wp.editPost.initializeEditor( 'editor', "%s", %d, %s, %s ) );
14961486 } );
14971487 } );
14981488} )();
@@ -1508,7 +1498,13 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
15081498 */
15091499 $ editor_settings = apply_filters ( 'block_editor_settings ' , $ editor_settings , $ post );
15101500
1511- $ script = sprintf ( $ init_script , wp_json_encode ( $ editor_settings ), $ post ->post_type , $ post ->ID );
1501+ $ script = sprintf (
1502+ $ init_script ,
1503+ $ post ->post_type ,
1504+ $ post ->ID ,
1505+ wp_json_encode ( $ editor_settings ),
1506+ wp_json_encode ( $ initial_edits )
1507+ );
15121508 wp_add_inline_script ( 'wp-edit-post ' , $ script );
15131509
15141510 /**
0 commit comments