LLMS_Abstract_Generator_Posts::create_reusable_block( int $block_id, array $block )
Creates a reusable block
Parameters Parameters
- $block_id
-
(int) (Required) WP_Post ID of the block being imported. This will be the ID as found on the original site.
- $block
-
(array) (Required) Array of block data.<br>
- 'title'
(string) Title of the reusable block.<br> - 'content'
(string) Content of the reusable block.<br>
- 'title'
Return Return
(bool|int) The WP_Post ID of the new block on success or false on error.
Source Source
File: includes/abstracts/llms-abstract-generator-posts.php
protected function create_reusable_block( $block_id, $block ) {
$block_id = absint( $block_id );
// Check if the block was previously imported.
$id = empty( $this->reusable_blocks[ $block_id ] ) ? false : $this->reusable_blocks[ $block_id ];
if ( ! $id ) {
// If the block already exists, don't create it again.
$existing = get_post( $block_id );
if ( $existing && 'wp_block' === $existing->post_type && $block['title'] === $existing->post_title && $block['content'] === $existing->post_content ) {
return false;
}
$id = $this->insert_resuable_block( $block_id, $block );
}
// Don't return 0 if `wp_insert_post()` fails.
return $id ? $id : false;
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 4.7.0 | Introduced. |