Tribe__Events__Editor::update_post_content_to_blocks( int $post )
Making sure we have correct post content for blocks after going into Gutenberg
Contents
Parameters
- $post
-
(int) (Required) Which post we will migrate
Return
(bool)
Source
File: src/Tribe/Editor.php
public function update_post_content_to_blocks( $post ) {
$post = get_post( $post );
$blocks = $this->get_classic_template();
$content = array();
foreach ( $blocks as $key => $block_param ) {
$slug = reset( $block_param );
/**
* Add an opportunity to set the default params of a block when migrating from classic into
* blocks editor.
*
* @since 4.7
*
* @param mixed $params Either array if set to values or slug string
* @param string $slug Name of the block edited
* @param WP_Post $post Post that is being affected
*/
$params = apply_filters( 'tribe_blocks_editor_update_classic_content_params', end( $block_param ), $slug, $post );
$json_param = false;
// Checks for Params to attach to the tag
if ( is_array( $params ) ) {
$json_param = json_encode( $params );
}
$block_tag = "<!-- wp:{$slug} {$json_param} /-->";
if ( 'core/paragraph' === $slug ) {
if ( '' === $post->post_content ) {
continue;
}
$content[] = '<!-- wp:freeform -->';
$content[] = $post->post_content;
$content[] = '<!-- /wp:freeform -->';
} else {
$content[] = $block_tag;
}
}
$content = implode( "\n\r", $content );
/**
* Allow filtering of the Content updated
*
* @since 4.7
*
* @param string $content Content that will be updated
* @param WP_Post $post Which post we will migrate
* @param array $blocks Which blocks we are updating with
*/
$content = apply_filters( 'tribe_blocks_editor_update_classic_content', $content, $post, $blocks );
$status = wp_update_post( array(
'ID' => $post->ID,
'post_content' => $content,
) );
return $status;
}
Changelog
| Version | Description |
|---|---|
| 4.7 | Introduced. |