*/ private const BLOCK_ASSETS = [ self::FAQ_BLOCK => 'faq-block', self::HOWTO_BLOCK => 'howto-block', self::TOC_BLOCK => 'toc-block', ]; /** * Wire up hooks. * * @return void */ public function init(): void { add_action('enqueue_block_editor_assets', [$this, 'enqueue_editor_assets']); add_action('enqueue_block_assets', [$this, 'enqueue_block_styles']); add_filter('render_block', [$this, 'inject_block_schema'], 10, 2); } /** * Enqueue each block's editor script. * * @return void */ public function enqueue_editor_assets(): void { foreach (self::BLOCK_ASSETS as $handle) { $asset_path = THINKRANK_PLUGIN_DIR . "assets/{$handle}.asset.php"; $asset = file_exists($asset_path) ? include $asset_path : ['dependencies' => ['wp-blocks', 'wp-element', 'wp-block-editor', 'wp-components', 'wp-i18n'], 'version' => THINKRANK_VERSION]; wp_enqueue_script( "thinkrank-{$handle}", THINKRANK_PLUGIN_URL . "assets/{$handle}.js", $asset['dependencies'] ?? [], $asset['version'] ?? THINKRANK_VERSION, true ); wp_set_script_translations("thinkrank-{$handle}", 'thinkrank'); } } /** * Enqueue block stylesheets where blocks render. * * Hooked to enqueue_block_assets — not enqueue_block_editor_assets — so * core mirrors them into the iframed editor canvas instead of only the * editor's outer document. On the front end each loads only when its * block is present. * * @return void */ public function enqueue_block_styles(): void { // Dashicons, for the editor canvas only. // // Our block UIs use icon-only