carhop__plugins__PROD-DEV/plugins/carhop-blocks/carhop-blocks.php

128 lines
3.5 KiB
PHP

<?php
/**
* Plugin Name: Carhop Blocks
* Description: Un série de Blocks sur mesure pour l'écriture du contenu de Carhop
* Author: Deligraph
* Text Domain: carhop-blocks
* Version: 0.1.0
* Requires at least: 6.7
* Requires PHP: 7.4
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: carhop-blocks
*
*
* @package CreateBlock
*/
if (! defined('ABSPATH')) {
exit; // Exit if accessed directly.
}
##### REGISTER BLOCKS #####
function create_block_carhop_blocks_block_init()
{
##### REGISTER ACF BLOCKS #####
register_block_type(__DIR__ . '/acf-blocks/gallery');
register_block_type(__DIR__ . '/acf-blocks/social-networks');
register_block_type(__DIR__ . '/acf-blocks/custom-video');
register_block_type(__DIR__ . '/acf-blocks/team-carhop');
if (function_exists('wp_register_block_types_from_metadata_collection')) {
wp_register_block_types_from_metadata_collection(__DIR__ . '/build', __DIR__ . '/build/blocks-manifest.php');
return;
}
if (function_exists('wp_register_block_metadata_collection')) {
wp_register_block_metadata_collection(__DIR__ . '/build', __DIR__ . '/build/blocks-manifest.php');
}
$manifest_data = require __DIR__ . '/build/blocks-manifest.php';
foreach (array_keys($manifest_data) as $block_type) {
register_block_type(__DIR__ . "/build/{$block_type}");
}
}
add_action('init', 'create_block_carhop_blocks_block_init');
##### REGISTER BLOCK CATEGORIES #####
function carhop_add_block_categories($categories)
{
return array_merge(
[
[
'slug' => 'carhop-blocks',
'title' => __('Blocs Carhop ', 'carhop-blocks'),
'icon' => 'heart',
],
],
$categories
);
}
add_action('block_categories_all', 'carhop_add_block_categories', 25, 2);
##### CUSTOM BLOCKS SETTINGS #####
require_once __DIR__ . '/src/audio-player/audio-player.php';
/* ----------------------------------------------------------------
##### ENQUEUE BLOCKS
------------------------------------------------------------------*/
function carhop_register_blocks()
{
if (!function_exists('register_block_type')) {
return;
}
register_block_type(__DIR__ . '/acf-blocks/gallery');
register_block_type(__DIR__ . '/acf-blocks/social-networks');
register_block_type(__DIR__ . '/acf-blocks/custom-video');
register_block_type(__DIR__ . '/acf-blocks/team-carhop');
// Enregistrer le script pour le bloc gallery
wp_register_script(
'carhop-gallery-view',
plugins_url('acf-blocks/gallery/view.js', __FILE__),
array(),
filemtime(__DIR__ . '/acf-blocks/gallery/view.js'),
true
);
}
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');