@@ -30,8 +30,11 @@ function get_post_types_with_editor() {
3030 if ( ! function_exists ( 'use_block_editor_for_post_type ' ) ) {
3131 require_once ABSPATH . 'wp-admin/includes/post.php ' ;
3232 }
33+ $ post_types = array_filter ( $ post_types , 'use_block_editor_for_post_type ' );
34+ $ post_types [] = 'wp_navigation ' ;
35+ $ post_types = array_filter ( $ post_types , 'post_type_exists ' );
3336
34- return array_filter ( $ post_types, ' use_block_editor_for_post_type ' ) ;
37+ return $ post_types ;
3538}
3639
3740/**
@@ -84,7 +87,11 @@ function wp_rest_blocks_init() {
8487 * @return bool
8588 */
8689function has_blocks_get_callback ( array $ object ) {
87- $ post = get_post ( $ object ['id ' ] );
90+ if ( isset ( $ object ['content ' ]['raw ' ] ) ) {
91+ return has_blocks ( $ object ['content ' ]['raw ' ] );
92+ }
93+ $ id = ! empty ( $ object ['wp_id ' ] ) ? $ object ['wp_id ' ] : $ object ['id ' ];
94+ $ post = get_post ( $ id );
8895 if ( ! $ post ) {
8996 return false ;
9097 }
@@ -100,7 +107,12 @@ function has_blocks_get_callback( array $object ) {
100107 * @return array
101108 */
102109function blocks_get_callback ( array $ object ) {
103- $ post = get_post ( $ object ['id ' ] );
110+ $ id = ! empty ( $ object ['wp_id ' ] ) ? $ object ['wp_id ' ] : $ object ['id ' ];
111+ if ( isset ( $ object ['content ' ]['raw ' ] ) ) {
112+ return get_blocks ( $ object ['content ' ]['raw ' ], $ id );
113+ }
114+ $ id = ! empty ( $ object ['wp_id ' ] ) ? $ object ['wp_id ' ] : $ object ['id ' ];
115+ $ post = get_post ( $ id );
104116 $ output = [];
105117 if ( ! $ post ) {
106118 return $ output ;
0 commit comments