29 lines
1.0 KiB
PHP
29 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace AcornPlugin\Acorn;
|
|
|
|
use Illuminate\Support\Facades\Blade;
|
|
|
|
/**
|
|
* Emits Livewire's frontend assets exactly once, from the plugin that owns the
|
|
* Acorn boot. Livewire v4's @livewireScripts self-initialises from the data-*
|
|
* attributes on the injected script.
|
|
* WordPress never dispatches Laravel's RequestHandled event, so the
|
|
* directives must be echoed into wp_head/wp_footer by hand.
|
|
*/
|
|
final class LivewireAssets
|
|
{
|
|
public static function registerOnce(): void
|
|
{
|
|
// Livewire renders its own trusted <style>/<script> markup — escaping it
|
|
// would corrupt the output, so the EscapeOutput sniff is suppressed here.
|
|
add_action('wp_head', static function (): void {
|
|
echo Blade::render('@livewireStyles'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
|
});
|
|
|
|
add_action('wp_footer', static function (): void {
|
|
echo Blade::render('@livewireScripts'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
|
});
|
|
}
|
|
}
|