'homegrade-blocks', 'title' => __('Blocs Homegrade ', 'block-course'), 'icon' => 'heart', ], ], $categories ); } add_action('block_categories', 'wpblock_add_block_categories', 25, 2); /* --------------------------- REGISTER BLOCKS ---------------------------*/ function create_block_multiblocks_block_init() { // Dynamics register_block_type(__DIR__ . '/blocks/questions-container/build'); register_block_type(__DIR__ . '/blocks/vocabulaire-summary/build'); register_block_type(__DIR__ . '/blocks/illustration-thematique/build'); register_block_type(__DIR__ . '/blocks/focused-schema/build'); register_block_type(__DIR__ . '/blocks/focused-thematique/build'); // Statics register_block_type(__DIR__ . '/blocks/content-heading/build'); register_block_type(__DIR__ . '/blocks/points-cles/build'); register_block_type(__DIR__ . '/blocks/picture-banner/build'); register_block_type(__DIR__ . '/blocks/highlight/build'); register_block_type(__DIR__ . '/blocks/dynamicTest/build'); } add_action('init', 'create_block_multiblocks_block_init'); /* --------------------------- ENQUEUE EDITOR JS CONTEXT ---------------------------*/ function homegrade_blocks_enqueue_editor_assets() { $asset_file = include(plugin_dir_path(__FILE__) . 'build/index.asset.php'); wp_enqueue_script('homegrade-blocks-script', plugins_url('build/index.js', __FILE__), $asset_file['dependencies'], $asset_file['version']); wp_enqueue_style('blocks-course-plugin-boilerplate-style', plugins_url('build/index.css', __FILE__)); } add_action('enqueue_block_editor_assets', 'homegrade_blocks_enqueue_editor_assets'); /* ------------------------------------- ENQUEUE SCRIPTS AND STYLES FOR FRONT -------------------------------------*/ function blocks_course_plugin_enqueue_assets() { $asset_file = include(plugin_dir_path(__FILE__) . 'build/index.asset.php'); wp_enqueue_script('homegrade-blocks-tooltipjs', plugin_dir_url(__FILE__) . 'src/format-types/tooltip-front.js'); wp_enqueue_style('homegrade-blocks-tooltipcss', plugin_dir_url(__FILE__) . 'src/format-types/tooltip.css'); wp_enqueue_script('homegrade-blocks-brochurejs', plugin_dir_url(__FILE__) . 'src/format-types/brochure-front.js'); wp_enqueue_style('homegrade-blocks-brochurecss', plugin_dir_url(__FILE__) . 'src/format-types/brochure.css'); wp_localize_script('homegrade-blocks-brochurejs', 'img_path_datas', array( 'downloadIconPath' => plugin_dir_url(__FILE__) . '/src/img/icon_brochure_download.svg' )); } add_action('wp_enqueue_scripts', 'blocks_course_plugin_enqueue_assets'); /* --------------------------- ALLOWED BLOCKS ---------------------------*/ function homegrade_allowed_block_types($allowed_blocks, $editor_context) { if ('conseils' === $editor_context->post->post_type) { $allowed_blocks = array( 'core/paragraph', 'core/list', 'core/list-item', 'homegrade-content-blocks/chapter-header', 'homegrade-content-blocks/points-cles', 'homegrade-content-blocks/questions-container' ); } add_filter('homegrade_allowed_block_types', 'misha_allowed_block_types', 25, 2); if ('fiche-questions' === $editor_context->post->post_type) { $allowed_blocks = array( 'core/paragraph', 'core/heading', 'core/list', 'core/list-item', 'homegrade-content-blocks/chapter-header', 'homegrade-content-blocks/points-cles', 'homegrade-content-blocks/questions-container' ); } return $allowed_blocks; ####ONLY DEREGISTER FEW BLOCKS // get all the registered blocks // $blocks = WP_Block_Type_Registry::get_instance()->get_all_registered(); // then disable some of them // unset($blocks['core/paragraph']); // unset($blocks['core/heading']); // return the new list of allowed blocks // return array_keys($blocks); } /* ------------------------------------- POST TYPE TEMPLATES -------------------------------------*/ include_once('templates.php');