esc_url_raw(plugin_dir_url(__FILE__)), 'selectorOverride' => defined('PATTERN_CSS_SELECTOR_OVERRIDE') ? constant('PATTERN_CSS_SELECTOR_OVERRIDE') : null, 'globalCss' => get_option('pcss_global_css', ''), 'globalCssCompiled' => get_option('pcss_global_css_compiled', ''), 'allowManualOverride' => defined('PATTERN_CSS_ALLOW_MANUAL_OVERRIDE'), ]) . ';', 'before' ); wp_enqueue_style('kevinbatdorf/pattern-css', plugins_url('build/index.css', __FILE__)); }); // This loads in global styles add_action('wp_enqueue_scripts', function () { $global_css_compiled = get_option('pcss_global_css_compiled', ''); if (empty($global_css_compiled)) return; wp_register_style('pcss-global-css', false, [], null); wp_enqueue_style('pcss-global-css'); wp_add_inline_style('pcss-global-css', $global_css_compiled); }, 10); // This works by looking for blocks with the compiled CSS attribute // during the render phase, and inlines the css if found. // That keeps the inline styles ONLY loaded on pages that have the block. add_filter('pre_render_block', function ($pre_render, $parsed_block) { // $pre_render is null by default if (!isset($parsed_block['attrs']['pcssAdditionalCssCompiled'])) return $pre_render; if (empty($parsed_block['attrs']['pcssAdditionalCssCompiled'])) return $pre_render; $pcss_additional_css = $parsed_block['attrs']['pcssAdditionalCssCompiled']; $pcss_block_id = $parsed_block['attrs']['pcssClassId']; if (empty($pcss_block_id) || empty($pcss_additional_css)) return $pre_render; // Skip if already registered (e.g. same block in a Query Loop) if (wp_style_is("pcss-block-{$pcss_block_id}", 'registered')) return $pre_render; wp_register_style("pcss-block-{$pcss_block_id}", false, [], null); wp_enqueue_style("pcss-block-{$pcss_block_id}"); wp_add_inline_style("pcss-block-{$pcss_block_id}", $pcss_additional_css); return $pre_render; }, 10, 2); include_once(__DIR__ . '/php/router.php'); include_once(__DIR__ . '/php/routes.php');