Skip to content

Commit

Permalink
Add rendered and raw version to the content.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Apr 19, 2019
1 parent 9dea6b2 commit b84a588
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/class-wp-rest-widget-areas-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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 ),
),
)
);
}

Expand All @@ -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 ) ) {
Expand Down

0 comments on commit b84a588

Please sign in to comment.