From b84a588a82444dfa78fadd4fccd3557a013016f0 Mon Sep 17 00:00:00 2001 From: Jorge Date: Fri, 19 Apr 2019 14:39:33 +0100 Subject: [PATCH] Add rendered and raw version to the content. --- lib/class-wp-rest-widget-areas-controller.php | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/class-wp-rest-widget-areas-controller.php b/lib/class-wp-rest-widget-areas-controller.php index 14e7794fc4aed3..0bd61478c3fab2 100644 --- a/lib/class-wp-rest-widget-areas-controller.php +++ b/lib/class-wp-rest-widget-areas-controller.php @@ -116,13 +116,13 @@ protected function get_sidebar_data( $sidebar_id ) { ); } - $sidebar = $wp_registered_sidebars[ $sidebar_id ]; - $content = ''; + $sidebar = $wp_registered_sidebars[ $sidebar_id ]; + $content_string = ''; $sidebars_items = wp_get_sidebars_widgets(); if ( is_numeric( $sidebars_items[ $sidebar_id ] ) ) { - $post = get_post( $sidebars_items[ $sidebar_id ] ); - $content = apply_filters( 'the_content', $post->post_content ); + $post = get_post( $sidebars_items[ $sidebar_id ] ); + $content_string = $post->post_content; apply_filters( 'the_content', $post->post_content ); } elseif ( ! empty( $sidebars_items[ $sidebar_id ] ) ) { $blocks = array(); foreach ( $sidebars_items[ $sidebar_id ] as $item ) { @@ -136,12 +136,19 @@ protected function get_sidebar_data( $sidebar_id ) { 'innerHTML' => '', ); } - $content = serialize_blocks( $blocks ); + $content_string = serialize_blocks( $blocks ); } return array_merge( $sidebar, - array( 'content' => $content ) + array( + 'content' => array( + 'raw' => $content_string, + /** This filter is documented in wp-includes/post-template.php */ + 'rendered' => apply_filters( 'the_content', $content_string ), + 'block_version' => block_version( $content_string ), + ), + ) ); } @@ -162,6 +169,7 @@ protected function update_sidebar_data( $sidebar_id, $request ) { array( 'ID' => is_numeric( $sidebar ) ? $sidebar : 0, 'post_content' => $request['content'], + 'post_type' => 'wp_area', ) ); if ( ! is_numeric( $sidebar ) ) {