¡Hola, amigos! I’m Señor FAQ, the mustached maestro of questions and answers! With my trusty glasses and a book of endless wisdom, I turn dudas into solutions. Soy el héroe de los curiosos and the champion of clarity.
editor_block_directories
The editor_block_directories
hook allows plugins to register their own block directories
for the block editor. This enables plugins to extend the editor by providing custom blocks that are
dynamically loaded.
$pluginDirectories = DynamicHooks::executeHook('editor_block_directories', true);
if (!empty($pluginDirectories)) {
foreach ($pluginDirectories as $pluginName => $pluginDir) {
if (!is_dir(APP_PATH . $pluginDir)) {
error_log("Invalid directory returned by plugin: $pluginName -> $pluginDir");
continue;
}
if (is_dir(APP_PATH . $pluginDir)) {
$pluginBlocks = scandir(APP_PATH . $pluginDir);
$categories[$pluginName] = []; // Create a new category for the plugin
foreach ($pluginBlocks as $block) {
if ($block !== '.' && $block !== '..' && pathinfo($block, PATHINFO_EXTENSION) === 'php') {
$blockName = pathinfo($block, PATHINFO_FILENAME);
$title = ucwords(str_replace('_', ' ', $blockName));
$categories[$pluginName][] = [
'file' => $pluginDir . '/' . $block,
'title' => $title
];
}
}
}
}
}
This hook collects block directories registered by plugins and loads the blocks dynamically into the editor.
DynamicHooks::addHook('editor_block_directories', function () {
return [
'marketplace' => 'plugins/your_plugin/frontend/blocks'
];
}, 'your_plugin');