Skip to content

Apply defer loading strategy to frontend scripts - #27

Open
datengraben wants to merge 5 commits into
masterfrom
claude/wordpress-core-plugin-integration-2pao8t
Open

Apply defer loading strategy to frontend scripts#27
datengraben wants to merge 5 commits into
masterfrom
claude/wordpress-core-plugin-integration-2pao8t

Conversation

@datengraben

Copy link
Copy Markdown
Owner

Register the non-critical frontend libraries (leaflet and add-ons, select2,
moment.js, vue, commons-search, map shortcode bundle) with the WordPress 6.3+
"defer" loading strategy via the script $args array.

Passing the args as an array is backwards compatible: on WordPress < 6.3 the
truthy array is interpreted as the legacy $in_footer flag. WordPress computes
defer eligibility across the whole dependency tree and falls back to blocking
automatically where a dependent or an attached inline script requires it, so
existing behaviour is preserved while eligible chains load without blocking
HTML parsing.

Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01MG9PEjjSwXQKnRfWSxnKcj

claude added 5 commits June 22, 2026 18:26
Register the non-critical frontend libraries (leaflet and add-ons, select2,
moment.js, vue, commons-search, map shortcode bundle) with the WordPress 6.3+
"defer" loading strategy via the script $args array.

Passing the args as an array is backwards compatible: on WordPress < 6.3 the
truthy array is interpreted as the legacy $in_footer flag. WordPress computes
defer eligibility across the whole dependency tree and falls back to blocking
automatically where a dependent or an attached inline script requires it, so
existing behaviour is preserved while eligible chains load without blocking
HTML parsing.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MG9PEjjSwXQKnRfWSxnKcj
Migrate all 16 date_i18n() call sites to wp_date() (the modern, timezone-aware
replacement added in WordPress 5.3), finishing a migration already begun in
BookingCodes/BookingCodesMessage.

CommonsBooking stores "local" (offset-baked) timestamps — the wall-clock time
encoded as if it were UTC (see Booking::getEndDate() docblock). Passing such a
timestamp to wp_date() with the default site timezone would double-apply the UTC
offset and shift every booking time. The behaviour-preserving, DST-safe
equivalent is wp_date($format, $ts, new DateTimeZone('UTC')).

To keep that detail in one place and document the intent, add
Helper::formatLocalTimestamp() and route all call sites (including the existing
Helper::FormattedDate/FormattedTime wrappers) through it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MG9PEjjSwXQKnRfWSxnKcj
The PHPCS run cache configured in .phpcs.xml.dist (.cache-phpcs-free.cache)
is a local artifact, alongside the already-ignored .phpunit.result.cache.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MG9PEjjSwXQKnRfWSxnKcj
Two WordPress-core integrations:

#6 Cache gating: disable the result cache based on wp_get_environment_type()
(local/development) instead of WP_DEBUG. This decouples "show debug output"
from "turn caching off", so WP_DEBUG can be enabled on staging/production to
debug an issue while caching stays active. Cache::getCacheItem() now also uses
the single isDisabled() source of truth, and the commonsbooking_disableCache
filter is unchanged.

Because wp_get_environment_type() defaults to 'production' when undefined,
WP_ENVIRONMENT_TYPE=local is set in .wp-env.json (dev + tests) and forced in the
PHPUnit bootstrap, so caching stays disabled during tests regardless of the
runner (CI does not use wp-env) and test isolation is preserved.

#7 Translations: move the textdomain loader from plugins_loaded to init
(WordPress 6.7 guidance), hooked as early as possible so the bundled-.mo-first
override still applies before CPT labels are translated. The only pre-init
callbacks (load_location_map_admin, AddImageSizes) do not translate, so no
just-in-time loading is introduced.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MG9PEjjSwXQKnRfWSxnKcj
Adds a dynamic, server-rendered block "commonsbooking/bookings" that wraps the
existing [cb_bookings] rendering path, giving editors visual insertion + a live
preview (ServerSideRender) and two real settings the shortcode never exposed:
postsPerPage and showFilters.

- block.json + a no-JSX editor script (index.js) using core packages
  (wp-blocks/element/block-editor/components/server-side-render/i18n), so no new
  build pipeline is needed. Registered via register_block_type with a
  render_callback (not block.json's `render` field) to keep WP 5.9 support.
- View\Booking: shortcode() and the new renderBlock() now share a private
  renderBookingList( postsPerPage, showFilters ); the shortcode behaviour is
  unchanged at its defaults.
- Template honours showFilters and emits data-posts-per-page; bookings.js reads
  that attribute additively (absent on shortcode pages => server default), so
  paging respects the block setting without changing existing behaviour.

The frontend runtime is intentionally untouched (existing jQuery driver). A
later phase could move it to the WordPress Interactivity API.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MG9PEjjSwXQKnRfWSxnKcj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants