1294a177ae
This work was done with Claude. Added bundling of CSS & JS with WebPack. This also means minimization. --------- Co-authored-by: Martin Slachta <martin.slachta@outlook.com> Reviewed-on: #1
60 lines
2.0 KiB
PHP
60 lines
2.0 KiB
PHP
<?php
|
||
|
||
/**
|
||
* Defines assets that must be included to the client. Separated into assets for
|
||
* admin and the default user.
|
||
*/
|
||
|
||
function rsv_build_url(string $file): string {
|
||
return plugin_dir_url(__FILE__) . '../build/' . $file;
|
||
}
|
||
|
||
function rsv_build_file(string $file): string {
|
||
return plugin_dir_path(__FILE__) . '../build/' . $file;
|
||
}
|
||
|
||
function rsv_localize_api(string $handle): void {
|
||
wp_localize_script($handle, 'ReservairServiceAPI', [
|
||
'restUrl' => rest_url('reservations/v1'),
|
||
'nonce' => wp_create_nonce('wp_rest'),
|
||
]);
|
||
|
||
wp_localize_script($handle, 'ReservairStrings', [
|
||
'timeline' => [
|
||
'not_reservable' => 'Tento objekt nelze rezervovat.',
|
||
'no_blocks' => 'Tento den není dostupný žádný blok. Vyberte jiné datum.',
|
||
'seats' => 'míst',
|
||
],
|
||
'summary' => [
|
||
'title' => 'Vybrané termíny',
|
||
'clear_all' => 'Smazat vše',
|
||
'count_one' => '1 termín',
|
||
'count_few' => '%d termíny',
|
||
'count_many' => '%d termínů',
|
||
'currency' => 'Kč',
|
||
],
|
||
'form' => [
|
||
'success_title' => 'Rezervace potvrzena!',
|
||
'success_subtitle' => 'Potvrzení jsme zaslali na váš e‑mail.',
|
||
'new_reservation' => 'Nová rezervace',
|
||
'error_generic' => 'Něco se pokazilo. Zkuste to prosím znovu.',
|
||
],
|
||
]);
|
||
}
|
||
|
||
// --- Public hooks ---
|
||
|
||
function rsv_enqueue_assets(): void {
|
||
wp_enqueue_script('rsv-client', rsv_build_url('client.js'), [], filemtime(rsv_build_file('client.js')));
|
||
wp_enqueue_style('rsv-client', rsv_build_url('client.css'), [], filemtime(rsv_build_file('client.css')));
|
||
|
||
rsv_localize_api('rsv-client');
|
||
}
|
||
|
||
function rsv_enqueue_admin_assets(): void {
|
||
wp_enqueue_script('rsv-admin', rsv_build_url('admin.js'), [], filemtime(rsv_build_file('admin.js')));
|
||
wp_enqueue_style('rsv-admin', rsv_build_url('admin.css'), [], filemtime(rsv_build_file('admin.css')));
|
||
|
||
rsv_localize_api('rsv-admin');
|
||
}
|