FEATURE addind a blockVariation style for the core heading to handle a streoked after

This commit is contained in:
Antoine M 2025-11-26 11:58:07 +01:00
parent 2d24bd3a1d
commit ae873507e2
2 changed files with 44 additions and 0 deletions

View File

@ -100,3 +100,28 @@ function carhop_register_blocks()
);
}
add_action('init', 'carhop_register_blocks');
/* ----------------------------------------------------------------
##### EDITOR EXTENSIONS
------------------------------------------------------------------*/
/**
* Étend le bloc Titre (core/heading) avec un attribut "carhopVariant"
* et ajoute une interface pour choisir une variante (ajoute une classe CSS).
*/
function carhop_enqueue_editor_assets()
{
$script_path = __DIR__ . '/src/core-heading-variant/editor.js';
if (!file_exists($script_path)) {
return;
}
wp_enqueue_script(
'carhop-heading-variant',
plugins_url('src/core-heading-variant/editor.js', __FILE__),
array('wp-blocks', 'wp-element', 'wp-dom-ready', 'wp-components', 'wp-compose', 'wp-data', 'wp-hooks', 'wp-i18n', 'wp-block-editor', 'wp-edit-post'),
filemtime($script_path),
true
);
}
add_action('enqueue_block_editor_assets', 'carhop_enqueue_editor_assets');

View File

@ -0,0 +1,19 @@
// wp.blocks.registerBlockVariation("core/heading", {
// name: "heading-variant",
// title: "Titre + trait ",
// attributes: {
// className: "is-styled-stroked-after",
// },
// scope: ["inserter", "block", "transform"],
// });
wp.blocks.registerBlockStyle("core/heading", {
name: "stroked-after",
label: "Titre + trait ",
});
// wp.blocks.registerBlockStyle("carhop-blocks/heading", {
// name: "stroked-after",
// label: "Titre + trait ",
// });