135 lines
3.2 KiB
PHP
135 lines
3.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Plugin Name: Homegrade content blocks
|
|
* Description: Un série de Blocks sur mesure pour l'écriture du contenu Homegrade
|
|
* Requires at least: 6.1
|
|
* Requires PHP: 7.0
|
|
* Version: 0.1.0
|
|
* Author: Deligraph
|
|
* Author URI: https://deligraph.com/
|
|
* Text Domain: test-de-block
|
|
*
|
|
* @package create-block
|
|
*/
|
|
|
|
|
|
include_once('templates.php');
|
|
|
|
function create_block_test_de_block_block_init()
|
|
{
|
|
|
|
register_block_type(__DIR__ . '/build/chapter-header');
|
|
register_block_type(__DIR__ . '/build/questions-container');
|
|
register_block_type(__DIR__ . '/build/questions-container-auto');
|
|
register_block_type(__DIR__ . '/build/content-heading');
|
|
register_block_type(__DIR__ . '/build/points-cles');
|
|
// register_block_type(__DIR__ . '/build/wpblock-cover');
|
|
// register_block_type(__DIR__ . '/build/wpblock-citation');
|
|
}
|
|
add_action('init', 'create_block_test_de_block_block_init');
|
|
|
|
|
|
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);
|
|
}
|
|
|
|
function wpblock_add_block_categories($categories)
|
|
{
|
|
return array_merge(
|
|
|
|
[
|
|
[
|
|
'slug' => 'homegrade-blocks',
|
|
'title' => __('Blocs Homegrade ', 'block-course'),
|
|
'icon' => 'heart',
|
|
|
|
],
|
|
],
|
|
$categories
|
|
);
|
|
}
|
|
add_action('block_categories', 'wpblock_add_block_categories', 25, 2);
|
|
|
|
|
|
function blocks_course_plugin_enqueue_assets()
|
|
{
|
|
$asset_file = include(plugin_dir_path(__FILE__) . 'build/index.asset.php');
|
|
wp_enqueue_script('homegrade-content-blocks', plugins_url('build/filters/filters.js', __FILE__), $asset_file['dependencies'], $asset_file['version']);
|
|
}
|
|
|
|
add_action('enqueue_block_editor_assets', 'blocks_course_plugin_enqueue_assets');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (function_exists("getThematiqueFamilySlug")) {
|
|
function getThematiqueFamilySlug($thematique_slug)
|
|
{
|
|
|
|
switch ($thematique_slug) {
|
|
case "energie":
|
|
case "urbanisme":
|
|
return "energies-urbanisme";
|
|
|
|
case "acoustique":
|
|
case "petites-coproprietes":
|
|
return "acoustique-coproprietes";
|
|
|
|
case "isolation":
|
|
case "au-quotidien":
|
|
return "isolation-quotidien";
|
|
|
|
case "energies":
|
|
case "urbanisme":
|
|
return "energies-urbanisme";
|
|
|
|
case "patrimoine":
|
|
case "renovation":
|
|
return "patrimoine-renovation";
|
|
|
|
case "location":
|
|
return "location";
|
|
}
|
|
}
|
|
}
|