LLMS_Abstract_Generator_Posts::handle_reusable_blocks( LLMS_Post_Model $post, array $raw )
Handle importing of reusable blocks stored in post content
Parameters Parameters
- $post
-
(LLMS_Post_Model) (Required) Instance of a post model.
- $raw
-
(array) (Required) Array of raw data.
Return Return
(null|bool) Returns null
when importing is disabled, false
when there are no blocks to import, and true
on success.
Source Source
File: includes/abstracts/llms-abstract-generator-posts.php
protected function handle_reusable_blocks( $post, $raw ) { // Importing blocks is disabled. if ( ! $this->is_reusable_block_importing_enabled() ) { return null; } // No blocks to import. if ( empty( $raw['_extras']['blocks'] ) ) { return false; } $find = array(); $replace = array(); foreach ( $raw['_extras']['blocks'] as $block_id => $block ) { $new_id = $this->create_reusable_block( $block_id, $block ); if ( ! is_wp_error( $new_id ) && is_numeric( $new_id ) ) { $find[] = sprintf( '<!-- wp:block {"ref":%d}', absint( $block_id ) ); $replace[] = sprintf( '<!-- wp:block {"ref":%d}', $new_id ); } } if ( $find && $replace ) { $args = array( 'ID' => $post->get( 'id' ), 'post_content' => str_replace( $find, $replace, $post->get( 'content', true ) ), ); return wp_update_post( $args ) ? true : false; } return false; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
4.7.0 | Introduced. |