true] ); wp_set_script_translations(self::HANDLE, 'codexa-blocks', CODEXA_BLOCKS_DIR . 'languages'); if (is_file(CODEXA_BLOCKS_DIR . 'build/editor/index.css')) { wp_register_style( self::HANDLE, CODEXA_BLOCKS_URL . 'build/editor/index.css', ['wp-components', BlockRegistrar::COMMON_STYLE], $version ); // wp-scripts also writes index-rtl.css; right-to-left languages get it instead. wp_style_add_data(self::HANDLE, 'rtl', 'replace'); } } /** * Turns off WordPress's own Settings and Styles tabs for Codexa blocks, * which draw their own (InspectorTabs). Runs on block_editor_settings_all. * * @param array $settings Block editor settings. * @return array The settings, with WordPress's tabs off for every block in the codexa-blocks namespace. */ public function useOwnTabs(array $settings): array { $tabs = is_array($settings['blockInspectorTabs'] ?? null) ? $settings['blockInspectorTabs'] : []; foreach (array_keys(\WP_Block_Type_Registry::get_instance()->get_all_registered()) as $name) { if (str_starts_with($name, 'codexa-blocks/')) { $tabs[$name] = false; } } $settings['blockInspectorTabs'] = $tabs; return $settings; } /** * Loads the bundle in the block editor, with the data it reads from window * (icon sets, post sources, divider shapes and the Pro page). Runs on * enqueue_block_editor_assets, after add-ons have added theirs. * * @return void */ public function enqueue(): void { wp_add_inline_script( self::HANDLE, 'window.codexaBlocksIconSets = ' . wp_json_encode(Icons::editorSets()) . ';' . 'window.codexaBlocksPostSources = ' . wp_json_encode(Posts::editorSources()) . ';' . 'window.codexaBlocksPostSourcesExtended = ' . wp_json_encode(Posts::sourcesExtended()) . ';' . 'window.codexaBlocksDividerShapes = ' . wp_json_encode(Dividers::editorShapes()) . ';' . 'window.codexaBlocksProUrl = ' . wp_json_encode(esc_url_raw(self::PRO_URL)) . ';', 'before' ); wp_enqueue_script(self::HANDLE); wp_enqueue_style(self::HANDLE); } }