feat: make Event Details block tense-aware (expose event timing + adapt past-event CTAs)#407
Open
chubes4 wants to merge 1 commit into
Open
feat: make Event Details block tense-aware (expose event timing + adapt past-event CTAs)#407chubes4 wants to merge 1 commit into
chubes4 wants to merge 1 commit into
Conversation
…t-event CTAs) The Event Details block was tense-blind: it knew the start/end datetimes but never derived or exposed whether an event is past/ongoing/upcoming, and its button hooks forced every consumer to re-query the event-dates table to derive tense themselves. - Compute timing once per render via the canonical public helper (same source-of-truth logic as the calendar upcoming/past SQL filters). - Add public helper data_machine_events_get_timing( $post_id ) delegating to the existing datamachine_get_event_timing(), matching the prefixed public API. - Pass $timing as a new trailing arg to data_machine_events_action_buttons and data_machine_events_after_price_display (back-compatible; old-arity callbacks keep working). - Suppress the block's own ticket button and Add-to-Calendar dropdown on past events by default, via new filterable defaults data_machine_events_show_ticket_button / data_machine_events_show_add_to_calendar. A past ticket button forced back on gets a ticket-button--past modifier class. Fully back-compatible and layer-generic (no consumer-specific concepts). Closes #406
Contributor
Homeboy Results —
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #406.
The Event Details block (
inc/Blocks/EventDetails/render.php) was tense-blind: it knew the start/end datetimes but never derived or exposed whether an event is past / ongoing / upcoming, and its button hooks only passed($post_id, $ticket_url). Every consumer had to re-query the event-dates table to derive tense itself, and the block rendered a live "Get Tickets" button + a full Add-to-Calendar dropdown even on shows that already happened.This PR makes the generic layer know and share tense, and makes its own CTAs tense-aware — without introducing any consumer-specific concept.
What changed
Timing states computed
Timing is computed once per render as
'upcoming' | 'ongoing' | 'past', using the canonical public helper — the same source-of-truth logic (start >= now= upcoming,start < now && end >= now= ongoing, else past) already used by the calendar's upcoming/past SQL filters (datamachine_get_event_timing()/UpcomingFilter). No new date-math was invented.New hook argument (back-compatible)
$timingis now passed as the trailing argument to:data_machine_events_action_buttons→(int $post_id, string $ticket_url, string $timing)data_machine_events_after_price_display→(int $post_id, string $price, string $timing)Existing args are preserved. WordPress actions ignore extra args for callbacks registered with a lower accepted-arg count, so every existing 2-arg / 1-arg consumer keeps working unchanged. The bundled Add-to-Calendar callback was bumped from
2→3accepted args (with a defaulted$timing = 'upcoming'param) so it can react to tense.New filters (sensible generic default, overridable)
data_machine_events_show_ticket_button(bool $show, int $post_id, string $timing)— defaults tofalseonpast,trueotherwise. Buying tickets to a finished show is a dead CTA.data_machine_events_show_add_to_calendar(bool $show, int $post_id, string $timing)— defaults tofalseonpast,trueotherwise.When a site overrides the ticket button back on for a past event, it renders with an extra
ticket-button--pastmodifier class for de-emphasis styling. The existingdata_machine_events_ticket_button_classesfilter now also receives$post_idand$timing(additive; 1-arg callbacks unaffected).Public helper
data_machine_events_get_timing( int $post_id ): stringadded toinc/public-api.php, delegating to the existingdatamachine_get_event_timing(). It matches the rest of the prefixeddata_machine_events_*public surface so consumers stop re-querying the dates table to derive tense. Falls back to'past'if the underlying helper is unavailable.Back-compat
Fully back-compatible:
add_action/add_filtercallbacks receive no extra args and keep working.pasttiming and is filterable in both directions.Layer purity
No consumer-specific concepts introduced — grepped the added lines for
attendance|concert|my-shows|setlist|import|extrachilland confirmed clean. This layer only knows/shares tense and adapts its own ticket/calendar CTAs; consumer-side composition (attendance-first layouts, etc.) stays in the downstream plugin per the issue.Verification
php -lclean on all three changed PHP files.homeboy lint data-machine-events: phpstan (level 7) passes with 0 findings on the change. Theeslintstep fails, but it fails identically on cleanmainand this PR touches zero JS files — pre-existing env/config issue, not introduced here.homeboy test data-machine-eventscould not run: the runner aborts at "WP Codebox CLI setup" (no candidate passed 'wp-codebox --version') before any test executes — a stale host wrapper, not a code failure. No existing test references the changed hooks, and all changes are additive/back-compatible.Docs
Updated
docs/integration-api.md(new filters, updated action signatures, new helper) anddocs/event-details-block.md(new "Tense-Aware Rendering" section).