Last active
May 11, 2024 11:08
-
-
Save BhargavBhandari90/719c24ee50a74a7789cb0ffaabebfcf7 to your computer and use it in GitHub Desktop.
Make Custom Block compatible with BuddyBoss App's App Editor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get rid of BBApp block compatibility error. | |
* | |
* @param [type] $allow_blocks_for_editor_to_app_editor | |
* @return void | |
*/ | |
function bb_allow_blocks_for_editor_to_app_editor( $allow_blocks_for_editor_to_app_editor ) { | |
$allow_blocks_for_editor_to_app_editor[] = 'your-block-name'; // Get from block.json ( "name" attribute ) | |
return $allow_blocks_for_editor_to_app_editor; | |
} | |
add_filter( 'allow_blocks_for_editor_to_app_editor', 'bb_allow_blocks_for_editor_to_app_editor' ); | |
/** | |
* Set helpful attributes to block response. | |
* | |
* @param array $app_page_data | |
* @param array $block_data | |
* @param array $render | |
* @return array | |
*/ | |
function bb_bbapp_custom_block_data( $app_page_data, $block_data, $render ) { | |
if ( 'your-block-name' === $block_data['blockName'] ) { | |
$app_page_data['data']['attrs'] = $block_data['attrs']; | |
} | |
return $app_page_data; | |
} | |
add_filter( 'bbapp_custom_block_data', 'bb_bbapp_custom_block_data', 10 , 3 ); | |
/** | |
* Add block in allowed to app editor list. | |
* | |
* @param array $allowed_block_types | |
* @return array | |
*/ | |
function bb_bbapp_app_page_app_blocks( $allowed_block_types ) { | |
$allowed_block_types[] = 'your-block-name'; // Get from block.json ( "name" attribute ) | |
return $allowed_block_types; | |
} | |
add_filter( 'bbapp_app_page_app_blocks', 'bb_bbapp_app_page_app_blocks' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment