"@import url('{$style}')", ]; return $settings; }); /** * Inject scripts into the block editor. * * @return void */ add_filter('admin_head', function () { if (! get_current_screen()?->is_block_editor()) { return; } $dependencies = json_decode(Vite::content('editor.deps.json')); foreach ($dependencies as $dependency) { if (! wp_script_is($dependency)) { wp_enqueue_script($dependency); } } echo Vite::withEntryPoints([ 'resources/js/editor.js', ])->toHtml(); }); /** * Add Vite's HMR client to the block editor. * * @return void */ add_action('enqueue_block_assets', function () { if (! is_admin() || ! get_current_screen()?->is_block_editor()) { return; } if (! Vite::isRunningHot()) { return; } $script = sprintf( <<<'JS' window.__vite_client_url = '%s'; window.self !== window.top && document.head.appendChild( Object.assign(document.createElement('script'), { type: 'module', src: '%s' }) ); JS, untrailingslashit(Vite::asset('')), Vite::asset('@vite/client') ); wp_add_inline_script('wp-blocks', $script); }); /** * Use the generated theme.json file. * * @return string */ add_filter('theme_file_path', function ($path, $file) { return $file === 'theme.json' ? public_path('build/assets/theme.json') : $path; }, 10, 2); /** * Register the initial theme setup. * * @return void */ add_action('after_setup_theme', function () { /** * Disable full-site editing support. * * @link https://wptavern.com/gutenberg-10-5-embeds-pdfs-adds-verse-block-color-options-and-introduces-new-patterns */ remove_theme_support('block-templates'); /** * Register the navigation menus. * * @link https://developer.wordpress.org/reference/functions/register_nav_menus/ */ register_nav_menus([ 'primary_navigation' => __('Primary Navigation', 'sage'), ]); /** * Disable the default block patterns. * * @link https://developer.wordpress.org/block-editor/developers/themes/theme-support/#disabling-the-default-block-patterns */ remove_theme_support('core-block-patterns'); /** * Enable plugins to manage the document title. * * @link https://developer.wordpress.org/reference/functions/add_theme_support/#title-tag */ add_theme_support('title-tag'); /** * Enable post thumbnail support. * * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ */ add_theme_support('post-thumbnails'); /** * Enable responsive embed support. * * @link https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-support/#responsive-embedded-content */ add_theme_support('responsive-embeds'); /** * Enable HTML5 markup support. * * @link https://developer.wordpress.org/reference/functions/add_theme_support/#html5 */ add_theme_support('html5', [ 'caption', 'comment-form', 'comment-list', 'gallery', 'search-form', 'script', 'style', ]); /** * Enable selective refresh for widgets in customizer. * * @link https://developer.wordpress.org/reference/functions/add_theme_support/#customize-selective-refresh-widgets */ add_theme_support('customize-selective-refresh-widgets'); }, 20); /** * Register the theme sidebars. * * @return void */ add_action('widgets_init', function () { $config = [ 'before_widget' => '', 'before_title' => '