*/ private const BLOCK_ASSETS = [ self::FAQ_BLOCK => 'faq-block', self::HOWTO_BLOCK => 'howto-block', self::TOC_BLOCK => 'toc-block', ]; /** * Webpack asset handle for the Rank Math block converter. Not a block of * its own — it is an editor extension, so it is deliberately outside * BLOCK_ASSETS, which also drives block stylesheet loading. */ private const CONVERTER_ASSET = 'rank-math-block-converter'; /** * 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 { // The converter is not a block; it repairs Rank Math's FAQ / HowTo // blocks in place (#777) and so has to load wherever those blocks might // be edited, alongside the block scripts themselves. $handles = array_merge(array_values(self::BLOCK_ASSETS), [self::CONVERTER_ASSET]); foreach ($handles 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