New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add block data to REST API #2649

Closed
wants to merge 54 commits into
base: master
from
Commits
Jump to file or symbol
Failed to load files and symbols.
+8 −12
Diff settings

Always

Just for now

Viewing a subset of changes. View all

remove extraneous extra loop

  • Loading branch information...
adamsilverstein committed Sep 4, 2017
commit 5a17b339129fd509648dc56999ce4aa487366142
View
@@ -107,7 +107,6 @@ function get_block_data_for_api_from_post_content( $content ) {
$registry = WP_Block_Type_Registry::get_instance();
$blocks = gutenberg_parse_blocks( $content );
$data = array();
$data_pre = array();
// Loop thru the blocks, adding rendered content when available.
foreach ( $blocks as $block ) {
@@ -119,18 +118,15 @@ function get_block_data_for_api_from_post_content( $content ) {
if ( null !== $block_type ) {
$block['renderedContent'] = $block_type->render( $attributes, $raw_content );
}
$data_pre[] = $block;
}
}
// Remap the block fields for the response.
foreach ( $data_pre as $block ) {
$data[] = array(
'type' => $block['blockName'],
'attributes' => $block['attrs'],
'content' => $block['rawContent'],
'rendered' => isset( $block['renderedContent'] ) ? $block['renderedContent'] : null,
);
// Remap the block fields for the response.
$data[] = array(
'type' => $block['blockName'],
'attributes' => $block['attrs'],
'content' => $block['rawContent'],
'rendered' => isset( $block['renderedContent'] ) ? $block['renderedContent'] : null,
);
}
}
return $data;
ProTip! Use n and p to navigate between commits in a pull request.